<s> import unittest <EOL> from test import support <EOL> from itertools import * <EOL> from weakref import proxy <EOL> from decimal import Decimal <EOL> from fractions import Fraction <EOL> import sys <EOL> import operator <EOL> import random <EOL> import copy <EOL> import pickle <EOL> from functools import reduce <EOL> maxsize = support . MAX_Py_ssize_t <EOL> minsize = - maxsize - <NUM_LIT:1> <EOL> def lzip ( * args ) : <EOL> return list ( zip ( * args ) ) <EOL> def onearg ( x ) : <EOL> '<STR_LIT>' <EOL> return <NUM_LIT:2> * x <EOL> def errfunc ( * args ) : <EOL> '<STR_LIT>' <EOL> raise ValueError <EOL> def gen3 ( ) : <EOL> '<STR_LIT>' <EOL> for i in ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ) : <EOL> yield i <EOL> def isEven ( x ) : <EOL> '<STR_LIT>' <EOL> return x % <NUM_LIT:2> == <NUM_LIT:0> <EOL> def isOdd ( x ) : <EOL> '<STR_LIT>' <EOL> return x % <NUM_LIT:2> == <NUM_LIT:1> <EOL> def tupleize ( * args ) : <EOL> return args <EOL> def irange ( n ) : <EOL> for i in range ( n ) : <EOL> yield i <EOL> class StopNow : <EOL> '<STR_LIT>' <EOL> def __iter__ ( self ) : <EOL> return self <EOL> def __next__ ( self ) : <EOL> raise StopIteration <EOL> def take ( n , seq ) : <EOL> '<STR_LIT>' <EOL> return list ( islice ( seq , n ) ) <EOL> def prod ( iterable ) : <EOL> return reduce ( operator . mul , iterable , <NUM_LIT:1> ) <EOL> def fact ( n ) : <EOL> '<STR_LIT>' <EOL> return prod ( range ( <NUM_LIT:1> , n + <NUM_LIT:1> ) ) <EOL> def testR ( r ) : <EOL> return r [ <NUM_LIT:0> ] <EOL> def testR2 ( r ) : <EOL> return r [ <NUM_LIT:2> ] <EOL> def underten ( x ) : <EOL> return x < <NUM_LIT:10> <EOL> class TestBasicOps ( unittest . TestCase ) : <EOL> def pickletest ( self , it , stop = <NUM_LIT:4> , take = <NUM_LIT:1> , compare = None ) : <EOL> """<STR_LIT>""" <EOL> def expand ( it , i = <NUM_LIT:0> ) : <EOL> if i > <NUM_LIT:10> : <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> if isinstance ( it , str ) : <EOL> return it <EOL> try : <EOL> l = list ( islice ( it , stop ) ) <EOL> except TypeError : <EOL> return it <EOL> return [ expand ( e , i + <NUM_LIT:1> ) for e in l ] <EOL> dump = pickle . dumps ( it ) <EOL> i2 = pickle . loads ( dump ) <EOL> self . assertEqual ( type ( it ) , type ( i2 ) ) <EOL> a , b = expand ( it ) , expand ( i2 ) <EOL> self . assertEqual ( a , b ) <EOL> if compare : <EOL> c = expand ( compare ) <EOL> self . assertEqual ( a , c ) <EOL> i3 = pickle . loads ( dump ) <EOL> took = <NUM_LIT:0> <EOL> try : <EOL> for i in range ( take ) : <EOL> next ( i3 ) <EOL> took += <NUM_LIT:1> <EOL> except StopIteration : <EOL> pass <EOL> dump = pickle . dumps ( i3 ) <EOL> i4 = pickle . loads ( dump ) <EOL> a , b = expand ( i3 ) , expand ( i4 ) <EOL> self . assertEqual ( a , b ) <EOL> if compare : <EOL> c = expand ( compare [ took : ] ) <EOL> self . assertEqual ( a , c ) ; <EOL> def test_accumulate ( self ) : <EOL> self . assertEqual ( list ( accumulate ( range ( <NUM_LIT:10> ) ) ) , <EOL> [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:6> , <NUM_LIT:10> , <NUM_LIT:15> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> self . assertEqual ( list ( accumulate ( iterable = range ( <NUM_LIT:10> ) ) ) , <EOL> [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:6> , <NUM_LIT:10> , <NUM_LIT:15> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> for typ in int , complex , Decimal , Fraction : <EOL> self . assertEqual ( <EOL> list ( accumulate ( map ( typ , range ( <NUM_LIT:10> ) ) ) ) , <EOL> list ( map ( typ , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:6> , <NUM_LIT:10> , <NUM_LIT:15> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) ) ) <EOL> self . assertEqual ( list ( accumulate ( '<STR_LIT:abc>' ) ) , [ '<STR_LIT:a>' , '<STR_LIT>' , '<STR_LIT:abc>' ] ) <EOL> self . assertEqual ( list ( accumulate ( [ ] ) ) , [ ] ) <EOL> self . assertEqual ( list ( accumulate ( [ <NUM_LIT:7> ] ) ) , [ <NUM_LIT:7> ] ) <EOL> self . assertRaises ( TypeError , accumulate , range ( <NUM_LIT:10> ) , <NUM_LIT:5> , <NUM_LIT:6> ) <EOL> self . assertRaises ( TypeError , accumulate ) <EOL> self . assertRaises ( TypeError , accumulate , x = range ( <NUM_LIT:10> ) ) <EOL> self . assertRaises ( TypeError , list , accumulate ( [ <NUM_LIT:1> , [ ] ] ) ) <EOL> s = [ <NUM_LIT:2> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:5> , <NUM_LIT:7> , <NUM_LIT:0> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:1> , <NUM_LIT:6> ] <EOL> self . assertEqual ( list ( accumulate ( s , min ) ) , <EOL> [ <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] ) <EOL> self . assertEqual ( list ( accumulate ( s , max ) ) , <EOL> [ <NUM_LIT:2> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:9> , <NUM_LIT:9> , <NUM_LIT:9> , <NUM_LIT:9> , <NUM_LIT:9> , <NUM_LIT:9> , <NUM_LIT:9> ] ) <EOL> self . assertEqual ( list ( accumulate ( s , operator . mul ) ) , <EOL> [ <NUM_LIT:2> , <NUM_LIT:16> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] ) <EOL> with self . assertRaises ( TypeError ) : <EOL> list ( accumulate ( s , chr ) ) <EOL> self . pickletest ( accumulate ( range ( <NUM_LIT:10> ) ) ) <EOL> def test_chain ( self ) : <EOL> def chain2 ( * iterables ) : <EOL> '<STR_LIT>' <EOL> for it in iterables : <EOL> for element in it : <EOL> yield element <EOL> for c in ( chain , chain2 ) : <EOL> self . assertEqual ( list ( c ( '<STR_LIT:abc>' , '<STR_LIT>' ) ) , list ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( list ( c ( '<STR_LIT:abc>' ) ) , list ( '<STR_LIT:abc>' ) ) <EOL> self . assertEqual ( list ( c ( '<STR_LIT>' ) ) , [ ] ) <EOL> self . assertEqual ( take ( <NUM_LIT:4> , c ( '<STR_LIT:abc>' , '<STR_LIT>' ) ) , list ( '<STR_LIT>' ) ) <EOL> self . assertRaises ( TypeError , list , c ( <NUM_LIT:2> , <NUM_LIT:3> ) ) <EOL> def test_chain_from_iterable ( self ) : <EOL> self . assertEqual ( list ( chain . from_iterable ( [ '<STR_LIT:abc>' , '<STR_LIT>' ] ) ) , list ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( list ( chain . from_iterable ( [ '<STR_LIT:abc>' ] ) ) , list ( '<STR_LIT:abc>' ) ) <EOL> self . assertEqual ( list ( chain . from_iterable ( [ '<STR_LIT>' ] ) ) , [ ] ) <EOL> self . assertEqual ( take ( <NUM_LIT:4> , chain . from_iterable ( [ '<STR_LIT:abc>' , '<STR_LIT>' ] ) ) , list ( '<STR_LIT>' ) ) <EOL> self . assertRaises ( TypeError , list , chain . from_iterable ( [ <NUM_LIT:2> , <NUM_LIT:3> ] ) ) <EOL> def test_chain_reducible ( self ) : <EOL> operators = [ copy . deepcopy , <EOL> lambda s : pickle . loads ( pickle . dumps ( s ) ) ] <EOL> for oper in operators : <EOL> it = chain ( '<STR_LIT:abc>' , '<STR_LIT>' ) <EOL> self . assertEqual ( list ( oper ( it ) ) , list ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( next ( it ) , '<STR_LIT:a>' ) <EOL> self . assertEqual ( list ( oper ( it ) ) , list ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( list ( oper ( chain ( '<STR_LIT>' ) ) ) , [ ] ) <EOL> self . assertEqual ( take ( <NUM_LIT:4> , oper ( chain ( '<STR_LIT:abc>' , '<STR_LIT>' ) ) ) , list ( '<STR_LIT>' ) ) <EOL> self . assertRaises ( TypeError , list , oper ( chain ( <NUM_LIT:2> , <NUM_LIT:3> ) ) ) <EOL> self . pickletest ( chain ( '<STR_LIT:abc>' , '<STR_LIT>' ) , compare = list ( '<STR_LIT>' ) ) <EOL> def test_combinations ( self ) : <EOL> self . assertRaises ( TypeError , combinations , '<STR_LIT:abc>' ) <EOL> self . assertRaises ( TypeError , combinations , '<STR_LIT:abc>' , <NUM_LIT:2> , <NUM_LIT:1> ) <EOL> self . assertRaises ( TypeError , combinations , None ) <EOL> self . assertRaises ( ValueError , combinations , '<STR_LIT:abc>' , - <NUM_LIT:2> ) <EOL> for op in ( lambda a : a , lambda a : pickle . loads ( pickle . dumps ( a ) ) ) : <EOL> self . assertEqual ( list ( op ( combinations ( '<STR_LIT:abc>' , <NUM_LIT:32> ) ) ) , [ ] ) <EOL> self . assertEqual ( list ( op ( combinations ( '<STR_LIT>' , <NUM_LIT:2> ) ) ) , <EOL> [ ( '<STR_LIT:A>' , '<STR_LIT:B>' ) , ( '<STR_LIT:A>' , '<STR_LIT:C>' ) , ( '<STR_LIT:A>' , '<STR_LIT:D>' ) , ( '<STR_LIT:B>' , '<STR_LIT:C>' ) , ( '<STR_LIT:B>' , '<STR_LIT:D>' ) , ( '<STR_LIT:C>' , '<STR_LIT:D>' ) ] ) <EOL> testIntermediate = combinations ( '<STR_LIT>' , <NUM_LIT:2> ) <EOL> next ( testIntermediate ) <EOL> self . assertEqual ( list ( op ( testIntermediate ) ) , <EOL> [ ( '<STR_LIT:A>' , '<STR_LIT:C>' ) , ( '<STR_LIT:A>' , '<STR_LIT:D>' ) , ( '<STR_LIT:B>' , '<STR_LIT:C>' ) , ( '<STR_LIT:B>' , '<STR_LIT:D>' ) , ( '<STR_LIT:C>' , '<STR_LIT:D>' ) ] ) <EOL> self . assertEqual ( list ( op ( combinations ( range ( <NUM_LIT:4> ) , <NUM_LIT:3> ) ) ) , <EOL> [ ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ) , ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:3> ) , ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:3> ) , ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ] ) <EOL> testIntermediate = combinations ( range ( <NUM_LIT:4> ) , <NUM_LIT:3> ) <EOL> next ( testIntermediate ) <EOL> self . assertEqual ( list ( op ( testIntermediate ) ) , <EOL> [ ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:3> ) , ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:3> ) , ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ] ) <EOL> def combinations1 ( iterable , r ) : <EOL> '<STR_LIT>' <EOL> pool = tuple ( iterable ) <EOL> n = len ( pool ) <EOL> if r > n : <EOL> return <EOL> indices = list ( range ( r ) ) <EOL> yield tuple ( pool [ i ] for i in indices ) <EOL> while <NUM_LIT:1> : <EOL> for i in reversed ( range ( r ) ) : <EOL> if indices [ i ] != i + n - r : <EOL> break <EOL> else : <EOL> return <EOL> indices [ i ] += <NUM_LIT:1> <EOL> for j in range ( i + <NUM_LIT:1> , r ) : <EOL> indices [ j ] = indices [ j - <NUM_LIT:1> ] + <NUM_LIT:1> <EOL> yield tuple ( pool [ i ] for i in indices ) <EOL> def combinations2 ( iterable , r ) : <EOL> '<STR_LIT>' <EOL> pool = tuple ( iterable ) <EOL> n = len ( pool ) <EOL> for indices in permutations ( range ( n ) , r ) : <EOL> if sorted ( indices ) == list ( indices ) : <EOL> yield tuple ( pool [ i ] for i in indices ) <EOL> def combinations3 ( iterable , r ) : <EOL> '<STR_LIT>' <EOL> pool = tuple ( iterable ) <EOL> n = len ( pool ) <EOL> for indices in combinations_with_replacement ( range ( n ) , r ) : <EOL> if len ( set ( indices ) ) == r : <EOL> yield tuple ( pool [ i ] for i in indices ) <EOL> for n in range ( <NUM_LIT:7> ) : <EOL> values = [ <NUM_LIT:5> * x - <NUM_LIT:12> for x in range ( n ) ] <EOL> for r in range ( n + <NUM_LIT:2> ) : <EOL> result = list ( combinations ( values , r ) ) <EOL> self . assertEqual ( len ( result ) , <NUM_LIT:0> if r > n else fact ( n ) / fact ( r ) / fact ( n - r ) ) <EOL> self . assertEqual ( len ( result ) , len ( set ( result ) ) ) <EOL> self . assertEqual ( result , sorted ( result ) ) <EOL> for c in result : <EOL> self . assertEqual ( len ( c ) , r ) <EOL> self . assertEqual ( len ( set ( c ) ) , r ) <EOL> self . assertEqual ( list ( c ) , sorted ( c ) ) <EOL> self . assertTrue ( all ( e in values for e in c ) ) <EOL> self . assertEqual ( list ( c ) , <EOL> [ e for e in values if e in c ] ) <EOL> self . assertEqual ( result , list ( combinations1 ( values , r ) ) ) <EOL> self . assertEqual ( result , list ( combinations2 ( values , r ) ) ) <EOL> self . assertEqual ( result , list ( combinations3 ( values , r ) ) ) <EOL> self . pickletest ( combinations ( values , r ) ) <EOL> @ support . impl_detail ( "<STR_LIT>" ) <EOL> def test_combinations_tuple_reuse ( self ) : <EOL> self . assertEqual ( len ( set ( map ( id , combinations ( '<STR_LIT>' , <NUM_LIT:3> ) ) ) ) , <NUM_LIT:1> ) <EOL> self . assertNotEqual ( len ( set ( map ( id , list ( combinations ( '<STR_LIT>' , <NUM_LIT:3> ) ) ) ) ) , <NUM_LIT:1> ) <EOL> def test_combinations_with_replacement ( self ) : <EOL> cwr = combinations_with_replacement <EOL> self . assertRaises ( TypeError , cwr , '<STR_LIT:abc>' ) <EOL> self . assertRaises ( TypeError , cwr , '<STR_LIT:abc>' , <NUM_LIT:2> , <NUM_LIT:1> ) <EOL> self . assertRaises ( TypeError , cwr , None ) <EOL> self . assertRaises ( ValueError , cwr , '<STR_LIT:abc>' , - <NUM_LIT:2> ) <EOL> for op in ( lambda a : a , lambda a : pickle . loads ( pickle . dumps ( a ) ) ) : <EOL> self . assertEqual ( list ( op ( cwr ( '<STR_LIT>' , <NUM_LIT:2> ) ) ) , <EOL> [ ( '<STR_LIT:A>' , '<STR_LIT:A>' ) , ( '<STR_LIT:A>' , '<STR_LIT:B>' ) , ( '<STR_LIT:A>' , '<STR_LIT:C>' ) , ( '<STR_LIT:B>' , '<STR_LIT:B>' ) , ( '<STR_LIT:B>' , '<STR_LIT:C>' ) , ( '<STR_LIT:C>' , '<STR_LIT:C>' ) ] ) <EOL> testIntermediate = cwr ( '<STR_LIT>' , <NUM_LIT:2> ) <EOL> next ( testIntermediate ) <EOL> self . assertEqual ( list ( op ( testIntermediate ) ) , <EOL> [ ( '<STR_LIT:A>' , '<STR_LIT:B>' ) , ( '<STR_LIT:A>' , '<STR_LIT:C>' ) , ( '<STR_LIT:B>' , '<STR_LIT:B>' ) , ( '<STR_LIT:B>' , '<STR_LIT:C>' ) , ( '<STR_LIT:C>' , '<STR_LIT:C>' ) ] ) <EOL> def cwr1 ( iterable , r ) : <EOL> '<STR_LIT>' <EOL> pool = tuple ( iterable ) <EOL> n = len ( pool ) <EOL> if not n and r : <EOL> return <EOL> indices = [ <NUM_LIT:0> ] * r <EOL> yield tuple ( pool [ i ] for i in indices ) <EOL> while <NUM_LIT:1> : <EOL> for i in reversed ( range ( r ) ) : <EOL> if indices [ i ] != n - <NUM_LIT:1> : <EOL> break <EOL> else : <EOL> return <EOL> indices [ i : ] = [ indices [ i ] + <NUM_LIT:1> ] * ( r - i ) <EOL> yield tuple ( pool [ i ] for i in indices ) <EOL> def cwr2 ( iterable , r ) : <EOL> '<STR_LIT>' <EOL> pool = tuple ( iterable ) <EOL> n = len ( pool ) <EOL> for indices in product ( range ( n ) , repeat = r ) : <EOL> if sorted ( indices ) == list ( indices ) : <EOL> yield tuple ( pool [ i ] for i in indices ) <EOL> def numcombs ( n , r ) : <EOL> if not n : <EOL> return <NUM_LIT:0> if r else <NUM_LIT:1> <EOL> return fact ( n + r - <NUM_LIT:1> ) / fact ( r ) / fact ( n - <NUM_LIT:1> ) <EOL> for n in range ( <NUM_LIT:7> ) : <EOL> values = [ <NUM_LIT:5> * x - <NUM_LIT:12> for x in range ( n ) ] <EOL> for r in range ( n + <NUM_LIT:2> ) : <EOL> result = list ( cwr ( values , r ) ) <EOL> self . assertEqual ( len ( result ) , numcombs ( n , r ) ) <EOL> self . assertEqual ( len ( result ) , len ( set ( result ) ) ) <EOL> self . assertEqual ( result , sorted ( result ) ) <EOL> regular_combs = list ( combinations ( values , r ) ) <EOL> if n == <NUM_LIT:0> or r <= <NUM_LIT:1> : <EOL> self . assertEqual ( result , regular_combs ) <EOL> else : <EOL> self . assertTrue ( set ( result ) >= set ( regular_combs ) ) <EOL> for c in result : <EOL> self . assertEqual ( len ( c ) , r ) <EOL> noruns = [ k for k , v in groupby ( c ) ] <EOL> self . assertEqual ( len ( noruns ) , len ( set ( noruns ) ) ) <EOL> self . assertEqual ( list ( c ) , sorted ( c ) ) <EOL> self . assertTrue ( all ( e in values for e in c ) ) <EOL> self . assertEqual ( noruns , <EOL> [ e for e in values if e in c ] ) <EOL> self . assertEqual ( result , list ( cwr1 ( values , r ) ) ) <EOL> self . assertEqual ( result , list ( cwr2 ( values , r ) ) ) <EOL> self . pickletest ( cwr ( values , r ) ) <EOL> @ support . impl_detail ( "<STR_LIT>" ) <EOL> def test_combinations_with_replacement_tuple_reuse ( self ) : <EOL> cwr = combinations_with_replacement <EOL> self . assertEqual ( len ( set ( map ( id , cwr ( '<STR_LIT>' , <NUM_LIT:3> ) ) ) ) , <NUM_LIT:1> ) <EOL> self . assertNotEqual ( len ( set ( map ( id , list ( cwr ( '<STR_LIT>' , <NUM_LIT:3> ) ) ) ) ) , <NUM_LIT:1> ) <EOL> def test_permutations ( self ) : <EOL> self . assertRaises ( TypeError , permutations ) <EOL> self . assertRaises ( TypeError , permutations , '<STR_LIT:abc>' , <NUM_LIT:2> , <NUM_LIT:1> ) <EOL> self . assertRaises ( TypeError , permutations , None ) <EOL> self . assertRaises ( ValueError , permutations , '<STR_LIT:abc>' , - <NUM_LIT:2> ) <EOL> self . assertEqual ( list ( permutations ( '<STR_LIT:abc>' , <NUM_LIT:32> ) ) , [ ] ) <EOL> self . assertRaises ( TypeError , permutations , '<STR_LIT:abc>' , '<STR_LIT:s>' ) <EOL> self . assertEqual ( list ( permutations ( range ( <NUM_LIT:3> ) , <NUM_LIT:2> ) ) , <EOL> [ ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( <NUM_LIT:0> , <NUM_LIT:2> ) , ( <NUM_LIT:1> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , <NUM_LIT:2> ) , ( <NUM_LIT:2> , <NUM_LIT:0> ) , ( <NUM_LIT:2> , <NUM_LIT:1> ) ] ) <EOL> def permutations1 ( iterable , r = None ) : <EOL> '<STR_LIT>' <EOL> pool = tuple ( iterable ) <EOL> n = len ( pool ) <EOL> r = n if r is None else r <EOL> if r > n : <EOL> return <EOL> indices = list ( range ( n ) ) <EOL> cycles = list ( range ( n - r + <NUM_LIT:1> , n + <NUM_LIT:1> ) ) [ : : - <NUM_LIT:1> ] <EOL> yield tuple ( pool [ i ] for i in indices [ : r ] ) <EOL> while n : <EOL> for i in reversed ( range ( r ) ) : <EOL> cycles [ i ] -= <NUM_LIT:1> <EOL> if cycles [ i ] == <NUM_LIT:0> : <EOL> indices [ i : ] = indices [ i + <NUM_LIT:1> : ] + indices [ i : i + <NUM_LIT:1> ] <EOL> cycles [ i ] = n - i <EOL> else : <EOL> j = cycles [ i ] <EOL> indices [ i ] , indices [ - j ] = indices [ - j ] , indices [ i ] <EOL> yield tuple ( pool [ i ] for i in indices [ : r ] ) <EOL> break <EOL> else : <EOL> return <EOL> def permutations2 ( iterable , r = None ) : <EOL> '<STR_LIT>' <EOL> pool = tuple ( iterable ) <EOL> n = len ( pool ) <EOL> r = n if r is None else r <EOL> for indices in product ( range ( n ) , repeat = r ) : <EOL> if len ( set ( indices ) ) == r : <EOL> yield tuple ( pool [ i ] for i in indices ) <EOL> for n in range ( <NUM_LIT:7> ) : <EOL> values = [ <NUM_LIT:5> * x - <NUM_LIT:12> for x in range ( n ) ] <EOL> for r in range ( n + <NUM_LIT:2> ) : <EOL> result = list ( permutations ( values , r ) ) <EOL> self . assertEqual ( len ( result ) , <NUM_LIT:0> if r > n else fact ( n ) / fact ( n - r ) ) <EOL> self . assertEqual ( len ( result ) , len ( set ( result ) ) ) <EOL> self . assertEqual ( result , sorted ( result ) ) <EOL> for p in result : <EOL> self . assertEqual ( len ( p ) , r ) <EOL> self . assertEqual ( len ( set ( p ) ) , r ) <EOL> self . assertTrue ( all ( e in values for e in p ) ) <EOL> self . assertEqual ( result , list ( permutations1 ( values , r ) ) ) <EOL> self . assertEqual ( result , list ( permutations2 ( values , r ) ) ) <EOL> if r == n : <EOL> self . assertEqual ( result , list ( permutations ( values , None ) ) ) <EOL> self . assertEqual ( result , list ( permutations ( values ) ) ) <EOL> self . pickletest ( permutations ( values , r ) ) <EOL> @ support . impl_detail ( "<STR_LIT>" ) <EOL> def test_permutations_tuple_reuse ( self ) : <EOL> self . assertEqual ( len ( set ( map ( id , permutations ( '<STR_LIT>' , <NUM_LIT:3> ) ) ) ) , <NUM_LIT:1> ) <EOL> self . assertNotEqual ( len ( set ( map ( id , list ( permutations ( '<STR_LIT>' , <NUM_LIT:3> ) ) ) ) ) , <NUM_LIT:1> ) <EOL> def test_combinatorics ( self ) : <EOL> for n in range ( <NUM_LIT:6> ) : <EOL> s = '<STR_LIT>' [ : n ] <EOL> for r in range ( <NUM_LIT:8> ) : <EOL> prod = list ( product ( s , repeat = r ) ) <EOL> cwr = list ( combinations_with_replacement ( s , r ) ) <EOL> perm = list ( permutations ( s , r ) ) <EOL> comb = list ( combinations ( s , r ) ) <EOL> self . assertEqual ( len ( prod ) , n ** r ) <EOL> self . assertEqual ( len ( cwr ) , ( fact ( n + r - <NUM_LIT:1> ) / fact ( r ) / fact ( n - <NUM_LIT:1> ) ) if n else ( not r ) ) <EOL> self . assertEqual ( len ( perm ) , <NUM_LIT:0> if r > n else fact ( n ) / fact ( n - r ) ) <EOL> self . assertEqual ( len ( comb ) , <NUM_LIT:0> if r > n else fact ( n ) / fact ( r ) / fact ( n - r ) ) <EOL> self . assertEqual ( prod , sorted ( set ( prod ) ) ) <EOL> self . assertEqual ( cwr , sorted ( set ( cwr ) ) ) <EOL> self . assertEqual ( perm , sorted ( set ( perm ) ) ) <EOL> self . assertEqual ( comb , sorted ( set ( comb ) ) ) <EOL> self . assertEqual ( cwr , [ t for t in prod if sorted ( t ) == list ( t ) ] ) <EOL> self . assertEqual ( perm , [ t for t in prod if len ( set ( t ) ) == r ] ) <EOL> self . assertEqual ( comb , [ t for t in perm if sorted ( t ) == list ( t ) ] ) <EOL> self . assertEqual ( comb , [ t for t in cwr if len ( set ( t ) ) == r ] ) <EOL> self . assertEqual ( comb , list ( filter ( set ( cwr ) . __contains__ , perm ) ) ) <EOL> self . assertEqual ( comb , list ( filter ( set ( perm ) . __contains__ , cwr ) ) ) <EOL> self . assertEqual ( comb , sorted ( set ( cwr ) & set ( perm ) ) ) <EOL> def test_compress ( self ) : <EOL> self . assertEqual ( list ( compress ( data = '<STR_LIT>' , selectors = [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> ] ) ) , list ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( list ( compress ( '<STR_LIT>' , [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> ] ) ) , list ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( list ( compress ( '<STR_LIT>' , [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] ) ) , list ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( list ( compress ( '<STR_LIT>' , [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ] ) ) , list ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( list ( compress ( '<STR_LIT>' , [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> ] ) ) , list ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( list ( compress ( '<STR_LIT>' , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ] ) ) , list ( '<STR_LIT>' ) ) <EOL> n = <NUM_LIT> <EOL> data = chain . from_iterable ( repeat ( range ( <NUM_LIT:6> ) , n ) ) <EOL> selectors = chain . from_iterable ( repeat ( ( <NUM_LIT:0> , <NUM_LIT:1> ) ) ) <EOL> self . assertEqual ( list ( compress ( data , selectors ) ) , [ <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:5> ] * n ) <EOL> self . assertRaises ( TypeError , compress , None , range ( <NUM_LIT:6> ) ) <EOL> self . assertRaises ( TypeError , compress , range ( <NUM_LIT:6> ) , None ) <EOL> self . assertRaises ( TypeError , compress , range ( <NUM_LIT:6> ) ) <EOL> self . assertRaises ( TypeError , compress , range ( <NUM_LIT:6> ) , None ) <EOL> for op in ( lambda a : copy . copy ( a ) , lambda a : copy . deepcopy ( a ) , lambda a : pickle . loads ( pickle . dumps ( a ) ) ) : <EOL> for data , selectors , result1 , result2 in [ <EOL> ( '<STR_LIT>' , [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> ] , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ] , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> ] , '<STR_LIT>' , '<STR_LIT:C>' ) , <EOL> ( '<STR_LIT>' , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ] , '<STR_LIT>' , '<STR_LIT:C>' ) , <EOL> ] : <EOL> self . assertEqual ( list ( op ( compress ( data = data , selectors = selectors ) ) ) , list ( result1 ) ) <EOL> self . assertEqual ( list ( op ( compress ( data , selectors ) ) ) , list ( result1 ) ) <EOL> testIntermediate = compress ( data , selectors ) <EOL> if result1 : <EOL> next ( testIntermediate ) <EOL> self . assertEqual ( list ( op ( testIntermediate ) ) , list ( result2 ) ) <EOL> def test_count ( self ) : <EOL> self . assertEqual ( lzip ( '<STR_LIT:abc>' , count ( ) ) , [ ( '<STR_LIT:a>' , <NUM_LIT:0> ) , ( '<STR_LIT:b>' , <NUM_LIT:1> ) , ( '<STR_LIT:c>' , <NUM_LIT:2> ) ] ) <EOL> self . assertEqual ( lzip ( '<STR_LIT:abc>' , count ( <NUM_LIT:3> ) ) , [ ( '<STR_LIT:a>' , <NUM_LIT:3> ) , ( '<STR_LIT:b>' , <NUM_LIT:4> ) , ( '<STR_LIT:c>' , <NUM_LIT:5> ) ] ) <EOL> self . assertEqual ( take ( <NUM_LIT:2> , lzip ( '<STR_LIT:abc>' , count ( <NUM_LIT:3> ) ) ) , [ ( '<STR_LIT:a>' , <NUM_LIT:3> ) , ( '<STR_LIT:b>' , <NUM_LIT:4> ) ] ) <EOL> self . assertEqual ( take ( <NUM_LIT:2> , zip ( '<STR_LIT:abc>' , count ( - <NUM_LIT:1> ) ) ) , [ ( '<STR_LIT:a>' , - <NUM_LIT:1> ) , ( '<STR_LIT:b>' , <NUM_LIT:0> ) ] ) <EOL> self . assertEqual ( take ( <NUM_LIT:2> , zip ( '<STR_LIT:abc>' , count ( - <NUM_LIT:3> ) ) ) , [ ( '<STR_LIT:a>' , - <NUM_LIT:3> ) , ( '<STR_LIT:b>' , - <NUM_LIT:2> ) ] ) <EOL> self . assertRaises ( TypeError , count , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ) <EOL> self . assertRaises ( TypeError , count , '<STR_LIT:a>' ) <EOL> self . assertEqual ( list ( islice ( count ( maxsize - <NUM_LIT:5> ) , <NUM_LIT:10> ) ) , <EOL> list ( range ( maxsize - <NUM_LIT:5> , maxsize + <NUM_LIT:5> ) ) ) <EOL> self . assertEqual ( list ( islice ( count ( - maxsize - <NUM_LIT:5> ) , <NUM_LIT:10> ) ) , <EOL> list ( range ( - maxsize - <NUM_LIT:5> , - maxsize + <NUM_LIT:5> ) ) ) <EOL> self . assertEqual ( list ( islice ( count ( <NUM_LIT:10> , maxsize + <NUM_LIT:5> ) , <NUM_LIT:3> ) ) , <EOL> list ( range ( <NUM_LIT:10> , <NUM_LIT:10> + <NUM_LIT:3> * ( maxsize + <NUM_LIT:5> ) , maxsize + <NUM_LIT:5> ) ) ) <EOL> c = count ( <NUM_LIT:3> ) <EOL> self . assertEqual ( repr ( c ) , '<STR_LIT>' ) <EOL> next ( c ) <EOL> self . assertEqual ( repr ( c ) , '<STR_LIT>' ) <EOL> c = count ( - <NUM_LIT:9> ) <EOL> self . assertEqual ( repr ( c ) , '<STR_LIT>' ) <EOL> next ( c ) <EOL> self . assertEqual ( repr ( count ( <NUM_LIT> ) ) , '<STR_LIT>' ) <EOL> self . assertEqual ( next ( c ) , - <NUM_LIT:8> ) <EOL> for i in ( - sys . maxsize - <NUM_LIT:5> , - sys . maxsize + <NUM_LIT:5> , - <NUM_LIT:10> , - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:10> , sys . maxsize - <NUM_LIT:5> , sys . maxsize + <NUM_LIT:5> ) : <EOL> r1 = repr ( count ( i ) ) <EOL> r2 = '<STR_LIT>' . __mod__ ( i ) <EOL> self . assertEqual ( r1 , r2 ) <EOL> for value in - <NUM_LIT:3> , <NUM_LIT:3> , maxsize - <NUM_LIT:5> , maxsize + <NUM_LIT:5> : <EOL> c = count ( value ) <EOL> self . assertEqual ( next ( copy . copy ( c ) ) , value ) <EOL> self . assertEqual ( next ( copy . deepcopy ( c ) ) , value ) <EOL> self . pickletest ( count ( value ) ) <EOL> count ( <NUM_LIT:1> , maxsize + <NUM_LIT:5> ) ; sys . exc_info ( ) <EOL> def test_count_with_stride ( self ) : <EOL> self . assertEqual ( lzip ( '<STR_LIT:abc>' , count ( <NUM_LIT:2> , <NUM_LIT:3> ) ) , [ ( '<STR_LIT:a>' , <NUM_LIT:2> ) , ( '<STR_LIT:b>' , <NUM_LIT:5> ) , ( '<STR_LIT:c>' , <NUM_LIT:8> ) ] ) <EOL> self . assertEqual ( lzip ( '<STR_LIT:abc>' , count ( start = <NUM_LIT:2> , step = <NUM_LIT:3> ) ) , <EOL> [ ( '<STR_LIT:a>' , <NUM_LIT:2> ) , ( '<STR_LIT:b>' , <NUM_LIT:5> ) , ( '<STR_LIT:c>' , <NUM_LIT:8> ) ] ) <EOL> self . assertEqual ( lzip ( '<STR_LIT:abc>' , count ( step = - <NUM_LIT:1> ) ) , <EOL> [ ( '<STR_LIT:a>' , <NUM_LIT:0> ) , ( '<STR_LIT:b>' , - <NUM_LIT:1> ) , ( '<STR_LIT:c>' , - <NUM_LIT:2> ) ] ) <EOL> self . assertEqual ( lzip ( '<STR_LIT:abc>' , count ( <NUM_LIT:2> , <NUM_LIT:0> ) ) , [ ( '<STR_LIT:a>' , <NUM_LIT:2> ) , ( '<STR_LIT:b>' , <NUM_LIT:2> ) , ( '<STR_LIT:c>' , <NUM_LIT:2> ) ] ) <EOL> self . assertEqual ( lzip ( '<STR_LIT:abc>' , count ( <NUM_LIT:2> , <NUM_LIT:1> ) ) , [ ( '<STR_LIT:a>' , <NUM_LIT:2> ) , ( '<STR_LIT:b>' , <NUM_LIT:3> ) , ( '<STR_LIT:c>' , <NUM_LIT:4> ) ] ) <EOL> self . assertEqual ( lzip ( '<STR_LIT:abc>' , count ( <NUM_LIT:2> , <NUM_LIT:3> ) ) , [ ( '<STR_LIT:a>' , <NUM_LIT:2> ) , ( '<STR_LIT:b>' , <NUM_LIT:5> ) , ( '<STR_LIT:c>' , <NUM_LIT:8> ) ] ) <EOL> self . assertEqual ( take ( <NUM_LIT:20> , count ( maxsize - <NUM_LIT:15> , <NUM_LIT:3> ) ) , take ( <NUM_LIT:20> , range ( maxsize - <NUM_LIT:15> , maxsize + <NUM_LIT:100> , <NUM_LIT:3> ) ) ) <EOL> self . assertEqual ( take ( <NUM_LIT:20> , count ( - maxsize - <NUM_LIT:15> , <NUM_LIT:3> ) ) , take ( <NUM_LIT:20> , range ( - maxsize - <NUM_LIT:15> , - maxsize + <NUM_LIT:100> , <NUM_LIT:3> ) ) ) <EOL> self . assertEqual ( take ( <NUM_LIT:3> , count ( <NUM_LIT:2> , <NUM_LIT> - <NUM_LIT> ) ) , [ <NUM_LIT:2> , <NUM_LIT> - <NUM_LIT> , <NUM_LIT> - <NUM_LIT> ] ) <EOL> self . assertEqual ( take ( <NUM_LIT:3> , count ( Decimal ( '<STR_LIT>' ) , Decimal ( '<STR_LIT>' ) ) ) , <EOL> [ Decimal ( '<STR_LIT>' ) , Decimal ( '<STR_LIT>' ) , Decimal ( '<STR_LIT>' ) ] ) <EOL> self . assertEqual ( take ( <NUM_LIT:3> , count ( Fraction ( <NUM_LIT:2> , <NUM_LIT:3> ) , Fraction ( <NUM_LIT:1> , <NUM_LIT:7> ) ) ) , <EOL> [ Fraction ( <NUM_LIT:2> , <NUM_LIT:3> ) , Fraction ( <NUM_LIT> , <NUM_LIT> ) , Fraction ( <NUM_LIT:20> , <NUM_LIT> ) ] ) <EOL> self . assertEqual ( repr ( take ( <NUM_LIT:3> , count ( <NUM_LIT:10> , <NUM_LIT> ) ) ) , repr ( [ <NUM_LIT:10> , <NUM_LIT> , <NUM_LIT> ] ) ) <EOL> c = count ( <NUM_LIT:3> , <NUM_LIT:5> ) <EOL> self . assertEqual ( repr ( c ) , '<STR_LIT>' ) <EOL> next ( c ) <EOL> self . assertEqual ( repr ( c ) , '<STR_LIT>' ) <EOL> c = count ( - <NUM_LIT:9> , <NUM_LIT:0> ) <EOL> self . assertEqual ( repr ( c ) , '<STR_LIT>' ) <EOL> next ( c ) <EOL> self . assertEqual ( repr ( c ) , '<STR_LIT>' ) <EOL> c = count ( - <NUM_LIT:9> , - <NUM_LIT:3> ) <EOL> self . assertEqual ( repr ( c ) , '<STR_LIT>' ) <EOL> next ( c ) <EOL> self . assertEqual ( repr ( c ) , '<STR_LIT>' ) <EOL> self . assertEqual ( repr ( c ) , '<STR_LIT>' ) <EOL> self . assertEqual ( repr ( count ( <NUM_LIT> , <NUM_LIT> ) ) , '<STR_LIT>' ) <EOL> self . assertEqual ( repr ( count ( <NUM_LIT> , <NUM_LIT:1> ) ) , '<STR_LIT>' ) <EOL> self . assertEqual ( repr ( count ( <NUM_LIT> , <NUM_LIT> ) ) , '<STR_LIT>' ) <EOL> for i in ( - sys . maxsize - <NUM_LIT:5> , - sys . maxsize + <NUM_LIT:5> , - <NUM_LIT:10> , - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:10> , sys . maxsize - <NUM_LIT:5> , sys . maxsize + <NUM_LIT:5> ) : <EOL> for j in ( - sys . maxsize - <NUM_LIT:5> , - sys . maxsize + <NUM_LIT:5> , - <NUM_LIT:10> , - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:10> , sys . maxsize - <NUM_LIT:5> , sys . maxsize + <NUM_LIT:5> ) : <EOL> r1 = repr ( count ( i , j ) ) <EOL> if j == <NUM_LIT:1> : <EOL> r2 = ( '<STR_LIT>' % i ) <EOL> else : <EOL> r2 = ( '<STR_LIT>' % ( i , j ) ) <EOL> self . assertEqual ( r1 , r2 ) <EOL> self . pickletest ( count ( i , j ) ) <EOL> def test_cycle ( self ) : <EOL> self . assertEqual ( take ( <NUM_LIT:10> , cycle ( '<STR_LIT:abc>' ) ) , list ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( list ( cycle ( '<STR_LIT>' ) ) , [ ] ) <EOL> self . assertRaises ( TypeError , cycle ) <EOL> self . assertRaises ( TypeError , cycle , <NUM_LIT:5> ) <EOL> self . assertEqual ( list ( islice ( cycle ( gen3 ( ) ) , <NUM_LIT:10> ) ) , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:0> ] ) <EOL> c = cycle ( '<STR_LIT:abc>' ) <EOL> self . assertEqual ( next ( c ) , '<STR_LIT:a>' ) <EOL> self . assertEqual ( take ( <NUM_LIT:10> , copy . deepcopy ( c ) ) , list ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( take ( <NUM_LIT:10> , pickle . loads ( pickle . dumps ( c ) ) ) , list ( '<STR_LIT>' ) ) <EOL> next ( c ) <EOL> self . assertEqual ( take ( <NUM_LIT:10> , pickle . loads ( pickle . dumps ( c ) ) ) , list ( '<STR_LIT>' ) ) <EOL> self . pickletest ( cycle ( '<STR_LIT:abc>' ) ) <EOL> def test_groupby ( self ) : <EOL> self . assertEqual ( [ ] , list ( groupby ( [ ] ) ) ) <EOL> self . assertEqual ( [ ] , list ( groupby ( [ ] , key = id ) ) ) <EOL> self . assertRaises ( TypeError , list , groupby ( '<STR_LIT:abc>' , [ ] ) ) <EOL> self . assertRaises ( TypeError , groupby , None ) <EOL> self . assertRaises ( TypeError , groupby , '<STR_LIT:abc>' , lambda x : x , <NUM_LIT:10> ) <EOL> s = [ ( <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT:20> ) , ( <NUM_LIT:0> , <NUM_LIT:11> , <NUM_LIT> ) , ( <NUM_LIT:0> , <NUM_LIT:12> , <NUM_LIT> ) , ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT> ) , <EOL> ( <NUM_LIT:2> , <NUM_LIT:15> , <NUM_LIT> ) , ( <NUM_LIT:3> , <NUM_LIT:16> , <NUM_LIT> ) , ( <NUM_LIT:3> , <NUM_LIT> , <NUM_LIT> ) ] <EOL> dup = [ ] <EOL> for k , g in groupby ( s , lambda r : r [ <NUM_LIT:0> ] ) : <EOL> for elem in g : <EOL> self . assertEqual ( k , elem [ <NUM_LIT:0> ] ) <EOL> dup . append ( elem ) <EOL> self . assertEqual ( s , dup ) <EOL> dup = [ ] <EOL> for k , g in pickle . loads ( pickle . dumps ( groupby ( s , testR ) ) ) : <EOL> for elem in g : <EOL> self . assertEqual ( k , elem [ <NUM_LIT:0> ] ) <EOL> dup . append ( elem ) <EOL> self . assertEqual ( s , dup ) <EOL> dup = [ ] <EOL> for k , g in groupby ( s , testR ) : <EOL> for ik , ig in groupby ( g , testR2 ) : <EOL> for elem in ig : <EOL> self . assertEqual ( k , elem [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( ik , elem [ <NUM_LIT:2> ] ) <EOL> dup . append ( elem ) <EOL> self . assertEqual ( s , dup ) <EOL> dup = [ ] <EOL> for k , g in pickle . loads ( pickle . dumps ( groupby ( s , testR ) ) ) : <EOL> for ik , ig in pickle . loads ( pickle . dumps ( groupby ( g , testR2 ) ) ) : <EOL> for elem in ig : <EOL> self . assertEqual ( k , elem [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( ik , elem [ <NUM_LIT:2> ] ) <EOL> dup . append ( elem ) <EOL> self . assertEqual ( s , dup ) <EOL> keys = [ k for k , g in groupby ( s , testR ) ] <EOL> expectedkeys = set ( [ r [ <NUM_LIT:0> ] for r in s ] ) <EOL> self . assertEqual ( set ( keys ) , expectedkeys ) <EOL> self . assertEqual ( len ( keys ) , len ( expectedkeys ) ) <EOL> s = '<STR_LIT>' <EOL> r = [ k for k , g in groupby ( sorted ( s ) ) ] <EOL> self . assertEqual ( r , [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' , '<STR_LIT:d>' , '<STR_LIT:r>' ] ) <EOL> r = [ k for k , g in groupby ( sorted ( s ) ) if list ( islice ( g , <NUM_LIT:1> , <NUM_LIT:2> ) ) ] <EOL> self . assertEqual ( r , [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:r>' ] ) <EOL> r = [ ( len ( list ( g ) ) , k ) for k , g in groupby ( sorted ( s ) ) ] <EOL> self . assertEqual ( r , [ ( <NUM_LIT:5> , '<STR_LIT:a>' ) , ( <NUM_LIT:2> , '<STR_LIT:b>' ) , ( <NUM_LIT:1> , '<STR_LIT:c>' ) , ( <NUM_LIT:1> , '<STR_LIT:d>' ) , ( <NUM_LIT:2> , '<STR_LIT:r>' ) ] ) <EOL> r = sorted ( [ ( len ( list ( g ) ) , k ) for k , g in groupby ( sorted ( s ) ) ] , reverse = True ) [ : <NUM_LIT:3> ] <EOL> self . assertEqual ( r , [ ( <NUM_LIT:5> , '<STR_LIT:a>' ) , ( <NUM_LIT:2> , '<STR_LIT:r>' ) , ( <NUM_LIT:2> , '<STR_LIT:b>' ) ] ) <EOL> class ExpectedError ( Exception ) : <EOL> pass <EOL> def delayed_raise ( n = <NUM_LIT:0> ) : <EOL> for i in range ( n ) : <EOL> yield '<STR_LIT>' <EOL> raise ExpectedError <EOL> def gulp ( iterable , keyp = None , func = list ) : <EOL> return [ func ( g ) for k , g in groupby ( iterable , keyp ) ] <EOL> self . assertRaises ( ExpectedError , gulp , delayed_raise ( <NUM_LIT:0> ) ) <EOL> self . assertRaises ( ExpectedError , gulp , delayed_raise ( <NUM_LIT:1> ) ) <EOL> class DummyCmp : <EOL> def __eq__ ( self , dst ) : <EOL> raise ExpectedError <EOL> s = [ DummyCmp ( ) , DummyCmp ( ) , None ] <EOL> self . assertRaises ( ExpectedError , gulp , s , func = id ) <EOL> self . assertRaises ( ExpectedError , gulp , s ) <EOL> def keyfunc ( obj ) : <EOL> if keyfunc . skip > <NUM_LIT:0> : <EOL> keyfunc . skip -= <NUM_LIT:1> <EOL> return obj <EOL> else : <EOL> raise ExpectedError <EOL> keyfunc . skip = <NUM_LIT:0> <EOL> self . assertRaises ( ExpectedError , gulp , [ None ] , keyfunc ) <EOL> keyfunc . skip = <NUM_LIT:1> <EOL> self . assertRaises ( ExpectedError , gulp , [ None , None ] , keyfunc ) <EOL> def test_filter ( self ) : <EOL> self . assertEqual ( list ( filter ( isEven , range ( <NUM_LIT:6> ) ) ) , [ <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:4> ] ) <EOL> self . assertEqual ( list ( filter ( None , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:0> ] ) ) , [ <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> self . assertEqual ( list ( filter ( bool , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:0> ] ) ) , [ <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> self . assertEqual ( take ( <NUM_LIT:4> , filter ( isEven , count ( ) ) ) , [ <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> ] ) <EOL> self . assertRaises ( TypeError , filter ) <EOL> self . assertRaises ( TypeError , filter , lambda x : x ) <EOL> self . assertRaises ( TypeError , filter , lambda x : x , range ( <NUM_LIT:6> ) , <NUM_LIT:7> ) <EOL> self . assertRaises ( TypeError , filter , isEven , <NUM_LIT:3> ) <EOL> self . assertRaises ( TypeError , next , filter ( range ( <NUM_LIT:6> ) , range ( <NUM_LIT:6> ) ) ) <EOL> ans = [ <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:4> ] <EOL> c = filter ( isEven , range ( <NUM_LIT:6> ) ) <EOL> self . assertEqual ( list ( copy . copy ( c ) ) , ans ) <EOL> c = filter ( isEven , range ( <NUM_LIT:6> ) ) <EOL> self . assertEqual ( list ( copy . deepcopy ( c ) ) , ans ) <EOL> c = filter ( isEven , range ( <NUM_LIT:6> ) ) <EOL> self . assertEqual ( list ( pickle . loads ( pickle . dumps ( c ) ) ) , ans ) <EOL> next ( c ) <EOL> self . assertEqual ( list ( pickle . loads ( pickle . dumps ( c ) ) ) , ans [ <NUM_LIT:1> : ] ) <EOL> c = filter ( isEven , range ( <NUM_LIT:6> ) ) <EOL> self . pickletest ( c ) <EOL> def test_filterfalse ( self ) : <EOL> self . assertEqual ( list ( filterfalse ( isEven , range ( <NUM_LIT:6> ) ) ) , [ <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:5> ] ) <EOL> self . assertEqual ( list ( filterfalse ( None , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:0> ] ) ) , [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] ) <EOL> self . assertEqual ( list ( filterfalse ( bool , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:0> ] ) ) , [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] ) <EOL> self . assertEqual ( take ( <NUM_LIT:4> , filterfalse ( isEven , count ( ) ) ) , [ <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:5> , <NUM_LIT:7> ] ) <EOL> self . assertRaises ( TypeError , filterfalse ) <EOL> self . assertRaises ( TypeError , filterfalse , lambda x : x ) <EOL> self . assertRaises ( TypeError , filterfalse , lambda x : x , range ( <NUM_LIT:6> ) , <NUM_LIT:7> ) <EOL> self . assertRaises ( TypeError , filterfalse , isEven , <NUM_LIT:3> ) <EOL> self . assertRaises ( TypeError , next , filterfalse ( range ( <NUM_LIT:6> ) , range ( <NUM_LIT:6> ) ) ) <EOL> self . pickletest ( filterfalse ( isEven , range ( <NUM_LIT:6> ) ) ) <EOL> def test_zip ( self ) : <EOL> ans = [ ( x , y ) for x , y in zip ( '<STR_LIT:abc>' , count ( ) ) ] <EOL> self . assertEqual ( ans , [ ( '<STR_LIT:a>' , <NUM_LIT:0> ) , ( '<STR_LIT:b>' , <NUM_LIT:1> ) , ( '<STR_LIT:c>' , <NUM_LIT:2> ) ] ) <EOL> self . assertEqual ( list ( zip ( '<STR_LIT:abc>' , range ( <NUM_LIT:6> ) ) ) , lzip ( '<STR_LIT:abc>' , range ( <NUM_LIT:6> ) ) ) <EOL> self . assertEqual ( list ( zip ( '<STR_LIT>' , range ( <NUM_LIT:3> ) ) ) , lzip ( '<STR_LIT>' , range ( <NUM_LIT:3> ) ) ) <EOL> self . assertEqual ( take ( <NUM_LIT:3> , zip ( '<STR_LIT>' , count ( ) ) ) , lzip ( '<STR_LIT>' , range ( <NUM_LIT:3> ) ) ) <EOL> self . assertEqual ( list ( zip ( '<STR_LIT>' ) ) , lzip ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( list ( zip ( ) ) , lzip ( ) ) <EOL> self . assertRaises ( TypeError , zip , <NUM_LIT:3> ) <EOL> self . assertRaises ( TypeError , zip , range ( <NUM_LIT:3> ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( [ tuple ( list ( pair ) ) for pair in zip ( '<STR_LIT:abc>' , '<STR_LIT>' ) ] , <EOL> lzip ( '<STR_LIT:abc>' , '<STR_LIT>' ) ) <EOL> self . assertEqual ( [ pair for pair in zip ( '<STR_LIT:abc>' , '<STR_LIT>' ) ] , <EOL> lzip ( '<STR_LIT:abc>' , '<STR_LIT>' ) ) <EOL> @ support . impl_detail ( "<STR_LIT>" ) <EOL> def test_zip_tuple_reuse ( self ) : <EOL> ids = list ( map ( id , zip ( '<STR_LIT:abc>' , '<STR_LIT>' ) ) ) <EOL> self . assertEqual ( min ( ids ) , max ( ids ) ) <EOL> ids = list ( map ( id , list ( zip ( '<STR_LIT:abc>' , '<STR_LIT>' ) ) ) ) <EOL> self . assertEqual ( len ( dict . fromkeys ( ids ) ) , len ( ids ) ) <EOL> ans = [ ( x , y ) for x , y in copy . copy ( zip ( '<STR_LIT:abc>' , count ( ) ) ) ] <EOL> self . assertEqual ( ans , [ ( '<STR_LIT:a>' , <NUM_LIT:0> ) , ( '<STR_LIT:b>' , <NUM_LIT:1> ) , ( '<STR_LIT:c>' , <NUM_LIT:2> ) ] ) <EOL> ans = [ ( x , y ) for x , y in copy . deepcopy ( zip ( '<STR_LIT:abc>' , count ( ) ) ) ] <EOL> self . assertEqual ( ans , [ ( '<STR_LIT:a>' , <NUM_LIT:0> ) , ( '<STR_LIT:b>' , <NUM_LIT:1> ) , ( '<STR_LIT:c>' , <NUM_LIT:2> ) ] ) <EOL> ans = [ ( x , y ) for x , y in pickle . loads ( pickle . dumps ( zip ( '<STR_LIT:abc>' , count ( ) ) ) ) ] <EOL> self . assertEqual ( ans , [ ( '<STR_LIT:a>' , <NUM_LIT:0> ) , ( '<STR_LIT:b>' , <NUM_LIT:1> ) , ( '<STR_LIT:c>' , <NUM_LIT:2> ) ] ) <EOL> testIntermediate = zip ( '<STR_LIT:abc>' , count ( ) ) <EOL> next ( testIntermediate ) <EOL> ans = [ ( x , y ) for x , y in pickle . loads ( pickle . dumps ( testIntermediate ) ) ] <EOL> self . assertEqual ( ans , [ ( '<STR_LIT:b>' , <NUM_LIT:1> ) , ( '<STR_LIT:c>' , <NUM_LIT:2> ) ] ) <EOL> self . pickletest ( zip ( '<STR_LIT:abc>' , count ( ) ) ) <EOL> def test_ziplongest ( self ) : <EOL> for args in [ <EOL> [ '<STR_LIT:abc>' , range ( <NUM_LIT:6> ) ] , <EOL> [ range ( <NUM_LIT:6> ) , '<STR_LIT:abc>' ] , <EOL> [ range ( <NUM_LIT:1000> ) , range ( <NUM_LIT> , <NUM_LIT> ) , range ( <NUM_LIT> , <NUM_LIT> ) ] , <EOL> [ range ( <NUM_LIT:1000> ) , range ( <NUM_LIT:0> ) , range ( <NUM_LIT> , <NUM_LIT> ) , range ( <NUM_LIT> ) , range ( <NUM_LIT> ) ] , <EOL> [ range ( <NUM_LIT:1000> ) , range ( <NUM_LIT:0> ) , range ( <NUM_LIT> , <NUM_LIT> ) , range ( <NUM_LIT> ) , range ( <NUM_LIT> ) , range ( <NUM_LIT:0> ) ] , <EOL> ] : <EOL> target = [ tuple ( [ arg [ i ] if i < len ( arg ) else None for arg in args ] ) <EOL> for i in range ( max ( map ( len , args ) ) ) ] <EOL> self . assertEqual ( list ( zip_longest ( * args ) ) , target ) <EOL> self . assertEqual ( list ( zip_longest ( * args , ** { } ) ) , target ) <EOL> target = [ tuple ( ( e is None and '<STR_LIT:X>' or e ) for e in t ) for t in target ] <EOL> self . assertEqual ( list ( zip_longest ( * args , ** dict ( fillvalue = '<STR_LIT:X>' ) ) ) , target ) <EOL> self . assertEqual ( take ( <NUM_LIT:3> , zip_longest ( '<STR_LIT>' , count ( ) ) ) , list ( zip ( '<STR_LIT>' , range ( <NUM_LIT:3> ) ) ) ) <EOL> self . assertEqual ( list ( zip_longest ( ) ) , list ( zip ( ) ) ) <EOL> self . assertEqual ( list ( zip_longest ( [ ] ) ) , list ( zip ( [ ] ) ) ) <EOL> self . assertEqual ( list ( zip_longest ( '<STR_LIT>' ) ) , list ( zip ( '<STR_LIT>' ) ) ) <EOL> self . assertEqual ( list ( zip_longest ( '<STR_LIT:abc>' , '<STR_LIT>' , ** { } ) ) , <EOL> list ( zip ( list ( '<STR_LIT:abc>' ) + [ None ] , '<STR_LIT>' ) ) ) <EOL> self . assertRaises ( TypeError , zip_longest , <NUM_LIT:3> ) <EOL> self . assertRaises ( TypeError , zip_longest , range ( <NUM_LIT:3> ) , <NUM_LIT:3> ) <EOL> for stmt in [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] : <EOL> try : <EOL> eval ( stmt , globals ( ) , locals ( ) ) <EOL> except TypeError : <EOL> pass <EOL> else : <EOL> self . fail ( '<STR_LIT>' + stmt ) <EOL> self . assertEqual ( [ tuple ( list ( pair ) ) for pair in zip_longest ( '<STR_LIT:abc>' , '<STR_LIT>' ) ] , <EOL> list ( zip ( '<STR_LIT:abc>' , '<STR_LIT>' ) ) ) <EOL> self . assertEqual ( [ pair for pair in zip_longest ( '<STR_LIT:abc>' , '<STR_LIT>' ) ] , <EOL> list ( zip ( '<STR_LIT:abc>' , '<STR_LIT>' ) ) ) <EOL> @ support . impl_detail ( "<STR_LIT>" ) <EOL> def test_zip_longest_tuple_reuse ( self ) : <EOL> ids = list ( map ( id , zip_longest ( '<STR_LIT:abc>' , '<STR_LIT>' ) ) ) <EOL> self . assertEqual ( min ( ids ) , max ( ids ) ) <EOL> ids = list ( map ( id , list ( zip_longest ( '<STR_LIT:abc>' , '<STR_LIT>' ) ) ) ) <EOL> self . assertEqual ( len ( dict . fromkeys ( ids ) ) , len ( ids ) ) <EOL> def test_zip_longest_pickling ( self ) : <EOL> self . pickletest ( zip_longest ( "<STR_LIT:abc>" , "<STR_LIT>" ) ) <EOL> self . pickletest ( zip_longest ( "<STR_LIT:abc>" , "<STR_LIT>" ) ) <EOL> self . pickletest ( zip_longest ( "<STR_LIT:abc>" , "<STR_LIT>" , fillvalue = <NUM_LIT:1> ) ) <EOL> self . pickletest ( zip_longest ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> def test_bug_7244 ( self ) : <EOL> class Repeater : <EOL> def __init__ ( self , o , t , e ) : <EOL> self . o = o <EOL> self . t = int ( t ) <EOL> self . e = e <EOL> def __iter__ ( self ) : <EOL> return self <EOL> def __next__ ( self ) : <EOL> if self . t > <NUM_LIT:0> : <EOL> self . t -= <NUM_LIT:1> <EOL> return self . o <EOL> else : <EOL> raise self . e <EOL> r1 = Repeater ( <NUM_LIT:1> , <NUM_LIT:3> , StopIteration ) <EOL> r2 = Repeater ( <NUM_LIT:2> , <NUM_LIT:4> , StopIteration ) <EOL> def run ( r1 , r2 ) : <EOL> result = [ ] <EOL> for i , j in zip_longest ( r1 , r2 , fillvalue = <NUM_LIT:0> ) : <EOL> with support . captured_output ( '<STR_LIT>' ) : <EOL> print ( ( i , j ) ) <EOL> result . append ( ( i , j ) ) <EOL> return result <EOL> self . assertEqual ( run ( r1 , r2 ) , [ ( <NUM_LIT:1> , <NUM_LIT:2> ) , ( <NUM_LIT:1> , <NUM_LIT:2> ) , ( <NUM_LIT:1> , <NUM_LIT:2> ) , ( <NUM_LIT:0> , <NUM_LIT:2> ) ] ) <EOL> r1 = Repeater ( <NUM_LIT:1> , <NUM_LIT:3> , RuntimeError ) <EOL> r2 = Repeater ( <NUM_LIT:2> , <NUM_LIT:4> , StopIteration ) <EOL> it = zip_longest ( r1 , r2 , fillvalue = <NUM_LIT:0> ) <EOL> self . assertEqual ( next ( it ) , ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> self . assertEqual ( next ( it ) , ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> self . assertEqual ( next ( it ) , ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> self . assertRaises ( RuntimeError , next , it ) <EOL> def test_product ( self ) : <EOL> for args , result in [ <EOL> ( [ ] , [ ( ) ] ) , <EOL> ( [ '<STR_LIT>' ] , [ ( '<STR_LIT:a>' , ) , ( '<STR_LIT:b>' , ) ] ) , <EOL> ( [ range ( <NUM_LIT:2> ) , range ( <NUM_LIT:3> ) ] , [ ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( <NUM_LIT:0> , <NUM_LIT:2> ) , ( <NUM_LIT:1> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , ( <NUM_LIT:1> , <NUM_LIT:2> ) ] ) , <EOL> ( [ range ( <NUM_LIT:0> ) , range ( <NUM_LIT:2> ) , range ( <NUM_LIT:3> ) ] , [ ] ) , <EOL> ( [ range ( <NUM_LIT:2> ) , range ( <NUM_LIT:0> ) , range ( <NUM_LIT:3> ) ] , [ ] ) , <EOL> ( [ range ( <NUM_LIT:2> ) , range ( <NUM_LIT:3> ) , range ( <NUM_LIT:0> ) ] , [ ] ) , <EOL> ] : <EOL> self . assertEqual ( list ( product ( * args ) ) , result ) <EOL> for r in range ( <NUM_LIT:4> ) : <EOL> self . assertEqual ( list ( product ( * ( args * r ) ) ) , <EOL> list ( product ( * args , ** dict ( repeat = r ) ) ) ) <EOL> self . assertEqual ( len ( list ( product ( * [ range ( <NUM_LIT:7> ) ] * <NUM_LIT:6> ) ) ) , <NUM_LIT:7> ** <NUM_LIT:6> ) <EOL> self . assertRaises ( TypeError , product , range ( <NUM_LIT:6> ) , None ) <EOL> def product1 ( * args , ** kwds ) : <EOL> pools = list ( map ( tuple , args ) ) * kwds . get ( '<STR_LIT>' , <NUM_LIT:1> ) <EOL> n = len ( pools ) <EOL> if n == <NUM_LIT:0> : <EOL> yield ( ) <EOL> return <EOL> if any ( len ( pool ) == <NUM_LIT:0> for pool in pools ) : <EOL> return <EOL> indices = [ <NUM_LIT:0> ] * n <EOL> yield tuple ( pool [ i ] for pool , i in zip ( pools , indices ) ) <EOL> while <NUM_LIT:1> : <EOL> for i in reversed ( range ( n ) ) : <EOL> if indices [ i ] == len ( pools [ i ] ) - <NUM_LIT:1> : <EOL> continue <EOL> indices [ i ] += <NUM_LIT:1> <EOL> for j in range ( i + <NUM_LIT:1> , n ) : <EOL> indices [ j ] = <NUM_LIT:0> <EOL> yield tuple ( pool [ i ] for pool , i in zip ( pools , indices ) ) <EOL> break <EOL> else : <EOL> return <EOL> def product2 ( * args , ** kwds ) : <EOL> '<STR_LIT>' <EOL> pools = list ( map ( tuple , args ) ) * kwds . get ( '<STR_LIT>' , <NUM_LIT:1> ) <EOL> result = [ [ ] ] <EOL> for pool in pools : <EOL> result = [ x + [ y ] for x in result for y in pool ] <EOL> for prod in result : <EOL> yield tuple ( prod ) <EOL> argtypes = [ '<STR_LIT>' , '<STR_LIT:abc>' , '<STR_LIT>' , range ( <NUM_LIT:0> ) , range ( <NUM_LIT:4> ) , dict ( a = <NUM_LIT:1> , b = <NUM_LIT:2> , c = <NUM_LIT:3> ) , <EOL> set ( '<STR_LIT>' ) , range ( <NUM_LIT:11> ) , tuple ( range ( <NUM_LIT> ) ) ] <EOL> for i in range ( <NUM_LIT:100> ) : <EOL> args = [ random . choice ( argtypes ) for j in range ( random . randrange ( <NUM_LIT:5> ) ) ] <EOL> expected_len = prod ( map ( len , args ) ) <EOL> self . assertEqual ( len ( list ( product ( * args ) ) ) , expected_len ) <EOL> self . assertEqual ( list ( product ( * args ) ) , list ( product1 ( * args ) ) ) <EOL> self . assertEqual ( list ( product ( * args ) ) , list ( product2 ( * args ) ) ) <EOL> args = map ( iter , args ) <EOL> self . assertEqual ( len ( list ( product ( * args ) ) ) , expected_len ) <EOL> @ support . impl_detail ( "<STR_LIT>" ) <EOL> def test_product_tuple_reuse ( self ) : <EOL> self . assertEqual ( len ( set ( map ( id , product ( '<STR_LIT:abc>' , '<STR_LIT>' ) ) ) ) , <NUM_LIT:1> ) <EOL> self . assertNotEqual ( len ( set ( map ( id , list ( product ( '<STR_LIT:abc>' , '<STR_LIT>' ) ) ) ) ) , <NUM_LIT:1> ) <EOL> def test_product_pickling ( self ) : <EOL> for args , result in [ <EOL> ( [ ] , [ ( ) ] ) , <EOL> ( [ '<STR_LIT>' ] , [ ( '<STR_LIT:a>' , ) , ( '<STR_LIT:b>' , ) ] ) , <EOL> ( [ range ( <NUM_LIT:2> ) , range ( <NUM_LIT:3> ) ] , [ ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( <NUM_LIT:0> , <NUM_LIT:2> ) , ( <NUM_LIT:1> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , ( <NUM_LIT:1> , <NUM_LIT:2> ) ] ) , <EOL> ( [ range ( <NUM_LIT:0> ) , range ( <NUM_LIT:2> ) , range ( <NUM_LIT:3> ) ] , [ ] ) , <EOL> ( [ range ( <NUM_LIT:2> ) , range ( <NUM_LIT:0> ) , range ( <NUM_LIT:3> ) ] , [ ] ) , <EOL> ( [ range ( <NUM_LIT:2> ) , range ( <NUM_LIT:3> ) , range ( <NUM_LIT:0> ) ] , [ ] ) , <EOL> ] : <EOL> self . assertEqual ( list ( copy . copy ( product ( * args ) ) ) , result ) <EOL> self . assertEqual ( list ( copy . deepcopy ( product ( * args ) ) ) , result ) <EOL> self . pickletest ( product ( * args ) ) <EOL> def test_repeat ( self ) : <EOL> self . assertEqual ( list ( repeat ( object = '<STR_LIT:a>' , times = <NUM_LIT:3> ) ) , [ '<STR_LIT:a>' , '<STR_LIT:a>' , '<STR_LIT:a>' ] ) <EOL> self . assertEqual ( lzip ( range ( <NUM_LIT:3> ) , repeat ( '<STR_LIT:a>' ) ) , <EOL> [ ( <NUM_LIT:0> , '<STR_LIT:a>' ) , ( <NUM_LIT:1> , '<STR_LIT:a>' ) , ( <NUM_LIT:2> , '<STR_LIT:a>' ) ] ) <EOL> self . assertEqual ( list ( repeat ( '<STR_LIT:a>' , <NUM_LIT:3> ) ) , [ '<STR_LIT:a>' , '<STR_LIT:a>' , '<STR_LIT:a>' ] ) <EOL> self . assertEqual ( take ( <NUM_LIT:3> , repeat ( '<STR_LIT:a>' ) ) , [ '<STR_LIT:a>' , '<STR_LIT:a>' , '<STR_LIT:a>' ] ) <EOL> self . assertEqual ( list ( repeat ( '<STR_LIT:a>' , <NUM_LIT:0> ) ) , [ ] ) <EOL> self . assertEqual ( list ( repeat ( '<STR_LIT:a>' , - <NUM_LIT:3> ) ) , [ ] ) <EOL> self . assertRaises ( TypeError , repeat ) <EOL> self . assertRaises ( TypeError , repeat , None , <NUM_LIT:3> , <NUM_LIT:4> ) <EOL> self . assertRaises ( TypeError , repeat , None , '<STR_LIT:a>' ) <EOL> r = repeat ( <NUM_LIT:1> + <NUM_LIT> ) <EOL> self . assertEqual ( repr ( r ) , '<STR_LIT>' ) <EOL> r = repeat ( <NUM_LIT:1> + <NUM_LIT> , <NUM_LIT:5> ) <EOL> self . assertEqual ( repr ( r ) , '<STR_LIT>' ) <EOL> list ( r ) <EOL> self . assertEqual ( repr ( r ) , '<STR_LIT>' ) <EOL> c = repeat ( object = '<STR_LIT:a>' , times = <NUM_LIT:10> ) <EOL> self . assertEqual ( next ( c ) , '<STR_LIT:a>' ) <EOL> self . assertEqual ( take ( <NUM_LIT:2> , copy . copy ( c ) ) , list ( '<STR_LIT:a>' * <NUM_LIT:2> ) ) <EOL> self . assertEqual ( take ( <NUM_LIT:2> , copy . deepcopy ( c ) ) , list ( '<STR_LIT:a>' * <NUM_LIT:2> ) ) <EOL> self . pickletest ( repeat ( object = '<STR_LIT:a>' , times = <NUM_LIT:10> ) ) <EOL> def test_map ( self ) : <EOL> self . assertEqual ( list ( map ( operator . pow , range ( <NUM_LIT:3> ) , range ( <NUM_LIT:1> , <NUM_LIT:7> ) ) ) , <EOL> [ <NUM_LIT:0> ** <NUM_LIT:1> , <NUM_LIT:1> ** <NUM_LIT:2> , <NUM_LIT:2> ** <NUM_LIT:3> ] ) <EOL> self . assertEqual ( list ( map ( tupleize , '<STR_LIT:abc>' , range ( <NUM_LIT:5> ) ) ) , <EOL> [ ( '<STR_LIT:a>' , <NUM_LIT:0> ) , ( '<STR_LIT:b>' , <NUM_LIT:1> ) , ( '<STR_LIT:c>' , <NUM_LIT:2> ) ] ) <EOL> self . assertEqual ( list ( map ( tupleize , '<STR_LIT:abc>' , count ( ) ) ) , <EOL> [ ( '<STR_LIT:a>' , <NUM_LIT:0> ) , ( '<STR_LIT:b>' , <NUM_LIT:1> ) , ( '<STR_LIT:c>' , <NUM_LIT:2> ) ] ) <EOL> self . assertEqual ( take ( <NUM_LIT:2> , map ( tupleize , '<STR_LIT:abc>' , count ( ) ) ) , <EOL> [ ( '<STR_LIT:a>' , <NUM_LIT:0> ) , ( '<STR_LIT:b>' , <NUM_LIT:1> ) ] ) <EOL> self . assertEqual ( list ( map ( operator . pow , [ ] ) ) , [ ] ) <EOL> self . assertRaises ( TypeError , map ) <EOL> self . assertRaises ( TypeError , list , map ( None , range ( <NUM_LIT:3> ) , range ( <NUM_LIT:3> ) ) ) <EOL> self . assertRaises ( TypeError , map , operator . neg ) <EOL> self . assertRaises ( TypeError , next , map ( <NUM_LIT:10> , range ( <NUM_LIT:5> ) ) ) <EOL> self . assertRaises ( ValueError , next , map ( errfunc , [ <NUM_LIT:4> ] , [ <NUM_LIT:5> ] ) ) <EOL> self . assertRaises ( TypeError , next , map ( onearg , [ <NUM_LIT:4> ] , [ <NUM_LIT:5> ] ) ) <EOL> ans = [ ( '<STR_LIT:a>' , <NUM_LIT:0> ) , ( '<STR_LIT:b>' , <NUM_LIT:1> ) , ( '<STR_LIT:c>' , <NUM_LIT:2> ) ] <EOL> c = map ( tupleize , '<STR_LIT:abc>' , count ( ) ) <EOL> self . assertEqual ( list ( copy . copy ( c ) ) , ans ) <EOL> c = map ( tupleize , '<STR_LIT:abc>' , count ( ) ) <EOL> self . assertEqual ( list ( copy . deepcopy ( c ) ) , ans ) <EOL> c = map ( tupleize , '<STR_LIT:abc>' , count ( ) ) <EOL> self . pickletest ( c ) <EOL> def test_starmap ( self ) : <EOL> self . assertEqual ( list ( starmap ( operator . pow , zip ( range ( <NUM_LIT:3> ) , range ( <NUM_LIT:1> , <NUM_LIT:7> ) ) ) ) , <EOL> [ <NUM_LIT:0> ** <NUM_LIT:1> , <NUM_LIT:1> ** <NUM_LIT:2> , <NUM_LIT:2> ** <NUM_LIT:3> ] ) <EOL> self . assertEqual ( take ( <NUM_LIT:3> , starmap ( operator . pow , zip ( count ( ) , count ( <NUM_LIT:1> ) ) ) ) , <EOL> [ <NUM_LIT:0> ** <NUM_LIT:1> , <NUM_LIT:1> ** <NUM_LIT:2> , <NUM_LIT:2> ** <NUM_LIT:3> ] ) <EOL> self . assertEqual ( list ( starmap ( operator . pow , [ ] ) ) , [ ] ) <EOL> self . assertEqual ( list ( starmap ( operator . pow , [ iter ( [ <NUM_LIT:4> , <NUM_LIT:5> ] ) ] ) ) , [ <NUM_LIT:4> ** <NUM_LIT:5> ] ) <EOL> self . assertRaises ( TypeError , list , starmap ( operator . pow , [ None ] ) ) <EOL> self . assertRaises ( TypeError , starmap ) <EOL> self . assertRaises ( TypeError , starmap , operator . pow , [ ( <NUM_LIT:4> , <NUM_LIT:5> ) ] , '<STR_LIT>' ) <EOL> self . assertRaises ( TypeError , next , starmap ( <NUM_LIT:10> , [ ( <NUM_LIT:4> , <NUM_LIT:5> ) ] ) ) <EOL> self . assertRaises ( ValueError , next , starmap ( errfunc , [ ( <NUM_LIT:4> , <NUM_LIT:5> ) ] ) ) <EOL> self . assertRaises ( TypeError , next , starmap ( onearg , [ ( <NUM_LIT:4> , <NUM_LIT:5> ) ] ) ) <EOL> ans = [ <NUM_LIT:0> ** <NUM_LIT:1> , <NUM_LIT:1> ** <NUM_LIT:2> , <NUM_LIT:2> ** <NUM_LIT:3> ] <EOL> c = starmap ( operator . pow , zip ( range ( <NUM_LIT:3> ) , range ( <NUM_LIT:1> , <NUM_LIT:7> ) ) ) <EOL> self . assertEqual ( list ( copy . copy ( c ) ) , ans ) <EOL> c = starmap ( operator . pow , zip ( range ( <NUM_LIT:3> ) , range ( <NUM_LIT:1> , <NUM_LIT:7> ) ) ) <EOL> self . assertEqual ( list ( copy . deepcopy ( c ) ) , ans ) <EOL> c = starmap ( operator . pow , zip ( range ( <NUM_LIT:3> ) , range ( <NUM_LIT:1> , <NUM_LIT:7> ) ) ) <EOL> self . pickletest ( c ) <EOL> def test_islice ( self ) : <EOL> for args in [ <EOL> ( <NUM_LIT:10> , <NUM_LIT:20> , <NUM_LIT:3> ) , <EOL> ( <NUM_LIT:10> , <NUM_LIT:3> , <NUM_LIT:20> ) , <EOL> ( <NUM_LIT:10> , <NUM_LIT:20> ) , <EOL> ( <NUM_LIT:10> , <NUM_LIT:3> ) , <EOL> ( <NUM_LIT:20> , ) <EOL> ] : <EOL> self . assertEqual ( list ( islice ( range ( <NUM_LIT:100> ) , * args ) ) , <EOL> list ( range ( * args ) ) ) <EOL> for args , tgtargs in [ <EOL> ( ( <NUM_LIT:10> , <NUM_LIT> , <NUM_LIT:3> ) , ( ( <NUM_LIT:10> , <NUM_LIT:100> , <NUM_LIT:3> ) ) ) , <EOL> ( ( <NUM_LIT:10> , <NUM_LIT> ) , ( ( <NUM_LIT:10> , <NUM_LIT:100> ) ) ) , <EOL> ( ( <NUM_LIT> , ) , ( <NUM_LIT:100> , ) ) <EOL> ] : <EOL> self . assertEqual ( list ( islice ( range ( <NUM_LIT:100> ) , * args ) ) , <EOL> list ( range ( * tgtargs ) ) ) <EOL> self . assertEqual ( list ( islice ( range ( <NUM_LIT:10> ) , None ) ) , list ( range ( <NUM_LIT:10> ) ) ) <EOL> self . assertEqual ( list ( islice ( range ( <NUM_LIT:10> ) , None , None ) ) , list ( range ( <NUM_LIT:10> ) ) ) <EOL> self . assertEqual ( list ( islice ( range ( <NUM_LIT:10> ) , None , None , None ) ) , list ( range ( <NUM_LIT:10> ) ) ) <EOL> self . assertEqual ( list ( islice ( range ( <NUM_LIT:10> ) , <NUM_LIT:2> , None ) ) , list ( range ( <NUM_LIT:2> , <NUM_LIT:10> ) ) ) <EOL> self . assertEqual ( list ( islice ( range ( <NUM_LIT:10> ) , <NUM_LIT:1> , None , <NUM_LIT:2> ) ) , list ( range ( <NUM_LIT:1> , <NUM_LIT:10> , <NUM_LIT:2> ) ) ) <EOL> it = iter ( range ( <NUM_LIT:10> ) ) <EOL> self . assertEqual ( list ( islice ( it , <NUM_LIT:3> ) ) , list ( range ( <NUM_LIT:3> ) ) ) <EOL> self . assertEqual ( list ( it ) , list ( range ( <NUM_LIT:3> , <NUM_LIT:10> ) ) ) <EOL> ra = range ( <NUM_LIT:10> ) <EOL> self . assertRaises ( TypeError , islice , ra ) <EOL> self . assertRaises ( TypeError , islice , ra , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ) <EOL> self . assertRaises ( ValueError , islice , ra , - <NUM_LIT:5> , <NUM_LIT:10> , <NUM_LIT:1> ) <EOL> self . assertRaises ( ValueError , islice , ra , <NUM_LIT:1> , - <NUM_LIT:5> , - <NUM_LIT:1> ) <EOL> self . assertRaises ( ValueError , islice , ra , <NUM_LIT:1> , <NUM_LIT:10> , - <NUM_LIT:1> ) <EOL> self . assertRaises ( ValueError , islice , ra , <NUM_LIT:1> , <NUM_LIT:10> , <NUM_LIT:0> ) <EOL> self . assertRaises ( ValueError , islice , ra , '<STR_LIT:a>' ) <EOL> self . assertRaises ( ValueError , islice , ra , '<STR_LIT:a>' , <NUM_LIT:1> ) <EOL> self . assertRaises ( ValueError , islice , ra , <NUM_LIT:1> , '<STR_LIT:a>' ) <EOL> self . assertRaises ( ValueError , islice , ra , '<STR_LIT:a>' , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> self . assertRaises ( ValueError , islice , ra , <NUM_LIT:1> , '<STR_LIT:a>' , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( list ( islice ( count ( ) , <NUM_LIT:1> , <NUM_LIT:10> , maxsize ) ) ) , <NUM_LIT:1> ) <EOL> c = count ( ) <EOL> self . assertEqual ( list ( islice ( c , <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:50> ) ) , [ <NUM_LIT:1> ] ) <EOL> self . assertEqual ( next ( c ) , <NUM_LIT:3> ) <EOL> for args in [ <EOL> ( <NUM_LIT:10> , <NUM_LIT:20> , <NUM_LIT:3> ) , <EOL> ( <NUM_LIT:10> , <NUM_LIT:3> , <NUM_LIT:20> ) , <EOL> ( <NUM_LIT:10> , <NUM_LIT:20> ) , <EOL> ( <NUM_LIT:10> , <NUM_LIT:3> ) , <EOL> ( <NUM_LIT:20> , ) <EOL> ] : <EOL> self . assertEqual ( list ( copy . copy ( islice ( range ( <NUM_LIT:100> ) , * args ) ) ) , <EOL> list ( range ( * args ) ) ) <EOL> self . assertEqual ( list ( copy . deepcopy ( islice ( range ( <NUM_LIT:100> ) , * args ) ) ) , <EOL> list ( range ( * args ) ) ) <EOL> self . pickletest ( islice ( range ( <NUM_LIT:100> ) , * args ) ) <EOL> def test_takewhile ( self ) : <EOL> data = [ <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:5> , <NUM_LIT:20> , <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:8> ] <EOL> self . assertEqual ( list ( takewhile ( underten , data ) ) , [ <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:5> ] ) <EOL> self . assertEqual ( list ( takewhile ( underten , [ ] ) ) , [ ] ) <EOL> self . assertRaises ( TypeError , takewhile ) <EOL> self . assertRaises ( TypeError , takewhile , operator . pow ) <EOL> self . assertRaises ( TypeError , takewhile , operator . pow , [ ( <NUM_LIT:4> , <NUM_LIT:5> ) ] , '<STR_LIT>' ) <EOL> self . assertRaises ( TypeError , next , takewhile ( <NUM_LIT:10> , [ ( <NUM_LIT:4> , <NUM_LIT:5> ) ] ) ) <EOL> self . assertRaises ( ValueError , next , takewhile ( errfunc , [ ( <NUM_LIT:4> , <NUM_LIT:5> ) ] ) ) <EOL> t = takewhile ( bool , [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] ) <EOL> self . assertEqual ( list ( t ) , [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ] ) <EOL> self . assertRaises ( StopIteration , next , t ) <EOL> self . assertEqual ( list ( copy . copy ( takewhile ( underten , data ) ) ) , [ <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:5> ] ) <EOL> self . assertEqual ( list ( copy . deepcopy ( takewhile ( underten , data ) ) ) , <EOL> [ <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:5> ] ) <EOL> self . pickletest ( takewhile ( underten , data ) ) <EOL> def test_dropwhile ( self ) : <EOL> data = [ <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:5> , <NUM_LIT:20> , <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:8> ] <EOL> self . assertEqual ( list ( dropwhile ( underten , data ) ) , [ <NUM_LIT:20> , <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:8> ] ) <EOL> self . assertEqual ( list ( dropwhile ( underten , [ ] ) ) , [ ] ) <EOL> self . assertRaises ( TypeError , dropwhile ) <EOL> self . assertRaises ( TypeError , dropwhile , operator . pow ) <EOL> self . assertRaises ( TypeError , dropwhile , operator . pow , [ ( <NUM_LIT:4> , <NUM_LIT:5> ) ] , '<STR_LIT>' ) <EOL> self . assertRaises ( TypeError , next , dropwhile ( <NUM_LIT:10> , [ ( <NUM_LIT:4> , <NUM_LIT:5> ) ] ) ) <EOL> self . assertRaises ( ValueError , next , dropwhile ( errfunc , [ ( <NUM_LIT:4> , <NUM_LIT:5> ) ] ) ) <EOL> self . assertEqual ( list ( copy . copy ( dropwhile ( underten , data ) ) ) , [ <NUM_LIT:20> , <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:8> ] ) <EOL> self . assertEqual ( list ( copy . deepcopy ( dropwhile ( underten , data ) ) ) , <EOL> [ <NUM_LIT:20> , <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:8> ] ) <EOL> self . pickletest ( dropwhile ( underten , data ) ) <EOL> def test_tee ( self ) : <EOL> n = <NUM_LIT:200> <EOL> a , b = tee ( [ ] ) <EOL> self . assertEqual ( list ( a ) , [ ] ) <EOL> self . assertEqual ( list ( b ) , [ ] ) <EOL> a , b = tee ( irange ( n ) ) <EOL> self . assertEqual ( lzip ( a , b ) , lzip ( range ( n ) , range ( n ) ) ) <EOL> a , b = tee ( irange ( n ) ) <EOL> self . assertEqual ( list ( a ) , list ( range ( n ) ) ) <EOL> self . assertEqual ( list ( b ) , list ( range ( n ) ) ) <EOL> a , b = tee ( irange ( n ) ) <EOL> for i in range ( <NUM_LIT:100> ) : <EOL> self . assertEqual ( next ( a ) , i ) <EOL> del a <EOL> self . assertEqual ( list ( b ) , list ( range ( n ) ) ) <EOL> a , b = tee ( irange ( n ) ) <EOL> for i in range ( <NUM_LIT:100> ) : <EOL> self . assertEqual ( next ( a ) , i ) <EOL> del b <EOL> self . assertEqual ( list ( a ) , list ( range ( <NUM_LIT:100> , n ) ) ) <EOL> for j in range ( <NUM_LIT:5> ) : <EOL> order = [ <NUM_LIT:0> ] * n + [ <NUM_LIT:1> ] * n <EOL> random . shuffle ( order ) <EOL> lists = ( [ ] , [ ] ) <EOL> its = tee ( irange ( n ) ) <EOL> for i in order : <EOL> value = next ( its [ i ] ) <EOL> lists [ i ] . append ( value ) <EOL> self . assertEqual ( lists [ <NUM_LIT:0> ] , list ( range ( n ) ) ) <EOL> self . assertEqual ( lists [ <NUM_LIT:1> ] , list ( range ( n ) ) ) <EOL> self . assertRaises ( TypeError , tee ) <EOL> self . assertRaises ( TypeError , tee , <NUM_LIT:3> ) <EOL> self . assertRaises ( TypeError , tee , [ <NUM_LIT:1> , <NUM_LIT:2> ] , '<STR_LIT:x>' ) <EOL> self . assertRaises ( TypeError , tee , [ <NUM_LIT:1> , <NUM_LIT:2> ] , <NUM_LIT:3> , '<STR_LIT:x>' ) <EOL> a , b = tee ( '<STR_LIT:abc>' ) <EOL> c = type ( a ) ( '<STR_LIT>' ) <EOL> self . assertEqual ( list ( c ) , list ( '<STR_LIT>' ) ) <EOL> a , b , c = tee ( range ( <NUM_LIT> ) , <NUM_LIT:3> ) <EOL> for i in range ( <NUM_LIT:100> ) : <EOL> self . assertEqual ( next ( a ) , i ) <EOL> self . assertEqual ( list ( b ) , list ( range ( <NUM_LIT> ) ) ) <EOL> self . assertEqual ( [ next ( c ) , next ( c ) ] , list ( range ( <NUM_LIT:2> ) ) ) <EOL> self . assertEqual ( list ( a ) , list ( range ( <NUM_LIT:100> , <NUM_LIT> ) ) ) <EOL> self . assertEqual ( list ( c ) , list ( range ( <NUM_LIT:2> , <NUM_LIT> ) ) ) <EOL> self . assertRaises ( TypeError , tee , '<STR_LIT:abc>' , '<STR_LIT>' ) <EOL> self . assertRaises ( ValueError , tee , [ ] , - <NUM_LIT:1> ) <EOL> for n in range ( <NUM_LIT:5> ) : <EOL> result = tee ( '<STR_LIT:abc>' , n ) <EOL> self . assertEqual ( type ( result ) , tuple ) <EOL> self . assertEqual ( len ( result ) , n ) <EOL> self . assertEqual ( [ list ( x ) for x in result ] , [ list ( '<STR_LIT:abc>' ) ] * n ) <EOL> a , b = tee ( '<STR_LIT:abc>' ) <EOL> c , d = tee ( a ) <EOL> self . assertTrue ( a is c ) <EOL> t1 , t2 = tee ( '<STR_LIT:abc>' ) <EOL> tnew = type ( t1 ) <EOL> self . assertRaises ( TypeError , tnew ) <EOL> self . assertRaises ( TypeError , tnew , <NUM_LIT:10> ) <EOL> t3 = tnew ( t1 ) <EOL> self . assertTrue ( list ( t1 ) == list ( t2 ) == list ( t3 ) == list ( '<STR_LIT:abc>' ) ) <EOL> a , b = tee ( range ( <NUM_LIT:10> ) ) <EOL> p = proxy ( a ) <EOL> self . assertEqual ( getattr ( p , '<STR_LIT>' ) , type ( b ) ) <EOL> del a <EOL> self . assertRaises ( ReferenceError , getattr , p , '<STR_LIT>' ) <EOL> ans = list ( '<STR_LIT:abc>' ) <EOL> long_ans = list ( range ( <NUM_LIT> ) ) <EOL> a , b = tee ( '<STR_LIT:abc>' ) <EOL> self . assertEqual ( list ( copy . copy ( a ) ) , ans ) <EOL> self . assertEqual ( list ( copy . copy ( b ) ) , ans ) <EOL> a , b = tee ( list ( range ( <NUM_LIT> ) ) ) <EOL> self . assertEqual ( list ( copy . copy ( a ) ) , long_ans ) <EOL> self . assertEqual ( list ( copy . copy ( b ) ) , long_ans ) <EOL> a , b = tee ( '<STR_LIT:abc>' ) <EOL> take ( <NUM_LIT:2> , a ) <EOL> take ( <NUM_LIT:1> , b ) <EOL> self . assertEqual ( list ( copy . copy ( a ) ) , ans [ <NUM_LIT:2> : ] ) <EOL> self . assertEqual ( list ( copy . copy ( b ) ) , ans [ <NUM_LIT:1> : ] ) <EOL> self . assertEqual ( list ( a ) , ans [ <NUM_LIT:2> : ] ) <EOL> self . assertEqual ( list ( b ) , ans [ <NUM_LIT:1> : ] ) <EOL> a , b = tee ( range ( <NUM_LIT> ) ) <EOL> take ( <NUM_LIT:100> , a ) <EOL> take ( <NUM_LIT> , b ) <EOL> self . assertEqual ( list ( copy . copy ( a ) ) , long_ans [ <NUM_LIT:100> : ] ) <EOL> self . assertEqual ( list ( copy . copy ( b ) ) , long_ans [ <NUM_LIT> : ] ) <EOL> self . assertEqual ( list ( a ) , long_ans [ <NUM_LIT:100> : ] ) <EOL> self . assertEqual ( list ( b ) , long_ans [ <NUM_LIT> : ] ) <EOL> a , b = tee ( '<STR_LIT:abc>' ) <EOL> self . assertEqual ( list ( copy . deepcopy ( a ) ) , ans ) <EOL> self . assertEqual ( list ( copy . deepcopy ( b ) ) , ans ) <EOL> self . assertEqual ( list ( a ) , ans ) <EOL> self . assertEqual ( list ( b ) , ans ) <EOL> a , b = tee ( range ( <NUM_LIT> ) ) <EOL> self . assertEqual ( list ( copy . deepcopy ( a ) ) , long_ans ) <EOL> self . assertEqual ( list ( copy . deepcopy ( b ) ) , long_ans ) <EOL> self . assertEqual ( list ( a ) , long_ans ) <EOL> self . assertEqual ( list ( b ) , long_ans ) <EOL> a , b = tee ( '<STR_LIT:abc>' ) <EOL> take ( <NUM_LIT:2> , a ) <EOL> take ( <NUM_LIT:1> , b ) <EOL> self . assertEqual ( list ( copy . deepcopy ( a ) ) , ans [ <NUM_LIT:2> : ] ) <EOL> self . assertEqual ( list ( copy . deepcopy ( b ) ) , ans [ <NUM_LIT:1> : ] ) <EOL> self . assertEqual ( list ( a ) , ans [ <NUM_LIT:2> : ] ) <EOL> self . assertEqual ( list ( b ) , ans [ <NUM_LIT:1> : ] ) <EOL> a , b = tee ( range ( <NUM_LIT> ) ) <EOL> take ( <NUM_LIT:100> , a ) <EOL> take ( <NUM_LIT> , b ) <EOL> self . assertEqual ( list ( copy . deepcopy ( a ) ) , long_ans [ <NUM_LIT:100> : ] ) <EOL> self . assertEqual ( list ( copy . deepcopy ( b ) ) , long_ans [ <NUM_LIT> : ] ) <EOL> self . assertEqual ( list ( a ) , long_ans [ <NUM_LIT:100> : ] ) <EOL> self . assertEqual ( list ( b ) , long_ans [ <NUM_LIT> : ] ) <EOL> self . pickletest ( iter ( tee ( '<STR_LIT:abc>' ) ) ) <EOL> a , b = tee ( '<STR_LIT:abc>' ) <EOL> self . pickletest ( a , compare = ans ) <EOL> self . pickletest ( b , compare = ans ) <EOL> def test_tee_del_backward ( self ) : <EOL> forward , backward = tee ( repeat ( None , <NUM_LIT> ) ) <EOL> any ( forward ) <EOL> del backward <EOL> def test_StopIteration ( self ) : <EOL> self . assertRaises ( StopIteration , next , zip ( ) ) <EOL> for f in ( chain , cycle , zip , groupby ) : <EOL> self . assertRaises ( StopIteration , next , f ( [ ] ) ) <EOL> self . assertRaises ( StopIteration , next , f ( StopNow ( ) ) ) <EOL> self . assertRaises ( StopIteration , next , islice ( [ ] , None ) ) <EOL> self . assertRaises ( StopIteration , next , islice ( StopNow ( ) , None ) ) <EOL> p , q = tee ( [ ] ) <EOL> self . assertRaises ( StopIteration , next , p ) <EOL> self . assertRaises ( StopIteration , next , q ) <EOL> p , q = tee ( StopNow ( ) ) <EOL> self . assertRaises ( StopIteration , next , p ) <EOL> self . assertRaises ( StopIteration , next , q ) <EOL> self . assertRaises ( StopIteration , next , repeat ( None , <NUM_LIT:0> ) ) <EOL> for f in ( filter , filterfalse , map , takewhile , dropwhile , starmap ) : <EOL> self . assertRaises ( StopIteration , next , f ( lambda x : x , [ ] ) ) <EOL> self . assertRaises ( StopIteration , next , f ( lambda x : x , StopNow ( ) ) ) <EOL> class TestExamples ( unittest . TestCase ) : <EOL> def test_accumulate ( self ) : <EOL> self . assertEqual ( list ( accumulate ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] ) ) , [ <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:6> , <NUM_LIT:10> , <NUM_LIT:15> ] ) <EOL> def test_accumulate_reducible ( self ) : <EOL> data = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] <EOL> accumulated = [ <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:6> , <NUM_LIT:10> , <NUM_LIT:15> ] <EOL> it = accumulate ( data ) <EOL> self . assertEqual ( list ( pickle . loads ( pickle . dumps ( it ) ) ) , accumulated [ : ] ) <EOL> self . assertEqual ( next ( it ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( list ( pickle . loads ( pickle . dumps ( it ) ) ) , accumulated [ <NUM_LIT:1> : ] ) <EOL> self . assertEqual ( list ( copy . deepcopy ( it ) ) , accumulated [ <NUM_LIT:1> : ] ) <EOL> self . assertEqual ( list ( copy . copy ( it ) ) , accumulated [ <NUM_LIT:1> : ] ) <EOL> def test_chain ( self ) : <EOL> self . assertEqual ( '<STR_LIT>' . join ( chain ( '<STR_LIT>' , '<STR_LIT>' ) ) , '<STR_LIT>' ) <EOL> def test_chain_from_iterable ( self ) : <EOL> self . assertEqual ( '<STR_LIT>' . join ( chain . from_iterable ( [ '<STR_LIT>' , '<STR_LIT>' ] ) ) , '<STR_LIT>' ) <EOL> def test_combinations ( self ) : <EOL> self . assertEqual ( list ( combinations ( '<STR_LIT>' , <NUM_LIT:2> ) ) , <EOL> [ ( '<STR_LIT:A>' , '<STR_LIT:B>' ) , ( '<STR_LIT:A>' , '<STR_LIT:C>' ) , ( '<STR_LIT:A>' , '<STR_LIT:D>' ) , ( '<STR_LIT:B>' , '<STR_LIT:C>' ) , ( '<STR_LIT:B>' , '<STR_LIT:D>' ) , ( '<STR_LIT:C>' , '<STR_LIT:D>' ) ] ) <EOL> self . assertEqual ( list ( combinations ( range ( <NUM_LIT:4> ) , <NUM_LIT:3> ) ) , <EOL> [ ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ) , ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:3> ) , ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:3> ) , ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ] ) <EOL> def test_combinations_with_replacement ( self ) : <EOL> self . assertEqual ( list ( combinations_with_replacement ( '<STR_LIT>' , <NUM_LIT:2> ) ) , <EOL> [ ( '<STR_LIT:A>' , '<STR_LIT:A>' ) , ( '<STR_LIT:A>' , '<STR_LIT:B>' ) , ( '<STR_LIT:A>' , '<STR_LIT:C>' ) , ( '<STR_LIT:B>' , '<STR_LIT:B>' ) , ( '<STR_LIT:B>' , '<STR_LIT:C>' ) , ( '<STR_LIT:C>' , '<STR_LIT:C>' ) ] ) <EOL> def test_compress ( self ) : <EOL> self . assertEqual ( list ( compress ( '<STR_LIT>' , [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> ] ) ) , list ( '<STR_LIT>' ) ) <EOL> def test_count ( self ) : <EOL> self . assertEqual ( list ( islice ( count ( <NUM_LIT:10> ) , <NUM_LIT:5> ) ) , [ <NUM_LIT:10> , <NUM_LIT:11> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> def test_cycle ( self ) : <EOL> self . assertEqual ( list ( islice ( cycle ( '<STR_LIT>' ) , <NUM_LIT:12> ) ) , list ( '<STR_LIT>' ) ) <EOL> def test_dropwhile ( self ) : <EOL> self . assertEqual ( list ( dropwhile ( lambda x : x < <NUM_LIT:5> , [ <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:4> , <NUM_LIT:1> ] ) ) , [ <NUM_LIT:6> , <NUM_LIT:4> , <NUM_LIT:1> ] ) <EOL> def test_groupby ( self ) : <EOL> self . assertEqual ( [ k for k , g in groupby ( '<STR_LIT>' ) ] , <EOL> list ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( [ ( list ( g ) ) for k , g in groupby ( '<STR_LIT>' ) ] , <EOL> [ list ( '<STR_LIT>' ) , list ( '<STR_LIT>' ) , list ( '<STR_LIT>' ) , list ( '<STR_LIT:D>' ) ] ) <EOL> def test_filter ( self ) : <EOL> self . assertEqual ( list ( filter ( lambda x : x % <NUM_LIT:2> , range ( <NUM_LIT:10> ) ) ) , [ <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:5> , <NUM_LIT:7> , <NUM_LIT:9> ] ) <EOL> def test_filterfalse ( self ) : <EOL> self . assertEqual ( list ( filterfalse ( lambda x : x % <NUM_LIT:2> , range ( <NUM_LIT:10> ) ) ) , [ <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:8> ] ) <EOL> def test_map ( self ) : <EOL> self . assertEqual ( list ( map ( pow , ( <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:10> ) , ( <NUM_LIT:5> , <NUM_LIT:2> , <NUM_LIT:3> ) ) ) , [ <NUM_LIT:32> , <NUM_LIT:9> , <NUM_LIT:1000> ] ) <EOL> def test_islice ( self ) : <EOL> self . assertEqual ( list ( islice ( '<STR_LIT>' , <NUM_LIT:2> ) ) , list ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( list ( islice ( '<STR_LIT>' , <NUM_LIT:2> , <NUM_LIT:4> ) ) , list ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( list ( islice ( '<STR_LIT>' , <NUM_LIT:2> , None ) ) , list ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( list ( islice ( '<STR_LIT>' , <NUM_LIT:0> , None , <NUM_LIT:2> ) ) , list ( '<STR_LIT>' ) ) <EOL> def test_zip ( self ) : <EOL> self . assertEqual ( list ( zip ( '<STR_LIT>' , '<STR_LIT>' ) ) , [ ( '<STR_LIT:A>' , '<STR_LIT:x>' ) , ( '<STR_LIT:B>' , '<STR_LIT:y>' ) ] ) <EOL> def test_zip_longest ( self ) : <EOL> self . assertEqual ( list ( zip_longest ( '<STR_LIT>' , '<STR_LIT>' , fillvalue = '<STR_LIT:->' ) ) , <EOL> [ ( '<STR_LIT:A>' , '<STR_LIT:x>' ) , ( '<STR_LIT:B>' , '<STR_LIT:y>' ) , ( '<STR_LIT:C>' , '<STR_LIT:->' ) , ( '<STR_LIT:D>' , '<STR_LIT:->' ) ] ) <EOL> def test_permutations ( self ) : <EOL> self . assertEqual ( list ( permutations ( '<STR_LIT>' , <NUM_LIT:2> ) ) , <EOL> list ( map ( tuple , '<STR_LIT>' . split ( ) ) ) ) <EOL> self . assertEqual ( list ( permutations ( range ( <NUM_LIT:3> ) ) ) , <EOL> [ ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ) , ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:1> ) , ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:2> ) , ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:0> ) , ( <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:1> ) , ( <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:0> ) ] ) <EOL> def test_product ( self ) : <EOL> self . assertEqual ( list ( product ( '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> list ( map ( tuple , '<STR_LIT>' . split ( ) ) ) ) <EOL> self . assertEqual ( list ( product ( range ( <NUM_LIT:2> ) , repeat = <NUM_LIT:3> ) ) , <EOL> [ ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ) , ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> ) , <EOL> ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> ) , ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ) ] ) <EOL> def test_repeat ( self ) : <EOL> self . assertEqual ( list ( repeat ( <NUM_LIT:10> , <NUM_LIT:3> ) ) , [ <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:10> ] ) <EOL> def test_stapmap ( self ) : <EOL> self . assertEqual ( list ( starmap ( pow , [ ( <NUM_LIT:2> , <NUM_LIT:5> ) , ( <NUM_LIT:3> , <NUM_LIT:2> ) , ( <NUM_LIT:10> , <NUM_LIT:3> ) ] ) ) , <EOL> [ <NUM_LIT:32> , <NUM_LIT:9> , <NUM_LIT:1000> ] ) <EOL> def test_takewhile ( self ) : <EOL> self . assertEqual ( list ( takewhile ( lambda x : x < <NUM_LIT:5> , [ <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:4> , <NUM_LIT:1> ] ) ) , [ <NUM_LIT:1> , <NUM_LIT:4> ] ) <EOL> class TestGC ( unittest . TestCase ) : <EOL> def makecycle ( self , iterator , container ) : <EOL> container . append ( iterator ) <EOL> next ( iterator ) <EOL> del container , iterator <EOL> def test_accumulate ( self ) : <EOL> a = [ ] <EOL> self . makecycle ( accumulate ( [ <NUM_LIT:1> , <NUM_LIT:2> , a , <NUM_LIT:3> ] ) , a ) <EOL> def test_chain ( self ) : <EOL> a = [ ] <EOL> self . makecycle ( chain ( a ) , a ) <EOL> def test_chain_from_iterable ( self ) : <EOL> a = [ ] <EOL> self . makecycle ( chain . from_iterable ( [ a ] ) , a ) <EOL> def test_combinations ( self ) : <EOL> a = [ ] <EOL> self . makecycle ( combinations ( [ <NUM_LIT:1> , <NUM_LIT:2> , a , <NUM_LIT:3> ] , <NUM_LIT:3> ) , a ) <EOL> def test_combinations_with_replacement ( self ) : <EOL> a = [ ] <EOL> self . makecycle ( combinations_with_replacement ( [ <NUM_LIT:1> , <NUM_LIT:2> , a , <NUM_LIT:3> ] , <NUM_LIT:3> ) , a ) <EOL> def test_compress ( self ) : <EOL> a = [ ] <EOL> self . makecycle ( compress ( '<STR_LIT>' , [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ] ) , a ) <EOL> def test_count ( self ) : <EOL> a = [ ] <EOL> Int = type ( '<STR_LIT>' , ( int , ) , dict ( x = a ) ) <EOL> self . makecycle ( count ( Int ( <NUM_LIT:0> ) , Int ( <NUM_LIT:1> ) ) , a ) <EOL> def test_cycle ( self ) : <EOL> a = [ ] <EOL> self . makecycle ( cycle ( [ a ] * <NUM_LIT:2> ) , a ) <EOL> def test_dropwhile ( self ) : <EOL> a = [ ] <EOL> self . makecycle ( dropwhile ( bool , [ <NUM_LIT:0> , a , a ] ) , a ) <EOL> def test_groupby ( self ) : <EOL> a = [ ] <EOL> self . makecycle ( groupby ( [ a ] * <NUM_LIT:2> , lambda x : x ) , a ) <EOL> def test_issue2246 ( self ) : <EOL> n = <NUM_LIT:10> <EOL> keyfunc = lambda x : x <EOL> for i , j in groupby ( range ( n ) , key = keyfunc ) : <EOL> keyfunc . __dict__ . setdefault ( '<STR_LIT:x>' , [ ] ) . append ( j ) <EOL> def test_filter ( self ) : <EOL> a = [ ] <EOL> self . makecycle ( filter ( lambda x : True , [ a ] * <NUM_LIT:2> ) , a ) <EOL> def test_filterfalse ( self ) : <EOL> a = [ ] <EOL> self . makecycle ( filterfalse ( lambda x : False , a ) , a ) <EOL> def test_zip ( self ) : <EOL> a = [ ] <EOL> self . makecycle ( zip ( [ a ] * <NUM_LIT:2> , [ a ] * <NUM_LIT:3> ) , a ) <EOL> def test_zip_longest ( self ) : <EOL> a = [ ] <EOL> self . makecycle ( zip_longest ( [ a ] * <NUM_LIT:2> , [ a ] * <NUM_LIT:3> ) , a ) <EOL> b = [ a , None ] <EOL> self . makecycle ( zip_longest ( [ a ] * <NUM_LIT:2> , [ a ] * <NUM_LIT:3> , fillvalue = b ) , a ) <EOL> def test_map ( self ) : <EOL> a = [ ] <EOL> self . makecycle ( map ( lambda x : x , [ a ] * <NUM_LIT:2> ) , a ) <EOL> def test_islice ( self ) : <EOL> a = [ ] <EOL> self . makecycle ( islice ( [ a ] * <NUM_LIT:2> , None ) , a ) <EOL> def test_permutations ( self ) : <EOL> a = [ ] <EOL> self . makecycle ( permutations ( [ <NUM_LIT:1> , <NUM_LIT:2> , a , <NUM_LIT:3> ] , <NUM_LIT:3> ) , a ) <EOL> def test_product ( self ) : <EOL> a = [ ] <EOL> self . makecycle ( product ( [ <NUM_LIT:1> , <NUM_LIT:2> , a , <NUM_LIT:3> ] , repeat = <NUM_LIT:3> ) , a ) <EOL> def test_repeat ( self ) : <EOL> a = [ ] <EOL> self . makecycle ( repeat ( a ) , a ) <EOL> def test_starmap ( self ) : <EOL> a = [ ] <EOL> self . makecycle ( starmap ( lambda * t : t , [ ( a , a ) ] * <NUM_LIT:2> ) , a ) <EOL> def test_takewhile ( self ) : <EOL> a = [ ] <EOL> self . makecycle ( takewhile ( bool , [ <NUM_LIT:1> , <NUM_LIT:0> , a , a ] ) , a ) <EOL> def R ( seqn ) : <EOL> '<STR_LIT>' <EOL> for i in seqn : <EOL> yield i <EOL> class G : <EOL> '<STR_LIT>' <EOL> def __init__ ( self , seqn ) : <EOL> self . seqn = seqn <EOL> def __getitem__ ( self , i ) : <EOL> return self . seqn [ i ] <EOL> class I : <EOL> '<STR_LIT>' <EOL> def __init__ ( self , seqn ) : <EOL> self . seqn = seqn <EOL> self . i = <NUM_LIT:0> <EOL> def __iter__ ( self ) : <EOL> return self <EOL> def __next__ ( self ) : <EOL> if self . i >= len ( self . seqn ) : raise StopIteration <EOL> v = self . seqn [ self . i ] <EOL> self . i += <NUM_LIT:1> <EOL> return v <EOL> class Ig : <EOL> '<STR_LIT>' <EOL> def __init__ ( self , seqn ) : <EOL> self . seqn = seqn <EOL> self . i = <NUM_LIT:0> <EOL> def __iter__ ( self ) : <EOL> for val in self . seqn : <EOL> yield val <EOL> class X : <EOL> '<STR_LIT>' <EOL> def __init__ ( self , seqn ) : <EOL> self . seqn = seqn <EOL> self . i = <NUM_LIT:0> <EOL> def __next__ ( self ) : <EOL> if self . i >= len ( self . seqn ) : raise StopIteration <EOL> v = self . seqn [ self . i ] <EOL> self . i += <NUM_LIT:1> <EOL> return v <EOL> class N : <EOL> '<STR_LIT>' <EOL> def __init__ ( self , seqn ) : <EOL> self . seqn = seqn <EOL> self . i = <NUM_LIT:0> <EOL> def __iter__ ( self ) : <EOL> return self <EOL> class E : <EOL> '<STR_LIT>' <EOL> def __init__ ( self , seqn ) : <EOL> self . seqn = seqn <EOL> self . i = <NUM_LIT:0> <EOL> def __iter__ ( self ) : <EOL> return self <EOL> def __next__ ( self ) : <EOL> <NUM_LIT:3> // <NUM_LIT:0> <EOL> class S : <EOL> '<STR_LIT>' <EOL> def __init__ ( self , seqn ) : <EOL> pass <EOL> def __iter__ ( self ) : <EOL> return self <EOL> def __next__ ( self ) : <EOL> raise StopIteration <EOL> def L ( seqn ) : <EOL> '<STR_LIT>' <EOL> return chain ( map ( lambda x : x , R ( Ig ( G ( seqn ) ) ) ) ) <EOL> class TestVariousIteratorArgs ( unittest . TestCase ) : <EOL> def test_accumulate ( self ) : <EOL> s = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] <EOL> r = [ <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:6> , <NUM_LIT:10> , <NUM_LIT:15> ] <EOL> n = len ( s ) <EOL> for g in ( G , I , Ig , L , R ) : <EOL> self . assertEqual ( list ( accumulate ( g ( s ) ) ) , r ) <EOL> self . assertEqual ( list ( accumulate ( S ( s ) ) ) , [ ] ) <EOL> self . assertRaises ( TypeError , accumulate , X ( s ) ) <EOL> self . assertRaises ( TypeError , accumulate , N ( s ) ) <EOL> self . assertRaises ( ZeroDivisionError , list , accumulate ( E ( s ) ) ) <EOL> def test_chain ( self ) : <EOL> for s in ( "<STR_LIT>" , "<STR_LIT>" , range ( <NUM_LIT:1000> ) , ( '<STR_LIT>' , <NUM_LIT> ) , range ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> ) ) : <EOL> for g in ( G , I , Ig , S , L , R ) : <EOL> self . assertEqual ( list ( chain ( g ( s ) ) ) , list ( g ( s ) ) ) <EOL> self . assertEqual ( list ( chain ( g ( s ) , g ( s ) ) ) , list ( g ( s ) ) + list ( g ( s ) ) ) <EOL> self . assertRaises ( TypeError , list , chain ( X ( s ) ) ) <EOL> self . assertRaises ( TypeError , list , chain ( N ( s ) ) ) <EOL> self . assertRaises ( ZeroDivisionError , list , chain ( E ( s ) ) ) <EOL> def test_compress ( self ) : <EOL> for s in ( "<STR_LIT>" , "<STR_LIT>" , range ( <NUM_LIT:1000> ) , ( '<STR_LIT>' , <NUM_LIT> ) , range ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> ) ) : <EOL> n = len ( s ) <EOL> for g in ( G , I , Ig , S , L , R ) : <EOL> self . assertEqual ( list ( compress ( g ( s ) , repeat ( <NUM_LIT:1> ) ) ) , list ( g ( s ) ) ) <EOL> self . assertRaises ( TypeError , compress , X ( s ) , repeat ( <NUM_LIT:1> ) ) <EOL> self . assertRaises ( TypeError , compress , N ( s ) , repeat ( <NUM_LIT:1> ) ) <EOL> self . assertRaises ( ZeroDivisionError , list , compress ( E ( s ) , repeat ( <NUM_LIT:1> ) ) ) <EOL> def test_product ( self ) : <EOL> for s in ( "<STR_LIT>" , "<STR_LIT>" , range ( <NUM_LIT:1000> ) , ( '<STR_LIT>' , <NUM_LIT> ) , range ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> ) ) : <EOL> self . assertRaises ( TypeError , product , X ( s ) ) <EOL> self . assertRaises ( TypeError , product , N ( s ) ) <EOL> self . assertRaises ( ZeroDivisionError , product , E ( s ) ) <EOL> def test_cycle ( self ) : <EOL> for s in ( "<STR_LIT>" , "<STR_LIT>" , range ( <NUM_LIT:1000> ) , ( '<STR_LIT>' , <NUM_LIT> ) , range ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> ) ) : <EOL> for g in ( G , I , Ig , S , L , R ) : <EOL> tgtlen = len ( s ) * <NUM_LIT:3> <EOL> expected = list ( g ( s ) ) * <NUM_LIT:3> <EOL> actual = list ( islice ( cycle ( g ( s ) ) , tgtlen ) ) <EOL> self . assertEqual ( actual , expected ) <EOL> self . assertRaises ( TypeError , cycle , X ( s ) ) <EOL> self . assertRaises ( TypeError , cycle , N ( s ) ) <EOL> self . assertRaises ( ZeroDivisionError , list , cycle ( E ( s ) ) ) <EOL> def test_groupby ( self ) : <EOL> for s in ( range ( <NUM_LIT:10> ) , range ( <NUM_LIT:0> ) , range ( <NUM_LIT:1000> ) , ( <NUM_LIT:7> , <NUM_LIT:11> ) , range ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> ) ) : <EOL> for g in ( G , I , Ig , S , L , R ) : <EOL> self . assertEqual ( [ k for k , sb in groupby ( g ( s ) ) ] , list ( g ( s ) ) ) <EOL> self . assertRaises ( TypeError , groupby , X ( s ) ) <EOL> self . assertRaises ( TypeError , groupby , N ( s ) ) <EOL> self . assertRaises ( ZeroDivisionError , list , groupby ( E ( s ) ) ) <EOL> def test_filter ( self ) : <EOL> for s in ( range ( <NUM_LIT:10> ) , range ( <NUM_LIT:0> ) , range ( <NUM_LIT:1000> ) , ( <NUM_LIT:7> , <NUM_LIT:11> ) , range ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> ) ) : <EOL> for g in ( G , I , Ig , S , L , R ) : <EOL> self . assertEqual ( list ( filter ( isEven , g ( s ) ) ) , <EOL> [ x for x in g ( s ) if isEven ( x ) ] ) <EOL> self . assertRaises ( TypeError , filter , isEven , X ( s ) ) <EOL> self . assertRaises ( TypeError , filter , isEven , N ( s ) ) <EOL> self . assertRaises ( ZeroDivisionError , list , filter ( isEven , E ( s ) ) ) <EOL> def test_filterfalse ( self ) : <EOL> for s in ( range ( <NUM_LIT:10> ) , range ( <NUM_LIT:0> ) , range ( <NUM_LIT:1000> ) , ( <NUM_LIT:7> , <NUM_LIT:11> ) , range ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> ) ) : <EOL> for g in ( G , I , Ig , S , L , R ) : <EOL> self . assertEqual ( list ( filterfalse ( isEven , g ( s ) ) ) , <EOL> [ x for x in g ( s ) if isOdd ( x ) ] ) <EOL> self . assertRaises ( TypeError , filterfalse , isEven , X ( s ) ) <EOL> self . assertRaises ( TypeError , filterfalse , isEven , N ( s ) ) <EOL> self . assertRaises ( ZeroDivisionError , list , filterfalse ( isEven , E ( s ) ) ) <EOL> def test_zip ( self ) : <EOL> for s in ( "<STR_LIT>" , "<STR_LIT>" , range ( <NUM_LIT:1000> ) , ( '<STR_LIT>' , <NUM_LIT> ) , range ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> ) ) : <EOL> for g in ( G , I , Ig , S , L , R ) : <EOL> self . assertEqual ( list ( zip ( g ( s ) ) ) , lzip ( g ( s ) ) ) <EOL> self . assertEqual ( list ( zip ( g ( s ) , g ( s ) ) ) , lzip ( g ( s ) , g ( s ) ) ) <EOL> self . assertRaises ( TypeError , zip , X ( s ) ) <EOL> self . assertRaises ( TypeError , zip , N ( s ) ) <EOL> self . assertRaises ( ZeroDivisionError , list , zip ( E ( s ) ) ) <EOL> def test_ziplongest ( self ) : <EOL> for s in ( "<STR_LIT>" , "<STR_LIT>" , range ( <NUM_LIT:1000> ) , ( '<STR_LIT>' , <NUM_LIT> ) , range ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> ) ) : <EOL> for g in ( G , I , Ig , S , L , R ) : <EOL> self . assertEqual ( list ( zip_longest ( g ( s ) ) ) , list ( zip ( g ( s ) ) ) ) <EOL> self . assertEqual ( list ( zip_longest ( g ( s ) , g ( s ) ) ) , list ( zip ( g ( s ) , g ( s ) ) ) ) <EOL> self . assertRaises ( TypeError , zip_longest , X ( s ) ) <EOL> self . assertRaises ( TypeError , zip_longest , N ( s ) ) <EOL> self . assertRaises ( ZeroDivisionError , list , zip_longest ( E ( s ) ) ) <EOL> def test_map ( self ) : <EOL> for s in ( range ( <NUM_LIT:10> ) , range ( <NUM_LIT:0> ) , range ( <NUM_LIT:100> ) , ( <NUM_LIT:7> , <NUM_LIT:11> ) , range ( <NUM_LIT:20> , <NUM_LIT:50> , <NUM_LIT:5> ) ) : <EOL> for g in ( G , I , Ig , S , L , R ) : <EOL> self . assertEqual ( list ( map ( onearg , g ( s ) ) ) , <EOL> [ onearg ( x ) for x in g ( s ) ] ) <EOL> self . assertEqual ( list ( map ( operator . pow , g ( s ) , g ( s ) ) ) , <EOL> [ x ** x for x in g ( s ) ] ) <EOL> self . assertRaises ( TypeError , map , onearg , X ( s ) ) <EOL> self . assertRaises ( TypeError , map , onearg , N ( s ) ) <EOL> self . assertRaises ( ZeroDivisionError , list , map ( onearg , E ( s ) ) ) <EOL> def test_islice ( self ) : <EOL> for s in ( "<STR_LIT>" , "<STR_LIT>" , range ( <NUM_LIT:1000> ) , ( '<STR_LIT>' , <NUM_LIT> ) , range ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> ) ) : <EOL> for g in ( G , I , Ig , S , L , R ) : <EOL> self . assertEqual ( list ( islice ( g ( s ) , <NUM_LIT:1> , None , <NUM_LIT:2> ) ) , list ( g ( s ) ) [ <NUM_LIT:1> : : <NUM_LIT:2> ] ) <EOL> self . assertRaises ( TypeError , islice , X ( s ) , <NUM_LIT:10> ) <EOL> self . assertRaises ( TypeError , islice , N ( s ) , <NUM_LIT:10> ) <EOL> self . assertRaises ( ZeroDivisionError , list , islice ( E ( s ) , <NUM_LIT:10> ) ) <EOL> def test_starmap ( self ) : <EOL> for s in ( range ( <NUM_LIT:10> ) , range ( <NUM_LIT:0> ) , range ( <NUM_LIT:100> ) , ( <NUM_LIT:7> , <NUM_LIT:11> ) , range ( <NUM_LIT:20> , <NUM_LIT:50> , <NUM_LIT:5> ) ) : <EOL> for g in ( G , I , Ig , S , L , R ) : <EOL> ss = lzip ( s , s ) <EOL> self . assertEqual ( list ( starmap ( operator . pow , g ( ss ) ) ) , <EOL> [ x ** x for x in g ( s ) ] ) <EOL> self . assertRaises ( TypeError , starmap , operator . pow , X ( ss ) ) <EOL> self . assertRaises ( TypeError , starmap , operator . pow , N ( ss ) ) <EOL> self . assertRaises ( ZeroDivisionError , list , starmap ( operator . pow , E ( ss ) ) ) <EOL> def test_takewhile ( self ) : <EOL> for s in ( range ( <NUM_LIT:10> ) , range ( <NUM_LIT:0> ) , range ( <NUM_LIT:1000> ) , ( <NUM_LIT:7> , <NUM_LIT:11> ) , range ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> ) ) : <EOL> for g in ( G , I , Ig , S , L , R ) : <EOL> tgt = [ ] <EOL> for elem in g ( s ) : <EOL> if not isEven ( elem ) : break <EOL> tgt . append ( elem ) <EOL> self . assertEqual ( list ( takewhile ( isEven , g ( s ) ) ) , tgt ) <EOL> self . assertRaises ( TypeError , takewhile , isEven , X ( s ) ) <EOL> self . assertRaises ( TypeError , takewhile , isEven , N ( s ) ) <EOL> self . assertRaises ( ZeroDivisionError , list , takewhile ( isEven , E ( s ) ) ) <EOL> def test_dropwhile ( self ) : <EOL> for s in ( range ( <NUM_LIT:10> ) , range ( <NUM_LIT:0> ) , range ( <NUM_LIT:1000> ) , ( <NUM_LIT:7> , <NUM_LIT:11> ) , range ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> ) ) : <EOL> for g in ( G , I , Ig , S , L , R ) : <EOL> tgt = [ ] <EOL> for elem in g ( s ) : <EOL> if not tgt and isOdd ( elem ) : continue <EOL> tgt . append ( elem ) <EOL> self . assertEqual ( list ( dropwhile ( isOdd , g ( s ) ) ) , tgt ) <EOL> self . assertRaises ( TypeError , dropwhile , isOdd , X ( s ) ) <EOL> self . assertRaises ( TypeError , dropwhile , isOdd , N ( s ) ) <EOL> self . assertRaises ( ZeroDivisionError , list , dropwhile ( isOdd , E ( s ) ) ) <EOL> def test_tee ( self ) : <EOL> for s in ( "<STR_LIT>" , "<STR_LIT>" , range ( <NUM_LIT:1000> ) , ( '<STR_LIT>' , <NUM_LIT> ) , range ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> ) ) : <EOL> for g in ( G , I , Ig , S , L , R ) : <EOL> it1 , it2 = tee ( g ( s ) ) <EOL> self . assertEqual ( list ( it1 ) , list ( g ( s ) ) ) <EOL> self . assertEqual ( list ( it2 ) , list ( g ( s ) ) ) <EOL> self . assertRaises ( TypeError , tee , X ( s ) ) <EOL> self . assertRaises ( TypeError , tee , N ( s ) ) <EOL> self . assertRaises ( ZeroDivisionError , list , tee ( E ( s ) ) [ <NUM_LIT:0> ] ) <EOL> class LengthTransparency ( unittest . TestCase ) : <EOL> def test_repeat ( self ) : <EOL> from test . test_iterlen import len <EOL> self . assertEqual ( len ( repeat ( None , <NUM_LIT:50> ) ) , <NUM_LIT:50> ) <EOL> self . assertRaises ( TypeError , len , repeat ( None ) ) <EOL> class RegressionTests ( unittest . TestCase ) : <EOL> def test_sf_793826 ( self ) : <EOL> def mutatingtuple ( tuple1 , f , tuple2 ) : <EOL> def g ( value , first = [ <NUM_LIT:1> ] ) : <EOL> if first : <EOL> del first [ : ] <EOL> f ( next ( z ) ) <EOL> return value <EOL> items = list ( tuple2 ) <EOL> items [ <NUM_LIT:1> : <NUM_LIT:1> ] = list ( tuple1 ) <EOL> gen = map ( g , items ) <EOL> z = zip ( * [ gen ] * len ( tuple1 ) ) <EOL> next ( z ) <EOL> def f ( t ) : <EOL> global T <EOL> T = t <EOL> first [ : ] = list ( T ) <EOL> first = [ ] <EOL> mutatingtuple ( ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) , f , ( <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ) ) <EOL> second = list ( T ) <EOL> self . assertEqual ( first , second ) <EOL> def test_sf_950057 ( self ) : <EOL> def gen1 ( ) : <EOL> hist . append ( <NUM_LIT:0> ) <EOL> yield <NUM_LIT:1> <EOL> hist . append ( <NUM_LIT:1> ) <EOL> raise AssertionError <EOL> hist . append ( <NUM_LIT:2> ) <EOL> def gen2 ( x ) : <EOL> hist . append ( <NUM_LIT:3> ) <EOL> yield <NUM_LIT:2> <EOL> hist . append ( <NUM_LIT:4> ) <EOL> if x : <EOL> raise StopIteration <EOL> hist = [ ] <EOL> self . assertRaises ( AssertionError , list , chain ( gen1 ( ) , gen2 ( False ) ) ) <EOL> self . assertEqual ( hist , [ <NUM_LIT:0> , <NUM_LIT:1> ] ) <EOL> hist = [ ] <EOL> self . assertRaises ( AssertionError , list , chain ( gen1 ( ) , gen2 ( True ) ) ) <EOL> self . assertEqual ( hist , [ <NUM_LIT:0> , <NUM_LIT:1> ] ) <EOL> hist = [ ] <EOL> self . assertRaises ( AssertionError , list , cycle ( gen1 ( ) ) ) <EOL> self . assertEqual ( hist , [ <NUM_LIT:0> , <NUM_LIT:1> ] ) <EOL> class SubclassWithKwargsTest ( unittest . TestCase ) : <EOL> def test_keywords_in_subclass ( self ) : <EOL> for cls in ( repeat , zip , filter , filterfalse , chain , map , <EOL> starmap , islice , takewhile , dropwhile , cycle , compress ) : <EOL> class Subclass ( cls ) : <EOL> def __init__ ( self , newarg = None , * args ) : <EOL> cls . __init__ ( self , * args ) <EOL> try : <EOL> Subclass ( newarg = <NUM_LIT:1> ) <EOL> except TypeError as err : <EOL> self . assertNotIn ( "<STR_LIT>" , err . args [ <NUM_LIT:0> ] ) <EOL> libreftest = """<STR_LIT>""" <EOL> __test__ = { '<STR_LIT>' : libreftest } <EOL> def test_main ( verbose = None ) : <EOL> test_classes = ( TestBasicOps , TestVariousIteratorArgs , TestGC , <EOL> RegressionTests , LengthTransparency , <EOL> SubclassWithKwargsTest , TestExamples ) <EOL> support . run_unittest ( * test_classes ) <EOL> if verbose and hasattr ( sys , "<STR_LIT>" ) : <EOL> import gc <EOL> counts = [ None ] * <NUM_LIT:5> <EOL> for i in range ( len ( counts ) ) : <EOL> support . run_unittest ( * test_classes ) <EOL> gc . collect ( ) <EOL> counts [ i ] = sys . gettotalrefcount ( ) <EOL> print ( counts ) <EOL> support . run_doctest ( sys . modules [ __name__ ] , verbose ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test_main ( verbose = True ) </s>
