diff Lib/test/test_random.py @ 64517:e83af141dffd

Fix corner case for Random.choice() and add tests.
author Raymond Hettinger <python@rcn.com>
date Tue, 07 Sep 2010 10:06:56 +0000
parents c2f8418a0e14
children 1c22c1e453d4
line wrap: on
line diff
--- a/Lib/test/test_random.py	Tue Sep 07 09:32:57 2010 +0000
+++ b/Lib/test/test_random.py	Tue Sep 07 10:06:56 2010 +0000
@@ -42,6 +42,13 @@
         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