MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_pdf

Method test_pdf

Lib/test/test_statistics.py:2966–3003  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 9

pdfMethod · 0.95
cdfMethod · 0.95
NormalDistClass · 0.85
enumerateFunction · 0.85
assertTrueMethod · 0.80
assertLessMethod · 0.45
assertAlmostEqualMethod · 0.45
assertRaisesMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected