summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2016-11-21 22:34:51 (GMT)
committerRaymond Hettinger <python@rcn.com>2016-11-21 22:34:51 (GMT)
commit6088cfcfd4be60930aee8c06ca6e72e0f29edef6 (patch)
tree099df08fb26aedff268d5eadf7a5e57847b33a0d
parente425bd95e9f3ceb767e1894cce8cc01a63e7013b (diff)
parentbf87126a636bddf2d9a8f432215fe2efb98ba8fe (diff)
downloadcpython-6088cfcfd4be60930aee8c06ca6e72e0f29edef6.zip
cpython-6088cfcfd4be60930aee8c06ca6e72e0f29edef6.tar.gz
cpython-6088cfcfd4be60930aee8c06ca6e72e0f29edef6.tar.bz2
merge
-rw-r--r--Lib/random.py2
-rw-r--r--Lib/test/test_random.py1
2 files changed, 2 insertions, 1 deletions
diff --git a/Lib/random.py b/Lib/random.py
index ca90e14..49b0f14 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 d2fa9d2..e228104 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