mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
Reverting the Revision: 77368. I committed Flox's big patch for tests by
mistake. ( It may come in for sure tough)
This commit is contained in:
parent
3ddc435af6
commit
ce8e33a095
107 changed files with 436 additions and 794 deletions
|
@ -9,7 +9,6 @@ import operator
|
|||
import random
|
||||
import copy
|
||||
import pickle
|
||||
from functools import reduce
|
||||
maxsize = test_support.MAX_Py_ssize_t
|
||||
minsize = -maxsize-1
|
||||
|
||||
|
@ -123,7 +122,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:
|
||||
|
@ -179,7 +178,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)]
|
||||
|
@ -258,7 +257,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:
|
||||
|
@ -289,9 +288,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)))
|
||||
|
@ -544,8 +543,7 @@ 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 = [tuple([arg[i] if i < len(arg) else None for arg in args])
|
||||
for i in range(max(map(len, args)))]
|
||||
target = map(None, *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'
|
||||
|
@ -557,8 +555,7 @@ 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', **{})),
|
||||
zip(list('abc') + [None], 'defg')) # empty keyword dict
|
||||
self.assertEqual(list(izip_longest('abc', 'defg', **{})), map(None, 'abc', 'defg')) # empty keyword dict
|
||||
self.assertRaises(TypeError, izip_longest, 3)
|
||||
self.assertRaises(TypeError, izip_longest, range(3), 3)
|
||||
|
||||
|
@ -1434,7 +1431,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 t:t[0]-t[1]):
|
||||
>>> for k, g in groupby(enumerate(data), lambda (i,x):i-x):
|
||||
... print map(operator.itemgetter(1), g)
|
||||
...
|
||||
[1]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue