| 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__() |