mirror of
https://github.com/python/cpython.git
synced 2025-08-29 05:05:03 +00:00
Fix corner case for Random.choice() and add tests.
This commit is contained in:
parent
c324697bac
commit
dc4872eefe
2 changed files with 12 additions and 1 deletions
|
@ -42,6 +42,13 @@ class TestBasicOps(unittest.TestCase):
|
|||
self.assertRaises(TypeError, self.gen.seed, 1, 2, 3, 4)
|
||||
self.assertRaises(TypeError, type(self.gen), [])
|
||||
|
||||
def test_choice(self):
|
||||
choice = self.gen.choice
|
||||
with self.assertRaises(IndexError):
|
||||
choice([])
|
||||
self.assertEqual(choice([50]), 50)
|
||||
self.assertIn(choice([25, 75]), [25, 75])
|
||||
|
||||
def test_sample(self):
|
||||
# For the entire allowable range of 0 <= k <= N, validate that
|
||||
# the sample is of the correct length and contains only unique items
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue