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_sort.cpython-35.opt-2.pyc



���]�!�@s�ddlmZddlZddlZddlZddlmZejZdaddd�Z	Gdd�dej
�ZGdd	�d	ej
�ZGd
d�dej
�Z
edkr�ej�dS)
�)�supportN)�
cmp_to_keycCs<trtd|�|dd�}|rB|jdt|��n
|j�t|�t|�kr�td|�tdt|�t|��t|�t|�t|�td7adSx|t|�D]n\}}||}||k	r�td|�td|||�t|�t|�t|�td7adSq�WdS)Nz    checking�keyzerror inzlength mismatch;�zout of order at index)�verbose�print�sortr�len�nerrors�	enumerate)�tagZexpected�rawZcompareZorig�iZgood�maybe�r�./opt/alt/python35/lib64/python3.5/test_sort.py�checks0












rc@seZdZdd�ZdS)�TestBasec

sdg}x?tdd�D].}d|}|jt|d|d��qW|jdddg�G�fdd�dt��Gd	d
�d
t��xv|D]n}tt|��}tr�td|�|dd�}td||�|dd�}|j�td
||�|dd�}tj	|�td||�|dd�}|j�|dd�}td||dd��tr�td�td�|dd�}|j
dtdd���td||�t|�dkrdd�}|dd�}|j
t|j
d|��fdd�|D�}|dd�}tj	|�d�_d}y|j
�Wntk
r�d}YnX|r�d�_td||��fdd�t|�D�}dd�|D�}	|	j
�d d�|	D�}td!||�q�WdS)"Nrr�
��di�cs@eZdZdZdd�Z�fdd�Zdd�ZdS)	z+TestBase.testStressfully.<locals>.ComplainsTcSs
||_dS)N)r)�selfrrrr�__init__7sz4TestBase.testStressfully.<locals>.Complains.__init__csG�jr7tj�dkr7tr1td||�t�|j|jkS)Ng����MbP?z        complaining at)�maybe_complain�randomrr�RuntimeErrorr)r�other)�	Complainsrr�__lt__:s
z2TestBase.testStressfully.<locals>.Complains.__lt__cSsd|jS)Nz
Complains(%d))r)rrrr�__repr__Asz4TestBase.testStressfully.<locals>.Complains.__repr__N)�__name__�
__module__�__qualname__rrrrr)rrrr4src@s4eZdZdd�Zdd�Zdd�ZdS)z(TestBase.testStressfully.<locals>.StablecSs||_||_dS)N)r�index)rrrrrrrEs	z1TestBase.testStressfully.<locals>.Stable.__init__cSs|j|jkS)N)r)rrrrrrIsz/TestBase.testStressfully.<locals>.Stable.__lt__cSsd|j|jfS)NzStable(%d, %d))rr#)rrrrrLsz1TestBase.testStressfully.<locals>.Stable.__repr__N)r r!r"rrrrrrr�StableDsr$zTesting size�identity�reversedzrandom permutationzreversed via functioncSs||k||kS)Nr)�a�brrr�<lambda>bsz*TestBase.testStressfully.<locals>.<lambda>z3    Checking against an insane comparison function.z?        If the implementation isn't careful, this may segfault.rcSsttj�d�dS)N�r)�intr)r'r(rrrr)hsz(an insane function left some permutationcSs
t�dS)N)r)�xrrr�bad_keylsz)TestBase.testStressfully.<locals>.bad_keycsg|]}�|��qSrr)�.0r)rrr�
<listcomp>qs	z,TestBase.testStressfully.<locals>.<listcomp>TFz+exception during sort left some permutationcs(g|]}�tjd�|��qS)r)r�	randrange)r.r)r$rrr/~s	cSsg|]}||jf�qSr)r#)r.�errrr/s	cSsg|]\}}|�qSrr)r.r1rrrrr/�s	Z	stability)�range�extend�object�listrrr�reverser�shufflerrr	�assertRaisesrr)
rZsizesZpower�nr,�s�yr-Z
it_complainedZ	augmentedr)rr$r�testStressfully,sd	
"







	
	
zTestBase.testStressfullyN)r r!r"r<rrrrr+src@s(eZdZdd�Zdd�ZdS)�TestBugscsOG�fdd�d���fdd�td�D��|jt�j�dS)Ncs"eZdZ�fdd�ZdS)z"TestBugs.test_bug453523.<locals>.CcsB�r%tj�dkr%�j�n
�jd�tj�dkS)Ng�?r*g�?)r�pop�append)rr)�Lrrr�s

z)TestBugs.test_bug453523.<locals>.C.__lt__N)r r!r"rr)r@rr�C�srAcsg|]}���qSrr)r.r)rArrr/�s	z+TestBugs.test_bug453523.<locals>.<listcomp>�2)r2r8�
ValueErrorr)rr)rAr@r�test_bug453523�szTestBugs.test_bug453523cs�g}x�td�D]}}�fdd�}ddg�|jt�jdt|���fdd�}|jt�jdt|��|g}qWdS)N�cs+�jd��j�||k||kS)Nr*)r?r>)r,r;)r@rr�mutating_cmp�s

z7TestBugs.test_undetected_mutation.<locals>.mutating_cmprrrcs.�jd��dd�=||k||kS)Nr*)r?)r,r;)r@rrrF�s

)r2r8rCrr)rZmemorywasterrrFr)r@r�test_undetected_mutation�sz!TestBugs.test_undetected_mutationN)r r!r"rDrGrrrrr=�sr=c@s|eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�TestDecorateSortUndecoratecCsbdj�}|dd�}tj|�|jdtj�dd�}|jdt|��dS)Nz,The quick Brown fox Jumped over The lazy DogrcSs-|j�|j�}}||k||kS)N)�lower)r,r;ZxlowerZylowerrrr�my_cmp�sz9TestDecorateSortUndecorate.test_decorated.<locals>.my_cmp)�splitrr7r�strrIr)r�data�copyrJrrr�test_decorated�s
z)TestDecorateSortUndecorate.test_decoratedcCs/dj�}|jt|jddd��dS)Nz,The quick Brown fox Jumped over The lazy DogrcSsdS)Nrr)r,r;rrrr)�sz>TestDecorateSortUndecorate.test_baddecorator.<locals>.<lambda>)rKr8�	TypeErrorr)rrMrrr�test_baddecorator�sz,TestDecorateSortUndecorate.test_baddecoratorcCs]dd�td�D�}|dd�}|jddd��|j�|j||�dS)NcSs%g|]}tjd�|f�qS)r)rr0)r.rrrrr/�s	z=TestDecorateSortUndecorate.test_stability.<locals>.<listcomp>��rcSs|dS)Nrr)�trrrr)�sz;TestDecorateSortUndecorate.test_stability.<locals>.<lambda>)r2r�assertEqual)rrMrNrrr�test_stability�s

z)TestDecorateSortUndecorate.test_stabilitycCsXttdd��}|dd�}|jt|jddd��|j||�dS)NrrcSsd|S)Nrr)r,rrrr)�szDTestDecorateSortUndecorate.test_key_with_exception.<locals>.<lambda>���)r5r2r8�ZeroDivisionErrorrrT)rrM�duprrr�test_key_with_exception�sz2TestDecorateSortUndecorate.test_key_with_exceptioncsAttd����fdd�}|jt�jd|�dS)Nrcs'�dd�=td��dd�<|S)NrE)r2)r,)rMrr�k�s
z<TestDecorateSortUndecorate.test_key_with_mutation.<locals>.kr)r5r2r8rCr)rrZr)rMr�test_key_with_mutation�sz1TestDecorateSortUndecorate.test_key_with_mutationcsKttd���G�fdd�dt�}|jt�jd|�dS)Nrcs:eZdZdd�Z�fdd�Zdd�ZdS)zITestDecorateSortUndecorate.test_key_with_mutating_del.<locals>.SortKillercSsdS)Nr)rr,rrrr�szRTestDecorateSortUndecorate.test_key_with_mutating_del.<locals>.SortKiller.__init__cs'�dd�=td��dd�<dS)NrE)r2)r)rMrr�__del__�s
zQTestDecorateSortUndecorate.test_key_with_mutating_del.<locals>.SortKiller.__del__cSst|�t|�kS)N)�id)rrrrrr�szPTestDecorateSortUndecorate.test_key_with_mutating_del.<locals>.SortKiller.__lt__N)r r!r"rr\rr)rMrr�
SortKiller�sr^r)r5r2r4r8rCr)rr^r)rMr�test_key_with_mutating_del�sz5TestDecorateSortUndecorate.test_key_with_mutating_delcsKttd���G�fdd�dt�}|jt�jd|�dS)Nrcs.eZdZdd�Z�fdd�ZdS)zWTestDecorateSortUndecorate.test_key_with_mutating_del_and_exception.<locals>.SortKillercSs|dkrt�dS)Nr)r)rr,rrrr�sz`TestDecorateSortUndecorate.test_key_with_mutating_del_and_exception.<locals>.SortKiller.__init__cs-�dd�=ttd���dd�<dS)NrE)r5r2)r)rMrrr\�s
z_TestDecorateSortUndecorate.test_key_with_mutating_del_and_exception.<locals>.SortKiller.__del__N)r r!r"rr\r)rMrrr^�sr^r)r5r2r4r8rr)rr^r)rMr�(test_key_with_mutating_del_and_exception�szCTestDecorateSortUndecorate.test_key_with_mutating_del_and_exceptioncCsUttd��}tj|�|jdd�|j|ttddd���dS)Nrr6T�cr���rb)r5r2rr7rrT)rrMrrr�test_reverse�s
z'TestDecorateSortUndecorate.test_reversecCs�dd�td�D�}|dd�}|dd�}dd�}dd�}|jdt|�d	d
�|jdt|��|j||�|jddd�d	d
�|j||�dS)
NcSs%g|]}tjd�|f�qS)r)rr0)r.rrrrr/�s	zETestDecorateSortUndecorate.test_reverse_stability.<locals>.<listcomp>rRcSs)|d|d}}||k||kS)Nrr)r,r;�x0�y0rrrrJ�szATestDecorateSortUndecorate.test_reverse_stability.<locals>.my_cmpcSs)|d|d}}||k||kS)Nrr)r,r;rdrerrr�my_cmp_reversed�szJTestDecorateSortUndecorate.test_reverse_stability.<locals>.my_cmp_reversedrr6TcSs|dS)Nrr)r,rrrr)szCTestDecorateSortUndecorate.test_reverse_stability.<locals>.<lambda>)r2rrrT)rrMZcopy1�copy2rJrfrrr�test_reverse_stability�sz1TestDecorateSortUndecorate.test_reverse_stabilityN)r r!r"rOrQrUrYr[r_r`rcrhrrrrrH�s
rH�__main__)Ztestrr�sysZunittest�	functoolsrrr
rZTestCaserr=rHr �mainrrrr�<module>s	 [%^