Your IP : 216.73.216.213


Current Path : /proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/
Upload File :
Current File : //proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/test_heapq.cpython-34.pyc

�
g f�8�@sodZddlZddlZddlZddlmZddlmZmZejdddg�Z	ejdddg�Z
d	d
ddd
ddgZGdd�de�ZGdd�d�Z
Gdd�de
e�Zee
d�Gdd�de
e��ZGdd�d�ZGdd�d�ZGdd�d�Zdd �ZGd!d"�d"�ZGd#d$�d$�ZGd%d&�d&�ZGd'd(�d(�ZGd)d*�d*�ZGd+d,�d,�ZGd-d.�d.�Zdd/lmZd0d1�ZGd2d3�d3�ZGd4d5�d5�ZGd6d7�d7ee�Z ee
d�Gd8d9�d9ee��Z!e"d:krkej#�ndS);zUnittests for heapq.�N)�support)�TestCase�
skipUnless�heapqZblocked�_heapqZfresh�heapify�heappop�heappush�heappushpop�heapreplace�	_nlargest�
_nsmallestc@s7eZdZdd�Zeed�dd��ZdS)�TestModulescCs1x*tD]"}|jtt|�jd�qWdS)Nr)�
func_names�assertEqual�getattr�py_heapq�
__module__)�self�fname�r�4/opt/alt/python34/lib64/python3.4/test/test_heapq.py�test_py_functionss
zTestModules.test_py_functionszrequires _heapqcCs1x*tD]"}|jtt|�jd�qWdS)Nr)rrr�c_heapqr)rrrrr�test_c_functionss
zTestModules.test_c_functionsN)�__name__r�__qualname__rrrrrrrrrsrc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�ZdS) �TestHeapcCsJg}g}|j|�xMtd�D]?}tj�}|j|�|jj||�|j|�q&Wg}x6|r�|jj|�}|j|�|j|�qrW|dd�}|j�|j||�|j|�|j	t
|jjg�y9|j	t
|jjdd�|j	t
|jjd�Wntk
rEYnXdS)N�)�check_invariant�range�random�append�moduler	r�sortr�assertRaises�	TypeError�AttributeError)r�heap�data�i�itemZresultsZdata_sortedrrr�
test_push_pops.

	



zTestHeap.test_push_popcCsOxHt|�D]:\}}|r
|dd?}|j|||k�q
q
WdS)N�)�	enumerateZ
assertTrue)rr(�posr+�	parentposrrrr;szTestHeap.check_invariantcCsjxJtd�D]<}dd�t|�D�}|jj|�|j|�q
W|jt|jjd�dS)N�cSsg|]}tj��qSr)r!)�.0Zdummyrrr�
<listcomp>Ds	z)TestHeap.test_heapify.<locals>.<listcomp>)r r#rrr%r&)r�sizer(rrr�test_heapifyBs
zTestHeap.test_heapifycCs�dd�td�D�}g}xF|D]>}|jj||�t|�dkr&|jj|�q&q&W|j�|j|t|�dd��dS)NcSsg|]}tjd��qS)i�)r!�	randrange)r2r*rrrr3Ks	z-TestHeap.test_naive_nbest.<locals>.<listcomp>i��
i����)r r#r	�lenrr$r�sorted)rr)r(r+rrr�test_naive_nbestJs

zTestHeap.test_naive_nbestccs5yx|jj|�VqWWntk
r0YnXdS)N)r#r�
IndexError)rr(rrr�heapiterTs

zTestHeap.heapitercCs�dd�td�D�}|dd�}|jj|�x>|dd�D],}||dkrJ|jj||�qJqJW|jt|j|��t|�dd��|jt	|jjd�|jt	|jjdd�|jt
|jjgd�dS)NcSsg|]}tjd��qS)i�)r!r6)r2r*rrrr3bs	z'TestHeap.test_nbest.<locals>.<listcomp>i�r7ri����)r r#rrr�listr<r9r%r&r;)rr)r(r+rrr�
test_nbest\s/zTestHeap.test_nbestcCs�dd�td�D�}|dd�}|jj|�x+|dd�D]}|jj||�qJW|jt|j|��t|�dd��|j|jjgd�d�dS)NcSsg|]}tjd��qS)i�)r!r6)r2r*rrrr3os	z4TestHeap.test_nbest_with_pushpop.<locals>.<listcomp>i�r7�xi����)r r#rr
rr=r<r9)rr)r(r+rrr�test_nbest_with_pushpopns/z TestHeap.test_nbest_with_pushpopcCs"g}|jj|d�}|j||fgdf�dg}|jj|d�}|j||fdgdf�|jt|d�t�|jt|�t�dg}|jj|d�}|j||fdgdf�dg}|jj|d�}|j||fdgdf�dS)Nr7g$@r�	�)r#r
r�type�int�float)r�hr?rrr�test_heappushpopws			zTestHeap.test_heappushpopcs�x�td�D]�}tjd�}dd�t|�D�}|d@rh|dd���jj��n*g�x!|D]}�jj�|�quW��fdd�t|�D�}�j|t|��q
WdS)N�d�2cSsg|]}tjd��qS)�)r!r6)r2r*rrrr3�s	z*TestHeap.test_heapsort.<locals>.<listcomp>r-cs"g|]}�jj���qSr)r#r)r2r*)r(rrrr3�s	)r r!r6r#rr	rr9)rZtrialr4r)r+Zheap_sortedr)r(rr�
test_heapsort�s

"zTestHeap.test_heapsortcCs�g}xRttjd��D];}tdd�ttjd��D��}|j|�qW|jtt|��t|jj	|���|jt|jj	��g�dS)N�css|]}tjd�VqdS)i�N)r!r6)r2�jrrr�	<genexpr>�sz&TestHeap.test_merge.<locals>.<genexpr>r7)
r r!r6r9r"r�chainr=r#�merge)r�inputsr*�rowrrr�
test_merge�s(.zTestHeap.test_mergecCsEdd�}|jt��$t|jj|�|���WdQXdS)Ncss6ttd��}xtd�D]}||VqWdS)Nr7�)r=r )�sr*rrr�iterable�szCTestHeap.test_merge_does_not_suppress_index_error.<locals>.iterable)r%r;r=r#rP)rrVrrr�(test_merge_does_not_suppress_index_error�sz1TestHeap.test_merge_does_not_suppress_index_errorcCs�Gdd�dt�}ggggg}x^td�D]P}tjd�}tjd�}||�}||f|_||j|�q5Wx|D]}|j�q�Wdd�|jj|�D�}|j	|t
|��dS)Nc@seZdZdS)z*TestHeap.test_merge_stability.<locals>.IntN)rrrrrrr�Int�srXi N�i�cSsg|]}|j�qSr)�pair)r2r*rrrr3�s	z1TestHeap.test_merge_stability.<locals>.<listcomp>)rDr r!r6rZr"r$r#rPrr9)rrXrQr*�streamr?�obj�resultrrr�test_merge_stability�s
zTestHeap.test_merge_stabilityc
Cs�dd�td�D�}x�ddd�fD]�}x�dD]|}|jt|jj||��t|�d|��|jt|jj||d|��t|d|�d|��q9Wq,WdS)NcSs%g|]}tjd�|f�qS)i�)r!r6)r2r*rrrr3�s	z+TestHeap.test_nsmallest.<locals>.<listcomp>��cSs|dddS)Nri#i�r)r?rrr�<lambda>�sz)TestHeap.test_nsmallest.<locals>.<lambda>rr-�r7rH����L�key)	rr-rar7rHrbrcr_rd)r rr=r#�	nsmallestr9)rr)�f�nrrr�test_nsmallest�s
$zTestHeap.test_nsmallestc
Cs�dd�td�D�}x�ddd�fD]�}x�dD]�}|jt|jj||��t|dd�d|��|jt|jj||d|��t|d|dd�d|��q9Wq,WdS)NcSs%g|]}tjd�|f�qS)i�)r!r6)r2r*rrrr3�s	z*TestHeap.test_nlargest.<locals>.<listcomp>��cSs|dddS)Nri#i�r)r?rrrr`�sz(TestHeap.test_nlargest.<locals>.<lambda>rr-rar7rH����L�reverseTre)	rr-rar7rHrkrlrjrm)r rr=r#�nlargestr9)rr)rgrhrrr�
test_nlargest�s
$zTestHeap.test_nlargestcs��fdd�}Gdd�d�}Gdd�d�}dd�td	�D�}t|d
d�}�j|||�|��jt||�dS)NcsO�fdd��D���jj����fdd�tt���D�S)Ncsg|]}�|��qSrr)r2r?)�comprrr3�s	zDTestHeap.test_comparison_operator.<locals>.hsort.<locals>.<listcomp>cs%g|]}�jj��j�qSr)r#rr?)r2r*)r)rrrr3�s	)r#rr r8)r)rq)r)rqr)r�hsort�sz0TestHeap.test_comparison_operator.<locals>.hsortc@s(eZdZdd�Zdd�ZdS)z-TestHeap.test_comparison_operator.<locals>.LTcSs
||_dS)N)r?)rr?rrr�__init__�sz6TestHeap.test_comparison_operator.<locals>.LT.__init__cSs|j|jkS)N)r?)r�otherrrr�__lt__�sz4TestHeap.test_comparison_operator.<locals>.LT.__lt__N)rrrrsrurrrr�LT�srvc@s(eZdZdd�Zdd�ZdS)z-TestHeap.test_comparison_operator.<locals>.LEcSs
||_dS)N)r?)rr?rrrrs�sz6TestHeap.test_comparison_operator.<locals>.LE.__init__cSs|j|jkS)N)r?)rrtrrr�__le__�sz4TestHeap.test_comparison_operator.<locals>.LE.__le__N)rrrrsrwrrrr�LE�srxcSsg|]}tj��qSr)r!)r2r*rrrr3�s	z5TestHeap.test_comparison_operator.<locals>.<listcomp>rHrnT)r r9rr%r&)rrrrvrxr)�targetr)rr�test_comparison_operator�sz!TestHeap.test_comparison_operatorN)rrrr,rr5r:r<r>r@rGrKrSrWr^rirprzrrrrrs
				rc@seZdZeZdS)�TestHeapPythonN)rrrrr#rrrrr{�sr{zrequires _heapqc@seZdZeZdS)�	TestHeapCN)rrrrr#rrrrr|�sr|c@s"eZdZdZdd�ZdS)�LenOnlyz:Dummy sequence class defining __len__ but not __getitem__.cCsdS)Nr7r)rrrr�__len__�szLenOnly.__len__N)rrr�__doc__r~rrrrr}�sr}c@s"eZdZdZdd�ZdS)�GetOnlyz:Dummy sequence class defining __getitem__ but not __len__.cCsdS)Nr7r)rZndxrrr�__getitem__�szGetOnly.__getitem__N)rrrrr�rrrrr��sr�c@s8eZdZdZdd�ZeZZZZZ	dS)�CmpErrz;Dummy element that always raises an error during comparisoncCs
t�dS)N)�ZeroDivisionError)rrtrrr�__eq__�sz
CmpErr.__eq__N)
rrrrr��__ne__rurw�__gt__�__ge__rrrrr��sr�ccsx|D]}|VqWdS)zRegular generatorNr)�seqnr*rrr�R�s
r�c@s.eZdZdZdd�Zdd�ZdS)�GzSequence using __getitem__cCs
||_dS)N)r�)rr�rrrrssz
G.__init__cCs|j|S)N)r�)rr*rrrr�sz
G.__getitem__N)rrrrrsr�rrrrr�sr�c@s:eZdZdZdd�Zdd�Zdd�ZdS)	�Iz Sequence using iterator protocolcCs||_d|_dS)Nr)r�r*)rr�rrrrss	z
I.__init__cCs|S)Nr)rrrr�__iter__sz
I.__iter__cCsD|jt|j�kr!t�n|j|j}|jd7_|S)Nr-)r*r8r��
StopIteration)r�vrrr�__next__s
	z
I.__next__N)rrrrrsr�r�rrrrr�	sr�c@s.eZdZdZdd�Zdd�ZdS)�Igz9Sequence using iterator protocol defined with a generatorcCs||_d|_dS)Nr)r�r*)rr�rrrrss	zIg.__init__ccsx|jD]}|Vq
WdS)N)r�)r�valrrrr�szIg.__iter__N)rrrrrsr�rrrrr�sr�c@s.eZdZdZdd�Zdd�ZdS)�Xz Missing __getitem__ and __iter__cCs||_d|_dS)Nr)r�r*)rr�rrrrs!s	z
X.__init__cCsD|jt|j�kr!t�n|j|j}|jd7_|S)Nr-)r*r8r�r�)rr�rrrr�$s
	z
X.__next__N)rrrrrsr�rrrrr�sr�c@s.eZdZdZdd�Zdd�ZdS)�NzIterator missing __next__()cCs||_d|_dS)Nr)r�r*)rr�rrrrs,s	z
N.__init__cCs|S)Nr)rrrrr�/sz
N.__iter__N)rrrrrsr�rrrrr�*sr�c@s:eZdZdZdd�Zdd�Zdd�ZdS)	�EzTest propagation of exceptionscCs||_d|_dS)Nr)r�r*)rr�rrrrs4s	z
E.__init__cCs|S)Nr)rrrrr�7sz
E.__iter__cCsdddS)N�rr)rrrrr�9sz
E.__next__N)rrrrrsr�r�rrrrr�2sr�c@s:eZdZdZdd�Zdd�Zdd�ZdS)	�SzTest immediate stopcCsdS)Nr)rr�rrrrs>sz
S.__init__cCs|S)Nr)rrrrr�@sz
S.__iter__cCs
t�dS)N)r�)rrrrr�Bsz
S.__next__N)rrrrrsr�r�rrrrr�<sr�)rOcCs+ttdd�ttt|�����S)z Test multiple tiers of iteratorscSs|S)Nr)r?rrrr`HszL.<locals>.<lambda>)rO�mapr�r�r�)r�rrr�LFsr�c@s(eZdZdd�Zdd�ZdS)�SideEffectLTcCs||_||_dS)N)�valuer()rr�r(rrrrsLs	zSideEffectLT.__init__cCs#g|jdd�<|j|jkS)N)r(r�)rrtrrrruPszSideEffectLT.__lt__N)rrrrsrurrrrr�Ksr�c@speZdZdd�Zdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dS)�TestErrorHandlingcCs�x9|jj|jjfD]}|jttf|d�qWxN|jj|jj|jj|jj	fD]"}|jttf|dd�qgWdS)Nr7)
r#rrr%r&r'r	rrorf)rrgrrr�test_non_sequenceWs
z#TestErrorHandling.test_non_sequencecCs�x<|jj|jjfD]"}|jttf|t��qWx?|jj|jjfD]%}|jttf|t�d�qXWx9|jj	|jj
fD]}|jt|dt��q�WdS)Nr7ra)r#rrr%r&r'r}r	rrorf)rrgrrr�
test_len_only^s #zTestErrorHandling.test_len_onlycCs�x6|jj|jjfD]}|jt|t��qWx9|jj|jjfD]}|jt|t�d�qRWx9|jj|jj	fD]}|jt|dt��q�WdS)Nr7ra)
r#rrr%r&r�r	rrorf)rrgrrr�
test_get_onlyfszTestErrorHandling.test_get_onlycCs�t�t�t�g}x3|jj|jjfD]}|jt||�q1Wx6|jj|jjfD]}|jt||d�qgWx6|jj|jj	fD]}|jt|d|�q�WdS)Nr7ra)
r�r#rrr%r�r	rrorf)r�seqrgrrrr�nscCsdx]|jj|jj|jj|jj|jj|jjfD]}|jtt	f|d�q=WdS)Nr7)
r#rrr	rrorfr%r&r')rrgrrr�test_arg_parsingwsz"TestErrorHandling.test_arg_parsingc	Cs&x|jj|jjfD]}x�ddtd�d
tddd�fD]�}xQtttttfD]:}|j	t
|d	||���t
|d	|���qcW|j	t
|d	t|���g�|jt
|d	t|��|jt
|d	t|��|jt|d	t|��qGWqWdS)NZ123�i�r-�333333�?i�i�rLra)r-r�)r#rorfr r�r�r�r�r�rr=r�r%r&r�r�r�r�)rrgrU�grrr�test_iterable_args}s.8%z$TestErrorHandling.test_iterable_argscshg��j�fdd�td�D��|jttf��!|jj�td���WdQXdS)Nc3s|]}t|��VqdS)N)r�)r2r*)r(rrrN�sz@TestErrorHandling.test_heappush_mutating_heap.<locals>.<genexpr>��rL)�extendr r%r;�RuntimeErrorr#r	r�)rr)r(r�test_heappush_mutating_heap�s&z-TestErrorHandling.test_heappush_mutating_heapc	s\g��j�fdd�td�D��|jttf��|jj��WdQXdS)Nc3s|]}t|��VqdS)N)r�)r2r*)r(rrrN�sz?TestErrorHandling.test_heappop_mutating_heap.<locals>.<genexpr>r�)r�r r%r;r�r#r)rr)r(r�test_heappop_mutating_heap�s&z,TestErrorHandling.test_heappop_mutating_heapN)
rrrr�r�r�r�r�r�r�rrrrr�Us	r�c@seZdZeZdS)�TestErrorHandlingPythonN)rrrrr#rrrrr��sr�c@seZdZeZdS)�TestErrorHandlingCN)rrrrr#rrrrr��sr��__main__)$r�sysr!ZunittestZtestrrrZimport_fresh_modulerrrrrr{r|r}r�r�r�r�r�r�r�r�r�r��	itertoolsrOr�r�r�r�r�r�mainrrrr�<module>sD�
	
	
C