MCPcopy Index your code
hub / github.com/python/cpython / test_cdf

Method test_cdf

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

Source from the content-addressed store, hash-verified

3001 self.assertTrue(math.isnan(X.pdf(float('NaN'))))
3002
3003 def test_cdf(self):
3004 NormalDist = self.module.NormalDist
3005 X = NormalDist(100, 15)
3006 cdfs = [X.cdf(x) for x in range(1, 200)]
3007 self.assertEqual(set(map(type, cdfs)), {float})
3008 # Verify montonic
3009 self.assertEqual(cdfs, sorted(cdfs))
3010 # Verify center (should be exact)
3011 self.assertEqual(X.cdf(100), 0.50)
3012 # Check against a table of known values
3013 # https://en.wikipedia.org/wiki/Standard_normal_table#Cumulative
3014 Z = NormalDist()
3015 for z, cum_prob in [
3016 (0.00, 0.50000), (0.01, 0.50399), (0.02, 0.50798),
3017 (0.14, 0.55567), (0.29, 0.61409), (0.33, 0.62930),
3018 (0.54, 0.70540), (0.60, 0.72575), (1.17, 0.87900),
3019 (1.60, 0.94520), (2.05, 0.97982), (2.89, 0.99807),
3020 (3.52, 0.99978), (3.98, 0.99997), (4.07, 0.99998),
3021 ]:
3022 self.assertAlmostEqual(Z.cdf(z), cum_prob, places=5)
3023 self.assertAlmostEqual(Z.cdf(-z), 1.0 - cum_prob, places=5)
3024 # Error case: variance is zero
3025 Y = NormalDist(100, 0)
3026 with self.assertRaises(self.module.StatisticsError):
3027 Y.cdf(90)
3028 # Special values
3029 self.assertEqual(X.cdf(float('-Inf')), 0.0)
3030 self.assertEqual(X.cdf(float('Inf')), 1.0)
3031 self.assertTrue(math.isnan(X.cdf(float('NaN'))))
3032
3033 @support.skip_if_pgo_task
3034 @support.requires_resource('cpu')

Callers

nothing calls this directly

Calls 7

cdfMethod · 0.95
NormalDistClass · 0.85
setFunction · 0.85
assertTrueMethod · 0.80
assertEqualMethod · 0.45
assertAlmostEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected