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

Method test_sample_distribution

Lib/test/test_random.py:158–172  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

156 self.assertRaises(TypeError, self.gen.sample, population, 1.0)
157
158 def test_sample_distribution(self):
159 # For the entire allowable range of 0 <= k <= N, validate that
160 # sample generates all possible permutations
161 n = 5
162 pop = range(n)
163 trials = 10000 # large num prevents false negatives without slowing normal case
164 for k in range(n):
165 expected = factorial(n) // factorial(n-k)
166 perms = {}
167 for i in range(trials):
168 perms[tuple(self.gen.sample(pop, k))] = None
169 if len(perms) == expected:
170 break
171 else:
172 self.fail()
173
174 def test_sample_inputs(self):
175 # SF bug #801342 -- population can be any iterable defining __len__()

Callers

nothing calls this directly

Calls 3

factorialFunction · 0.70
sampleMethod · 0.45
failMethod · 0.45

Tested by

no test coverage detected