Your IP : 216.73.216.85


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-2.pyc



���]�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�3/opt/alt/python35/lib64/python3.5/test_itertools.py�lzipsr
cCsd|S)N�r)�xrrr�oneargsrcGs
t�dS)N)�
ValueError)r
rrr�errfuncsrccsxdD]}|VqWdS)Nrrr)rrrr)�irrr�gen3s
rcCs|ddkS)Nrrr)rrrr�isEven"srcCs|ddkS)Nrrr)rrrr�isOdd&srcGs|S)Nr)r
rrr�tupleize*srccs xt|�D]}|Vq
WdS)N)�range)�nrrrr�irange-src@s(eZdZdd�Zdd�ZdS)�StopNowcCs|S)Nr)�selfrrr�__iter__3szStopNow.__iter__cCs
t�dS)N)�
StopIteration)rrrr�__next__5szStopNow.__next__N)�__name__�
__module__�__qualname__rrrrrrr1srcCstt||��S)N)r�islice)r�seqrrr�take8sr%cCsttj|d�S)Nr)r�operator�mul)�iterablerrr�prod<sr)cCsttd|d��S)Nr)r)r)rrrr�fact?sr*cCs|dS)Nrr)�rrrr�testRDsr,cCs|dS)Nrr)r+rrr�testR2Gsr-cCs
|dkS)N�
r)rrrr�undertenJsr/cCsg|]}|dd��qS)cSstjtj||��S)N)�pickle�loads�dumps)�s�protorrr�<lambda>Msz<listcomp>.<lambda>r)�.0r4rrr�
<listcomp>Ms	r7c@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)Nrcsw�dkrtd��t|t�r+|Sytt|���}Wntk
r\|SYnX��fdd�|D�S)Nr.zinfinite recursion encounteredcs#g|]}�|�d��qS)rr)r6�e)�expandrrrr7^s	z;TestBasicOps.pickletest.<locals>.expand.<locals>.<listcomp>)�RuntimeError�
isinstance�strrr#�	TypeError)�itr�l)r;�stop)rrr;Ts
	z'TestBasicOps.pickletest.<locals>.expandr)r0r2r1�assertEqual�typer�nextr)r�protocolr@rBr%�compare�dumpZi2�a�b�cZi3ZtookrZi4r)r;rBr�
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��	r9��i�i�)rCr�
accumulater�int�complexrr�map�assertRaisesr?�min�maxr&r'�chrr0�HIGHEST_PROTOCOLrL)r�typr3r4rrr�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)Nr)�	iterablesr@�elementrrr�chain2�s

z'TestBasicOps.test_chain.<locals>.chain2rT�def�abcdef�r9�abcdrrM)�chainrCrr%r`r?)rrirKrrr�
test_chain�s%"(zTestBasicOps.test_chaincCs�|jttjddg��td��|jttjdg��td��|jttjdg��g�|jtdtjddg��td��|jtttjddg��dS)	NrTrjrkrlr9rmrrM)rCrrn�
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)
NrTrjrkrIZbcdefrlr9rmrrMrrG)�copy�deepcopy�
picklecopiersrnrCrrEr%r`r?rr0rdrL)rZoperr@r4rrr�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__�iterrCr)rr@rrr�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r5�sz0TestBasicOps.test_combinations.<locals>.<lambda>� �ABCD�A�B�C�Dr9rMrc3s�t|��t��}||kr(dStt|��}t�fdd�|D��Vx�x7tt|��D]}|||||krnPqnWdS||d7<x1t|d|�D]}||dd||<q�Wt�fdd�|D��Vq[WdS)Nc3s|]}�|VqdS)Nr)r6r)�poolrr�	<genexpr>�szHTestBasicOps.test_combinations.<locals>.combinations1.<locals>.<genexpr>rc3s|]}�|VqdS)Nr)r6r)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)Nc3s|]}�|VqdS)Nr)r6r)r�rrr��szHTestBasicOps.test_combinations.<locals>.combinations2.<locals>.<genexpr>)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)Nc3s|]}�|VqdS)Nr)r6r)r�rrr�szHTestBasicOps.test_combinations.<locals>.combinations3.<locals>.<genexpr>)r�r��combinations_with_replacementr�set)r(r+rr�r)r�r�
combinations3�s
z5TestBasicOps.test_combinations.<locals>.combinations3rVcSsg|]}d|d�qS)rW�r)r6rrrrr7s	z2TestBasicOps.test_combinations.<locals>.<listcomp>c3s|]}|�kVqdS)Nr)r6r:)�valuesrrr�sz1TestBasicOps.test_combinations.<locals>.<genexpr>cs"g|]}|�kr|�qSrr)r6r:)rKrrr7s	���)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?�combinationsrrtrCrrErr�r*r�r��
assertTrue�allr0rdrL)
r�op�testIntermediater�r�r�rr+�resultr4r)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)rCr�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r5*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)Nrc3s|]}�|VqdS)Nr)r6r)r�rrr�;szPTestBasicOps.test_combinations_with_replacement.<locals>.cwr1.<locals>.<genexpr>rc3s|]}�|VqdS)Nr)r6r)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)N�repeatc3s|]}�|VqdS)Nr)r6r)r�rrr�KszPTestBasicOps.test_combinations_with_replacement.<locals>.cwr2.<locals>.<genexpr>)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)r6rrrrr7Ss	zCTestBasicOps.test_combinations_with_replacement.<locals>.<listcomp>rcSsg|]\}}|�qSrr)r6�k�vrrrr7cs	c3s|]}|�kVqdS)Nr)r6r:)r�rrr�fszBTestBasicOps.test_combinations_with_replacement.<locals>.<genexpr>cs"g|]}|�kr|�qSrr)r6r:)rKrrr7hs	r�)r}r})r}r~)r}r)r~r~)r~r)rr)r}r~)r}r)r~r~)r~r)rr)r�r`r?rrtrCrrErr�r�r�r�r��groupbyr�r0rdrL)
r�cwrr�r�r�r�r�rr+r�Z
regular_combsZnorunsr4r)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�rCr�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{r3rMrc3s�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)Nrc3s|]}�|VqdS)Nr)r6r)r�rrr��szHTestBasicOps.test_permutations.<locals>.permutations1.<locals>.<genexpr>rc3s|]}�|VqdS)Nr)r6r)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)Nr�c3s|]}�|VqdS)Nr)r6r)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)r6rrrrr7�s	z2TestBasicOps.test_permutations.<locals>.<listcomp>c3s|]}|�kVqdS)Nr)r6r:)r�rrr��sz1TestBasicOps.test_permutations.<locals>.<genexpr>r�)rr)rr)rr)rr)rr)rr)r`r?r�rrCrrr�r*r�r�r�r�r0rdrL)rr�r�rr+r��pr4r)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)rCr�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)r6�trrrr7�s	z3TestBasicOps.test_combinatorics.<locals>.<listcomp>cs.g|]$}tt|���kr|�qSr)r�r�)r6r�)r+rrr7�s	cSs.g|]$}t|�t|�kr|�qSr)r�r)r6r�rrrr7�s	cs.g|]$}tt|���kr|�qSr)r�r�)r6r�)r+rrr7�s	)
rrr�r�r�r�rCr�r*r�r��filter�__contains__)rrr3r)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r5�sz,TestBasicOps.test_compress.<locals>.<lambda>cSs
tj|�S)N)rrrs)rIrrrr5�sZCEFZBCDEFr)rr)rCr�compressrnrpr�rr`r?rtrE)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)9NrTrIrrJrrKrrMr9rWr.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)rJr9)rKrW)rIrM)rJr9r�r�)rIr�)rJr���r�)rIr�r�)rJr�y
@�y
@�y@�y@�lCi����i����i����r�r�)rCr
�countr%r	r`r?�maxsizerrrr�reprrErD�float�sys�__mod__rrrsr0rdrL�exc_info)r�BIGINTrKr�r1�r2�valuer4rrr�
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�steprrr9�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)rKr9)rIr)rJrW)rKrXy
@�y@�y!@ �lCi����i����r�i����r�i����r�)rCr
r�r`r?r%r�rrrrr�rErDr]r�r�r0rdrL)rr�rKrr�r�r�r4rrr�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)rCr%�cyclerr`r?r#rrErrrsrr0rdr1r2rL)rrKr4rrr�
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)NrlrrT�deZfgrOrIrJrKr)r`r?r�rxrCrr#)rr@rrr�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r5�sz+TestBasicOps.test_groupby.<locals>.<lambda>r.rr��rPr�r�
��rrOrMrZ�r�cSs|dS)Nrr)r+rrrr5�scSsg|]\}}|�qSrr)r6r��grrrr7�s	z-TestBasicOps.test_groupby.<locals>.<listcomp>cSsg|]}|d�qS)rr)r6r+rrrr7�s	ZabracadabracSsg|]\}}|�qSrr)r6r�r�rrrr7�s	rIrJrKrvr+cSs4g|]*\}}tt|dd��r|�qS)rr)rr#)r6r�r�rrrr7�s	cSs.g|]$\}}tt|��|f�qSr)r�r)r6r�r�rrrr7�s	rWcSs.g|]$\}}tt|��|f�qSr)r�r)r6r�r�rrrr7�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)r6r�r�)�funcrrr7�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)r�dst)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)rCrr�r�r`r?�appendrr0rdr1r2r,r-r�r�r��	Exceptionr�)rr3�dupr�r��elemr4ZikZig�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)NrNrrr9rcSs|S)Nr)rrrrr5sz*TestBasicOps.test_filter.<locals>.<lambda>cSs|S)Nr)rrrrr5srVrM)rCrr�rr�boolr%r�r`r?rErrrsr0rdr1r2rL)r�ansrKr4rrr�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)NrNrrMrWrrr9rVcSs|S)Nr)rrrrr5)sz/TestBasicOps.test_filterfalse.<locals>.<lambda>cSs|S)Nr)rrrrr5*s)rCr�filterfalserrr�r%r�r`r?rEr0rdrL)rr4rrr�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)r6r�yrrrr72s	z)TestBasicOps.test_zip.<locals>.<listcomp>rTrIrrJrrKrrNrkrMcSs"g|]}tt|���qSr)r�r)r6�pairrrrr7;s	rjcSsg|]}|�qSrr)r6r�rrrr7=s	)rIr)rJr)rKr)	r	r�rCrrr
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)r6rr�rrrr7Hs	z5TestBasicOps.test_zip_tuple_reuse.<locals>.<listcomp>rIrrJrrKrcSs"g|]\}}||f�qSrr)r6rr�rrrr7Ks	cSs"g|]\}}||f�qSrr)r6rr�rrrr7Os	cSs"g|]\}}||f�qSrr)r6rr�rrrr7Us	)rIr)rJr)rKr)rIr)rJr)rKr)rIr)rJr)rKr)rJr)rKr)rr_r�r	rCrarbr��dict�fromkeysrrr�rsrr0rdr1r2rErL)r�idsr�r4r�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�)r6�arg)rrrr7cs	z;TestBasicOps.test_ziplongest.<locals>.<listcomp>.<listcomp>)r�)r6)r
)rrr7cs	z0TestBasicOps.test_ziplongest.<locals>.<listcomp>cSs)g|]}tdd�|D���qS)css'|]}|dkrdp|VqdS)N�Xr)r6r:rrrr�gsz:TestBasicOps.test_ziplongest.<locals>.<listcomp>.<genexpr>)r�)r6r�rrrr7gs	�	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)r6r�rrrr7�s	rjcSsg|]}|�qSrr)r6r�rrrr7�s	)rrbr_r�rCr�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�rrCrarbr�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)rr0rdrLr)rr4rrr�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"r	rrrrrr�Repeater�sr
rrMrr9cSsjg}x]t||dd�D]F\}}tjd��t||f�WdQRX|j||f�qW|S)Nr�r�stdout)rrZcaptured_output�printr�)r�r�r�rr�rrr�run�s"z'TestBasicOps.test_bug_7244.<locals>.runrr�)rr)rr)rr)rr)rr)rr)rr)rrCr<rrEr`)rr
r�r�r
r@rrr�
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)#NrUrIrJrrMrrr9r�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�)r6r�rrrr��sz>TestBasicOps.test_product.<locals>.product1.<locals>.<genexpr>css|]\}}||VqdS)Nr)r6r�rrrrr��scss|]\}}||VqdS)Nr)r6r�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)Nr�rcs*g|] }�D]}||g�qqSrr)r6rr�)r�rrr7�s	z?TestBasicOps.test_product.<locals>.product2.<locals>.<listcomp>)rr_r�r)r
rrr�r)r)r�r�product2�s%	

z+TestBasicOps.test_product.<locals>.product2rlrTrKZabcdefgr�r�r�csg|]}tj���qSr)�random�choice)r6r�)�argtypesrrr7�s	z-TestBasicOps.test_product.<locals>.<listcomp>rW)rI)rJ)rr)rr)rr)rr)rr)rri��)rrCrr�r�r�r`r?r�r�r�	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)rCr�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)	rrCrrrr�rsr0rdrL)rr
r�r4rrr�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�rxrCrEr`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�timesrMrrrr9yzrepeat((1+0j))rWzrepeat((1+0j), 5)zrepeat((1+0j), 0)r.)rrI)rrI)rrIr�y�?y�?�aar")rCrr�r
rr%r`r?r�rErrrsr0rdrL)rr+rKr4rrr�test_repeats,.((
((zTestBasicOps.test_repeatcCs�|jttdd��d�|jttdd��d�|jttddd��d�|jttddd	��d�dS)
NrIrzrepeat('a', 0)rr!r�r�r�r�)rCr�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.r9rrrX)rIr)rJr)rKr)rIr)rJr)rKr)rIr)rJr)rIr)rJr)rKr)rCrr_r&�powrrr�r%r`r?�negrErrrrrrsr0rdrL)rr�rKr4rrr�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)NrMrrVrrr9rW�extrar.rrrXrrrXi)r9rW)r9rW)r9rW)r9rWrrrX)rCr�starmapr&r%r	rr%r�ryr`r?rErrrrrrsr0rdrL)rr�rKr4rrr�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��nrrr9rWrrI�2css|]}|VqdS)Nr)r6rrrr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/r0�r+�r�)r1r2���r3r�r�)r.r�rM)r.rMr�)r.r�)r.rM)r�)rr)rCrr#rryr`r?rr�r�r�rErrrsr0rdrL�weakref�refZassertIsNotNonerZ
gc_collectZassertIsNone)rr
Ztgtargsr@ZrarKr4�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�rr9rNrXr(r.r)r9rW)r9rW)r9rW)rCr�	takewhiler/r`r?r&r%rErrr�rrrrsrr0rdrL)rr�r�r4rrr�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�rr9rNrXr(r.)r9rW)r9rW)r9rW)rCr�	dropwhiler/r`r?r&r%rErrrrrsrr0rdrL)rr�r4rrr�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��invalidcSsg|]}t|��qSr)r)r6rrrrr7"s	z)TestBasicOps.test_tee.<locals>.<listcomp>r.�	__class__i'�<rGr�)�teerCrrr
rrEr�shuffler�r`r?rDrr�r�r�r4�proxy�getattr�ReferenceErrorrrr%rsr0rdrLry)rrrIrJrr��orderZlistsZitsr�rKr�rv�t1Zt2ZtnewZt3r�r�Zlong_ansr4rrr�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r5�sz1TestBasicOps.test_StopIteration.<locals>.<lambda>cSs|S)Nr)rrrrr5�s)r`rrEr	rnr�r�rr#r@r�r�r�r_r8r:r))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�rrrrrrrrrr#r$r'r*r7r9r;rGrHrJrrrrr8PsZ)

PL?!"07n
*(:
L�	r8c@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)	NrrrMr9rWrNr.rO)rCrr\)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)	NrrrMr9rWrNr.rO)rr0rdr\rCrr1r2rErrrs)rr�Zaccumulatedr4r@rrr�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_rCrErr0rdr1r2rrrrs)rr@r4Zit_copyrrr�test_accumulate_reducible_none�s %z+TestExamples.test_accumulate_reducible_nonecCs&|jdjtdd��d�dS)Nrlr��DEFr�)rC�joinrn)rrrrro�szTestExamples.test_chaincCs,|jdjtjddg��d�dS)Nrlr�rOr�)rCrPrnrp)rrrrrq�sz%TestExamples.test_chain_from_iterablec	Csf|jttdd��ddd
dddg�|jtttd�d��ddddg�dS)Nr|rr}r~rr�r9rMrr)r}r~)r}r)r}r�)r~r)r~r�)rr�)rrr)rrrM)rrrM)rrrM)rCrr�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)rCrr�)rrrrr��sz/TestExamples.test_combinations_with_replacementc
Cs;|jttdddddddg��td��dS)Nr�rrr�)rCrr�)rrrrr��szTestExamples.test_compresscCs8|jtttd�d��dddddg�dS)Nr.rWr�r�r�r�)rCrr#r�)rrrrr��szTestExamples.test_countcCs/|jtttd�d��td��dS)Nr|r�ZABCDABCDABCD)rCrr#r�)rrrrr��szTestExamples.test_cyclec	CsA|jttdd�dddddg��dddg�dS)NcSs
|dkS)NrWr)rrrrr5�sz-TestExamples.test_dropwhile.<locals>.<lambda>rr9rN)rCrr:)rrrrr;�szTestExamples.test_dropwhilecCst|jdd�td�D�td��|jdd�td�D�td�td�td	�td
�g�dS)NcSsg|]\}}|�qSrr)r6r�r�rrrr7�s	z-TestExamples.test_groupby.<locals>.<listcomp>ZAAAABBBCCDAABBBZABCDABcSs"g|]\}}t|��qSr)r)r6r�r�rrrr7�s	Z
AAAABBBCCDZAAAAZBBB�CCr�)rCr�r)rrrrr��s
zTestExamples.test_groupbycCs>|jttdd�td���dddddg�dS)	NcSs|dS)Nrr)rrrrr5�sz*TestExamples.test_filter.<locals>.<lambda>r.rrMrWrVrY)rCrr�r)rrrrr��szTestExamples.test_filtercCs>|jttdd�td���dddddg�dS)	NcSs|dS)Nrr)rrrrr5�sz/TestExamples.test_filterfalse.<locals>.<lambda>r.rrr9rNrX)rCrr�r)rrrrr��szTestExamples.test_filterfalsecCs/|jtttdd	��dddg�dS)
NrrMr.rWr{rYi�)rrMr.)rWrrM)rCrr_r%)rrrrr'�szTestExamples.test_mapcCs�|jttdd��td��|jttddd��td��|jttddd��td��|jttdddd��td��dS)	Nr�rZABr9ZCDZCDEFGrZACEG)rCrr#)rrrrr7�s%((zTestExamples.test_islicecCs)|jttdd��ddg�dS)	Nr|�xyr}rr~r�)r}r)r~r�)rCrr	)rrrrr��szTestExamples.test_zipcCs5|jttdddd��ddd
dg�dS)Nr|rRr��-r}rr~r�rr�)r}r)r~r�)rrS)r�rS)rCrr)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)rCrr�r_r��splitr)rrrrr��szTestExamples.test_permutationscCsx|jttdd��tttdj����|jtttd�dd��d	d
ddd
dddg�dS)Nr|rRzAx Ay Bx By Cx Cy Dx Dyrr�rMrr)rrr)rrr)rrr)rrr)rrr)rrr)rrr)rrr)rCrr�r_r�rUr)rrrrr�s
!zTestExamples.test_productcCs,|jttdd��dddg�dS)Nr.rM)rCrr�)rrrrr#�szTestExamples.test_repeatcCs5|jtttdd	d
g��dddg�dS)NrrWrMr.r{rYi�)rrW)rMr)r.rM)rCrr)r%)rrrr�test_stapmap�s!zTestExamples.test_stapmapc	Cs>|jttdd�dddddg��ddg�dS)NcSs
|dkS)NrWr)rrrrr5sz-TestExamples.test_takewhile.<locals>.<lambda>rr9rN)rCrr8)rrrrr9szTestExamples.test_takewhileN)r r!r"rfrLrNrorqr�r�r�r�r�r;r�r�r�r'r7r�rTr�rr#rVr9rrrrrK�s.
rKc@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�rE)r�iterator�	containerrrr�	makecycles

zTestGC.makecyclecCs,g}|jtdd|dg�|�dS)NrrrM)rZr\)rrIrrrrfszTestGC.test_accumulatecCs g}|jt|�|�dS)N)rZrn)rrIrrrroszTestGC.test_chaincCs&g}|jtj|g�|�dS)N)rZrnrp)rrIrrrrqszTestGC.test_chain_from_iterablecCs/g}|jtdd|dgd�|�dS)NrrrM)rZr�)rrIrrrr�szTestGC.test_combinationscCs/g}|jtdd|dgd�|�dS)NrrrM)rZr�)rrIrrrr�sz)TestGC.test_combinations_with_replacementc	Cs5g}|jtdddddddg�|�dS)Nr�rr)rZr�)rrIrrrr� szTestGC.test_compresscCsMg}tdtftd|��}|jt|d�|d��|�dS)N�Intrrr)rDr]r�rZr�)rrIr[rrrr�$szTestGC.test_countcCs'g}|jt|gd�|�dS)Nr)rZr�)rrIrrrr�)szTestGC.test_cyclecCs,g}|jttd||g�|�dS)Nr)rZr:r�)rrIrrrr;-szTestGC.test_dropwhilecCs0g}|jt|gddd��|�dS)NrcSs|S)Nr)rrrrr53sz%TestGC.test_groupby.<locals>.<lambda>)rZr�)rrIrrrr�1szTestGC.test_groupbycCs[d}dd�}xBtt|�d|�D](\}}|jjdg�j|�q+WdS)Nr.cSs|S)Nr)rrrrr58sz'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r5>sz$TestGC.test_filter.<locals>.<lambda>r)rZr�)rrIrrrr�<szTestGC.test_filtercCs)g}|jtdd�|�|�dS)NcSsdS)NFr)rrrrr5Bsz)TestGC.test_filterfalse.<locals>.<lambda>)rZr�)rrIrrrr�@szTestGC.test_filterfalsecCs1g}|jt|gd|gd�|�dS)NrrM)rZr	)rrIrrrr�DszTestGC.test_zipcCsjg}|jt|gd|gd�|�|dg}|jt|gd|gdd|�|�dS)NrrMr�)rZr)rrIrJrrrrTHs'zTestGC.test_zip_longestcCs0g}|jtdd�|gd�|�dS)NcSs|S)Nr)rrrrr5Psz!TestGC.test_map.<locals>.<lambda>r)rZr_)rrIrrrr'NszTestGC.test_mapcCs*g}|jt|gdd�|�dS)Nr)rZr#)rrIrrrr7RszTestGC.test_islicecCs/g}|jtdd|dgd�|�dS)NrrrM)rZr�)rrIrrrr�VszTestGC.test_permutationscCs2g}|jtdd|dgdd�|�dS)NrrrMr�)rZr�)rrIrrrrZszTestGC.test_productcCs g}|jt|�|�dS)N)rZr�)rrIrrrr#^szTestGC.test_repeatcCs6g}|jtdd�||fgd�|�dS)NcWs|S)Nr)r�rrrr5dsz%TestGC.test_starmap.<locals>.<lambda>r)rZr))rrIrrrr*bszTestGC.test_starmapcCs/g}|jttdd||g�|�dS)Nrr)rZr8r�)rrIrrrr9fszTestGC.test_takewhileN)r r!r"rZrfrorqr�r�r�r�r�r;r�r^r�r�r�rTr'r7r�rr#r*r9rrrrrWs.rWccsx|D]}|VqWdS)Nr)�seqnrrrr�Rjs
r`c@s(eZdZdd�Zdd�ZdS)�GcCs
||_dS)N)r_)rr_rrrr	qsz
G.__init__cCs|j|S)N)r_)rrrrr�__getitem__ssz
G.__getitem__N)r r!r"r	rbrrrrraosrac@s4eZdZdd�Zdd�Zdd�ZdS)�IcCs||_d|_dS)Nr)r_r)rr_rrrr	xs	z
I.__init__cCs|S)Nr)rrrrr{sz
I.__iter__cCsA|jt|j�krt�|j|j}|jd7_|S)Nr)rr�r_r)rr�rrrr}s
z
I.__next__N)r r!r"r	rrrrrrrcvsrcc@s(eZdZdd�Zdd�ZdS)�IgcCs||_d|_dS)Nr)r_r)rr_rrrr	�s	zIg.__init__ccsx|jD]}|Vq
WdS)N)r_)r�valrrrr�szIg.__iter__N)r r!r"r	rrrrrrd�srdc@s(eZdZdd�Zdd�ZdS)r�cCs||_d|_dS)Nr)r_r)rr_rrrr	�s	z
X.__init__cCsA|jt|j�krt�|j|j}|jd7_|S)Nr)rr�r_r)rr�rrrr�s
z
X.__next__N)r r!r"r	rrrrrr��sr�c@s(eZdZdd�Zdd�ZdS)�NcCs||_d|_dS)Nr)r_r)rr_rrrr	�s	z
N.__init__cCs|S)Nr)rrrrr�sz
N.__iter__N)r r!r"r	rrrrrrf�srfc@s4eZdZdd�Zdd�Zdd�ZdS)�EcCs||_d|_dS)Nr)r_r)rr_rrr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	rrrrrrrg�srgc@s4eZdZdd�Zdd�Zdd�ZdS)�ScCsdS)Nr)rr_rrr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	rrrrrrrh�srhcCs+ttdd�ttt|�����S)NcSs|S)Nr)rrrrr5�szL.<locals>.<lambda>)rnr_r`rdra)r_rrr�L�sric@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)	NrrrMr9rWrNr.rO)r�rarcrdrir`rCrr\rhr`r?r�rf�ZeroDivisionErrorrg)rr3r+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)rmrn)rrarcrdrhrir`rCrrnr`r?r�rfrkrg)rr3r�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)Nrlrli�rm�333333�?i�i�rWr)rmro)rr�rarcrdrhrir`rCrr�r�r`r?r�rfrkrg)rr3rr�rrrr��s.;""z%TestVariousIteratorArgs.test_compresscCs�xzddtd�d	tddd�fD]Q}|jttt|��|jttt|��|jttt|��q(WdS)
Nrlrli�rm�333333�?i�i�rW)rmrp)rr`r?r�r�rfrkrg)rr3rrr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)Nrlrli�rm�333333�?i�i�rWrM)rmrq)rrarcrdrhrir`r�rr#r�rCr`r?r�rfrkrg)rr3r�ZtgtlenZexpected�actualrrr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)r6r�Zsbrrrr7�s	z8TestVariousIteratorArgs.test_groupby.<locals>.<listcomp>)rVr�)rrarcrdrhrir`rCr�rr`r?r�rfrkrg)rr3r�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)r6rrrrr7�s	z7TestVariousIteratorArgs.test_filter.<locals>.<listcomp>)rVr�)rrarcrdrhrir`rCrr�rr`r?r�rfrkrg)rr3r�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)r6rrrrr7�s	z<TestVariousIteratorArgs.test_filterfalse.<locals>.<listcomp>)rVr�)rrarcrdrhrir`rCrr�rr`r?r�rfrkrg)rr3r�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)
Nrlrli�rm�333333�?i�i�rW)rmrs)rrarcrdrhrir`rCrr	r
r`r?r�rfrkrg)rr3r�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)
Nrlrli�rm�333333�?i�i�rW)rmrt)rrarcrdrhrir`rCrrr	r`r?r�rfrkrg)rr3r�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)r6rrrrr7s	z4TestVariousIteratorArgs.test_map.<locals>.<listcomp>cSsg|]}||�qSrr)r6rrrrr7s	)rVr�)rrarcrdrhrir`rCrr_rr&r%r`r?r�rfrkrg)rr3r�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�rm�333333�?i�i�rWrrr.)rmru)rrarcrdrhrir`rCrr#r`r?r�rfrkrg)rr3r�rrrr7s.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)r6rrrrr7+s	z8TestVariousIteratorArgs.test_starmap.<locals>.<listcomp>)rVr�)rrarcrdrhrir`r
rCrr)r&r%r`r?r�rfrkrg)rr3r��ssrrr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�)rrarcrdrhrir`rr�rCrr8r`r?r�rfrkrg)rr3r��tgtr�rrrr90s:)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�)rrarcrdrhrir`rr�rCrr:r`r?r�rfrkrg)rr3r�rwr�rrrr;<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)Nrlrli�rm�333333�?i�i�rWr)rmrx)rrarcrdrhrir`r@rCrr`r?r�rfrkrg)rr3r�Zit1Zit2rrrrGHs."&z TestVariousIteratorArgs.test_teeN)r r!r"rfror�rr�r�r�r�r�rr'r7r*r9r;rGrrrrrj�s 						
rjc@s(eZdZdd�Zdd�ZdS)�LengthTransparencycCsj|jtjtdd��d�|jtjtdd��d�|jtjtd�d�d�dS)Nr,rr�)rCr&�length_hintr�)rrrrr#Ts""zLengthTransparency.test_repeatcCs�|jtjtdd��d�|jtjtdd��d�|jtjtddd��d�|jtjtddd��d�dS)	Nrrrr!r�r�r�r�)rCr&rzr�)rrrrr$Ys""%z2LengthTransparency.test_repeat_with_negative_timesN)r r!r"r#r$rrrrryRsryc@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)rE)r��first)rw�zrrr�hs
z@RegressionTests.test_sf_793826.<locals>.mutatingtuple.<locals>.g)rr_r	r�rE)Ztuple1rwZtuple2r��items�genr)rwr}r�
mutatingtupledsz5RegressionTests.test_sf_793826.<locals>.mutatingtuplecs |att��dd�<dS)N)�Tr)r�)r|rrrwssz)RegressionTests.test_sf_793826.<locals>.frrrMr9rWrN)rrrM)r9rWrN)rr�rC)rr�rw�secondr)r|r�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)NrMrr9)r�)r)r�rr�gen2�s
z,RegressionTests.test_sf_950057.<locals>.gen2FrrT)r`r�rrnrCr�)rr�r�r)r�r�test_sf_950057~s%%zRegressionTests.test_sf_950057c	CsGtjdd�td�D��}|jt��t|�WdQRXdS)Ncss|]}fVqdS)Nr)r6Zunusedrrrr��szERegressionTests.test_long_chain_of_empty_iterables.<locals>.<genexpr>i���)rnrprr`rrE)rr@rrr�"test_long_chain_of_empty_iterables�s"z2RegressionTests.test_long_chain_of_empty_iterablesN)r r!r"r�r�r�rrrrr{_sr{c@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"r	r)r�rr�Subclass�sr�r�rzdoes not take keyword argumentsr)r�r	r�r�rnr_r)r#r8r:r�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)�struct�calcsize�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.r9)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.r9)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)NZ4Pnirmr9rMr�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)r8rjrWr{ryr�rKr�rZrun_unittest�hasattrr��gcrr�Zcollectr�rZrun_doctest�modulesr )�verboseZtest_classesr�Zcountsrrrr�	test_main�s		




r��__main__r�T)=ZunittestZtestr�	itertoolsr4�decimalrZ	fractionsrr�r&rrrr0�	functoolsrr�ZMAX_Py_ssize_tr�Zminsizer
rrrrrrrrr%r)r*r,r-r/rrdrtZTestCaser8rKrWr`rarcrdr�rfrgrhrirjryr{r�Zcpython_onlyr�r�Z__test__r�r rrrr�<module>sz
		�����Lne
	
	�
C�"