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

Method test_sample

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected