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

Method test_cdf

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected