Skip to content
Prev Previous commit
Next Next commit
Add exact equidistribution test
  • Loading branch information
rhettinger committed May 7, 2020
commit 672f739050b398b806a798eb598fa2eace391790
5 changes: 5 additions & 0 deletions Lib/test/test_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ def test_sample_with_weights(self):
summary = Counter(sample(['x'], weights=[10], k=8))
self.assertEqual(summary, Counter(x=8))

# Case with all weights equal.
nc = len(colors)
summary = Counter(sample(colors, weights=[10]*nc, k=10*nc))
self.assertEqual(summary, Counter(10*colors))

# Test error handling
with self.assertRaises(TypeError):
sample(['red', 'green', 'blue'], weights=10, k=10) # weights not iterable
Expand Down