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

Method test_sample_distribution

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 4

factorialFunction · 0.90
lenFunction · 0.85
sampleMethod · 0.80
failMethod · 0.45

Tested by

no test coverage detected