HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.7/test/__pycache__/test_heapq.cpython-37.pyc
B

��g�>�@s�dZddlZddlZddlmZddlmZmZddlmZej	ddgd�Z
ej	ddgd	�Zd
ddd
ddddgZGdd�de�Z
Gdd�d�ZGdd�dee�Zeed�Gdd�dee��ZGdd�d�ZGdd�d�ZGdd �d �Zd!d"�ZGd#d$�d$�ZGd%d&�d&�ZGd'd(�d(�ZGd)d*�d*�ZGd+d,�d,�ZGd-d.�d.�ZGd/d0�d0�Zdd1lmZd2d3�ZGd4d5�d5�ZGd6d7�d7�Z Gd8d9�d9e e�Z!eed�Gd:d;�d;e e��Z"e#d<k�r�e�$�dS)=zUnittests for heapq.�N)�support)�TestCase�
skipUnless)�
itemgetter�heapq�_heapq)Zblocked)Zfresh�heapify�heappop�heappush�heappushpop�heapreplace�_heappop_max�_heapreplace_max�_heapify_maxc@s&eZdZdd�Zeed�dd��ZdS)�TestModulescCs&x tD]}|�tt|�jd�qWdS)Nr)�
func_names�assertEqual�getattr�py_heapq�
__module__)�self�fname�r�+/usr/local/lib/python3.7/test/test_heapq.py�test_py_functionss
zTestModules.test_py_functionszrequires _heapqcCs&x tD]}|�tt|�jd�qWdS)Nr)rrr�c_heapqr)rrrrr�test_c_functionss
zTestModules.test_c_functionsN)�__name__r�__qualname__rrrrrrrrrsrc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�ZdS) �TestHeapcCs�g}g}|�|�x:td�D].}t��}|�|�|j�||�|�|�qWg}x(|rz|j�|�}|�|�|�|�qTW|dd�}|��|�||�|�|�|�	t
|jjg�y*|�	t
|jjdd�|�	t
|jjd�Wntk
r�YnXdS)N�)�check_invariant�range�random�append�moduler
r	�sortr�assertRaises�	TypeError�AttributeError)r�heap�data�i�item�resultsZdata_sortedrrr�
test_push_pops.



zTestHeap.test_push_popcCs<x6t|�D]*\}}|r
|dd?}|�|||k�q
WdS)N�)�	enumerateZ
assertTrue)rr*�posr-�	parentposrrrr!;szTestHeap.check_invariantcCsZxBttd��dgD],}dd�t|�D�}|j�|�|�|�qW|�t|jjd�dS)N�i NcSsg|]}t���qSr)r#)�.0Zdummyrrr�
<listcomp>Dsz)TestHeap.test_heapify.<locals>.<listcomp>)�listr"r%rr!r'r()r�sizer*rrr�test_heapifyBs
zTestHeap.test_heapifycCsndd�td�D�}g}x2|D]*}|j�||�t|�dkr|j�|�qW|��|�|t|�dd��dS)NcSsg|]}t�d��qS)i�)r#�	randrange)r5r,rrrr6Ksz-TestHeap.test_naive_nbest.<locals>.<listcomp>i��
i����)r"r%r
�lenr	r&r�sorted)rr+r*r-rrr�test_naive_nbestJs
zTestHeap.test_naive_nbestccs2yx|j�|�VqWWntk
r,YnXdS)N)r%r	�
IndexError)rr*rrr�heapiterTs
zTestHeap.heapitercCs�dd�td�D�}|dd�}|j�|�x.|dd�D]}||dkr8|j�||�q8W|�t|�|��t|�dd��|�t	|jjd�|�t	|jjdd�|�t
|jjgd�dS)NcSsg|]}t�d��qS)i�)r#r:)r5r,rrrr6bsz'TestHeap.test_nbest.<locals>.<listcomp>i�r;ri����)r"r%rrrr7r@r=r'r(r?)rr+r*r-rrr�
test_nbest\s"zTestHeap.test_nbestcCs�dd�td�D�}|dd�}|j�|�x"|dd�D]}|j�||�q8W|�t|�|��t|�dd��|�|j�gd�d�dS)NcSsg|]}t�d��qS)i�)r#r:)r5r,rrrr6osz4TestHeap.test_nbest_with_pushpop.<locals>.<listcomp>i�r;i�����x)r"r%rrrr7r@r=)rr+r*r-rrr�test_nbest_with_pushpopns"z TestHeap.test_nbest_with_pushpopcCs�g}|j�|d�}|�||fgdf�dg}|j�|d�}|�||fdgdf�|�t|d�t�|�t|�t�dg}|j�|d�}|�||fdgdf�dg}|j�|d�}|�||fdgdf�dS)Nr;g$@r�	�)r%rr�type�int�float)r�hrBrrr�test_heappushpopwszTestHeap.test_heappushpopcs�x�td�D]�}t�d�}dd�t|�D�}|d@rL|dd���j���n g�x|D]}�j��|�qVW��fdd�t|�D�}��|t|��q
WdS)N�d�2cSsg|]}t�d��qS)�)r#r:)r5r,rrrr6�sz*TestHeap.test_heapsort.<locals>.<listcomp>r0csg|]}�j����qSr)r%r	)r5r,)r*rrrr6�s)r"r#r:r%rr
rr=)rZtrialr8r+r-Zheap_sortedr)r*rr�
test_heapsort�s

zTestHeap.test_heapsortc
Csg}x\tt�d��D]J}g}x6tt�d��D]$}t�d�t�dd�f}|�|�q,W|�|�qWx�dtd�td�tdd�gD]|}xvdD]n}g}x |D]}	|�t|	||d	��q�W|�tt|�||d	�t	|j
j|||d	����|�t	|j
���g�q�Wq~WdS)
NrMrK�ABCi���i�rr0)FT)�key�reverse)r"r#r:�choicer$rr=r�chainr7r%�merge)
r�inputsr,�row�j�tuprPrQZseqs�seqrrr�
test_merge�s 

zTestHeap.test_mergec	Cs8dd�}|�t��t|j�|�|���WdQRXdS)Ncss,ttd��}xtd�D]}||VqWdS)Nr;�)r7r")�sr,rrr�iterable�szCTestHeap.test_merge_does_not_suppress_index_error.<locals>.iterable)r'r?r7r%rT)rr]rrr�(test_merge_does_not_suppress_index_error�sz1TestHeap.test_merge_does_not_suppress_index_errorcCs�Gdd�dt�}ggggg}xDtd�D]8}t�d�}t�d�}||�}||f|_||�|�q&Wx|D]}|��qhWdd�|jj|�D�}|�	|t
|��dS)Nc@seZdZdS)z*TestHeap.test_merge_stability.<locals>.IntN)rrrrrrr�Int�sr_i N�i�cSsg|]
}|j�qSr)�pair)r5r,rrrr6�sz1TestHeap.test_merge_stability.<locals>.<listcomp>)rGr"r#r:rar$r&r%rTrr=)rr_rUr,�streamrB�obj�resultrrr�test_merge_stability�s



zTestHeap.test_merge_stabilityc
Cs�dd�td�D�}xvddd�fD]f}x`dD]X}|�t|j�||��t|�d|��|�t|jj|||d��t||d�d|��q*Wq WdS)NcSsg|]}t�d�|f�qS)i�)r#r:)r5r,rrrr6�sz+TestHeap.test_nsmallest.<locals>.<listcomp>i�cSs|dddS)Nri#i�r)rBrrr�<lambda>��z)TestHeap.test_nsmallest.<locals>.<lambda>)	rr0�r;rKi�i�i�iL)rP)r"rr7r%�	nsmallestr=)rr+�f�nrrr�test_nsmallest�s
zTestHeap.test_nsmallestc
Cs�dd�td�D�}x|ddd�fD]l}xfdD]^}|�t|j�||��t|dd�d|��|�t|jj|||d	��t||dd
�d|��q*Wq WdS)NcSsg|]}t�d�|f�qS)i�)r#r:)r5r,rrrr6�sz*TestHeap.test_nlargest.<locals>.<listcomp>i�cSs|dddS)Nri#i�r)rBrrrrf�rgz(TestHeap.test_nlargest.<locals>.<lambda>)	rr0rhr;rKi�i�i�iLT)rQ)rP)rPrQ)r"rr7r%�nlargestr=)rr+rjrkrrr�
test_nlargest�s
zTestHeap.test_nlargestcsj�fdd�}Gdd�d�}Gdd�d�}dd�td	�D�}t|d
d�}��|||�|���t||�dS)Ncs:�fdd��D���j�����fdd�tt���D�S)Ncsg|]}�|��qSrr)r5rB)�comprrr6�szDTestHeap.test_comparison_operator.<locals>.hsort.<locals>.<listcomp>csg|]}�j���j�qSr)r%r	rB)r5r,)r+rrrr6�s)r%rr"r<)r+ro)r)ror+r�hsort�sz0TestHeap.test_comparison_operator.<locals>.hsortc@seZdZdd�Zdd�ZdS)z-TestHeap.test_comparison_operator.<locals>.LTcSs
||_dS)N)rB)rrBrrr�__init__�sz6TestHeap.test_comparison_operator.<locals>.LT.__init__cSs|j|jkS)N)rB)r�otherrrr�__lt__�sz4TestHeap.test_comparison_operator.<locals>.LT.__lt__N)rrrrqrsrrrr�LT�srtc@seZdZdd�Zdd�ZdS)z-TestHeap.test_comparison_operator.<locals>.LEcSs
||_dS)N)rB)rrBrrrrq�sz6TestHeap.test_comparison_operator.<locals>.LE.__init__cSs|j|jkS)N)rB)rrrrrr�__le__�sz4TestHeap.test_comparison_operator.<locals>.LE.__le__N)rrrrqrurrrr�LE�srvcSsg|]}t���qSr)r#)r5r,rrrr6�sz5TestHeap.test_comparison_operator.<locals>.<listcomp>rKT)rQ)r"r=rr'r()rrprtrvr+�targetr)rr�test_comparison_operator�sz!TestHeap.test_comparison_operatorN)rrrr/r!r9r>r@rArCrJrNrZr^rerlrnrxrrrrrs
				rc@seZdZeZdS)�TestHeapPythonN)rrrrr%rrrrry�sryzrequires _heapqc@seZdZeZdS)�	TestHeapCN)rrrrr%rrrrrz�srzc@seZdZdZdd�ZdS)�LenOnlyz:Dummy sequence class defining __len__ but not __getitem__.cCsdS)Nr;r)rrrr�__len__�szLenOnly.__len__N)rrr�__doc__r|rrrrr{�sr{c@seZdZdZdd�ZdS)�GetOnlyz:Dummy sequence class defining __getitem__ but not __len__.cCsdS)Nr;r)rZndxrrr�__getitem__�szGetOnly.__getitem__N)rrrr}rrrrrr~�sr~c@s,eZdZdZdd�ZeZZZZZ	dS)�CmpErrz;Dummy element that always raises an error during comparisoncCst�dS)N)�ZeroDivisionError)rrrrrr�__eq__sz
CmpErr.__eq__N)
rrrr}r��__ne__rsru�__gt__�__ge__rrrrr�sr�ccsx|D]
}|VqWdS)zRegular generatorNr)�seqnr,rrr�Rs
r�c@s eZdZdZdd�Zdd�ZdS)�GzSequence using __getitem__cCs
||_dS)N)r�)rr�rrrrqsz
G.__init__cCs
|j|S)N)r�)rr,rrrrsz
G.__getitem__N)rrrr}rqrrrrrr�sr�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�Iz Sequence using iterator protocolcCs||_d|_dS)Nr)r�r,)rr�rrrrqsz
I.__init__cCs|S)Nr)rrrr�__iter__sz
I.__iter__cCs2|jt|j�krt�|j|j}|jd7_|S)Nr0)r,r<r��
StopIteration)r�vrrr�__next__s
z
I.__next__N)rrrr}rqr�r�rrrrr�sr�c@s eZdZdZdd�Zdd�ZdS)�Igz9Sequence using iterator protocol defined with a generatorcCs||_d|_dS)Nr)r�r,)rr�rrrrq"szIg.__init__ccsx|jD]
}|VqWdS)N)r�)r�valrrrr�%szIg.__iter__N)rrrr}rqr�rrrrr� sr�c@s eZdZdZdd�Zdd�ZdS)�Xz Missing __getitem__ and __iter__cCs||_d|_dS)Nr)r�r,)rr�rrrrq+sz
X.__init__cCs2|jt|j�krt�|j|j}|jd7_|S)Nr0)r,r<r�r�)rr�rrrr�.s
z
X.__next__N)rrrr}rqr�rrrrr�)sr�c@s eZdZdZdd�Zdd�ZdS)�NzIterator missing __next__()cCs||_d|_dS)Nr)r�r,)rr�rrrrq6sz
N.__init__cCs|S)Nr)rrrrr�9sz
N.__iter__N)rrrr}rqr�rrrrr�4sr�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�EzTest propagation of exceptionscCs||_d|_dS)Nr)r�r,)rr�rrrrq>sz
E.__init__cCs|S)Nr)rrrrr�Asz
E.__iter__cCsdddS)N�rr)rrrrr�Csz
E.__next__N)rrrr}rqr�r�rrrrr�<sr�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�SzTest immediate stopcCsdS)Nr)rr�rrrrqHsz
S.__init__cCs|S)Nr)rrrrr�Jsz
S.__iter__cCst�dS)N)r�)rrrrr�Lsz
S.__next__N)rrrr}rqr�r�rrrrr�Fsr�)rScCsttdd�ttt|�����S)z Test multiple tiers of iteratorscSs|S)Nr)rBrrrrfRrgzL.<locals>.<lambda>)rS�mapr�r�r�)r�rrr�LPsr�c@seZdZdd�Zdd�ZdS)�SideEffectLTcCs||_||_dS)N)�valuer*)rr�r*rrrrqVszSideEffectLT.__init__cCsg|jdd�<|j|jkS)N)r*r�)rrrrrrrsZszSideEffectLT.__lt__N)rrrrqrsrrrrr�Usr�c@s\eZdZdd�Zdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�ZdS)�TestErrorHandlingcCsjx*|jj|jjfD]}|�ttf|d�qWx8|jj|jj|jj|jj	fD]}|�ttf|dd�qJWdS)Nr;)
r%rr	r'r(r)r
rrmri)rrjrrr�test_non_sequenceas
z#TestErrorHandling.test_non_sequencecCs�x,|jj|jjfD]}|�ttf|t��qWx.|jj|jjfD]}|�ttf|t�d�q@Wx*|jj	|jj
fD]}|�t|dt��qpWdS)Nr;rh)r%rr	r'r(r)r{r
rrmri)rrjrrr�
test_len_onlyhszTestErrorHandling.test_len_onlycCs�x(|jj|jjfD]}|�t|t��qWx*|jj|jjfD]}|�t|t�d�q<Wx*|jj|jj	fD]}|�t|dt��qhWdS)Nr;rh)
r%rr	r'r(r~r
rrmri)rrjrrr�
test_get_onlypszTestErrorHandling.test_get_onlycCs�t�t�t�g}x&|jj|jjfD]}|�t||�q"Wx(|jj|jjfD]}|�t||d�qJWx(|jj|jj	fD]}|�t|d|�qtWdS)Nr;rh)
r�r%rr	r'r�r
rrmri)rrYrjrrrr�xscCsHxB|jj|jj|jj|jj|jj|jjfD]}|�tt	f|d�q*WdS)Nr;)
r%rr	r
rrmrir'r(r))rrjrrr�test_arg_parsing�sz"TestErrorHandling.test_arg_parsingc
Cs�x�|jj|jjfD]�}x�ddtd�dtddd�fD]�}x:tttttfD](}|�	t
|d||���t
|d|���qFW|�	t
|dt|���g�|�t
|dt|��|�t
|dt|��|�t|dt|��q2WqWdS)	NZ123�i�)r0g333333�?i�i��rh)r%rmrir"r�r�r�r�r�rr7r�r'r(r�r�r�r�)rrjr\�grrr�test_iterable_args�s (z$TestErrorHandling.test_iterable_argsc	sRg����fdd�td�D��|�ttf��|j��td���WdQRXdS)Nc3s|]}t|��VqdS)N)r�)r5r,)r*rr�	<genexpr>�sz@TestErrorHandling.test_heappush_mutating_heap.<locals>.<genexpr>��r�)�extendr"r'r?�RuntimeErrorr%r
r�)rr)r*r�test_heappush_mutating_heap�sz-TestErrorHandling.test_heappush_mutating_heapc	sJg����fdd�td�D��|�ttf��|j���WdQRXdS)Nc3s|]}t|��VqdS)N)r�)r5r,)r*rrr��sz?TestErrorHandling.test_heappop_mutating_heap.<locals>.<genexpr>r�)r�r"r'r?r�r%r	)rr)r*r�test_heappop_mutating_heap�sz,TestErrorHandling.test_heappop_mutating_heapcsBG�fdd�dt�}g�|j��|d��|�t|jj�d�dS)NcseZdZ�fdd�ZdS)zMTestErrorHandling.test_comparison_operator_modifiying_heap.<locals>.EvilClasscs���tS)N)�clear�NotImplemented)r�o)r*rrrs�szTTestErrorHandling.test_comparison_operator_modifiying_heap.<locals>.EvilClass.__lt__N)rrrrsr)r*rr�	EvilClass�sr�rr0)rGr%r
r'r?r)rr�r)r*r�(test_comparison_operator_modifiying_heap�sz:TestErrorHandling.test_comparison_operator_modifiying_heapcs�G�fdd�dt�}G�fdd�dt�}gg��|j��|d��|j��|d��|�ttf|jj�|d��|�ttf|jj�|d��dS)NcseZdZ�fdd�ZdS)zOTestErrorHandling.test_comparison_operator_modifiying_heap_two_heaps.<locals>.hcs���tS)N)r�r�)rr�)�list2rrrs�szVTestErrorHandling.test_comparison_operator_modifiying_heap_two_heaps.<locals>.h.__lt__N)rrrrsr)r�rrrI�srIcseZdZ�fdd�ZdS)zOTestErrorHandling.test_comparison_operator_modifiying_heap_two_heaps.<locals>.gcs���tS)N)r�r�)rr�)�list1rrrs�szVTestErrorHandling.test_comparison_operator_modifiying_heap_two_heaps.<locals>.g.__lt__N)rrrrsr)r�rrr��sr�rr0)rGr%r
r'r?r�)rrIr�r)r�r�r�2test_comparison_operator_modifiying_heap_two_heaps�s
zDTestErrorHandling.test_comparison_operator_modifiying_heap_two_heapsN)rrrr�r�r�r�r�r�r�r�r�rrrrr�_s	r�c@seZdZeZdS)�TestErrorHandlingPythonN)rrrrr%rrrrr��sr�c@seZdZeZdS)�TestErrorHandlingCN)rrrrr%rrrrr��sr��__main__)%r}r#ZunittestZtestrrr�operatorrZimport_fresh_modulerrrrrryrzr{r~r�r�r�r�r�r�r�r�r��	itertoolsrSr�r�r�r�r�r�mainrrrr�<module>sF

P

	
	
b