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

Method test_sample

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

Source from the content-addressed store, hash-verified

139 self.assertIn(choice(NA([25, 75])), [25, 75])
140
141 def test_sample(self):
142 # For the entire allowable range of 0 <= k <= N, validate that
143 # the sample is of the correct length and contains only unique items
144 N = 100
145 population = range(N)
146 for k in range(N+1):
147 s = self.gen.sample(population, k)
148 self.assertEqual(len(s), k)
149 uniq = set(s)
150 self.assertEqual(len(uniq), k)
151 self.assertTrue(uniq <= set(population))
152 self.assertEqual(self.gen.sample([], 0), []) # test edge case N==k==0
153 # Exception raised if size of sample exceeds that of population
154 self.assertRaises(ValueError, self.gen.sample, population, N+1)
155 self.assertRaises(ValueError, self.gen.sample, [], -1)
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

Callers

nothing calls this directly

Calls 5

setFunction · 0.85
assertTrueMethod · 0.80
sampleMethod · 0.45
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected