Your IP : 216.73.217.32


Current Path : /opt/alt/python35/lib64/python3.5/test/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/__pycache__/test_itertools.cpython-35.opt-1.pyc



��Yf�m�@sQddlZddlmZddlTddlZddlmZddlmZddl	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&��Z8dJZ9dKe9iZ:ddLdM�Z;e<dNkrMe;dOdP�dS)Q�N)�support)�*)�Decimal)�Fraction)�reduce�cGstt|��S)N)�list�zip)�args�r�8/opt/alt/python35/lib64/python3.5/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�Zdd�Z	e
jdd��Ze
j
d�dd��Zdd�Ze
jdd��Ze
j
d�dd��Zdd�Ze
jdd ��Ze
j
d�d!d"��Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Ze
j
d�d7d8��Zd9d:�Z e
j
d�d;d<��Z!d=d>�Z"d?d@�Z#dAdB�Z$e
jdCdD��Z%e
j
d�dEdF��Z&dGdH�Z'dIdJ�Z(dKdL�Z)dMdN�Z*dOdP�Z+dQdR�Z,dSdT�Z-dUdV�Z.dWdX�Z/dYdZ�Z0d[d\�Z1d]d^�Z2dS)_�TestBasicOps�rNcssd��fdd��tj||�}tj|�}|jt|�t|���|��|�}}	|j||	�|r��|�}
|j||
�tj|�}d}y/x(t|�D]}
t|�|d7}q�WWntk
r�YnXtj||�}tj|�}�|��|�}}	|j||	�|ro�||d��}
|j||
�dS)zITest that an iterator is the same after pickling, also when part-consumedrcsw�dkrtd��t|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��WdQRXx7ttjd�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	Cs9|jtt�jf�|jtt�jg�|jtt�jd�|jtt�jgf�|jtt�jtg�gf�t�}|jtddg�f�|jt|�dddddd	g�t�}|jtddg�td
g�f�|jt|�d
dddddd	g�dS)NrrTrjrIrJrK�dr;�fZghi)r`r@rn�__setstate__�iterrDr)rrArrr�test_chain_setstate�s%	(	(z TestBasicOps.test_chain_setstatec

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:rMrc3s�t|��t��}||kr(dStt|��}t�fdd�|D��Vx�x7tt|��D]}|||||krnPqnWdS||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>.combinations1c3srt|��t��}xStt|�|�D]<}t|�t|�kr.t�fdd�|D��Vq.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>.combinations2c3srt|��t��}xStt|�|�D]<}tt|��|kr.t�fdd�|D��Vq.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r8s	z2TestBasicOps.test_combinations.<locals>.<listcomp>c3s|]}|�kVqdS)Nr)r7r;)�valuesrrr�sz1TestBasicOps.test_combinations.<locals>.<genexpr>cs"g|]}|�kr|�qSrr)r7r;)rKrrr8s	���)r}r~)r}r)r}r�)r~r)r~r�)rr�)r}r)r}r�)r~r)r~r�)rr�)rrr)rrrM)rrrM)rrrM)rrrM)rrrM)rrrM)r`r@�combinationsrrtrDrrFrr�r+r�r��
assertTrue�allr1rdrL)
r�op�testIntermediater�r�r�rr,�resultr5r)rKr�r�test_combinations�sP%
$
F"
&zTestBasicOps.test_combinationscCs.|jttf��tdd�WdQRXdS)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)rDr�r�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r6*szATestBasicOps.test_combinations_with_replacement.<locals>.<lambda>�ABCr}r~rc3s�t|��t��}|r)|r)dSdg|}t�fdd�|D��Vx{x3tt|��D]}|||dkrjPqjWdS||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�Cs)r�r�r�r)r)r,rr�rr)r�r�cwr13s

#z=TestBasicOps.test_combinations_with_replacement.<locals>.cwr1c3sut|��t��}xVtt|�d|�D]<}t|�t|�kr1t�fdd�|D��Vq1WdS)z%Pure python version shown in the docs�repeatc3s|]}�|VqdS)Nr)r7r)r�rrr�KszPTestBasicOps.test_combinations_with_replacement.<locals>.cwr2.<locals>.<genexpr>N)r�r��productrr�r)r)r,rr�r)r�r�cwr2Es
z=TestBasicOps.test_combinations_with_replacement.<locals>.cwr2cSs>|s|rdSdSt||d�t|�t|d�S)Nrr)r+)rr,rrr�numcombsMszATestBasicOps.test_combinations_with_replacement.<locals>.numcombsrVcSsg|]}d|d�qS)rWr�r)r7rrrrr8Ss	zCTestBasicOps.test_combinations_with_replacement.<locals>.<listcomp>rcSsg|]\}}|�qSrr)r7�k�vrrrr8cs	c3s|]}|�kVqdS)Nr)r7r;)r�rrr�fszBTestBasicOps.test_combinations_with_replacement.<locals>.<genexpr>cs"g|]}|�kr|�qSrr)r7r;)rKrrr8hs	r�)r}r})r}r~)r}r)r~r~)r~r)rr)r}r~)r}r)r~r~)r~r)rr)r�r`r@rrtrDrrFrr�r�r�r�r��groupbyr�r1rdrL)
r�cwrr�r�r�r�r�rr,r�Z
regular_combsZnorunsr5r)rKr�r�"test_combinations_with_replacement#sL
"
"&	z/TestBasicOps.test_combinations_with_replacementcCs.|jttf��tdd�WdQRXdS)Nr�r�i@)r`r�r�r�)rrrr�+test_combinations_with_replacement_overflowosz8TestBasicOps.test_combinations_with_replacement_overflowc	Cslt}|jtttt|dd����d�|jttttt|dd�����d�dS)Nr�rMr)r�rDr�r�r_r�r�r)rr�rrr�.test_combinations_with_replacement_tuple_reuseus.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����x4tt
jd�D]}|j|t�|��q�WqWq�WdS)NrTrrr{r4rMrc3s�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�r�rrr�)r)r,rr�Zcyclesrr�r)r�r�
permutations1�s&.(	0
(z5TestBasicOps.test_permutations.<locals>.permutations1c3s�t|��t��}|dkr*|n|}xVtt|�d|�D]<}tt|��|krIt�fdd�|D��VqIWdS)z%Pure python version shown in the docsNr�c3s|]}�|VqdS)Nr)r7r)r�rrr��szHTestBasicOps.test_permutations.<locals>.permutations2.<locals>.<genexpr>)r�r�r�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�rrDrrr�r+r�r�r�r�r1rdrL)rr�r�rr,r��pr5r)r�r�test_permutations{s8	<"
*zTestBasicOps.test_permutationscCs.|jttf��tdd�WdQRXdS)Nr}rr�i@)r`r�r�r�)rrrr�test_permutations_overflow�sz'TestBasicOps.test_permutations_overflowc	Csf|jtttttdd����d�|jttttttdd�����d�dS)Nr�rMr)rDr�r�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)r�r�)r7r�)r,rrr8�s	cSs.g|]$}t|�t|�kr|�qSr)r�r)r7r�rrrr8�s	cs.g|]$}tt|���kr|�qSr)r�r�)r7r�)r,rrr8�s	)
rrr�r�r�r�rDr�r+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�xzdd�dd�gt	D]\}xSdddddddgddfdddddddgddfdddddddgddfddddgddfd	ddddddgd
dfgD]�\}}}}|jt|td|d|���t|��|jt|t||���t|��t||�}|r�t
|�|jt||��t|��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�sZCEFZBCDEFr)rr)rDr�compressrnrpr�rr`r@rtrF)rrr�r�r�Zresult1Zresult2r�rrr�
test_compress�s6=777.7,#!!!71+
zTestBasicOps.test_compressc	Cs�|jtdt��ddd g�|jtdtd��d!d"d#g�|jtdtdtd���d$d%g�|jtdtdtd&���d(d)g�|jtdtdtd*���d,d.g�|jttddd	�|jttd�|jtdttd
��tt	td
td
���|jtdttd
��tt	td
td
���|jtdtd��dd
dg�|jtdtd/��d0d1d2g�|jtdtt
d���t
d�t
d�t
d�g�|jtdttdd���tdd�td
d�tdd�g�d3}|jtdt|��||d|dg�td�}|jt|�d�t
|�|jt|�d�td4�}|jt|�d�t
|�|jt
|�d5�|jttd��d�|jttd��d�|jtt
td���t�xutjd
tjd
d6d7ddtjd
tjd
fD]7}tt|��}dj|�}|j||�q�Wx�d8dtd
td
fD]�}t|�}|jt
tj|��|�|jt
tj|��|�x1t	tjd�D]}|j|t|��qaWq�Wtdtd
�tj�dS)9NrTrIrrJrrKrrMr:rWr/g
@g@g@y@z1.1z2.1z3.1rXi�zcount(3)zcount(4)rYz	count(-9)g�$@zcount(10.25)g$@zcount(10.0)z	count(%r))rIr)rJr)rKr)rIrM)rJr:)rKrW)rIrM)rJr:r�r�)rIr�)rJr���r�)rIr�r�)rJr�y
@�y
@�y@�y@�lCi����i����i����r�r�)rDr
�countr&r	r`r@�maxsizerrrr�reprrFrE�float�sys�__mod__rrrsr1rdrL�exc_info)r�BIGINTrKr�r1�r2�valuer5rrr�
test_countsT%(... (("!+0

"C!zTestBasicOps.test_countcCs|jtdtdd��d2d3d4g�|jtdtd	dd
d��d5d6d7g�|jtdtd
d8��d9d;d=g�|jttdd�|jtdtdd��d>d?d@g�|jtdtdd��dAdBdCg�|jtdtdd��dDdEdFg�|jtdttdd��tdttdtdd���|jtdttdd��tdttdtdd���|jtdtdtd��ttdddtdtd���|jtdtdd��dddg�|jtdtddG��ddHdIg�|jtdtt	d�t	d���t	d�t	d�t	d�g�|jtdtt
dd�t
dd���t
dd�t
dd�t
dd�g�dJ}|jtdtd
|��d|d|g�|jttdtdd!���tdd"d#g��tdd�}|jt|�d$�t|�|jt|�d%�tdKd�}|jt|�d'�t|�|jt|�d'�tdLdM�}|jt|�d(�t|�|jt|�d)�|jt|�d)�|jttd*d��d+�|jttd*d��d,�|jttd*d-��d.�|jttdd-��d/�tdd-�}|jt
t|��t�|jt
t|��t�xtjdtjddNdOddtjdtjdfD]�}x�tjdtjddPdQdddtjdtjdf	D]�}tt||��}|dkr�d0|}nd1||f}|j||�x4ttjd�D]}|j|t||��q�Wq}Wq7WdS)RNrTrrMrIrJrWrKrX�start�steprrr:�rO�dr/g�?g
@g@y@g@g!@y @z1.1z.1z1.2z1.3rV�rPi�g@g)@g.@zcount(3, 5)zcount(8, 5)rYzcount(-9, 0)z
count(-9, -3)zcount(-12, -3)g%@zcount(10.5, 1.25)zcount(10.5)g�?zcount(10.5, 1.0)zcount(10, 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!@ �lCi����i����r�i����r�i����r�)rDr
r�r`r@r&r�rrrrr�rFrEr]r�r�r1rdrL)rr�rKrr�r�r�r5rrr�test_count_with_stride7sf+!+++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_cyclens$%F('

'

zTestBasicOps.test_cyclecCs{|jttd�jf�|jttd�jg�|jttd�jd�|jttd�jgf�|jttd�jfdf�td�}|jddgdf�|jtt|d��ddd	ddddd	ddddd	ddg�td�}|jddgd
f�|jtt|d��ddd	ddddddddddddg�dS)NrlrrTZdeZfgrOrIrJrKr)r`r@r�rxrDrr$)rrArrr�test_cycle_setstate�s""z TestBasicOps.test_cycle_setstatec
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r6�sz+TestBasicOps.test_groupby.<locals>.<lambda>r/rr��rPr�r�
��rrOrMrZ�r�cSs|dS)Nrr)r,rrrr6�scSsg|]\}}|�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	rIrJrKrvr,cSs4g|]*\}}tt|dd��r|�qS)rr)rr$)r7r�r�rrrr8�s	cSs.g|]$\}}tt|��|f�qSr)r�r)r7r�r�rrrr8�s	rWcSs.g|]$\}}tt|��|f�qSr)r�r)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)rrv)rr,)rWrI)rr,)rrJ)rDrr�r�r`r@�appendrr1rdr2r3r-r.r�r�r��	Exceptionr�)rr4�dupr�r��elemr5ZikZig�keysZexpectedkeysr,r�r�r�r)r�r�r�test_groupby�s�""
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r6sz*TestBasicOps.test_filter.<locals>.<lambda>cSs|S)Nr)rrrrr6srVrM)rDrr�rr�boolr&r�r`r@rFrrrsr1rdr2r3rL)r�ansrKr5rrr�test_filters,.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r82s	z)TestBasicOps.test_zip.<locals>.<listcomp>rTrIrrJrrKrrNrkrMcSs"g|]}tt|���qSr)r�r)r7�pairrrrr8;s	rjcSsg|]}|�qSrr)r7r�rrrr8=s	)rIr)rJr)rKr)	r	r�rDrrr
r&r`r@)rr�rrr�test_zip0s444"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r8Hs	z5TestBasicOps.test_zip_tuple_reuse.<locals>.<listcomp>rIrrJrrKrcSs"g|]\}}||f�qSrr)r7rr�rrrr8Ks	cSs"g|]\}}||f�qSrr)r7rr�rrrr8Os	cSs"g|]\}}||f�qSrr)r7rr�rrrr8Us	)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_reuse@s$$%((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r8cs	z;TestBasicOps.test_ziplongest.<locals>.<listcomp>.<listcomp>)r�)r7)r
)rrr8cs	z0TestBasicOps.test_ziplongest.<locals>.<listcomp>cSs)g|]}tdd�|D���qS)css'|]}|dkrdp|VqdS)N�Xr)r7r;rrrr�gsz:TestBasicOps.test_ziplongest.<locals>.<listcomp>.<genexpr>)r�)r7r�rrrr8gs	�	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r8�s	rjcSsg|]}|�qSrr)r7r�rrrr8�s	)rrbr_r�rDr�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�rDrarbr�r�r�)rr�rrr�test_zip_longest_tuple_reuse�s$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_pickling�s
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;)rrr�r;rrr�__init__�s	z5TestBasicOps.test_bug_7244.<locals>.Repeater.__init__cSs|S)Nr)rrrrr�sz5TestBasicOps.test_bug_7244.<locals>.Repeater.__iter__cSs2|jdkr%|jd8_|jS|j�dS)Nrr)r�rr;)rrrrr�sz5TestBasicOps.test_bug_7244.<locals>.Repeater.__next__N)r r!r"rrrrrrr�Repeater�srrrMrr:cSsjg}x]t||dd�D]F\}}tjd��t||f�WdQRX|j||f�qW|S)Nr�r�stdout)r�rZcaptured_output�printr�)r�r�r�rr�rrr�run�s"z'TestBasicOps.test_bug_7244.<locals>.runrr�)rr)rr)rr)rr)rr)rr)rr)rrDr=r�rFr`)rrr�r�rrArrr�
test_bug_7244�s%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�rVrNcs6ttt|��|jdd�}t|�}|dkrFfVdStdd�|D��rcdSdg|}tdd�t||�D��Vx�x�tt|��D]}||t||�dkr�q�||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
rrr�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�r�r`r@r�r�rZ	randranger*r_ry)rr
r�r,rrrZexpected_lenr)rr�test_product�s2-$$4'/	3'("((zTestBasicOps.test_productcCs8|jttf��tdgddd�WdQRXdS)NrUrrWr��r{i)r`r�r�r�)rrrr�test_product_overflow�sz"TestBasicOps.test_product_overflowc	Csf|jtttttdd����d�|jttttttdd�����d�dS)NrTrjr)rDr�r�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�rxrDrFr`r)rr�rrr�test_product_issue_25021s

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_repeats,.((
((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_times2s"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_map8s.-!!
"+"%%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'r!r	rr&r�ryr`r@rFrrrrrrsr1rdrL)rr�rKr5rrr�test_starmapVs(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$rryr`r@rr�r�r�rFrrrsr1rdrL�weakref�refZassertIsNotNonerZ
gc_collectZassertIsNone)rr
ZtgtargsrAZrarKr5�wrrrr�test_isliceqsr
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:rNrXr$r/r)r:rW)r:rW)r:rW)rDr�	takewhiler0r`r@r'r!rFrrr�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:rNrXr$r/)r:rW)r:rW)r:rW)rDr�	dropwhiler0r`r@r'r!rFrrrrrsrr1rdrL)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
rrFrZshuffler�r`r@rErr�r�r�r0�proxy�getattr�ReferenceErrorrrr&rsr1rdrLry)rrrIrJrr��orderZlistsZitsr�rKr�rvZt1Zt2ZtnewZt3r�r�Zlong_ansr5rrr�test_tee�s�."""%

 $".%%.F

))  

))  

))  

))  zTestBasicOps.test_teec	CsDttdd��\}}yt|�~Wn~~�YnXdS)Ni-1)r;r�r)rZforwardZbackwardrrr�test_tee_del_backwardws
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r6�sz1TestBasicOps.test_StopIteration.<locals>.<lambda>cSs|S)Nr)rrrrr6�s)r`rrFr	rnr�r�rr$r;r�r�r�r_r4r6r%)rrwr��qrrr�test_StopIteration�s  "zTestBasicOps.test_StopIteration)3r r!r"rLrfrorqrurzr�rZbigaddrspacetestr�Zimpl_detailr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrrrrrrr r#r&r3r5r7r@rArCrrrrr9PsZ)

PL?!"07n
*(:
L�	r9c@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�TestExamplescCs>|jttdddddg��dddddg�dS)	NrrrMr:rWrNr/rO)rDrr\)rrrrrf�szTestExamples.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_reducible�s59)z&TestExamples.test_accumulate_reduciblecCs�tdddgtj�}|jt|�d�xRttjd�D]=}tjtj	||��}|jt
|�ddg�qEW|jt
tj|��ddg�|jt
tj|��ddg�dS)NrTF)
r\r'�is_rDrFrr1rdr2r3rrrrs)rrAr5Zit_copyrrr�test_accumulate_reducible_none�s %z+TestExamples.test_accumulate_reducible_nonecCs&|jdjtdd��d�dS)Nrlr��DEFr�)rD�joinrn)rrrrro�szTestExamples.test_chaincCs,|jdjtjddg��d�dS)Nrlr�rHr�)rDrIrnrp)rrrrrq�sz%TestExamples.test_chain_from_iterablec	Csf|jttdd��ddd
dddg�|jtttd�d��ddddg�dS)Nr|rr}r~rr�r:rMrr)r}r~)r}r)r}r�)r~r)r~r�)rr�)rrr)rrrM)rrrM)rrrM)rDrr�r)rrrrr��szTestExamples.test_combinationsc	Cs5|jttdd��dddd	d
dg�dS)Nr�rr}r~r)r}r})r}r~)r}r)r~r~)r~r)rr)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)Nr|r�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)rDrr6)rrrrr7�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/rWr{rYi�)rrMr/)rWrrM)rDrr_r!)rrrrr#�szTestExamples.test_mapcCs�|jttdd��td��|jttddd��td��|jttddd��td��|jttdddd��td��dS)	Nr�rZABr:ZCDZCDEFGrZACEG)rDrr$)rrrrr3�s%((zTestExamples.test_islicecCs)|jttdd��ddg�dS)	Nr|�xyr}rr~r�)r}r)r~r�)rDrr	)rrrrr��szTestExamples.test_zipcCs5|jttdddd��ddd
dg�dS)Nr|rKr��-r}rr~r�rr�)r}r)r~r�)rrL)r�rL)rDrr�)rrrr�test_zip_longest�szTestExamples.test_zip_longestc
Csl|jttdd��tttdj����|jtttd���ddd	d
ddg�dS)
Nr|rz#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)Nr|rKzAx Ay Bx By Cx Cy Dx Dyrr�rMrr)rrr)rrr)rrr)rrr)rrr)rrr)rrr)rrr)rDrr�r_r�rNr)rrrrr�s
!zTestExamples.test_productcCs,|jttdd��dddg�dS)Nr/rM)rDrr�)rrrrr�szTestExamples.test_repeatcCs5|jtttdd	d
g��dddg�dS)NrrWrMr/r{rYi�)rrW)rMr)r/rM)rDrr%r!)rrrr�test_stapmap�s!zTestExamples.test_stapmapc	Cs>|jttdd�dddddg��ddg�dS)NcSs
|dkS)NrWr)rrrrr6sz-TestExamples.test_takewhile.<locals>.<lambda>rr:rN)rDrr4)rrrrr5szTestExamples.test_takewhileN)r r!r"rfrErGrorqr�r�r�r�r�r7r�r�r�r#r3r�rMr�rrrOr5rrrrrD�s.
rDc@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�	makecycles

zTestGC.makecyclecCs,g}|jtdd|dg�|�dS)NrrrM)rRr\)rrIrrrrfszTestGC.test_accumulatecCs g}|jt|�|�dS)N)rRrn)rrIrrrroszTestGC.test_chaincCs&g}|jtj|g�|�dS)N)rRrnrp)rrIrrrrqszTestGC.test_chain_from_iterablecCs/g}|jtdd|dgd�|�dS)NrrrM)rRr�)rrIrrrr�szTestGC.test_combinationscCs/g}|jtdd|dgd�|�dS)NrrrM)rRr�)rrIrrrr�sz)TestGC.test_combinations_with_replacementc	Cs5g}|jtdddddddg�|�dS)Nr�rr)rRr�)rrIrrrr� szTestGC.test_compresscCsMg}tdtftd|��}|jt|d�|d��|�dS)N�Intrrr)rEr]r�rRr�)rrIrSrrrr�$szTestGC.test_countcCs'g}|jt|gd�|�dS)Nr)rRr�)rrIrrrr�)szTestGC.test_cyclecCs,g}|jttd||g�|�dS)Nr)rRr6r�)rrIrrrr7-szTestGC.test_dropwhilecCs0g}|jt|gddd��|�dS)NrcSs|S)Nr)rrrrr63sz%TestGC.test_groupby.<locals>.<lambda>)rRr�)rrIrrrr�1szTestGC.test_groupbycCs[d}dd�}xBtt|�d|�D](\}}|jjdg�j|�q+WdS)Nr/cSs|S)Nr)rrrrr68sz'TestGC.test_issue2246.<locals>.<lambda>r�r)r�r�__dict__�
setdefaultr�)rrr�rr�rrr�test_issue22465s%zTestGC.test_issue2246cCs0g}|jtdd�|gd�|�dS)NcSsdS)NTr)rrrrr6>sz$TestGC.test_filter.<locals>.<lambda>r)rRr�)rrIrrrr�<szTestGC.test_filtercCs)g}|jtdd�|�|�dS)NcSsdS)NFr)rrrrr6Bsz)TestGC.test_filterfalse.<locals>.<lambda>)rRr�)rrIrrrr�@szTestGC.test_filterfalsecCs1g}|jt|gd|gd�|�dS)NrrM)rRr	)rrIrrrr�DszTestGC.test_zipcCsjg}|jt|gd|gd�|�|dg}|jt|gd|gdd|�|�dS)NrrMr�)rRr�)rrIrJrrrrMHs'zTestGC.test_zip_longestcCs0g}|jtdd�|gd�|�dS)NcSs|S)Nr)rrrrr6Psz!TestGC.test_map.<locals>.<lambda>r)rRr_)rrIrrrr#NszTestGC.test_mapcCs*g}|jt|gdd�|�dS)Nr)rRr$)rrIrrrr3RszTestGC.test_islicecCs/g}|jtdd|dgd�|�dS)NrrrM)rRr�)rrIrrrr�VszTestGC.test_permutationscCs2g}|jtdd|dgdd�|�dS)NrrrMr�)rRr�)rrIrrrrZszTestGC.test_productcCs g}|jt|�|�dS)N)rRr�)rrIrrrr^szTestGC.test_repeatcCs6g}|jtdd�||fgd�|�dS)NcWs|S)Nr)r�rrrr6dsz%TestGC.test_starmap.<locals>.<lambda>r)rRr%)rrIrrrr&bszTestGC.test_starmapcCs/g}|jttdd||g�|�dS)Nrr)rRr4r�)rrIrrrr5fszTestGC.test_takewhileN)r r!r"rRrfrorqr�r�r�r�r�r7r�rVr�r�r�rMr#r3r�rrr&r5rrrrrPs.rPccsx|D]}|VqWdS)zRegular generatorNr)�seqnrrrr�Rjs
rXc@s.eZdZdZdd�Zdd�ZdS)�GzSequence using __getitem__cCs
||_dS)N)rW)rrWrrrrqsz
G.__init__cCs|j|S)N)rW)rrrrr�__getitem__ssz
G.__getitem__N)r r!r"r#rrZrrrrrYosrYc@s:eZdZdZdd�Zdd�Zdd�ZdS)	�Iz Sequence using iterator protocolcCs||_d|_dS)Nr)rWr)rrWrrrrxs	z
I.__init__cCs|S)Nr)rrrrr{sz
I.__iter__cCsA|jt|j�krt�|j|j}|jd7_|S)Nr)rr�rWr)rr�rrrr}s
z
I.__next__N)r r!r"r#rrrrrrrr[vsr[c@s.eZdZdZdd�Zdd�ZdS)�Igz9Sequence using iterator protocol defined with a generatorcCs||_d|_dS)Nr)rWr)rrWrrrr�s	zIg.__init__ccsx|jD]}|Vq
WdS)N)rW)r�valrrrr�szIg.__iter__N)r r!r"r#rrrrrrr\�sr\c@s.eZdZdZdd�Zdd�ZdS)r�z Missing __getitem__ and __iter__cCs||_d|_dS)Nr)rWr)rrWrrrr�s	z
X.__init__cCsA|jt|j�krt�|j|j}|jd7_|S)Nr)rr�rWr)rr�rrrr�s
z
X.__next__N)r r!r"r#rrrrrrr��sr�c@s.eZdZdZdd�Zdd�ZdS)�NzIterator missing __next__()cCs||_d|_dS)Nr)rWr)rrWrrrr�s	z
N.__init__cCs|S)Nr)rrrrr�sz
N.__iter__N)r r!r"r#rrrrrrr^�sr^c@s:eZdZdZdd�Zdd�Zdd�ZdS)	�EzTest propagation of exceptionscCs||_d|_dS)Nr)rWr)rrWrrrr�s	z
E.__init__cCs|S)Nr)rrrrr�sz
E.__iter__cCsdddS)NrMrr)rrrrr�sz
E.__next__N)r r!r"r#rrrrrrrr_�sr_c@s:eZdZdZdd�Zdd�Zdd�ZdS)	�SzTest immediate stopcCsdS)Nr)rrWrrrr�sz
S.__init__cCs|S)Nr)rrrrr�sz
S.__iter__cCs
t�dS)N)r)rrrrr�sz
S.__next__N)r r!r"r#rrrrrrrr`�sr`cCs+ttdd�ttt|�����S)z Test multiple tiers of iteratorscSs|S)Nr)rrrrr6�szL.<locals>.<lambda>)rnr_rXr\rY)rWrrr�L�srac@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)r�rYr[r\rarXrDrr\r`r`r@r�r^�ZeroDivisionErrorr_)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)rerf)rrYr[r\r`rarXrDrrnr`r@r�r^rcr_)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)Nrdrli�re�333333�?i�i�rWr)rerg)rr�rYr[r\r`rarXrDrr�r�r`r@r�r^rcr_)rr4rr�rrrr��s.;""z%TestVariousIteratorArgs.test_compresscCs�xzddtd�d	tddd�fD]Q}|jttt|��|jttt|��|jttt|��q(WdS)
Nrdrli�re�333333�?i�i�rW)rerh)rr`r@r�r�r^rcr_)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)Nrdrli�re�333333�?i�i�rWrM)reri)rrYr[r\r`rarXr�rr$r�rDr`r@r�r^rcr_)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�)rrYr[r\r`rarXrDr�rr`r@r�r^rcr_)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�)rrYr[r\r`rarXrDrr�rr`r@r�r^rcr_)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�)rrYr[r\r`rarXrDrr�rr`r@r�r^rcr_)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)
Nrdrli�re�333333�?i�i�rW)rerj)rrYr[r\r`rarXrDrr	r
r`r@r�r^rcr_)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)
Nrdrli�re�333333�?i�i�rW)rerk)rrYr[r\r`rarXrDrr�r	r`r@r�r^rcr_)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r8s	z4TestVariousIteratorArgs.test_map.<locals>.<listcomp>cSsg|]}||�qSrr)r7rrrrr8s	)rVr�)rrYr[r\r`rarXrDrr_rr'r!r`r@r�r^rcr_)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�re�333333�?i�i�rWrrr/)rerl)rrYr[r\r`rarXrDrr$r`r@r�r^rcr_)rr4r�rrrr3s.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�)rrYr[r\r`rarXr
rDrr%r'r!r`r@r�r^rcr_)rr4r�Zssrrrr&&s:!z$TestVariousIteratorArgs.test_starmapcCsxtd�td�td�d	tddd�fD]�}x|ttttttfD]b}g}x.||�D] }t|�sP|j|�qlW|j	t
tt||���|�qSW|jt
ttt|��|jt
ttt|��|jtt
ttt|���q4WdS)
Nr/ri�rVr�i�i�rW)rVr�)rrYr[r\r`rarXrr�rDrr4r`r@r�r^rcr_)rr4r��tgtr�rrrr50s:)z&TestVariousIteratorArgs.test_takewhilecCs$xtd�td�td�d	tddd�fD]�}x�ttttttfD]k}g}x7||�D])}|r�t|�r�ql|j|�qlW|j	t
tt||���|�qSW|jt
ttt|��|jt
ttt|��|jtt
ttt|���q4WdS)
Nr/ri�rVr�i�i�rW)rVr�)rrYr[r\r`rarXrr�rDrr6r`r@r�r^rcr_)rr4r�rmr�rrrr7<s:)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)Nrdrli�re�333333�?i�i�rWr)rern)rrYr[r\r`rarXr;rDrr`r@r�r^rcr_)rr4r�Zit1Zit2rrrr@Hs."&z TestVariousIteratorArgs.test_teeN)r r!r"rfror�rr�r�r�r�r�rr#r3r&r5r7r@rrrrrb�s 						
rbc@s(eZdZdd�Zdd�ZdS)�LengthTransparencycCsj|jtjtdd��d�|jtjtdd��d�|jtjtd�d�d�dS)Nr(rr�)rDr'�length_hintr�)rrrrrTs""zLengthTransparency.test_repeatcCs�|jtjtdd��d�|jtjtdd��d�|jtjtddd��d�|jtjtddd��d�dS)	Nrrrrr�r�r�r�)rDr'rpr�)rrrrr Ys""%z2LengthTransparency.test_repeat_with_negative_timesN)r r!r"rr rrrrroRsroc@s4eZdZdd�Zdd�Zdd�ZdS)�RegressionTestscsTdd�}�fdd�}g�|d|d�tt�}|j�|�dS)
Ncssdg��fdd�}t|�}t|�|dd�<t||�}t|gt|���t��dS)Nrcs'|r#|dd�=�t���|S)N)rF)r��first)rw�zrrr�hs
z@RegressionTests.test_sf_793826.<locals>.mutatingtuple.<locals>.g)rr_r	r�rF)Ztuple1rwZtuple2r��items�genr)rwrsr�
mutatingtupledsz5RegressionTests.test_sf_793826.<locals>.mutatingtuplecs |att��dd�<dS)N)�Tr)r�)rrrrrwssz)RegressionTests.test_sf_793826.<locals>.frrrMr:rWrN)rrrM)r:rWrN)rrwrD)rrvrw�secondr)rrr�test_sf_793826as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�gen1�s


z,RegressionTests.test_sf_950057.<locals>.gen1c3s#�jd�dV�jd�dS)NrMrr:)r�)r)r{rr�gen2�s
z,RegressionTests.test_sf_950057.<locals>.gen2FrrT)r`rzrrnrDr�)rr|r}r)r{r�test_sf_950057~s%%zRegressionTests.test_sf_950057c	CsGtjdd�td�D��}|jt��t|�WdQRXdS)Ncss|]}fVqdS)Nr)r7Zunusedrrrr��szERegressionTests.test_long_chain_of_empty_iterables.<locals>.<genexpr>i���)rnrprr`rrF)rrArrr�"test_long_chain_of_empty_iterables�s"z2RegressionTests.test_long_chain_of_empty_iterablesN)r r!r"ryr~rrrrrrq_srqc@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r�szKSubclassWithKwargsTest.test_keywords_in_subclass.<locals>.Subclass.__init__)r r!r"rr)r�rr�Subclass�sr�r�rzdoes not take keyword argumentsr)r�r	r�r�rnr_r%r$r4r6r�r�r@ZassertNotInr
)rr��errr)r�r�test_keywords_in_subclass�sz0SubclassWithKwargsTest.test_keywords_in_subclassN)r r!r"r�rrrrr��sr�c@sUeZdZdd�ZejZdd�Zdd�Zdd�Zd	d
�Z	dS)�
SizeofTestcCstjd�|_dS)Nr)�structZcalcsize�ssize_t)rrrr�setUp�szSizeofTest.setUpcCs[tjd�}|j}|tdd�|d|j�|td�|d|j�dS)	NZ3PirUZ12rrTr/)rT)
rTrTrTrTrTrTrTrTrTrT)r�calcobjsize�check_sizeofr�r�)r�basesize�checkrrr�test_product_sizeof�s	!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r��s	r�a� 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 all_equal(iterable):
...     "Returns True if all the elements are equal to each other"
...     g = groupby(iterable)
...     return next(g, True) and not next(g, False)

>>> 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

>>> [all_equal(s) for s in ('', 'A', 'AAAA', 'AAAB', 'AAABA')]
[True, True, True, False, False]

>>> 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|�tjtjt|�dS)N�gettotalrefcountrrW)r9rbrPrqror�rDr�rZrun_unittest�hasattrr��gcrr�Zcollectr�r
Zrun_doctest�modulesr )�verboseZtest_classesr�Zcountsrrrr�	test_main�s		




r��__main__r�T)=ZunittestZtestr�	itertoolsr0�decimalrZ	fractionsrr�r'rrrr1�	functoolsrr�ZMAX_Py_ssize_tr�Zminsizer
rrrrrrrrr&r*r+r-r.r0rrdrtZTestCaser9rDrPrXrYr[r\r�r^r_r`rarbrorqr�Zcpython_onlyr�r�Z__test__r�r rrrr�<module>sz
		�����Lne
	
	�
C�"