From: Raymond Hettinger Date: Sun, 30 Oct 2016 00:42:36 +0000 (-0700) Subject: Issue #18844: Strengthen tests to include a case with unequal weighting X-Git-Tag: v3.6.0b3~18 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=77d574d4aeae4b7b9b976a68b367783a0932b6c8;p=python Issue #18844: Strengthen tests to include a case with unequal weighting --- diff --git a/Lib/test/test_random.py b/Lib/test/test_random.py index dd2715288a..a4413b5146 100644 --- a/Lib/test/test_random.py +++ b/Lib/test/test_random.py @@ -645,6 +645,23 @@ class MersenneTwister_TestBasicOps(TestBasicOps, unittest.TestCase): c = self.gen.choices(range(n), cum_weights=range(1, n+1), k=10000) self.assertEqual(a, c) + # Amerian Roulette + population = ['Red', 'Black', 'Green'] + weights = [18, 18, 2] + cum_weights = [18, 36, 38] + expanded_population = ['Red'] * 18 + ['Black'] * 18 + ['Green'] * 2 + + self.gen.seed(9035768) + a = self.gen.choices(expanded_population, k=10000) + + self.gen.seed(9035768) + b = self.gen.choices(population, weights, k=10000) + self.assertEqual(a, b) + + self.gen.seed(9035768) + c = self.gen.choices(population, cum_weights=cum_weights, k=10000) + self.assertEqual(a, c) + def gamma(z, sqrt2pi=(2.0*pi)**0.5): # Reflection to right half of complex plane if z < 0.5: