HEX
Server: LiteSpeed
System: Linux server.nevid-deploma.com 4.18.0-553.111.1.lve.el8.x86_64 #1 SMP Fri Mar 13 13:42:17 UTC 2026 x86_64
User: smilepac (1037)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //opt/cppython/lib/python3.8/test/__pycache__/test_sort.cpython-38.pyc
U

.D�g�5�@s�ddlmZddlZddlZddlmZejZdaddd�ZGdd�dej	�Z
Gdd	�d	ej	�ZGd
d�dej	�Zdd
�Z
Gdd�dej	�Zedkr�e��dS)�)�supportN��
cmp_to_keycCs�trtd|�|dd�}|r0|jt|�d�n|��t|�t|�kr�td|�tdt|�t|��t|�t|�t|�td7adSt|�D]V\}}||}||k	r�td|�td|||�t|�t|�t|�td7adSq�dS)Nz    checking��keyzerror inzlength mismatch;�zout of order at index)�verbose�print�sortr�len�nerrors�	enumerate)�tagZexpected�rawZcompareZorig�iZgood�maybe�r�-/opt/cppython/lib/python3.8/test/test_sort.py�check
s0


rc@seZdZdd�ZdS)�TestBasec
	sNdg}tdd�D]$}d|}|�t|d|d��q|�dddg�G�fdd�dt��Gd	d
�d
t��|D�]�}tt|��}tr�td|�|dd�}td||�|dd�}|��td
||�|dd�}t�	|�td||�|dd�}|��|dd�}td||dd��t�r0td�td�|dd�}|j
tdd��d�td||�t|�dk�r�dd�}|dd�}|j
t|j
|d��fdd�|D�}|dd�}t�	|�d�_d}z|�
�Wntk
�r�d}YnX|�rd�_td||��fdd�t|�D�}dd�|D�}	|	�
�d d�|	D�}td!||�qndS)"Nrr�
��di�cs,eZdZdZdd�Z�fdd�Zdd�ZdS)	z+TestBase.testStressfully.<locals>.ComplainsTcSs
||_dS�N�r)�selfrrrr�__init__6sz4TestBase.testStressfully.<locals>.Complains.__init__cs2�jr&t��dkr&tr"td||�t�|j|jkS)Ng����MbP?z        complaining at)�maybe_complain�randomrr	�RuntimeErrorr�r�other��	Complainsrr�__lt__9s
z2TestBase.testStressfully.<locals>.Complains.__lt__cSs
d|jS)Nz
Complains(%d)r�rrrr�__repr__@sz4TestBase.testStressfully.<locals>.Complains.__repr__N)�__name__�
__module__�__qualname__rrr$r&rr"rrr#3sr#c@s$eZdZdd�Zdd�Zdd�ZdS)z(TestBase.testStressfully.<locals>.StablecSs||_||_dSr�r�index)rrrrrrrDsz1TestBase.testStressfully.<locals>.Stable.__init__cSs|j|jkSrrr rrrr$Hsz/TestBase.testStressfully.<locals>.Stable.__lt__cSsd|j|jfS)NzStable(%d, %d)r*r%rrrr&Ksz1TestBase.testStressfully.<locals>.Stable.__repr__N)r'r(r)rr$r&rrrr�StableCsr,zTesting size�identity�reversedzrandom permutationzreversed via functioncSs||k||kSrr��a�brrr�<lambda>a�z*TestBase.testStressfully.<locals>.<lambda>z3    Checking against an insane comparison function.z?        If the implementation isn't careful, this may segfault.cSstt��d�dS)N�r)�intrr/rrrr2gr3rz(an insane function left some permutationcSst�dSr�r��xrrr�bad_keyksz)TestBase.testStressfully.<locals>.bad_keycsg|]}�|��qSrr��.0rr"rr�
<listcomp>psz,TestBase.testStressfully.<locals>.<listcomp>TFz+exception during sort left some permutationcsg|]}�t�d�|��qS)r�r�	randranger:)r,rrr<}scSsg|]}||jf�qSr)r+)r;�errrr<~scSsg|]\}}|�qSrr)r;r?rrrrr<�sZ	stability)�range�extend�object�listrr	r�reverser�shuffler
rr�assertRaisesrr)
rZsizesZpower�nr8�s�yr9Z
it_complainedZ	augmentedr)r#r,r�testStressfully+sd




zTestBase.testStressfullyN)r'r(r)rJrrrrr*src@seZdZdd�Zdd�ZdS)�TestBugscs:G�fdd�d���fdd�td�D��|�t�j�dS)NcseZdZ�fdd�ZdS)z"TestBugs.test_bug453523.<locals>.Ccs0�rt��dkr���n
��d�t��dkS)Ng�?r4g�?)r�pop�appendr ��Lrrr$�s

z)TestBugs.test_bug453523.<locals>.C.__lt__N�r'r(r)r$rrNrr�C�srQcsg|]
}���qSrrr:)rQrrr<�sz+TestBugs.test_bug453523.<locals>.<listcomp>�2)r@rF�
ValueErrorr
r%r)rQrOr�test_bug453523�szTestBugs.test_bug453523cshg}td�D]V}�fdd�}ddg�|jt�jt|�d��fdd�}|jt�jt|�d�|g}qdS)N�cs"��d����||k||kS�Nr4)rMrL�r8rIrNrr�mutating_cmp�s
z7TestBugs.test_undetected_mutation.<locals>.mutating_cmprrrcs$��d��dd�=||k||kSrV)rMrWrNrrrX�s

)r@rFrSr
r)rZmemorywasterrrXrrNr�test_undetected_mutation�sz!TestBugs.test_undetected_mutationN)r'r(r)rTrYrrrrrK�srKc@sTeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�TestDecorateSortUndecoratecCsHd��}|dd�}t�|�|jtjd�dd�}|jt|�d�dS)N�,The quick Brown fox Jumped over The lazy DogrcSs"|��|��}}||k||kSr)�lower)r8rIZxlowerZylowerrrr�my_cmp�sz9TestDecorateSortUndecorate.test_decorated.<locals>.my_cmp)�splitrrEr
�strr\r)r�data�copyr]rrr�test_decorated�s
z)TestDecorateSortUndecorate.test_decoratedcCs"d��}|jt|jdd�d�dS)Nr[cSsdS�NrrrWrrrr2�r3z>TestDecorateSortUndecorate.test_baddecorator.<locals>.<lambda>r)r^rF�	TypeErrorr
�rr`rrr�test_baddecorator�sz,TestDecorateSortUndecorate.test_baddecoratorcCsFdd�td�D�}|dd�}|jdd�d�|��|�||�dS)NcSsg|]}t�d�|f�qS�rr=r:rrrr<�sz=TestDecorateSortUndecorate.test_stability.<locals>.<listcomp>��cSs|dSrcr)�trrrr2�r3z;TestDecorateSortUndecorate.test_stability.<locals>.<lambda>r)r@r
�assertEqual)rr`rarrr�test_stability�s
z)TestDecorateSortUndecorate.test_stabilitycCs@ttdd��}|dd�}|jt|jdd�d�|�||�dS)N���rcSsd|S)Nrrr7rrrr2�r3zDTestDecorateSortUndecorate.test_key_with_exception.<locals>.<lambda>r)rCr@rF�ZeroDivisionErrorr
rj)rr`�duprrr�test_key_with_exception�sz2TestDecorateSortUndecorate.test_key_with_exceptioncs.ttd����fdd�}|jt�j|d�dS)Nrcs�dd�=td��dd�<|S�NrU�r@r7�r`rr�k�s
z<TestDecorateSortUndecorate.test_key_with_mutation.<locals>.kr)rCr@rFrSr
)rrsrrrr�test_key_with_mutation�sz1TestDecorateSortUndecorate.test_key_with_mutationcs6ttd���G�fdd�dt�}|jt�j|d�dS)Nrcs(eZdZdd�Z�fdd�Zdd�ZdS)zITestDecorateSortUndecorate.test_key_with_mutating_del.<locals>.SortKillercSsdSrr�rr8rrrr�szRTestDecorateSortUndecorate.test_key_with_mutating_del.<locals>.SortKiller.__init__cs�dd�=td��dd�<dSrprqr%rrrr�__del__�s
zQTestDecorateSortUndecorate.test_key_with_mutating_del.<locals>.SortKiller.__del__cSst|�t|�kSr)�idr rrrr$�szPTestDecorateSortUndecorate.test_key_with_mutating_del.<locals>.SortKiller.__lt__N)r'r(r)rrvr$rrrrr�
SortKiller�srxr)rCr@rBrFrSr
�rrxrrrr�test_key_with_mutating_del�sz5TestDecorateSortUndecorate.test_key_with_mutating_delcs6ttd���G�fdd�dt�}|jt�j|d�dS)Nrcs eZdZdd�Z�fdd�ZdS)zWTestDecorateSortUndecorate.test_key_with_mutating_del_and_exception.<locals>.SortKillercSs|dkrt�dS)Nrr6rurrrr�sz`TestDecorateSortUndecorate.test_key_with_mutating_del_and_exception.<locals>.SortKiller.__init__cs"�dd�=ttd���dd�<dSrp)rCr@r%rrrrrv�s
z_TestDecorateSortUndecorate.test_key_with_mutating_del_and_exception.<locals>.SortKiller.__del__N)r'r(r)rrvrrrrrrx�srxr)rCr@rBrFrr
ryrrrr�(test_key_with_mutating_del_and_exception�szCTestDecorateSortUndecorate.test_key_with_mutating_del_and_exceptioncCs>ttd��}t�|�|jdd�|�|ttddd���dS)NrT)rD�c���)rCr@rrEr
rjrerrr�test_reverse�s
z'TestDecorateSortUndecorate.test_reversecCs�dd�td�D�}|dd�}|dd�}dd�}dd�}|jt|�dd	�|jt|�d
�|�||�|jdd�dd	�|�||�dS)
NcSsg|]}t�d�|f�qSrgr=r:rrrr<�szETestDecorateSortUndecorate.test_reverse_stability.<locals>.<listcomp>rhcSs"|d|d}}||k||kSrcr�r8rIZx0Zy0rrrr]�szATestDecorateSortUndecorate.test_reverse_stability.<locals>.my_cmpcSs"|d|d}}||k||kSrcrrrrr�my_cmp_reversed�szJTestDecorateSortUndecorate.test_reverse_stability.<locals>.my_cmp_reversedT)rrDrcSs|dSrcrr7rrrr2r3zCTestDecorateSortUndecorate.test_reverse_stability.<locals>.<lambda>)r@r
rrj)rr`Zcopy1�copy2r]r�rrr�test_reverse_stability�sz1TestDecorateSortUndecorate.test_reverse_stabilityN)r'r(r)rbrfrkrortrzr{r~r�rrrrrZ�s
rZc	Cs�t�d�t�|�|dd�}dd�|D�}dd�|D�}|||fD]H}t|�}dd�tdd�|D��D�}t||�D]\}}|�||�qxqFdS)NrcSsg|]
}|f�qSrr�r;r8rrrr<sz:check_against_PyObject_RichCompareBool.<locals>.<listcomp>cSsg|]}|ff�qSrrr�rrrr<scSsg|]}|d�qS)rr)r;rIrrrr<scSsg|]}d|f�qS)rrr�rrrr<s)r�seedrE�sorted�zipZassertIs)	rrOZL_1ZL_2ZL_3Z	optimizedZ	reference�opt�refrrr�&check_against_PyObject_RichCompareBools

r�c@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�TestOptimizedComparescCs�ddgddgddgg}|D]B}|�t|j�|�tdd�|D�j�|�tdd�|D�j�qdd	gd
d	gd	dgd	d
gg}|D]}t||�q~dS)Nr�foog)r�cSsg|]
}|f�qSrrr�rrrr<*szBTestOptimizedCompares.test_safe_object_compare.<locals>.<listcomp>cSsg|]}|ff�qSrrr�rrrr<+srg�������?�)rFrdr
r�)rZheterogeneous_listsrOZfloat_int_listsrrr�test_safe_object_compare$s��z.TestOptimizedCompares.test_safe_object_comparec	s`G��fdd�dt��Gdd�dt��Gdd�dt����fdd�td	�D�}|d
�|�t��|��W5QRX��fdd�td	�D�}|d
�|�t��dd�|D���W5QRXGd
d�d�}|�|�g}|�t|j�|�tdd�|D�j�ttd��dgdd�td�D�dgdd�td�D�dd�td�D�g}|D]}t||��qJdS)NcseZdZ��fdd�ZdS)zITestOptimizedCompares.test_unsafe_object_compare.<locals>.WackyComparatorcs��_t�||�Sr)�	__class__r5r$r ��
WackyList2�elemrrr$:szPTestOptimizedCompares.test_unsafe_object_compare.<locals>.WackyComparator.__lt__NrPrr�rr�WackyComparator9sr�c@seZdZdS)zDTestOptimizedCompares.test_unsafe_object_compare.<locals>.WackyList1N)r'r(r)rrrr�
WackyList1>sr�c@seZdZdd�ZdS)zDTestOptimizedCompares.test_unsafe_object_compare.<locals>.WackyList2cSst�dSr)rSr rrrr$BszKTestOptimizedCompares.test_unsafe_object_compare.<locals>.WackyList2.__lt__NrPrrrrr�Asr�csg|]}��|�|g��qSrrr:�r�r�rrr<EszDTestOptimizedCompares.test_unsafe_object_compare.<locals>.<listcomp>rr}csg|]}��|�|g��qSrrr:r�rrr<JscSsg|]
}|f�qSrrr�rrrr<Msc@seZdZdd�ZdS)zMTestOptimizedCompares.test_unsafe_object_compare.<locals>.PointlessComparatorcSstSr)�NotImplementedr rrrr$RszTTestOptimizedCompares.test_unsafe_object_compare.<locals>.PointlessComparator.__lt__NrPrrrr�PointlessComparatorQsr�cSsg|]
}|f�qSrrr�rrrr<Vsrr�cSsg|]}t|��qSr�r_r�rrrr<[su￿cSsg|]}t|��qSr)�bytesr�rrrr<\scSsg|]}tdd��|��qS)cSs||kSrrrWrrrr2]r3zMTestOptimizedCompares.test_unsafe_object_compare.<locals>.<listcomp>.<lambda>rr�rrrr<]s)r5rCr@rFrSr
rdr�)rrOr�Zlistsr)r�r�r�r�r�test_unsafe_object_compare4s,�z0TestOptimizedCompares.test_unsafe_object_comparecCst|dd�td�D��dS)NcSsg|]}t|��qSrr�r�rrrr<bs�zCTestOptimizedCompares.test_unsafe_latin_compare.<locals>.<listcomp>r�r�r@r%rrr�test_unsafe_latin_compareas
�z/TestOptimizedCompares.test_unsafe_latin_comparecCst|dd�td�D��dS)NcSsg|]}|�qSrrr�rrrr<fs�zBTestOptimizedCompares.test_unsafe_long_compare.<locals>.<listcomp>rr�r%rrr�test_unsafe_long_comparees
�z.TestOptimizedCompares.test_unsafe_long_comparecCst|dd�td�D��dS)NcSsg|]}t|��qSr��floatr�rrrr<js�zCTestOptimizedCompares.test_unsafe_float_compare.<locals>.<listcomp>rr�r%rrr�test_unsafe_float_compareis
�z/TestOptimizedCompares.test_unsafe_float_comparecCs0t|td�gd�t|dd�td�D��dS)N�nanrcSsg|]}td��qS)r�r�)r;�_rrrr<vs�zCTestOptimizedCompares.test_unsafe_tuple_compare.<locals>.<listcomp>)r�r�r@r%rrr�test_unsafe_tuple_comparems
�z/TestOptimizedCompares.test_unsafe_tuple_comparecCs<|�tdddgj�|�tddgj�|�tddgj�dS)N)��?r�)F�A�)r0r)rr0)rFrdr
r%rrr�test_not_all_tuplesysz)TestOptimizedCompares.test_not_all_tuplesN)
r'r(r)r�r�r�r�r�r�r�rrrrr�#s-r��__main__)N)�testrrZunittest�	functoolsrrrrZTestCaserrKrZr�r�r'�mainrrrr�<module>s
 [%]\