(self)
| 2962 | self.assertNotEqual(data1, data2) |
| 2963 | |
| 2964 | def test_pdf(self): |
| 2965 | NormalDist = self.module.NormalDist |
| 2966 | X = NormalDist(100, 15) |
| 2967 | # Verify peak around center |
| 2968 | self.assertLess(X.pdf(99), X.pdf(100)) |
| 2969 | self.assertLess(X.pdf(101), X.pdf(100)) |
| 2970 | # Test symmetry |
| 2971 | for i in range(50): |
| 2972 | self.assertAlmostEqual(X.pdf(100 - i), X.pdf(100 + i)) |
| 2973 | # Test vs CDF |
| 2974 | dx = 2.0 ** -10 |
| 2975 | for x in range(90, 111): |
| 2976 | est_pdf = (X.cdf(x + dx) - X.cdf(x)) / dx |
| 2977 | self.assertAlmostEqual(X.pdf(x), est_pdf, places=4) |
| 2978 | # Test vs table of known values -- CRC 26th Edition |
| 2979 | Z = NormalDist() |
| 2980 | for x, px in enumerate([ |
| 2981 | 0.3989, 0.3989, 0.3989, 0.3988, 0.3986, |
| 2982 | 0.3984, 0.3982, 0.3980, 0.3977, 0.3973, |
| 2983 | 0.3970, 0.3965, 0.3961, 0.3956, 0.3951, |
| 2984 | 0.3945, 0.3939, 0.3932, 0.3925, 0.3918, |
| 2985 | 0.3910, 0.3902, 0.3894, 0.3885, 0.3876, |
| 2986 | 0.3867, 0.3857, 0.3847, 0.3836, 0.3825, |
| 2987 | 0.3814, 0.3802, 0.3790, 0.3778, 0.3765, |
| 2988 | 0.3752, 0.3739, 0.3725, 0.3712, 0.3697, |
| 2989 | 0.3683, 0.3668, 0.3653, 0.3637, 0.3621, |
| 2990 | 0.3605, 0.3589, 0.3572, 0.3555, 0.3538, |
| 2991 | ]): |
| 2992 | self.assertAlmostEqual(Z.pdf(x / 100.0), px, places=4) |
| 2993 | self.assertAlmostEqual(Z.pdf(-x / 100.0), px, places=4) |
| 2994 | # Error case: variance is zero |
| 2995 | Y = NormalDist(100, 0) |
| 2996 | with self.assertRaises(self.module.StatisticsError): |
| 2997 | Y.pdf(90) |
| 2998 | # Special values |
| 2999 | self.assertEqual(X.pdf(float('-Inf')), 0.0) |
| 3000 | self.assertEqual(X.pdf(float('Inf')), 0.0) |
| 3001 | self.assertTrue(math.isnan(X.pdf(float('NaN')))) |
| 3002 | |
| 3003 | def test_cdf(self): |
| 3004 | NormalDist = self.module.NormalDist |
nothing calls this directly
no test coverage detected