Back to index

python3.2  3.2.2
Public Member Functions
test.test_itertools.TestVariousIteratorArgs Class Reference

List of all members.

Public Member Functions

def test_accumulate
def test_chain
def test_compress
def test_product
def test_cycle
def test_groupby
def test_filter
def test_filterfalse
def test_zip
def test_ziplongest
def test_map
def test_islice
def test_starmap
def test_takewhile
def test_dropwhile
def test_tee

Detailed Description

Definition at line 1219 of file test_itertools.py.


Member Function Documentation

Definition at line 1221 of file test_itertools.py.

01221 
01222     def test_accumulate(self):
01223         s = [1,2,3,4,5]
01224         r = [1,3,6,10,15]
01225         n = len(s)
01226         for g in (G, I, Ig, L, R):
01227             self.assertEqual(list(accumulate(g(s))), r)
01228         self.assertEqual(list(accumulate(S(s))), [])
01229         self.assertRaises(TypeError, accumulate, X(s))
01230         self.assertRaises(TypeError, accumulate, N(s))
01231         self.assertRaises(ZeroDivisionError, list, accumulate(E(s)))

Here is the call graph for this function:

Definition at line 1232 of file test_itertools.py.

01232 
01233     def test_chain(self):
01234         for s in ("123", "", range(1000), ('do', 1.2), range(2000,2200,5)):
01235             for g in (G, I, Ig, S, L, R):
01236                 self.assertEqual(list(chain(g(s))), list(g(s)))
01237                 self.assertEqual(list(chain(g(s), g(s))), list(g(s))+list(g(s)))
01238             self.assertRaises(TypeError, list, chain(X(s)))
01239             self.assertRaises(TypeError, list, chain(N(s)))
01240             self.assertRaises(ZeroDivisionError, list, chain(E(s)))

Here is the call graph for this function:

Definition at line 1241 of file test_itertools.py.

01241 
01242     def test_compress(self):
01243         for s in ("123", "", range(1000), ('do', 1.2), range(2000,2200,5)):
01244             n = len(s)
01245             for g in (G, I, Ig, S, L, R):
01246                 self.assertEqual(list(compress(g(s), repeat(1))), list(g(s)))
01247             self.assertRaises(TypeError, compress, X(s), repeat(1))
01248             self.assertRaises(TypeError, compress, N(s), repeat(1))
01249             self.assertRaises(ZeroDivisionError, list, compress(E(s), repeat(1)))

Here is the call graph for this function:

Definition at line 1256 of file test_itertools.py.

01256 
01257     def test_cycle(self):
01258         for s in ("123", "", range(1000), ('do', 1.2), range(2000,2200,5)):
01259             for g in (G, I, Ig, S, L, R):
01260                 tgtlen = len(s) * 3
01261                 expected = list(g(s))*3
01262                 actual = list(islice(cycle(g(s)), tgtlen))
01263                 self.assertEqual(actual, expected)
01264             self.assertRaises(TypeError, cycle, X(s))
01265             self.assertRaises(TypeError, cycle, N(s))
01266             self.assertRaises(ZeroDivisionError, list, cycle(E(s)))

Here is the call graph for this function:

Definition at line 1352 of file test_itertools.py.

01352 
01353     def test_dropwhile(self):
01354         for s in (range(10), range(0), range(1000), (7,11), range(2000,2200,5)):
01355             for g in (G, I, Ig, S, L, R):
01356                 tgt = []
01357                 for elem in g(s):
01358                     if not tgt and isOdd(elem): continue
01359                     tgt.append(elem)
01360                 self.assertEqual(list(dropwhile(isOdd, g(s))), tgt)
01361             self.assertRaises(TypeError, dropwhile, isOdd, X(s))
01362             self.assertRaises(TypeError, dropwhile, isOdd, N(s))
01363             self.assertRaises(ZeroDivisionError, list, dropwhile(isOdd, E(s)))

Here is the call graph for this function:

Definition at line 1275 of file test_itertools.py.

01275 
01276     def test_filter(self):
01277         for s in (range(10), range(0), range(1000), (7,11), range(2000,2200,5)):
01278             for g in (G, I, Ig, S, L, R):
01279                 self.assertEqual(list(filter(isEven, g(s))),
01280                                  [x for x in g(s) if isEven(x)])
01281             self.assertRaises(TypeError, filter, isEven, X(s))
01282             self.assertRaises(TypeError, filter, isEven, N(s))
01283             self.assertRaises(ZeroDivisionError, list, filter(isEven, E(s)))

Here is the call graph for this function:

Definition at line 1284 of file test_itertools.py.

01284 
01285     def test_filterfalse(self):
01286         for s in (range(10), range(0), range(1000), (7,11), range(2000,2200,5)):
01287             for g in (G, I, Ig, S, L, R):
01288                 self.assertEqual(list(filterfalse(isEven, g(s))),
01289                                  [x for x in g(s) if isOdd(x)])
01290             self.assertRaises(TypeError, filterfalse, isEven, X(s))
01291             self.assertRaises(TypeError, filterfalse, isEven, N(s))
01292             self.assertRaises(ZeroDivisionError, list, filterfalse(isEven, E(s)))

Here is the call graph for this function:

Definition at line 1267 of file test_itertools.py.

01267 
01268     def test_groupby(self):
01269         for s in (range(10), range(0), range(1000), (7,11), range(2000,2200,5)):
01270             for g in (G, I, Ig, S, L, R):
01271                 self.assertEqual([k for k, sb in groupby(g(s))], list(g(s)))
01272             self.assertRaises(TypeError, groupby, X(s))
01273             self.assertRaises(TypeError, groupby, N(s))
01274             self.assertRaises(ZeroDivisionError, list, groupby(E(s)))

Here is the call graph for this function:

Definition at line 1322 of file test_itertools.py.

01322 
01323     def test_islice(self):
01324         for s in ("12345", "", range(1000), ('do', 1.2), range(2000,2200,5)):
01325             for g in (G, I, Ig, S, L, R):
01326                 self.assertEqual(list(islice(g(s),1,None,2)), list(g(s))[1::2])
01327             self.assertRaises(TypeError, islice, X(s), 10)
01328             self.assertRaises(TypeError, islice, N(s), 10)
01329             self.assertRaises(ZeroDivisionError, list, islice(E(s), 10))

Here is the call graph for this function:

Definition at line 1311 of file test_itertools.py.

01311 
01312     def test_map(self):
01313         for s in (range(10), range(0), range(100), (7,11), range(20,50,5)):
01314             for g in (G, I, Ig, S, L, R):
01315                 self.assertEqual(list(map(onearg, g(s))),
01316                                  [onearg(x) for x in g(s)])
01317                 self.assertEqual(list(map(operator.pow, g(s), g(s))),
01318                                  [x**x for x in g(s)])
01319             self.assertRaises(TypeError, map, onearg, X(s))
01320             self.assertRaises(TypeError, map, onearg, N(s))
01321             self.assertRaises(ZeroDivisionError, list, map(onearg, E(s)))

Here is the call graph for this function:

Definition at line 1250 of file test_itertools.py.

01250 
01251     def test_product(self):
01252         for s in ("123", "", range(1000), ('do', 1.2), range(2000,2200,5)):
01253             self.assertRaises(TypeError, product, X(s))
01254             self.assertRaises(TypeError, product, N(s))
01255             self.assertRaises(ZeroDivisionError, product, E(s))

Here is the call graph for this function:

Definition at line 1330 of file test_itertools.py.

01330 
01331     def test_starmap(self):
01332         for s in (range(10), range(0), range(100), (7,11), range(20,50,5)):
01333             for g in (G, I, Ig, S, L, R):
01334                 ss = lzip(s, s)
01335                 self.assertEqual(list(starmap(operator.pow, g(ss))),
01336                                  [x**x for x in g(s)])
01337             self.assertRaises(TypeError, starmap, operator.pow, X(ss))
01338             self.assertRaises(TypeError, starmap, operator.pow, N(ss))
01339             self.assertRaises(ZeroDivisionError, list, starmap(operator.pow, E(ss)))

Here is the call graph for this function:

Definition at line 1340 of file test_itertools.py.

01340 
01341     def test_takewhile(self):
01342         for s in (range(10), range(0), range(1000), (7,11), range(2000,2200,5)):
01343             for g in (G, I, Ig, S, L, R):
01344                 tgt = []
01345                 for elem in g(s):
01346                     if not isEven(elem): break
01347                     tgt.append(elem)
01348                 self.assertEqual(list(takewhile(isEven, g(s))), tgt)
01349             self.assertRaises(TypeError, takewhile, isEven, X(s))
01350             self.assertRaises(TypeError, takewhile, isEven, N(s))
01351             self.assertRaises(ZeroDivisionError, list, takewhile(isEven, E(s)))

Here is the call graph for this function:

Definition at line 1364 of file test_itertools.py.

01364 
01365     def test_tee(self):
01366         for s in ("123", "", range(1000), ('do', 1.2), range(2000,2200,5)):
01367             for g in (G, I, Ig, S, L, R):
01368                 it1, it2 = tee(g(s))
01369                 self.assertEqual(list(it1), list(g(s)))
01370                 self.assertEqual(list(it2), list(g(s)))
01371             self.assertRaises(TypeError, tee, X(s))
01372             self.assertRaises(TypeError, tee, N(s))
01373             self.assertRaises(ZeroDivisionError, list, tee(E(s))[0])

Here is the call graph for this function:

Definition at line 1293 of file test_itertools.py.

01293 
01294     def test_zip(self):
01295         for s in ("123", "", range(1000), ('do', 1.2), range(2000,2200,5)):
01296             for g in (G, I, Ig, S, L, R):
01297                 self.assertEqual(list(zip(g(s))), lzip(g(s)))
01298                 self.assertEqual(list(zip(g(s), g(s))), lzip(g(s), g(s)))
01299             self.assertRaises(TypeError, zip, X(s))
01300             self.assertRaises(TypeError, zip, N(s))
01301             self.assertRaises(ZeroDivisionError, list, zip(E(s)))

Here is the call graph for this function:

Definition at line 1302 of file test_itertools.py.

01302 
01303     def test_ziplongest(self):
01304         for s in ("123", "", range(1000), ('do', 1.2), range(2000,2200,5)):
01305             for g in (G, I, Ig, S, L, R):
01306                 self.assertEqual(list(zip_longest(g(s))), list(zip(g(s))))
01307                 self.assertEqual(list(zip_longest(g(s), g(s))), list(zip(g(s), g(s))))
01308             self.assertRaises(TypeError, zip_longest, X(s))
01309             self.assertRaises(TypeError, zip_longest, N(s))
01310             self.assertRaises(ZeroDivisionError, list, zip_longest(E(s)))

Here is the call graph for this function:


The documentation for this class was generated from the following file: