changeset: 104808:09a87b16d5e5 branch: 3.6 parent: 104806:32bfc81111b6 user: Raymond Hettinger date: Sat Oct 29 17:42:36 2016 -0700 files: Lib/test/test_random.py description: Issue #18844: Strengthen tests to include a case with unequal weighting diff -r 32bfc81111b6 -r 09a87b16d5e5 Lib/test/test_random.py --- a/Lib/test/test_random.py Sat Oct 29 16:55:36 2016 -0700 +++ b/Lib/test/test_random.py Sat Oct 29 17:42:36 2016 -0700 @@ -645,6 +645,23 @@ 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: