diff options
author | Senthil Kumaran <orsenthil@gmail.com> | 2010-01-08 18:41:40 +0000 |
---|---|---|
committer | Senthil Kumaran <orsenthil@gmail.com> | 2010-01-08 18:41:40 +0000 |
commit | 3ddc435af6873c6304058d7bcbcb19ee4fba7781 (patch) | |
tree | c7a03cf0a8b856bae2ebebba55b09f775845c7ca /Lib/test/test_itertools.py | |
parent | 3194d1454cbc11ec477d83fff3fc749972107d29 (diff) | |
download | cpython-git-3ddc435af6873c6304058d7bcbcb19ee4fba7781.tar.gz |
Fixing - Issue7026 - RuntimeError: dictionary changed size during iteration. Patch by flox
Diffstat (limited to 'Lib/test/test_itertools.py')
-rw-r--r-- | Lib/test/test_itertools.py | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py index 03f1d85111..d69aecf061 100644 --- a/Lib/test/test_itertools.py +++ b/Lib/test/test_itertools.py @@ -9,6 +9,7 @@ import operator import random import copy import pickle +from functools import reduce maxsize = test_support.MAX_Py_ssize_t minsize = -maxsize-1 @@ -122,7 +123,7 @@ class TestBasicOps(unittest.TestCase): values = [5*x-12 for x in range(n)] for r in range(n+2): result = list(combinations(values, r)) - self.assertEqual(len(result), 0 if r>n else fact(n) / fact(r) / fact(n-r)) # right number of combs + self.assertEqual(len(result), 0 if r>n else fact(n) // fact(r) // fact(n-r)) # right number of combs self.assertEqual(len(result), len(set(result))) # no repeats self.assertEqual(result, sorted(result)) # lexicographic order for c in result: @@ -178,7 +179,7 @@ class TestBasicOps(unittest.TestCase): def numcombs(n, r): if not n: return 0 if r else 1 - return fact(n+r-1) / fact(r)/ fact(n-1) + return fact(n+r-1) // fact(r) // fact(n-1) for n in range(7): values = [5*x-12 for x in range(n)] @@ -257,7 +258,7 @@ class TestBasicOps(unittest.TestCase): values = [5*x-12 for x in range(n)] for r in range(n+2): result = list(permutations(values, r)) - self.assertEqual(len(result), 0 if r>n else fact(n) / fact(n-r)) # right number of perms + self.assertEqual(len(result), 0 if r>n else fact(n) // fact(n-r)) # right number of perms self.assertEqual(len(result), len(set(result))) # no repeats self.assertEqual(result, sorted(result)) # lexicographic order for p in result: @@ -288,9 +289,9 @@ class TestBasicOps(unittest.TestCase): # Check size self.assertEquals(len(prod), n**r) - self.assertEquals(len(cwr), (fact(n+r-1) / fact(r)/ fact(n-1)) if n else (not r)) - self.assertEquals(len(perm), 0 if r>n else fact(n) / fact(n-r)) - self.assertEquals(len(comb), 0 if r>n else fact(n) / fact(r) / fact(n-r)) + self.assertEquals(len(cwr), (fact(n+r-1) // fact(r) // fact(n-1)) if n else (not r)) + self.assertEquals(len(perm), 0 if r>n else fact(n) // fact(n-r)) + self.assertEquals(len(comb), 0 if r>n else fact(n) // fact(r) // fact(n-r)) # Check lexicographic order without repeated tuples self.assertEquals(prod, sorted(set(prod))) @@ -543,7 +544,8 @@ class TestBasicOps(unittest.TestCase): [range(1000), range(0), range(3000,3050), range(1200), range(1500)], [range(1000), range(0), range(3000,3050), range(1200), range(1500), range(0)], ]: - target = map(None, *args) + target = [tuple([arg[i] if i < len(arg) else None for arg in args]) + for i in range(max(map(len, args)))] self.assertEqual(list(izip_longest(*args)), target) self.assertEqual(list(izip_longest(*args, **{})), target) target = [tuple((e is None and 'X' or e) for e in t) for t in target] # Replace None fills with 'X' @@ -555,7 +557,8 @@ class TestBasicOps(unittest.TestCase): self.assertEqual(list(izip_longest([])), zip([])) self.assertEqual(list(izip_longest('abcdef')), zip('abcdef')) - self.assertEqual(list(izip_longest('abc', 'defg', **{})), map(None, 'abc', 'defg')) # empty keyword dict + self.assertEqual(list(izip_longest('abc', 'defg', **{})), + zip(list('abc') + [None], 'defg')) # empty keyword dict self.assertRaises(TypeError, izip_longest, 3) self.assertRaises(TypeError, izip_longest, range(3), 3) @@ -1431,7 +1434,7 @@ Samuele # is differencing with a range so that consecutive numbers all appear in # same group. >>> data = [ 1, 4,5,6, 10, 15,16,17,18, 22, 25,26,27,28] ->>> for k, g in groupby(enumerate(data), lambda (i,x):i-x): +>>> for k, g in groupby(enumerate(data), lambda t:t[0]-t[1]): ... print map(operator.itemgetter(1), g) ... [1] |