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

Method test_sample_generation

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

Source from the content-addressed store, hash-verified

2940 self.assertEqual(type(nnd), NewNormalDist)
2941
2942 def test_sample_generation(self):
2943 NormalDist = self.module.NormalDist
2944 mu, sigma = 10_000, 3.0
2945 X = NormalDist(mu, sigma)
2946 n = 1_000
2947 data = X.samples(n)
2948 self.assertEqual(len(data), n)
2949 self.assertEqual(set(map(type, data)), {float})
2950 # mean(data) expected to fall within 8 standard deviations
2951 xbar = self.module.mean(data)
2952 self.assertTrue(mu - sigma*8 <= xbar <= mu + sigma*8)
2953
2954 # verify that seeding makes reproducible sequences
2955 n = 100
2956 data1 = X.samples(n, seed='happiness and joy')
2957 data2 = X.samples(n, seed='trouble and despair')
2958 data3 = X.samples(n, seed='happiness and joy')
2959 data4 = X.samples(n, seed='trouble and despair')
2960 self.assertEqual(data1, data3)
2961 self.assertEqual(data2, data4)
2962 self.assertNotEqual(data1, data2)
2963
2964 def test_pdf(self):
2965 NormalDist = self.module.NormalDist

Callers

nothing calls this directly

Calls 7

samplesMethod · 0.95
NormalDistClass · 0.85
setFunction · 0.85
meanMethod · 0.80
assertTrueMethod · 0.80
assertNotEqualMethod · 0.80
assertEqualMethod · 0.45

Tested by

no test coverage detected