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

Method test_alternative_constructor

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

Source from the content-addressed store, hash-verified

2919 self.assertEqual(type(nnd), NewNormalDist)
2920
2921 def test_alternative_constructor(self):
2922 NormalDist = self.module.NormalDist
2923 data = [96, 107, 90, 92, 110]
2924 # list input
2925 self.assertEqual(NormalDist.from_samples(data), NormalDist(99, 9))
2926 # tuple input
2927 self.assertEqual(NormalDist.from_samples(tuple(data)), NormalDist(99, 9))
2928 # iterator input
2929 self.assertEqual(NormalDist.from_samples(iter(data)), NormalDist(99, 9))
2930 # error cases
2931 with self.assertRaises(self.module.StatisticsError):
2932 NormalDist.from_samples([]) # empty input
2933 with self.assertRaises(self.module.StatisticsError):
2934 NormalDist.from_samples([10]) # only one input
2935
2936 # verify that subclass type is honored
2937 class NewNormalDist(NormalDist):
2938 pass
2939 nnd = NewNormalDist.from_samples(data)
2940 self.assertEqual(type(nnd), NewNormalDist)
2941
2942 def test_sample_generation(self):
2943 NormalDist = self.module.NormalDist

Callers

nothing calls this directly

Calls 4

NormalDistClass · 0.85
from_samplesMethod · 0.80
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected