Your IP : 216.73.216.213


Current Path : /opt/alt/python34/lib64/python3.4/test/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/test/__pycache__/test_itertools.cpython-34.pyc

�
f f7_�@sUddlZddlmZddlTddlZddlmZddlmZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlmZddl	Z	ddlZejZedZdd	�Zd
d�Zdd
�Zdd�Zdd�Zdd�Zdd�Zdd�ZGdd�d�Zdd�Zdd�Zdd�Zd d!�Z d"d#�Z!d$d%�Z"d&d'�e#e
j$d�D�Z%Gd(d)�d)ej&�Z'Gd*d+�d+ej&�Z(Gd,d-�d-ej&�Z)d.d/�Z*Gd0d1�d1�Z+Gd2d3�d3�Z,Gd4d5�d5�Z-Gd6d7�d7�Z.Gd8d9�d9�Z/Gd:d;�d;�Z0Gd<d=�d=�Z1d>d?�Z2Gd@dA�dAej&�Z3GdBdC�dCej&�Z4GdDdE�dEej&�Z5GdFdG�dGej&�Z6ej7GdHdI�dIej&��Z8dJZ9ie9dK6Z:ddLdM�Z;e<dNkrQe;dOdP�ndS)Q�N)�support)�*)�Decimal)�Fraction)�reduce�cGstt|��S)N)�list�zip)�args�r�8/opt/alt/python34/lib64/python3.4/test/test_itertools.py�lzipsr
cCsd|S)zTest function of one argument�r)�xrrr�oneargsrcGs
t�dS)z"Test function that raises an errorN)�
ValueError)r
rrr�errfuncsrccsxdD]}|VqWdS)zNon-restartable source sequencerrrN)rrrr)�irrr�gen3s
rcCs|ddkS)zTest predicaterrr)rrrr�isEven"srcCs|ddkS)zTest predicaterrr)rrrr�isOdd&srcGs|S)Nr)r
rrr�tupleize*srccs xt|�D]}|Vq
WdS)N)�range)�nrrrr�irange-src@s.eZdZdZdd�Zdd�ZdS)�StopNowz"Class emulating an empty iterable.cCs|S)Nr)�selfrrr�__iter__3szStopNow.__iter__cCs
t�dS)N)�
StopIteration)rrrr�__next__5szStopNow.__next__N)�__name__�
__module__�__qualname__�__doc__rrrrrrr1srcCstt||��S)zHConvenience function for partially consuming a long of infinite iterable)r�islice)r�seqrrr�take8sr&cCsttj|d�S)Nr)r�operator�mul)�iterablerrr�prod<sr*cCsttd|d��S)Z	Factorialr)r*r)rrrr�fact?sr+cCs|dS)Nrr)�rrrr�testRDsr-cCs|dS)Nrr)r,rrr�testR2Gsr.cCs
|dkS)N�
r)rrrr�undertenJsr0cCsg|]}|dd��qS)cSstjtj||��S)N)�pickle�loads�dumps)�s�protorrr�<lambda>Msz<listcomp>.<lambda>r)�.0r5rrr�
<listcomp>Ms	r8c@s�eZdZddddd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Ze	j
dd��Ze	jd�dd��Z
dd�Ze	j
dd��Ze	jd�dd��Zdd�Ze	j
dd��Ze	jd�dd ��Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Ze	jd�d3d4��Zd5d6�Ze	jd�d7d8��Zd9d:�Z d;d<�Z!d=d>�Z"e	j
d?d@��Z#e	jd�dAdB��Z$dCdD�Z%dEdF�Z&dGdH�Z'dIdJ�Z(dKdL�Z)dMdN�Z*dOdP�Z+dQdR�Z,dSdT�Z-dUdV�Z.dWdX�Z/dYdZ�Z0dS)[�TestBasicOps�rNcsyd��fdd��tj||�}tj|�}|jt|�t|���|��|�}}	|j||	�|r��|�}
|j||
�ntj|�}d}y/x(t|�D]}
t|�|d7}q�WWntk
r�YnXtj||�}tj|�}�|��|�}}	|j||	�|ru�||d��}
|j||
�ndS)zITest that an iterator is the same after pickling, also when part-consumedrcsz�dkrtd��nt|t�r.|Sytt|���}Wntk
r_|SYnX��fdd�|D�S)Nr/zinfinite recursion encounteredcs#g|]}�|�d��qS)rr)r7�e)�expandrrrr8^s	z;TestBasicOps.pickletest.<locals>.expand.<locals>.<listcomp>)�RuntimeError�
isinstance�strrr$�	TypeError)�itr�l)r<�stop)rrr<Ts
	z'TestBasicOps.pickletest.<locals>.expandrN)r1r3r2�assertEqual�typer�nextr)rZprotocolrArCr&�compare�dumpZi2�a�b�cZi3ZtookrZi4r)r<rCr�
pickletestRs0


zTestBasicOps.pickletestcCs
|jtttd���ddddddddd	d
g
�|jttdtd���ddddddddd	d
g
�xrttttfD]^}|jttt|td����tt|ddddddddd	d
g
���q�W|jttd��d
ddg�|jttg��g�|jttdg��dg�|j	t
ttd�dd�|j	t
t�|j	t
tdtd��|j	t
ttdgg��ddddddddddg
}|jtt|t��ddddddddddg
�|jtt|t��ddddddddddg
�|jtt|t
j��ddddddddddg
�|j	t
��tt|t��WdQXx7ttjd�D]"}|j|ttd���q�WdS)Nr/rr������$�-r)�abcrI�ab��rr��	r:��i�i�)rDr�
accumulater�int�complexrr�map�assertRaisesr@�min�maxr'r(�chrr1�HIGHEST_PROTOCOLrL)r�typr4r5rrr�test_accumulate{s4%%8%"$%%%zTestBasicOps.test_accumulatecCs�dd�}x�t|fD]�}|jt|dd��td��|jt|d��td��|jt|d��g�|jtd|dd��td��|jtt|d	d
��qWdS)Ncws+x$|D]}x|D]}|VqWqWdS)zPure python version in the docsNr)�	iterablesrA�elementrrr�chain2�s

z'TestBasicOps.test_chain.<locals>.chain2rT�def�abcdef�r:�abcdrrM)�chainrDrr&r`r@)rrirKrrr�
test_chain�s%"(zTestBasicOps.test_chaincCs�|jttjddg��td��|jttjdg��td��|jttjdg��g�|jtdtjddg��td��|jtttjddg��dS)	NrTrjrkrlr:rmrrM)rDrrn�
from_iterabler&r`r@)rrrr�test_chain_from_iterable�s
+(".z%TestBasicOps.test_chain_from_iterablecCs=x�tjgtD]�}tdd�}|jt||��td��|jt|�d�|jt||��td��|jt|td���g�|jtd|tdd���td��|jt	t|td	d
���qWx@t
tjd�D]+}|j
|tdd�dtd��q
WdS)
NrTrjrkrIZbcdefrlr:rmrrMrrG)�copy�deepcopy�
picklecopiersrnrDrrFr&r`r@rr1rdrL)rZoperrAr5rrr�test_chain_reducible�s""".&z!TestBasicOps.test_chain_reduciblec

s�|jttd�|jttddd�|jttd�|jttdd�x6dd�gtD]!}|jt|tdd���g�|jt|tdd���ddddd d!g�tdd�}t|�|jt||��d"d#d$d%d&g�|jt|ttd�d
���d'd(d)d*g�ttd�d
�}t|�|jt||��d+d,d-g�qiWdd�}dd�}dd�}xtd�D]}dd�t|�D��x�t|d�D]�}tt�|��}|jt	|�||kr+dn!t
|�t
|�t
||��|jt	|�t	t|���|j|t|��x�|D]��|jt	��|�|jt	t���|�|jt��t���|j
t�fdd��D���|jt���fdd��D��q�W|j|t|�|���|j|t|�|���|j|t|�|���x4ttjd�D]}	|j|	t�|��q�Wq�Wq�WdS).NrTrrcSs|S)Nr)rIrrrr6�sz0TestBasicOps.test_combinations.<locals>.<lambda>� �ABCD�A�B�C�Dr:rMrc3st|��t��}||kr(dStt|��}t�fdd�|D��Vx�x:tt|��D]"}|||||krnPqnqnWdS||d7<x1t|d|�D]}||dd||<q�Wt�fdd�|D��Vq[WdS)z%Pure python version shown in the docsNc3s|]}�|VqdS)Nr)r7r)�poolrr�	<genexpr>�szHTestBasicOps.test_combinations.<locals>.combinations1.<locals>.<genexpr>rc3s|]}�|VqdS)Nr)r7r)r|rrr}�s)�tuple�lenrr�reversed)r)r,r�indicesr�jr)r|r�
combinations1�sz5TestBasicOps.test_combinations.<locals>.combinations1c3sut|��t��}xVtt|�|�D]?}t|�t|�kr.t�fdd�|D��Vq.q.WdS)z%Pure python version shown in the docsc3s|]}�|VqdS)Nr)r7r)r|rrr}�szHTestBasicOps.test_combinations.<locals>.combinations2.<locals>.<genexpr>N)r~r�permutationsr�sortedr)r)r,rr�r)r|r�
combinations2�s
z5TestBasicOps.test_combinations.<locals>.combinations2c3sut|��t��}xVtt|�|�D]?}tt|��|kr.t�fdd�|D��Vq.q.WdS)zPure python version from cwr()c3s|]}�|VqdS)Nr)r7r)r|rrr}�szHTestBasicOps.test_combinations.<locals>.combinations3.<locals>.<genexpr>N)r~r�combinations_with_replacementr�set)r)r,rr�r)r|r�
combinations3�s
z5TestBasicOps.test_combinations.<locals>.combinations3rVcSsg|]}d|d�qS)rW�r)r7rrrrr8�s	z2TestBasicOps.test_combinations.<locals>.<listcomp>c3s|]}|�kVqdS)Nr)r7r;)�valuesrrr}sz1TestBasicOps.test_combinations.<locals>.<genexpr>cs"g|]}|�kr|�qSrr)r7r;)rKrrr8s	���)rxry)rxrz)rxr{)ryrz)ryr{)rzr{)rxrz)rxr{)ryrz)ryr{)rzr{)rrr)rrrM)rrrM)rrrM)rrrM)rrrM)rrrM)r`r@�combinationsrrtrDrrFrrr+r�r��
assertTrue�allr1rdrL)
r�op�testIntermediater�r�r�rr,�resultr5r)rKr�r�test_combinations�sP%
$
F"
&zTestBasicOps.test_combinationscCs-|jttf��tdd�WdQXdS)N�AAr�i )r`�
OverflowError�MemoryErrorr�)rrrr�test_combinations_overflowsz'TestBasicOps.test_combinations_overflowz"tuple reuse is specific to CPythonc	Csf|jtttttdd����d�|jttttttdd�����d�dS)N�abcderMr)rDrr�r_�idr��assertNotEqualr)rrrr�test_combinations_tuple_reuses.z*TestBasicOps.test_combinations_tuple_reusec

snt}|jt|d�|jt|ddd�|jt|d�|jt|dd�x�dd�gtD]�}|jt||dd���ddddddg�|dd�}t|�|jt||��dd d!d"d#g�qoWd
d�}dd
�}dd�}xOtd�D]A}dd�t|�D��xt|d�D]
}t|�|��}	|jt	|	�|||��|jt	|	�t	t
|	���|j|	t|	��tt�|��}
|dks�|dkr|j|	|
�n|j
t
|	�t
|
�k�x�|	D]��|jt	��|�dd�t��D�}|jt	|�t	t
|���|jt��t���|j
t�fdd��D���|j|�fdd��D��q-W|j|	t|�|���|j|	t|�|���x4ttjd�D]}|j||�|��q?WqUWq%WdS)$NrTrrcSs|S)Nr)rIrrrr6szATestBasicOps.test_combinations_with_replacement.<locals>.<lambda>�ABCrxryrzc3s�t|��t��}|r)|r)dSdg|}t�fdd�|D��Vx~x6tt|��D]}|||dkrjPqjqjWdS||dg||||d�<t�fdd�|D��VqWWdS)z%Pure python version shown in the docsNrc3s|]}�|VqdS)Nr)r7r)r|rrr}.szPTestBasicOps.test_combinations_with_replacement.<locals>.cwr1.<locals>.<genexpr>rc3s|]}�|VqdS)Nr)r7r)r|rrr}6s)r~rr�r)r)r,rr�rr)r|r�cwr1&s

#z=TestBasicOps.test_combinations_with_replacement.<locals>.cwr1c3sxt|��t��}xYtt|�d|�D]?}t|�t|�kr1t�fdd�|D��Vq1q1WdS)z%Pure python version shown in the docs�repeatc3s|]}�|VqdS)Nr)r7r)r|rrr}>szPTestBasicOps.test_combinations_with_replacement.<locals>.cwr2.<locals>.<genexpr>N)r~r�productrr�r)r)r,rr�r)r|r�cwr28s
z=TestBasicOps.test_combinations_with_replacement.<locals>.cwr2cSs>|s|rdSdSt||d�t|�t|d�S)Nrr)r+)rr,rrr�numcombs@szATestBasicOps.test_combinations_with_replacement.<locals>.numcombsrVcSsg|]}d|d�qS)rWr�r)r7rrrrr8Fs	zCTestBasicOps.test_combinations_with_replacement.<locals>.<listcomp>rcSsg|]\}}|�qSrr)r7�k�vrrrr8Vs	c3s|]}|�kVqdS)Nr)r7r;)r�rrr}YszBTestBasicOps.test_combinations_with_replacement.<locals>.<genexpr>cs"g|]}|�kr|�qSrr)r7r;)rKrrr8[s	r�)rxrx)rxry)rxrz)ryry)ryrz)rzrz)rxry)rxrz)ryry)ryrz)rzrz)r�r`r@rrtrDrrFrrr�r�r�r��groupbyr�r1rdrL)
r�cwrr�r�r�r�r�rr,r�Z
regular_combsZnorunsr5r)rKr�r�"test_combinations_with_replacementsL
"
"&	z/TestBasicOps.test_combinations_with_replacementcCs-|jttf��tdd�WdQXdS)Nr�r�i@)r`r�r�r�)rrrr�+test_combinations_with_replacement_overflowbsz8TestBasicOps.test_combinations_with_replacement_overflowc	Cslt}|jtttt|dd����d�|jttttt|dd�����d�dS)Nr�rMr)r�rDrr�r_r�r�r)rr�rrr�.test_combinations_with_replacement_tuple_reusehs.z;TestBasicOps.test_combinations_with_replacement_tuple_reusec	s�|jtt�|jttddd�|jttd�|jttdd�|jttdd��g�|jttdd�|jtttd�d��ddddddg�ddd	�}dd
d�}x�td�D]�}d
d�t|�D��x�t|d�D]�}tt�|��}|jt|�||krUdnt|�t||��|jt|�tt	|���|j|t
|��xf|D]^}|jt|�|�|jtt	|��|�|jt�fdd�|D���q�W|j|t|�|���|j|t|�|���||kr�|j|tt�d���|j|tt����nx4tt
jd�D]}|j|t�|��q�WqWq�WdS)NrTrrrvr4rMrc3s�t|��t��}|dkr*|n|}||kr@dStt|��}tt||d|d��ddd�}t�fdd�|d|�D��Vx�|r�x�tt|��D]�}||d8<||dkr)||dd�|||d�||d�<||||<q�||}||||||<||<t�fdd�|d|�D��VPq�WdSq�WdS)z%Pure python version shown in the docsNrc3s|]}�|VqdS)Nr)r7r)r|rrr}�szHTestBasicOps.test_permutations.<locals>.permutations1.<locals>.<genexpr>rc3s|]}�|VqdS)Nr)r7r)r|rrr}�s���)r~rrrr�)r)r,rr�Zcyclesrr�r)r|r�
permutations1xs&.(	0
(z5TestBasicOps.test_permutations.<locals>.permutations1c3s�t|��t��}|dkr*|n|}xYtt|�d|�D]?}tt|��|krIt�fdd�|D��VqIqIWdS)z%Pure python version shown in the docsNr�c3s|]}�|VqdS)Nr)r7r)r|rrr}�szHTestBasicOps.test_permutations.<locals>.permutations2.<locals>.<genexpr>)r~rr�rr�)r)r,rr�r)r|r�
permutations2�sz5TestBasicOps.test_permutations.<locals>.permutations2rVcSsg|]}d|d�qS)rWr�r)r7rrrrr8�s	z2TestBasicOps.test_permutations.<locals>.<listcomp>c3s|]}|�kVqdS)Nr)r7r;)r�rrr}�sz1TestBasicOps.test_permutations.<locals>.<genexpr>r�)rr)rr)rr)rr)rr)rr)r`r@r�rrDrrrr+r�r�r�r�r1rdrL)rr�r�rr,r��pr5r)r�r�test_permutationsns8	<"
*zTestBasicOps.test_permutationscCs-|jttf��tdd�WdQXdS)Nrxrr�i@)r`r�r�r�)rrrr�test_permutations_overflow�sz'TestBasicOps.test_permutations_overflowc	Csf|jtttttdd����d�|jttttttdd�����d�dS)Nr�rMr)rDrr�r_r�r�r�r)rrrr�test_permutations_tuple_reuse�s.z*TestBasicOps.test_permutations_tuple_reusecs�x�td�D]�}dd|�}x�td�D]��tt|d���}tt|���}tt|���}tt|���}|jt|�|��|jt|�|r�t|�d�t��t|d�n��|jt|��|krdnt|�t|���|jt|��|krMdn!t|�t��t|���|j|t	t
|���|j|t	t
|���|j|t	t
|���|j|t	t
|���|j|dd�|D��|j|�fd	d�|D��|j|d
d�|D��|j|�fdd�|D��|j|ttt
|�j|���|j|ttt
|�j|���|j|t	t
|�t
|�@��q0Wq
WdS)NrN�ABCDEFGrXr�rrcSs.g|]$}t|�t|�kr|�qSr)r�r)r7�trrrr8�s	z3TestBasicOps.test_combinatorics.<locals>.<listcomp>cs.g|]$}tt|���kr|�qSr)rr�)r7r�)r,rrr8�s	cSs.g|]$}t|�t|�kr|�qSr)r�r)r7r�rrrr8�s	cs.g|]$}tt|���kr|�qSr)rr�)r7r�)r,rrr8�s	)
rrr�r�r�r�rDrr+r�r��filter�__contains__)rrr4r*r�ZpermZcombr)r,r�test_combinatorics�s,I<F##((zTestBasicOps.test_combinatoricscCs�|jttdddddddddg��td��|jttdddddddg��td��|jttdddddddg��td��|jttdddddddg��td��|jttddddg��td��|jttd	ddddddg��td
��d}tjttd�|��}tjtd��}|jtt||��dd
dg|�|jttdtd��|jtttd�d�|jtttd��|jtttd�d�x}dd�dd�gt	D]_}xVdddddddgddfdddddddgddfdddddddgddfddddgddfd	ddddddgd
dfgD]�\}}}}|jt|td|d|���t|��|jt|t||���t|��t||�}|r�t
|�|jt||��t|��q�q�Wq6WdS)N�data�ABCDEF�	selectorsrr�ACEFrlZACr�ZBCi'rNrMrWcSs
tj|�S)N)rr)rIrrrr6�sz,TestBasicOps.test_compress.<locals>.<lambda>cSs
tj|�S)N)rrrs)rIrrrr6�sZCEFZBCDEFrz)rr)rDr�compressrnrpr�rr`r@rtrF)rrr�r�r�Zresult1Zresult2r�rrr�
test_compress�s6=777.7,#!!!71+
zTestBasicOps.test_compressc	Cs�|jtdt��dddg�|jtdtd��dddg�|jtdtdtd���ddg�|jtdtdtd���ddg�|jtdtdtd ���d"d$g�|jttddd	�|jttd�|jtttt	d
�d��tt
t	d
t	d
���|jtttt	d
�d��tt
t	d
t	d
���|jtttdt	d
�d��tt
dddt	d
t	d
���td�}|jt|�d�t|�|jt|�d
�td%�}|jt|�d�t|�|jttd��d�|jt|�d&�xut
j	d
t
j	d
d'd(ddt
j	d
t
j	d
fD]7}tt|��}dj|�}|j||�q�Wx�d)dt	d
t	d
fD]�}t|�}|jttj|��|�|jttj|��|�x1t
tjd�D]}|j|t|��qkWqWtdt	d
�t
j�dS)*NrTrIrrJrrKrrMr:rWr/zcount(3)zcount(4)rYz	count(-9)g�$@zcount(10.25)rXz	count(%r))rIr)rJr)rKr)rIrM)rJr:)rKrW)rIrM)rJr:r�r�)rIr�)rJr���r�)rIr�r�)rJr�i����i����i����r�r�)rDr
�countr&r	r`r@rr$�maxsizer�reprrF�sys�__mod__rrrsr1rdrL�exc_info)rrKr�r1�r2�valuer5rrr�
test_count�sD%(..."# %)

C!zTestBasicOps.test_countcCs�|jtdtdd��d/d0d1g�|jtdtd	dd
d��d2d3d4g�|jtdtd
d5��d6d8d:g�|jtdtdd��d;d<d=g�|jtdtdd��d>d?d@g�|jtdtdd��dAdBdCg�|jtdttdd��tdttdtdd���|jtdttdd��tdttdtdd���|jtdtddD��ddEdFg�|jtdttd�td���td�td�td�g�|jtdttdd�tdd���tdd�tdd�tdd�g�|jttdtdd���tddd g��tdd�}|jt|�d!�t	|�|jt|�d"�tdGd�}|jt|�d$�t	|�|jt|�d$�tdHdI�}|jt|�d%�t	|�|jt|�d&�|jt|�d&�|jttd'd(��d)�|jttd'd��d*�|jttd'd+��d,�xt
jdt
jddJdKddt
jdt
jdfD]�}x�t
jdt
jddLdMdddt
jdt
jdf	D]�}tt||��}|dkr�d-|}nd.||f}|j||�x4ttjd�D]}|j
|t||��q�WqYWqWdS)NNrTrrMrIrJrWrKrX�start�steprrr:�rO�dg
@y@g@g!@y @z1.1z.1z1.2z1.3rV�rPr/g@g)@g.@zcount(3, 5)zcount(8, 5)rYzcount(-9, 0)z
count(-9, -3)zcount(-12, -3)g%@g�?zcount(10.5, 1.25)zcount(10.5)g�?zcount(10.5, 1.0)z	count(%r)z
count(%r, %r))rIr)rJrW)rKrX)rIr)rJrW)rKrXr�)rIrr�)rJr�r�)rKr�)rIr)rJr)rKr)rIr)rJrM)rKr:)rIr)rJrW)rKrXy
@�y@�y!@ �i����i����r�i����r�i����r�)rDr
r�r&r�rrrr�rFr�r1rdrL)rrKrr�r�r�r5rrr�test_count_with_stride"sR+!+++CF+'"-+7


CF
z#TestBasicOps.test_count_with_stridecCs�|jtdtd��td��|jttd��g�|jtt�|jttd�|jtttt��d��ddddddddddg
�td�}|jt|�d	�|jtdt	j
|��td
��x�ttj
d�D]�}|jtdtjtj||���td
��t|�|jtdtjtj||���td��t|�t|�qWx1ttj
d�D]}|j|td��q�WdS)Nr/rTZ
abcabcabcarlrWrrrrIZ
bcabcabcabZ
cabcabcabc)rDr&�cyclerr`r@r$rrFrrrsrr1rdr2r3rL)rrKr5rrr�
test_cycleOs$%F('

'

zTestBasicOps.test_cyclec
s�|jgttg���|jgttgdt���|jtttdg��|jttd�|jttddd�d�d1d2d3d4d5d6d7d8g}g}xUt|dd��D]>\}}x/|D]'}|j||d�|j|�q�Wq�W|j||�x�ttj	d�D]�}g}xdtj
tjt|t�|��D]>\}}x/|D]'}|j||d�|j|�qpWq]W|j||�q,Wg}x�t|t�D]r\}}xct|t
�D]R\}}xC|D];}|j||d�|j||d�|j|�q�Wq�Wq�W|j||�x�ttj	d�D]�}g}x�tj
tjt|t�|��D]�\}}xxtj
tjt|t
�|��D]R\}}xC|D];}|j||d�|j||d�|j|�q�Wq�Wq�W|j||�qcWdd�t|t�D�}	tdd�|D��}
|jt|	�|
�|jt|	�t|
��d}dd�tt|��D�}|j|dddddg�d d�tt|��D�}|j|dddg�d!d�tt|��D�}|j|d9d:d;d<d=g�td#d�tt|��D�d$d%�dd�}|j|d>d?d@g�Gd&d'�d't��d�fd(d)�}dtd*d+�}
|j�|
|d��|j�|
|d��G�fd,d-�d-�}|�|�dg}|j�|
|d.t�|j�|
|���fd/d0��d�_|j�|
dg��d�_|j�|
ddg��dS)AN�keyrTcSs|S)Nr)rrrrr6nsz+TestBasicOps.test_groupby.<locals>.<lambda>r/rr��rPr�r�
��rrOrMrZ�r�cSs|dS)Nrr)r,rrrr6tscSsg|]\}}|�qSrr)r7r��grrrr8�s	z-TestBasicOps.test_groupby.<locals>.<listcomp>cSsg|]}|d�qS)rr)r7r,rrrr8�s	ZabracadabracSsg|]\}}|�qSrr)r7r�r�rrrr8�s	rIrJrK�dr,cSs4g|]*\}}tt|dd��r|�qS)rr)rr$)r7r�r�rrrr8�s	cSs.g|]$\}}tt|��|f�qSr)rr)r7r�r�rrrr8�s	rWcSs.g|]$\}}tt|��|f�qSr)rr)r7r�r�rrrr8�s	�reverseTc@seZdZdS)z0TestBasicOps.test_groupby.<locals>.ExpectedErrorN)r r!r"rrrr�
ExpectedError�sr�c3s&xt|�D]}dVq
W��dS)NZyo)r)rr)r�rr�
delayed_raise�s	z0TestBasicOps.test_groupby.<locals>.delayed_raisecs �fdd�t||�D�S)Ncs"g|]\}}�|��qSrr)r7r�r�)�funcrrr8�s	z;TestBasicOps.test_groupby.<locals>.gulp.<locals>.<listcomp>)r�)r)Zkeypr�r)r�r�gulp�sz'TestBasicOps.test_groupby.<locals>.gulpcs"eZdZ�fdd�ZdS)z+TestBasicOps.test_groupby.<locals>.DummyCmpcs
��dS)Nr)rZdst)r�rr�__eq__�sz2TestBasicOps.test_groupby.<locals>.DummyCmp.__eq__N)r r!r"r�r)r�rr�DummyCmp�sr�r�cs,�jdkr"�jd8_|S��dS)Nrr)�skip)�obj)r��keyfuncrrr��sz*TestBasicOps.test_groupby.<locals>.keyfunc)rr/r�)rr�rP)rr�rP)rr�rP)rr�r�)rrOr�)rMrZr�)rMr�r�)rWrI)rrJ)rrK)rr�)rr,)rWrI)rr,)rrJ)rDrr�r�r`r@�appendrr1rdr2r3r-r.r�rr��	Exceptionr�)rr4�dupr�r��elemr5ZikZig�keysZexpectedkeysr,r�r�r�r)r�r�r�test_groupbyhs�""
1

11
5		zTestBasicOps.test_groupbyc	Cs�|jttttd���dddg�|jttddddddg��ddg�|jtttdddddg��ddg�|jtdttt���ddddg�|jt	t�|jt	tdd��|jt	tdd�td�d	�|jt	ttd
�|jt	t
ttd�td���dddg}tttd��}|jttj|��|�tttd��}|jttj|��|�x�tt
jd�D]�}tttd��}|jtt
jt
j||���|�t
|�|jtt
jt
j||���|dd��q�Wx@tt
jd�D]+}tttd��}|j||�q{WdS)NrNrrr:rcSs|S)Nr)rrrrr6�sz*TestBasicOps.test_filter.<locals>.<lambda>cSs|S)Nr)rrrrr6�srVrM)rDrr�rr�boolr&r�r`r@rFrrrsr1rdr2r3rL)r�ansrKr5rrr�test_filter�s,.441%(+
9zTestBasicOps.test_filterc	Cs�|jttttd���dddg�|jttddddddg��dddg�|jtttdddddg��dddg�|jtdttt���ddddg�|jt	t�|jt	td	d
��|jt	tdd
�td�d�|jt	ttd�|jt	t
ttd�td���x:ttjd�D]%}|j
|tttd���qmWdS)NrNrrMrWrrr:rVcSs|S)Nr)rrrrr6�sz/TestBasicOps.test_filterfalse.<locals>.<lambda>cSs|S)Nr)rrrrr6�s)rDr�filterfalserrr�r&r�r`r@rFr1rdrL)rr5rrr�test_filterfalse�s.771%(zTestBasicOps.test_filterfalsecCs�dd�tdt��D�}|j|dddg�|jttdtd
���tdtd
���|jttdtd���tdtd���|jtdtdt���tdtd���|jttd��td��|jtt��t��|jttd�|jtttd�d�|jd
d�tdd�D�tdd��|jdd�tdd�D�tdd��dS)NcSs"g|]\}}||f�qSrr)r7r�yrrrr8s	z)TestBasicOps.test_zip.<locals>.<listcomp>rTrIrrJrrKrrNrkrMcSs"g|]}tt|���qSr)r~r)r7�pairrrrr8	s	rjcSsg|]}|�qSrr)r7r�rrrr8s	)rIr)rJr)rKr)	r	r�rDrrr
r&r`r@)rr�rrr�test_zip�s444"zTestBasicOps.test_zipcCs&ttttdd���}|jt|�t|��tttttdd����}|jttj	|��t|��dd�t
j
tdt���D�}|j|dddg�dd�t
jtdt���D�}|j|dddg�xht
tjd�D]S}dd�tjtjtdt��|��D�}|j|dddg�qWxut
tjd�D]`}tdt��}t|�d
d�tjtj||��D�}|j|ddg�q�Wx7t
tjd�D]"}|j|tdt���q�WdS)NrTrjcSs"g|]\}}||f�qSrr)r7rr�rrrr8s	z5TestBasicOps.test_zip_tuple_reuse.<locals>.<listcomp>rIrrJrrKrcSs"g|]\}}||f�qSrr)r7rr�rrrr8s	cSs"g|]\}}||f�qSrr)r7rr�rrrr8s	cSs"g|]\}}||f�qSrr)r7rr�rrrr8#s	)rIr)rJr)rKr)rIr)rJr)rKr)rIr)rJr)rKr)rJr)rKr)rr_r�r	rDrarbr�dict�fromkeysrrr�rsrr1rdr2r3rFrL)r�idsr�r5r�rrr�test_zip_tuple_reuses$$%((4
(z!TestBasicOps.test_zip_tuple_reusecsDxcdtd�gtd�dgtd�tdd�tdd�gtd�td�tdd�td	�td
�gtd�td�tdd�td	�td
�td�ggD]���fdd�tttt����D�}|jtt���|�|jtt�i��|�d
d�|D�}|jtt�tdd���|�q�W|jtdtdt	���tt
dtd����|jtt��tt
���|jttg��tt
g���|jttd��tt
d���|jttddi��tt
td�dgd���|jttd�|jtttd�d�xTddgD]F}yt
|t�t��Wntk
r�Yq�X|jd|�q�W|jdd�tdd�D�tt
dd���|jdd�tdd�D�tt
dd���dS)NrTrNi�i�i4i�i�ri�i�cs/g|]%�t�fdd��D���qS)cs2g|](}�t|�kr(|�nd�qS)N)r)r7�arg)rrrr81s	z;TestBasicOps.test_ziplongest.<locals>.<listcomp>.<listcomp>)r~)r7)r
)rrr81s	z0TestBasicOps.test_ziplongest.<locals>.<listcomp>cSs)g|]}tdd�|D���qS)css'|]}|dkrdp|VqdS)N�Xr)r7r;rrrr}5sz:TestBasicOps.test_ziplongest.<locals>.<listcomp>.<genexpr>)r~)r7r�rrrr85s	�	fillvaluer�rMrkZdefgzzip_longest('abc', fv=1)z3zip_longest('abc', fillvalue=1, bogus_keyword=None)zDid not raise Type in:  cSs"g|]}tt|���qSr)r~r)r7r�rrrr8Ns	rjcSsg|]}|�qSrr)r7r�rrrr8Ps	)rrbr_rrDr�zip_longestr�r&r�r	r`r@�eval�globals�localsZfail)r�targetZstmtr)r
r�test_ziplongest)s@$3F,:"((#

zTestBasicOps.test_ziplongestcCs�ttttdd���}|jt|�t|��tttttdd����}|jttj	|��t|��dS)NrTrj)
rr_r�r�rDrarbrr�r�)rr�rrr�test_zip_longest_tuple_reuseSs$z)TestBasicOps.test_zip_longest_tuple_reusecCs�x�ttjd�D]p}|j|tdd��|j|tdd��|j|tdddd��|j|tdd��qWdS)NrrTrjZdefghr�rl)rr1rdrLr�)rr5rrr�test_zip_longest_picklingZs
z&TestBasicOps.test_zip_longest_picklingcCs�Gdd�d�}|ddt�}|ddt�}dd�}|j|||�ddd
dg�|ddt�}|ddt�}t||d
d	�}|jt|�d�|jt|�d�|jt|�d�|jtt|�dS)Nc@s4eZdZdd�Zdd�Zdd�ZdS)z,TestBasicOps.test_bug_7244.<locals>.RepeatercSs%||_t|�|_||_dS)N)�or]r�r;)rr�r�r;rrr�__init__es	z5TestBasicOps.test_bug_7244.<locals>.Repeater.__init__cSs|S)Nr)rrrrrisz5TestBasicOps.test_bug_7244.<locals>.Repeater.__iter__cSs2|jdkr%|jd8_|jS|j�dS)Nrr)r�r�r;)rrrrrksz5TestBasicOps.test_bug_7244.<locals>.Repeater.__next__N)r r!r"rrrrrrr�RepeatercsrrrMrr:cSsig}x\t||dd�D]E\}}tjd��t||f�WdQX|j||f�qW|S)Nr�r�stdout)r�rZcaptured_output�printr�)r�r�r�rr�rrr�runvs"z'TestBasicOps.test_bug_7244.<locals>.runrr�)rr)rr)rr)rr)rr)rr)rr)rrDr=r�rFr`)rrr�r�rrArrr�
test_bug_7244as%zTestBasicOps.test_bug_7244cs�x6gfgfdgddgftd�td�gddddd d!gftd�td�td�ggftd�td�td�ggftd�td�td�ggfgD]w\}}|jtt|��|�xLtd�D]>}|jtt||��tt|td	|����q�Wq�W|jttttd
�gd���d"�|jtttd�d�dd
�}dd�}dddtd�td�tdddddd�td�td�t	td��g	�x�td�D]�}�fdd�tt
jd��D�}tt
t|��}|jttt|���|�|jtt|��t||���|jtt|��t||���t
t|�}|jttt|���|�qWdS)#NrUrIrJrrMrrr:r�rVrNcs9ttt|��|jdd�}t|�}|dkrFfVdStdd�|D��rcdSdg|}tdd�t||�D��Vx�x�tt|��D]�}||t||�dkr�q�n||d7<x%t|d|�D]}d||<q�Wtdd�t||�D��VPq�WdSq�WdS)Nr�rrcss!|]}t|�dkVqdS)rN)r)r7r|rrrr}�sz>TestBasicOps.test_product.<locals>.product1.<locals>.<genexpr>css|]\}}||VqdS)Nr)r7r|rrrrr}�scss|]\}}||VqdS)Nr)r7r|rrrrr}�s)	rr_r~�getr�anyr	r�r)r
�kwds�poolsrr�rr�rrr�product1�s&%
!!z+TestBasicOps.test_product.<locals>.product1c?sxttt|��|jdd�}gg}x'|D]��fdd�|D�}q5Wx|D]}t|�Vq_WdS)z Pure python version used in docsr�rcs*g|] }�D]}||g�qqSrr)r7rr�)r|rrr8�s	z?TestBasicOps.test_product.<locals>.product2.<locals>.<listcomp>N)rr_r~r)r
rr	r�r*r)r|r�product2�s%	

z+TestBasicOps.test_product.<locals>.product2rlrTrKZabcdefgr�r�r�csg|]}tj���qSr)�randomZchoice)r7r�)�argtypesrrr8�s	z-TestBasicOps.test_product.<locals>.<listcomp>rW)rI)rJ)rr)rr)rr)rr)rr)rri��)rrDrr�r�rr`r@r�r~rZ	randranger*r_�iter)rr
r�r,r
rrZexpected_lenr)r
r�test_product�s2-$$4'/	3'("((zTestBasicOps.test_productc
Cs7|jttf��tdddgd�WdQXdS)Nr�r�rUrWirv)r`r�r�r�)rrrr�test_product_overflow�sz"TestBasicOps.test_product_overflowc	Csf|jtttttdd����d�|jttttttdd�����d�dS)NrTrjr)rDrr�r_r�r�r�r)rrrr�test_product_tuple_reuse�s.z%TestBasicOps.test_product_tuple_reusec
CsPxIgfgfdgdd	gftd�td�gd
ddd
ddgftd�td�td�ggftd�td�td�ggftd�td�td�ggfgD]�\}}|jttjt|���|�|jttjt|���|�x1ttjd�D]}|j|t|��q(Wq�WdS)NrUrIrJrrMrr)rI)rJ)rr)rr)rr)rr)rr)rr)	rrDrrrr�rsr1rdrL)rr
r�r5rrr�test_product_pickling�s-$$4%%z"TestBasicOps.test_product_picklingcCshtdd�}|jd�|jt|�d	�td
fd�}|jd�|jtt|�dS)
NrrrMr�)rr)rM)rr)rrM)rr)rM)rrr)r��__setstate__rDrFr`r)rr�rrr�test_product_issue_25021�s

z%TestBasicOps.test_product_issue_25021cCsL|jttdddd��dddg�|jttd�td��dddg�|jttdd��dddg�|jtdtd��dddg�|jttdd��g�|jttdd��g�|jtt�|jttddd�|jttdd�td�}|jt|�d
�tdd�}|jt|�d�t|�|jt|�d
�tdddd�}|jt	|�d�|jtdt
j
|��td��|jtdt
j|��td��x:ttj
d�D]%}|j|tdddd��qWdS)N�objectrI�timesrMrrrr:yzrepeat((1+0j))rWzrepeat((1+0j), 5)zrepeat((1+0j), 0)r/)rrI)rrI)rrIr�y�?y�?�aar)rDrr�r
rr&r`r@r�rFrrrsr1rdrL)rr,rKr5rrr�test_repeat�s,.((
((zTestBasicOps.test_repeatcCs�|jttdd��d�|jttdd��d�|jttddd��d�|jttddd	��d�dS)
NrIrzrepeat('a', 0)rrr�r�r�r�)rDr�r�)rrrr�test_repeat_with_negative_timess"z,TestBasicOps.test_repeat_with_negative_timescCsg|jtttjtd�tdd���d
ddg�|jtttdtd���dddg�|jtttdt���dddg�|jtdttdt���ddg�|jtttjg��g�|j	t
t�|j	t
ttdtd�td���|j	t
ttj�|j	t
ttdtd���|j	t
tttdgdg��|j	t
tttdgdg��dddg}ttdt��}|jttj|��|�ttdt��}|jttj|��|�x@ttjd�D]+}ttdt��}|j||�q4WdS)NrMrrVrrrTrWrIrJrKr/r:rrrX)rIr)rJr)rKr)rIr)rJr)rKr)rIr)rJr)rIr)rJr)rKr)rDrr_r'�powrrr�r&r`r@�negrFrrrrrrsr1rdrL)rr�rKr5rrr�test_maps.-!!
"+"%%zTestBasicOps.test_mapc	Cs�|jtttjttd�tdd����d
ddg�|jtdttjtt�td����d
ddg�|jtttjg��g�|jtttjt	ddg�g��dg�|j
ttttjdg��|j
tt�|j
tttjdgd�|j
tttd	dg��|j
t
tttdg��|j
ttttdg��dddg}ttjttd�tdd���}|jttj|��|�ttjttd�tdd���}|jttj|��|�xUttjd�D]@}ttjttd�tdd���}|j||�q<WdS)NrMrrVrrr:rW�extrar/rrrXrrrXi)r:rW)r:rW)r:rW)r:rWrrrX)rDr�starmapr'rr	rr&r�rr`r@rFrrrrrrsr1rdrL)rr�rKr5rrr�test_starmap$s(30"4"***zTestBasicOps.test_starmapcCs�xNdddddgD]7}|jtttd�|��tt|���qWxNdddgD]=\}}|jtttd�|��tt|���qaW|jtttd�d��ttd���|jtttd�dd��ttd���|jtttd�ddd��ttd���|jtttd�dd��ttdd���|jtttd�ddd��ttddd���ttd��}|jtt|d��ttd���|jt|�ttdd���td�}|jtt|�|jtt|dddd�|jtt|ddd�|jtt|ddd�|jtt|ddd �|jtt|ddd
�|jtt|d�|jtt|dd�|jtt|dd�|jtt|ddd�|jtt|ddd�|jtttt	�ddt
���d�t	�}|jtt|ddd��dg�|jt|�d�x�d!d"d#d$d%gD]�}|jttjttd�|���tt|���|jttj
ttd�|���tt|���x:ttjd�D]%}|j|ttd�|��q[Wq�Wd
d�d&D�}tj|�}t|d�}|j|��t|�tj�|j|��dS)'Nr/r�rMr��nrrr:rWrrI�2css|]}|VqdS)Nr)r7rrrrr}�sz+TestBasicOps.test_islice.<locals>.<genexpr>)r/r�rM)r/rMr�)r/r�)r/rM)r��r/r"rM�r/r�rM)r$r%�r/r"�r/r�)r&r'�r"�r�)r(r)���r*r�r�)r/r�rM)r/rMr�)r/r�)r/rM)r�)rr)rDrr$rrr`r@rrr�r�rFrrrsr1rdrL�weakref�refZassertIsNotNonerZ
gc_collectZassertIsNone)rr
ZtgtargsrAZrarKr5�wrrrr�test_islice?sr
1477=+%.	(
'''

zTestBasicOps.test_islicecCs�ddddddddg}|jttt|��dddg�|jtttg��g�|jtt�|jtttj�|jtttjdgd	�|jtttd
d
g��|jt	ttt
dg��ttddddddg�}|jt|�dddg�|jtt|�|jtt
j
tt|���dddg�|jtt
jtt|���dddg�x4ttjd�D]}|j|tt|��q�WdS)NrrMrWr�rr:rNrXrr/r)r:rW)r:rW)r:rW)rDr�	takewhiler0r`r@r'rrFrrr�rrrrsrr1rdrL)rr�r�r5rrr�test_takewhile�s (!1!zTestBasicOps.test_takewhilecCs�ddddddddg}|jttt|��dddddg�|jtttg��g�|jtt�|jtttj�|jtttjdgd	�|jtttd
dg��|jt	ttt
d
g��|jttjtt|���dddddg�|jttjtt|���dddddg�x4t
tjd�D]}|j|tt|��qpWdS)NrrMrWr�rr:rNrXrr/)r:rW)r:rW)r:rW)rDr�	dropwhiler0r`r@r'rrFrrrrrsrr1rdrL)rr�r5rrr�test_dropwhile�s.7!zTestBasicOps.test_dropwhilecCs%d}tg�\}}|jt|�g�|jt|�g�tt|��\}}|jt||�tt|�t|���tt|��\}}|jt|�tt|���|jt|�tt|���tt|��\}}x*td�D]}|jt|�|�qW~|jt|�tt|���tt|��\}}x*td�D]}|jt|�|�quW~|jt|�ttd|���x�td�D]�}dg|dg|}tj|�ggf}tt|��}x/|D]'}t||�}	||j	|	�qW|j|dtt|���|j|dtt|���q�W|j
tt�|j
ttd�|j
ttddgd�|j
ttddgdd�td	�\}}t|�d
�}
|jt|
�td
��ttd�d�\}}}
x*td�D]}|jt|�|�qRW|jt|�ttd���|jt|
�t|
�gttd���|jt|�ttdd���|jt|
�ttdd���|j
ttd	d�|j
t
tgd�xytd�D]k}td	|�}|jt|�t�|jt|�|�|jd
d�|D�td	�g|�qEWtd	�\}}t|�\}
}|j||
k�td	�\}
}t|
�}|j
t|�|j
t|d�||
�}|jt|
�t|�koxt|�koxtd	�kn�ttd��\}}tj|�}|jt|d�t|��~|j
tt|d�td	�}ttd��}td	�\}}|jttj|��|�|jttj|��|�tttd���\}}|jttj|��|�|jttj|��|�td	�\}}td|�td|�|jttj|��|dd��|jttj|��|dd��|jt|�|dd��|jt|�|dd��ttd��\}}td|�td|�|jttj|��|dd��|jttj|��|dd��|jt|�|dd��|jt|�|dd��td	�\}}|jttj|��|�|jttj|��|�|jt|�|�|jt|�|�ttd��\}}|jttj|��|�|jttj|��|�|jt|�|�|jt|�|�td	�\}}td|�td|�|jttj|��|dd��|jttj|��|dd��|jt|�|dd��|jt|�|dd��ttd��\}}td|�td|�|jttj|��|dd��|jttj|��|dd��|jt|�|dd��|jt|�|dd��xuttjd�D]`}|j|ttd	���td	�\}}|j||d|�|j||d|�q�
WdS)N��r�rWrrrMrrrTrji�ZinvalidcSsg|]}t|��qSr)r)r7rrrrr8�s	z)TestBasicOps.test_tee.<locals>.<listcomp>r/�	__class__i'�<rGr�)�teerDrrr
rrFrZshuffler�r`r@rErr~rr�r+�proxy�getattr�ReferenceErrorrrr&rsr1rdrLr)rrrIrJrr�ZorderZlists�itsr�rKr�r�Zt1Zt2ZtnewZt3r�r�Zlong_ansr5rrr�test_tee�s�."""%

 $".%%.F

))  

))  

))  

))  zTestBasicOps.test_teec	CsDttdd��\}}yt|�~Wn~~�YnXdS)Ni-1)r6r�r)rZforwardZbackwardrrr�test_tee_del_backwardEs
z"TestBasicOps.test_tee_del_backwardcCs�|jttt��xOttttfD];}|jtt|g��|jtt|t���q)W|jtttgd��|jtttt�d��t	g�\}}|jtt|�|jtt|�t	t��\}}|jtt|�|jtt|�|jttt
dd��xgttt
tttfD]M}|jtt|dd�g��|jtt|dd�t���qKWdS)NrcSs|S)Nr)rrrrr6bsz1TestBasicOps.test_StopIteration.<locals>.<lambda>cSs|S)Nr)rrrrr6cs)r`rrFr	rnr�r�rr$r6r�r�r�r_r/r1r )r�fr��qrrr�test_StopIterationNs  "zTestBasicOps.test_StopIteration)1r r!r"rLrfrorqrur�rZbigaddrspacetestr�Zimpl_detailr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrrrrrr!r.r0r2r;r<r?rrrrr9PsV)
PL?!"(-n
*(:
L�	r9c@seZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-S).�TestExamplescCs>|jttdddddg��dddddg�dS)	NrrrMr:rWrNr/rO)rDrr\)rrrrrfgszTestExamples.test_accumulatecCsLdddddg}dddddg}x�ttjd�D]�}t|�}|jttjtj||���|dd��|jt|�d�|jttjtj||���|dd��q>Wt|�}|jt|�d�|jtt	j
|��|dd��|jtt	j	|��|dd��dS)	NrrrMr:rWrNr/rO)rr1rdr\rDrr2r3rFrrrs)rr�Zaccumulatedr5rArrr�test_accumulate_reduciblejs59)z&TestExamples.test_accumulate_reduciblecCs&|jdjtdd��d�dS)Nrlr��DEFr�)rD�joinrn)rrrrroyszTestExamples.test_chaincCs,|jdjtjddg��d�dS)Nrlr�rBr�)rDrCrnrp)rrrrrq|sz%TestExamples.test_chain_from_iterablec	Csf|jttdd��ddd
dddg�|jtttd�d��ddddg�dS)Nrwrrxryrzr{r:rMrr)rxry)rxrz)rxr{)ryrz)ryr{)rzr{)rrr)rrrM)rrrM)rrrM)rDrr�r)rrrrr�szTestExamples.test_combinationsc	Cs5|jttdd��dddd	d
dg�dS)Nr�rrxryrz)rxrx)rxry)rxrz)ryry)ryrz)rzrz)rDrr�)rrrrr��sz/TestExamples.test_combinations_with_replacementc
Cs;|jttdddddddg��td��dS)Nr�rrr�)rDrr�)rrrrr��szTestExamples.test_compresscCs8|jtttd�d��dddddg�dS)Nr/rWr�r�r�r�)rDrr$r�)rrrrr��szTestExamples.test_countcCs/|jtttd�d��td��dS)Nrwr�ZABCDABCDABCD)rDrr$r�)rrrrr��szTestExamples.test_cyclec	CsA|jttdd�dddddg��dddg�dS)NcSs
|dkS)NrWr)rrrrr6�sz-TestExamples.test_dropwhile.<locals>.<lambda>rr:rN)rDrr1)rrrrr2�szTestExamples.test_dropwhilecCst|jdd�td�D�td��|jdd�td�D�td�td�td	�td
�g�dS)NcSsg|]\}}|�qSrr)r7r�r�rrrr8�s	z-TestExamples.test_groupby.<locals>.<listcomp>ZAAAABBBCCDAABBBZABCDABcSs"g|]\}}t|��qSr)r)r7r�r�rrrr8�s	Z
AAAABBBCCDZAAAAZBBB�CCr{)rDr�r)rrrrr��s
zTestExamples.test_groupbycCs>|jttdd�td���dddddg�dS)	NcSs|dS)Nrr)rrrrr6�sz*TestExamples.test_filter.<locals>.<lambda>r/rrMrWrVrY)rDrr�r)rrrrr��szTestExamples.test_filtercCs>|jttdd�td���dddddg�dS)	NcSs|dS)Nrr)rrrrr6�sz/TestExamples.test_filterfalse.<locals>.<lambda>r/rrr:rNrX)rDrr�r)rrrrr��szTestExamples.test_filterfalsecCs/|jtttdd	��dddg�dS)
NrrMr/rWrvrYi�)rrMr/)rWrrM)rDrr_r)rrrrr�szTestExamples.test_mapcCs�|jttdd��td��|jttddd��td��|jttddd��td��|jttdddd��td��dS)	Nr�rZABr:ZCDZCDEFGrZACEG)rDrr$)rrrrr.�s%((zTestExamples.test_islicecCs)|jttdd��ddg�dS)	Nrw�xyrxrryr�)rxr)ryr�)rDrr	)rrrrr��szTestExamples.test_zipcCs5|jttdddd��ddd
dg�dS)NrwrEr��-rxrryr�rzr{)rxr)ryr�)rzrF)r{rF)rDrr�)rrrr�test_zip_longest�szTestExamples.test_zip_longestc
Csl|jttdd��tttdj����|jtttd���ddd	d
ddg�dS)
Nrwrz#AB AC AD BA BC BD CA CB CD DA DB DCrMrr)rrr)rrr)rrr)rrr)rrr)rrr)rDrr�r_r~�splitr)rrrrr��szTestExamples.test_permutationscCsx|jttdd��tttdj����|jtttd�dd��d	d
ddd
dddg�dS)NrwrEzAx Ay Bx By Cx Cy Dx Dyrr�rMrr)rrr)rrr)rrr)rrr)rrr)rrr)rrr)rrr)rDrr�r_r~rHr)rrrrr�s
!zTestExamples.test_productcCs,|jttdd��dddg�dS)Nr/rM)rDrr�)rrrrr�szTestExamples.test_repeatcCs5|jtttdd	d
g��dddg�dS)NrrWrMr/rvrYi�)rrW)rMr)r/rM)rDrr r)rrrr�test_stapmap�s!zTestExamples.test_stapmapc	Cs>|jttdd�dddddg��ddg�dS)NcSs
|dkS)NrWr)rrrrr6�sz-TestExamples.test_takewhile.<locals>.<lambda>rr:rN)rDrr/)rrrrr0�szTestExamples.test_takewhileN)r r!r"rfrArorqr�r�r�r�r�r2r�r�r�rr.r�rGr�rrrIr0rrrrr@es,r@c@s$eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/S)0�TestGCcCs!|j|�t|�~~dS)N)r�rF)r�iteratorZ	containerrrr�	makecycle�s

zTestGC.makecyclecCs,g}|jtdd|dg�|�dS)NrrrM)rLr\)rrIrrrrf�szTestGC.test_accumulatecCs g}|jt|�|�dS)N)rLrn)rrIrrrro�szTestGC.test_chaincCs&g}|jtj|g�|�dS)N)rLrnrp)rrIrrrrq�szTestGC.test_chain_from_iterablecCs/g}|jtdd|dgd�|�dS)NrrrM)rLr�)rrIrrrr��szTestGC.test_combinationscCs/g}|jtdd|dgd�|�dS)NrrrM)rLr�)rrIrrrr��sz)TestGC.test_combinations_with_replacementc	Cs5g}|jtdddddddg�|�dS)Nr�rr)rLr�)rrIrrrr��szTestGC.test_compresscCsMg}tdtftd|��}|jt|d�|d��|�dS)N�Intrrr)rEr]r�rLr�)rrIrMrrrr��szTestGC.test_countcCs'g}|jt|gd�|�dS)Nr)rLr�)rrIrrrr��szTestGC.test_cyclecCs,g}|jttd||g�|�dS)Nr)rLr1r�)rrIrrrr2�szTestGC.test_dropwhilecCs0g}|jt|gddd��|�dS)NrcSs|S)Nr)rrrrr6�sz%TestGC.test_groupby.<locals>.<lambda>)rLr�)rrIrrrr��szTestGC.test_groupbycCs[d}dd�}xBtt|�d|�D](\}}|jjdg�j|�q+WdS)Nr/cSs|S)Nr)rrrrr6�sz'TestGC.test_issue2246.<locals>.<lambda>r�r)r�r�__dict__�
setdefaultr�)rrr�rr�rrr�test_issue2246�s%zTestGC.test_issue2246cCs0g}|jtdd�|gd�|�dS)NcSsdS)NTr)rrrrr6sz$TestGC.test_filter.<locals>.<lambda>r)rLr�)rrIrrrr�szTestGC.test_filtercCs)g}|jtdd�|�|�dS)NcSsdS)NFr)rrrrr6sz)TestGC.test_filterfalse.<locals>.<lambda>)rLr�)rrIrrrr�szTestGC.test_filterfalsecCs1g}|jt|gd|gd�|�dS)NrrM)rLr	)rrIrrrr�szTestGC.test_zipcCsjg}|jt|gd|gd�|�|dg}|jt|gd|gdd|�|�dS)NrrMr�)rLr�)rrIrJrrrrGs'zTestGC.test_zip_longestcCs0g}|jtdd�|gd�|�dS)NcSs|S)Nr)rrrrr6sz!TestGC.test_map.<locals>.<lambda>r)rLr_)rrIrrrrszTestGC.test_mapcCs*g}|jt|gdd�|�dS)Nr)rLr$)rrIrrrr.szTestGC.test_islicecCs/g}|jtdd|dgd�|�dS)NrrrM)rLr�)rrIrrrr�szTestGC.test_permutationscCs2g}|jtdd|dgdd�|�dS)NrrrMr�)rLr�)rrIrrrrszTestGC.test_productcCs g}|jt|�|�dS)N)rLr�)rrIrrrr"szTestGC.test_repeatcCs6g}|jtdd�||fgd�|�dS)NcWs|S)Nr)r�rrrr6(sz%TestGC.test_starmap.<locals>.<lambda>r)rLr )rrIrrrr!&szTestGC.test_starmapcCs/g}|jttdd||g�|�dS)Nrr)rLr/r�)rrIrrrr0*szTestGC.test_takewhileN)r r!r"rLrfrorqr�r�r�r�r�r2r�rPr�r�r�rGrr.r�rrr!r0rrrrrJ�s.rJccsx|D]}|VqWdS)zRegular generatorNr)�seqnrrrr�R.s
rRc@s.eZdZdZdd�Zdd�ZdS)�GzSequence using __getitem__cCs
||_dS)N)rQ)rrQrrrr5sz
G.__init__cCs|j|S)N)rQ)rrrrr�__getitem__7sz
G.__getitem__N)r r!r"r#rrTrrrrrS3srSc@s:eZdZdZdd�Zdd�Zdd�ZdS)	�Iz Sequence using iterator protocolcCs||_d|_dS)Nr)rQr)rrQrrrr<s	z
I.__init__cCs|S)Nr)rrrrr?sz
I.__iter__cCsD|jt|j�kr!t�n|j|j}|jd7_|S)Nr)rrrQr)rr�rrrrAs
	z
I.__next__N)r r!r"r#rrrrrrrrU:srUc@s.eZdZdZdd�Zdd�ZdS)�Igz9Sequence using iterator protocol defined with a generatorcCs||_d|_dS)Nr)rQr)rrQrrrrIs	zIg.__init__ccsx|jD]}|Vq
WdS)N)rQ)r�valrrrrLszIg.__iter__N)r r!r"r#rrrrrrrVGsrVc@s.eZdZdZdd�Zdd�ZdS)r�z Missing __getitem__ and __iter__cCs||_d|_dS)Nr)rQr)rrQrrrrRs	z
X.__init__cCsD|jt|j�kr!t�n|j|j}|jd7_|S)Nr)rrrQr)rr�rrrrUs
	z
X.__next__N)r r!r"r#rrrrrrr�Psr�c@s.eZdZdZdd�Zdd�ZdS)�NzIterator missing __next__()cCs||_d|_dS)Nr)rQr)rrQrrrr]s	z
N.__init__cCs|S)Nr)rrrrr`sz
N.__iter__N)r r!r"r#rrrrrrrX[srXc@s:eZdZdZdd�Zdd�Zdd�ZdS)	�EzTest propagation of exceptionscCs||_d|_dS)Nr)rQr)rrQrrrres	z
E.__init__cCs|S)Nr)rrrrrhsz
E.__iter__cCsdddS)NrMrr)rrrrrjsz
E.__next__N)r r!r"r#rrrrrrrrYcsrYc@s:eZdZdZdd�Zdd�Zdd�ZdS)	�SzTest immediate stopcCsdS)Nr)rrQrrrrosz
S.__init__cCs|S)Nr)rrrrrqsz
S.__iter__cCs
t�dS)N)r)rrrrrssz
S.__next__N)r r!r"r#rrrrrrrrZmsrZcCs+ttdd�ttt|�����S)z Test multiple tiers of iteratorscSs|S)Nr)rrrrr6xszL.<locals>.<lambda>)rnr_rRrVrS)rQrrr�Lvsr[c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!S)"�TestVariousIteratorArgscCs�dddddg}dddddg}t|�}x?tttttfD](}|jtt||���|�qLW|jttt	|���g�|j
ttt|��|j
ttt
|��|j
tttt|���dS)	NrrrMr:rWrNr/rO)rrSrUrVr[rRrDrr\rZr`r@r�rX�ZeroDivisionErrorrY)rr4r,rr�rrrrf}s&"z'TestVariousIteratorArgs.test_accumulatecCs+x$ddtd�d	tddd�fD]�}x�ttttttfD]{}|jtt	||���t||���|jtt	||�||���t||��t||���qGW|j
ttt	t|���|j
ttt	t
|���|j
ttt	t|���q(WdS)
N�123rli��do�333333�?i�i�rW)r_r`)rrSrUrVrZr[rRrDrrnr`r@r�rXr]rY)rr4r�rrrro�s..Kz"TestVariousIteratorArgs.test_chaincCsxddtd�d
tddd�fD]�}t|�}xWttttttfD]=}|jt	t
||�td	���t	||���qSW|jt
t
t|�td	��|jt
t
t|�td	��|jtt	t
t|�td	���q(WdS)Nr^rli�r_�333333�?i�i�rWr)zdora)rrrSrUrVrZr[rRrDrr�r�r`r@r�rXr]rY)rr4rr�rrrr��s.;""z%TestVariousIteratorArgs.test_compresscCs�xzddtd�d	tddd�fD]Q}|jttt|��|jttt|��|jttt|��q(WdS)
Nr^rli�r_�333333�?i�i�rW)zdorb)rr`r@r�r�rXr]rY)rr4rrrr�s.z$TestVariousIteratorArgs.test_productcCsx�ddtd�d
tddd�fD]�}xwttttttfD]]}t|�d	}t||��d	}tt	t
||��|��}|j||�qGW|jt
t
t|��|jt
t
t|��|jttt
t|���q(WdS)Nr^rli�r_�333333�?i�i�rWrM)zdorc)rrSrUrVrZr[rRrrr$r�rDr`r@r�rXr]rY)rr4r�ZtgtlenZexpectedZactualrrrr��s.!z"TestVariousIteratorArgs.test_cyclecCs�x�td�td�td�dtddd�fD]�}xUttttttfD];}|jd	d
�t||��D�t	||���qSW|j
ttt|��|j
ttt
|��|j
tt	tt|���q4WdS)Nr/ri�rVr�i�i�rWcSsg|]\}}|�qSrr)r7r�Zsbrrrr8�s	z8TestVariousIteratorArgs.test_groupby.<locals>.<listcomp>)rVr�)rrSrUrVrZr[rRrDr�rr`r@r�rXr]rY)rr4r�rrrr��s:9z$TestVariousIteratorArgs.test_groupbycCs�x�td�td�td�dtddd�fD]�}xXttttttfD]>}|jtt	t
||���d	d
�||�D��qSW|jtt	t
t
|��|jtt	t
t|��|jttt	t
t|���q4WdS)Nr/ri�rVr�i�i�rWcSs"g|]}t|�r|�qSr)r)r7rrrrr8�s	z7TestVariousIteratorArgs.test_filter.<locals>.<listcomp>)rVr�)rrSrUrVrZr[rRrDrr�rr`r@r�rXr]rY)rr4r�rrrr��s:z#TestVariousIteratorArgs.test_filtercCs�x�td�td�td�dtddd�fD]�}xXttttttfD]>}|jtt	t
||���d	d
�||�D��qSW|jtt	t
t
|��|jtt	t
t|��|jttt	t
t|���q4WdS)Nr/ri�rVr�i�i�rWcSs"g|]}t|�r|�qSr)r)r7rrrrr8�s	z<TestVariousIteratorArgs.test_filterfalse.<locals>.<listcomp>)rVr�)rrSrUrVrZr[rRrDrr�rr`r@r�rXr]rY)rr4r�rrrr��s:z(TestVariousIteratorArgs.test_filterfalsecCsxddtd�d	tddd�fD]�}x�ttttttfD]t}|jtt	||���t
||���|jtt	||�||���t
||�||���qGW|jtt	t
|��|jtt	t|��|jttt	t|���q(WdS)
Nr^rli�r_�333333�?i�i�rW)zdord)rrSrUrVrZr[rRrDrr	r
r`r@r�rXr]rY)rr4r�rrrr��s..Dz TestVariousIteratorArgs.test_zipc	Cs$xddtd�d	tddd�fD]�}x�ttttttfD]�}|jtt	||���tt
||����|jtt	||�||���tt
||�||����qGW|jtt	t
|��|jtt	t|��|jttt	t|���q(WdS)
Nr^rli�r_�333333�?i�i�rW)zdore)rrSrUrVrZr[rRrDrr�r	r`r@r�rXr]rY)rr4r�rrrr��s.4Jz'TestVariousIteratorArgs.test_ziplongestc	Cs;x4td�td�td�dtddd�fD]�}x�ttttttfD]�}|jtt	t
||���d	d
�||�D��|jtt	tj||�||���dd
�||�D��qSW|j
tt	t
t|��|j
tt	t
t|��|j
ttt	t
t|���q4WdS)
Nr/rr�rVr�r�r#rWcSsg|]}t|��qSr)r)r7rrrrr8�s	z4TestVariousIteratorArgs.test_map.<locals>.<listcomp>cSsg|]}||�qSrr)r7rrrrr8�s	)rVr�)rrSrUrVrZr[rRrDrr_rr'rr`r@r�rXr]rY)rr4r�rrrr�s:*z TestVariousIteratorArgs.test_mapc	Cs�x�ddtd�dtddd�fD]�}xdttttttfD]J}|jtt	||�d	dd
��t||��d	dd
��qGW|j
tt	t|�d�|j
tt	t
|�d�|j
ttt	t|�d��q(WdS)
NZ12345rli�r_�333333�?i�i�rWrrr/)zdorf)rrSrUrVrZr[rRrDrr$r`r@r�rXr]rY)rr4r�rrrr.�s.Hz#TestVariousIteratorArgs.test_islicecCsxtd�td�td�dtddd�fD]�}xjttttttfD]P}t||�}|jt	t
tj||���d	d
�||�D��qSW|j
tt
tjt|��|j
tt
tjt|��|j
tt	t
tjt|���q4WdS)Nr/rr�rVr�r�r#rWcSsg|]}||�qSrr)r7rrrrr8�s	z8TestVariousIteratorArgs.test_starmap.<locals>.<listcomp>)rVr�)rrSrUrVrZr[rRr
rDrr r'rr`r@r�rXr]rY)rr4r�Zssrrrr!�s:!z$TestVariousIteratorArgs.test_starmapcCsxtd�td�td�d	tddd�fD]�}xttttttfD]e}g}x1||�D]#}t|�s�Pn|j|�qlW|j	t
tt||���|�qSW|jt
ttt|��|jt
ttt|��|jtt
ttt|���q4WdS)
Nr/ri�rVr�i�i�rW)rVr�)rrSrUrVrZr[rRrr�rDrr/r`r@r�rXr]rY)rr4r��tgtr�rrrr0�s:)z&TestVariousIteratorArgs.test_takewhilecCs'x td�td�td�d	tddd�fD]�}x�ttttttfD]n}g}x:||�D],}|r�t|�r�qln|j|�qlW|j	t
tt||���|�qSW|jt
ttt|��|jt
ttt|��|jtt
ttt|���q4WdS)
Nr/ri�rVr�i�i�rW)rVr�)rrSrUrVrZr[rRrr�rDrr1r`r@r�rXr]rY)rr4r�rgr�rrrr2s:)z&TestVariousIteratorArgs.test_dropwhilecCs
xddtd�d
tddd�fD]�}x|ttttttfD]b}t||��\}}|jt	|�t	||���|jt	|�t	||���qGW|j
ttt|��|j
ttt
|��|j
tt	tt|��d	�q(WdS)Nr^rli�r_�333333�?i�i�rWr)zdorh)rrSrUrVrZr[rRr6rDrr`r@r�rXr]rY)rr4r�Zit1Zit2rrrr;s."&z TestVariousIteratorArgs.test_teeN)r r!r"rfror�rr�r�r�r�r�r�rr.r!r0r2r;rrrrr\{s 						
r\c@s(eZdZdd�Zdd�ZdS)�LengthTransparencycCsj|jtjtdd��d�|jtjtdd��d�|jtjtd�d�d�dS)Nr#rr�)rDr'�length_hintr�)rrrrrs""zLengthTransparency.test_repeatcCs�|jtjtdd��d�|jtjtdd��d�|jtjtddd��d�|jtjtddd��d�dS)	Nrrrrr�r�r�r�)rDr'rjr�)rrrrrs""%z2LengthTransparency.test_repeat_with_negative_timesN)r r!r"rrrrrrrisric@s(eZdZdd�Zdd�ZdS)�RegressionTestscsTdd�}�fdd�}g�|d|d�tt�}|j�|�dS)
Ncssdg��fdd�}t|�}t|�|dd�<t||�}t|gt|���t��dS)Nrcs*|r&|dd�=�t���n|S)N)rF)r��first)r=�zrrr�,s
z@RegressionTests.test_sf_793826.<locals>.mutatingtuple.<locals>.g)rr_r	rrF)Ztuple1r=Ztuple2r��items�genr)r=rmr�
mutatingtuple(sz5RegressionTests.test_sf_793826.<locals>.mutatingtuplecs |att��dd�<dS)N)�Tr)r�)rlrrr=7sz)RegressionTests.test_sf_793826.<locals>.frrrMr:rWrN)rrrM)r:rWrN)rrqrD)rrpr=�secondr)rlr�test_sf_793826%szRegressionTests.test_sf_793826cs��fdd�}�fdd�}g�|jttt|�|d���|j�ddg�g�|jttt|�|d���|j�ddg�g�|jttt|���|j�ddg�dS)	Nc3s6�jd�dV�jd�t��jd�dS)Nrrr)r��AssertionErrorr)�histrr�gen1Fs


z,RegressionTests.test_sf_950057.<locals>.gen1c3s2�jd�dV�jd�|r.t�ndS)NrMrr:)r�r)r)rurr�gen2Ms


z,RegressionTests.test_sf_950057.<locals>.gen2FrrT)r`rtrrnrDr�)rrvrwr)rur�test_sf_950057Bs%%zRegressionTests.test_sf_950057N)r r!r"rsrxrrrrrk#srkc@seZdZdd�ZdS)�SubclassWithKwargsTestcs�x�tttttttttt	t
tfD]r�G�fdd�d��}y|dd�Wq+tk
r�}z|j
d|jd�WYdd}~Xq+Xq+WdS)Ncs%eZdZd�fdd�ZdS)zBSubclassWithKwargsTest.test_keywords_in_subclass.<locals>.SubclassNcs�j||�dS)N)r)r�newargr
)�clsrrrfszKSubclassWithKwargsTest.test_keywords_in_subclass.<locals>.Subclass.__init__)r r!r"rr)r{rr�Subclassesr|rzrzdoes not take keyword argumentsr)r�r	r�r�rnr_r r$r/r1r�r�r@ZassertNotInr
)rr|�errr)r{r�test_keywords_in_subclassasz0SubclassWithKwargsTest.test_keywords_in_subclassN)r r!r"r~rrrrry`sryc@sUeZdZdd�ZejZdd�Zdd�Zdd�Zd	d
�Z	dS)�
SizeofTestcCstjd�|_dS)Nr)�structZcalcsize�ssize_t)rrrr�setUppszSizeofTest.setUpcCs[tjd�}|j}|tdd�|d|j�|td�|d|j�dS)	NZ3PirUZ12rrTr/)�abc)
r�r�r�r�r�r�r�r�r�r�)r�calcobjsize�check_sizeofr�r�)r�basesize�checkrrr�test_product_sizeofus	!zSizeofTest.test_product_sizeofcCsdtjd�}|j}|tdd�|d|j�|ttd�d�|d|j�dS)N�3PnirmrMr/r:)rr�r�r�r�r)rr�r�rrr�test_combinations_sizeof{s	!z#SizeofTest.test_combinations_sizeofcCsjt}tjd�}|j}||dd�|d|j�||td�d�|d|j�dS)Nr�rmrMr/r:)r�rr�r�r�r)rr�r�r�rrr�)test_combinations_with_replacement_sizeof�s
	!z4SizeofTest.test_combinations_with_replacement_sizeofcCs�tjd�}|j}|td�|d|jd|j�|tdd�|d|jd|j�|tdd�|d|jd|j�|ttd�d�|d|jd|j�dS)NZ4Pnirmr:rMr�rWr/)rr�r�r�r�r)rr�r�rrr�test_permutations_sizeof�s	z#SizeofTest.test_permutations_sizeofN)
r r!r"r�rr�r�r�r�r�rrrrrns	ra� Doctest for examples in the library reference: libitertools.tex


>>> amounts = [120.15, 764.05, 823.14]
>>> for checknum, amount in zip(count(1200), amounts):
...     print('Check %d is for $%.2f' % (checknum, amount))
...
Check 1200 is for $120.15
Check 1201 is for $764.05
Check 1202 is for $823.14

>>> import operator
>>> for cube in map(operator.pow, range(1,4), repeat(3)):
...    print(cube)
...
1
8
27

>>> reportlines = ['EuroPython', 'Roster', '', 'alex', '', 'laura', '', 'martin', '', 'walter', '', 'samuele']
>>> for name in islice(reportlines, 3, None, 2):
...    print(name.title())
...
Alex
Laura
Martin
Walter
Samuele

>>> from operator import itemgetter
>>> d = dict(a=1, b=2, c=1, d=2, e=1, f=2, g=3)
>>> di = sorted(sorted(d.items()), key=itemgetter(1))
>>> for k, g in groupby(di, itemgetter(1)):
...     print(k, list(map(itemgetter(0), g)))
...
1 ['a', 'c', 'e']
2 ['b', 'd', 'f']
3 ['g']

# Find runs of consecutive numbers using groupby.  The key to the solution
# is differencing with a range so that consecutive numbers all appear in
# same group.
>>> data = [ 1,  4,5,6, 10, 15,16,17,18, 22, 25,26,27,28]
>>> for k, g in groupby(enumerate(data), lambda t:t[0]-t[1]):
...     print(list(map(operator.itemgetter(1), g)))
...
[1]
[4, 5, 6]
[10]
[15, 16, 17, 18]
[22]
[25, 26, 27, 28]

>>> def take(n, iterable):
...     "Return first n items of the iterable as a list"
...     return list(islice(iterable, n))

>>> def enumerate(iterable, start=0):
...     return zip(count(start), iterable)

>>> def tabulate(function, start=0):
...     "Return function(0), function(1), ..."
...     return map(function, count(start))

>>> def nth(iterable, n, default=None):
...     "Returns the nth item or a default value"
...     return next(islice(iterable, n, None), default)

>>> def quantify(iterable, pred=bool):
...     "Count how many times the predicate is true"
...     return sum(map(pred, iterable))

>>> def padnone(iterable):
...     "Returns the sequence elements and then returns None indefinitely"
...     return chain(iterable, repeat(None))

>>> def ncycles(iterable, n):
...     "Returns the sequence elements n times"
...     return chain(*repeat(iterable, n))

>>> def dotproduct(vec1, vec2):
...     return sum(map(operator.mul, vec1, vec2))

>>> def flatten(listOfLists):
...     return list(chain.from_iterable(listOfLists))

>>> def repeatfunc(func, times=None, *args):
...     "Repeat calls to func with specified arguments."
...     "   Example:  repeatfunc(random.random)"
...     if times is None:
...         return starmap(func, repeat(args))
...     else:
...         return starmap(func, repeat(args, times))

>>> def pairwise(iterable):
...     "s -> (s0,s1), (s1,s2), (s2, s3), ..."
...     a, b = tee(iterable)
...     try:
...         next(b)
...     except StopIteration:
...         pass
...     return zip(a, b)

>>> def grouper(n, iterable, fillvalue=None):
...     "grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx"
...     args = [iter(iterable)] * n
...     return zip_longest(*args, fillvalue=fillvalue)

>>> def roundrobin(*iterables):
...     "roundrobin('ABC', 'D', 'EF') --> A D E B F C"
...     # Recipe credited to George Sakkis
...     pending = len(iterables)
...     nexts = cycle(iter(it).__next__ for it in iterables)
...     while pending:
...         try:
...             for next in nexts:
...                 yield next()
...         except StopIteration:
...             pending -= 1
...             nexts = cycle(islice(nexts, pending))

>>> def powerset(iterable):
...     "powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
...     s = list(iterable)
...     return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))

>>> def unique_everseen(iterable, key=None):
...     "List unique elements, preserving order. Remember all elements ever seen."
...     # unique_everseen('AAAABBBCCDAABBB') --> A B C D
...     # unique_everseen('ABBCcAD', str.lower) --> A B C D
...     seen = set()
...     seen_add = seen.add
...     if key is None:
...         for element in iterable:
...             if element not in seen:
...                 seen_add(element)
...                 yield element
...     else:
...         for element in iterable:
...             k = key(element)
...             if k not in seen:
...                 seen_add(k)
...                 yield element

>>> def unique_justseen(iterable, key=None):
...     "List unique elements, preserving order. Remember only the element just seen."
...     # unique_justseen('AAAABBBCCDAABBB') --> A B C D A B
...     # unique_justseen('ABBCcAD', str.lower) --> A B C A D
...     return map(next, map(itemgetter(1), groupby(iterable, key)))

>>> def first_true(iterable, default=False, pred=None):
...     '''Returns the first true value in the iterable.
...
...     If no true value is found, returns *default*
...
...     If *pred* is not None, returns the first item
...     for which pred(item) is true.
...
...     '''
...     # first_true([a,b,c], x) --> a or b or c or x
...     # first_true([a,b], x, f) --> a if f(a) else b if f(b) else x
...     return next(filter(pred, iterable), default)

This is not part of the examples but it tests to make sure the definitions
perform as purported.

>>> take(10, count())
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

>>> list(enumerate('abc'))
[(0, 'a'), (1, 'b'), (2, 'c')]

>>> list(islice(tabulate(lambda x: 2*x), 4))
[0, 2, 4, 6]

>>> nth('abcde', 3)
'd'

>>> nth('abcde', 9) is None
True

>>> quantify(range(99), lambda x: x%2==0)
50

>>> a = [[1, 2, 3], [4, 5, 6]]
>>> flatten(a)
[1, 2, 3, 4, 5, 6]

>>> list(repeatfunc(pow, 5, 2, 3))
[8, 8, 8, 8, 8]

>>> import random
>>> take(5, map(int, repeatfunc(random.random)))
[0, 0, 0, 0, 0]

>>> list(pairwise('abcd'))
[('a', 'b'), ('b', 'c'), ('c', 'd')]

>>> list(pairwise([]))
[]

>>> list(pairwise('a'))
[]

>>> list(islice(padnone('abc'), 0, 6))
['a', 'b', 'c', None, None, None]

>>> list(ncycles('abc', 3))
['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c']

>>> dotproduct([1,2,3], [4,5,6])
32

>>> list(grouper(3, 'abcdefg', 'x'))
[('a', 'b', 'c'), ('d', 'e', 'f'), ('g', 'x', 'x')]

>>> list(roundrobin('abc', 'd', 'ef'))
['a', 'd', 'e', 'b', 'f', 'c']

>>> list(powerset([1,2,3]))
[(), (1,), (2,), (3,), (1, 2), (1, 3), (2, 3), (1, 2, 3)]

>>> all(len(list(powerset(range(n)))) == 2**n for n in range(18))
True

>>> list(powerset('abcde')) == sorted(sorted(set(powerset('abcde'))), key=len)
True

>>> list(unique_everseen('AAAABBBCCDAABBB'))
['A', 'B', 'C', 'D']

>>> list(unique_everseen('ABBCcAD', str.lower))
['A', 'B', 'C', 'D']

>>> list(unique_justseen('AAAABBBCCDAABBB'))
['A', 'B', 'C', 'D', 'A', 'B']

>>> list(unique_justseen('ABBCcAD', str.lower))
['A', 'B', 'C', 'A', 'D']

>>> first_true('ABC0DEF1', '9', str.isdigit)
'0'

�
libreftestcCs�ttttttttf}tj	|�|r�t
td�r�ddl}dgd}xAt
t|��D]-}tj	|�|j�tj�||<qlWt|�ntjtjt|�dS)N�gettotalrefcountrrW)r9r\rJrkriryr@rrZrun_unittest�hasattrr��gcrrZcollectr�rZrun_doctest�modulesr )�verboseZtest_classesr�Zcountsrrrr�	test_main�s		




r��__main__r�T)=ZunittestZtestr�	itertoolsr+�decimalrZ	fractionsrr�r'rrrr1�	functoolsrr�ZMAX_Py_ssize_tr�Zminsizer
rrrrrrrrr&r*r+r-r.r0rrdrtZTestCaser9r@rJrRrSrUrVr�rXrYrZr[r\rirkryZcpython_onlyrr�Z__test__r�r rrrr�<module>sz
		�����de
	
	�
=�