diff options
author | Raymond Hettinger <python@rcn.com> | 2016-10-14 05:19:38 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2016-10-14 05:19:38 (GMT) |
commit | 7b16652f1c898c57f5b11f2f61860bf4f1c47bf7 (patch) | |
tree | dd0699dbad473a27c7903b2c3eea1c711109d924 /Lib/test/test_random.py | |
parent | a0ef768ddf7a8196c77544545d2dfb7e09473e4d (diff) | |
download | cpython-7b16652f1c898c57f5b11f2f61860bf4f1c47bf7.zip cpython-7b16652f1c898c57f5b11f2f61860bf4f1c47bf7.tar.gz cpython-7b16652f1c898c57f5b11f2f61860bf4f1c47bf7.tar.bz2 |
Issue #18844: Add more tests
Diffstat (limited to 'Lib/test/test_random.py')
-rw-r--r-- | Lib/test/test_random.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_random.py b/Lib/test/test_random.py index 840f3e7..4d5a874 100644 --- a/Lib/test/test_random.py +++ b/Lib/test/test_random.py @@ -205,6 +205,20 @@ class TestBasicOps: ]: self.assertTrue(set(choices(data, cum_weights=weights, k=5)) <= set(data)) + # Test weight focused on a single element of the population + self.assertEqual(choices('abcd', [1, 0, 0, 0]), ['a']) + self.assertEqual(choices('abcd', [0, 1, 0, 0]), ['b']) + self.assertEqual(choices('abcd', [0, 0, 1, 0]), ['c']) + self.assertEqual(choices('abcd', [0, 0, 0, 1]), ['d']) + + # Test consistency with random.choice() for empty population + with self.assertRaises(IndexError): + choices([], k=1) + with self.assertRaises(IndexError): + choices([], weights=[], k=1) + with self.assertRaises(IndexError): + choices([], cum_weights=[], k=5) + def test_gauss(self): # Ensure that the seed() method initializes all the hidden state. In # particular, through 2.2.1 it failed to reset a piece of state used |