diff options
| author | Raymond Hettinger <python@rcn.com> | 2016-11-21 14:34:51 -0800 |
|---|---|---|
| committer | Raymond Hettinger <python@rcn.com> | 2016-11-21 14:34:51 -0800 |
| commit | 6088cfcfd4be60930aee8c06ca6e72e0f29edef6 (patch) | |
| tree | 099df08fb26aedff268d5eadf7a5e57847b33a0d | |
| parent | e425bd95e9f3ceb767e1894cce8cc01a63e7013b (diff) | |
| parent | bf87126a636bddf2d9a8f432215fe2efb98ba8fe (diff) | |
| download | cpython-git-6088cfcfd4be60930aee8c06ca6e72e0f29edef6.tar.gz | |
merge
| -rw-r--r-- | Lib/random.py | 2 | ||||
| -rw-r--r-- | Lib/test/test_random.py | 1 |
2 files changed, 2 insertions, 1 deletions
diff --git a/Lib/random.py b/Lib/random.py index ca90e1459d..49b0f149a5 100644 --- a/Lib/random.py +++ b/Lib/random.py @@ -314,7 +314,7 @@ class Random(_random.Random): randbelow = self._randbelow n = len(population) if not 0 <= k <= n: - raise ValueError("Sample larger than population") + raise ValueError("Sample larger than population or is negative") result = [None] * k setsize = 21 # size of a small set minus size of an empty list if k > 5: diff --git a/Lib/test/test_random.py b/Lib/test/test_random.py index d2fa9d2551..e228104efd 100644 --- a/Lib/test/test_random.py +++ b/Lib/test/test_random.py @@ -110,6 +110,7 @@ class TestBasicOps: self.assertEqual(self.gen.sample([], 0), []) # test edge case N==k==0 # Exception raised if size of sample exceeds that of population self.assertRaises(ValueError, self.gen.sample, population, N+1) + self.assertRaises(ValueError, self.gen.sample, [], -1) def test_sample_distribution(self): # For the entire allowable range of 0 <= k <= N, validate that |
