[Python-checkins] cpython (merge 3.6 -> default): merge
raymond.hettinger
python-checkins at python.org
Fri Oct 14 01:20:06 EDT 2016
https://hg.python.org/cpython/rev/2dd8689ce678
changeset: 104486:2dd8689ce678
parent: 104483:9513fac97ddd
parent: 104485:d4e715e725ef
user: Raymond Hettinger <python at rcn.com>
date: Fri Oct 14 01:20:00 2016 -0400
summary:
merge
files:
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
--- a/Lib/test/test_random.py
+++ b/Lib/test/test_random.py
@@ -205,6 +205,20 @@
]:
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
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list