Your IP : 216.73.216.60


Current Path : /opt/alt/python35/lib64/python3.5/test/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/__pycache__/test_binop.cpython-35.opt-2.pyc



���]3�@svddlZddlmZddlmZmZmZmZmZm	Z	ddl
mZdd�Zdd�Z
d	d
�Zdd�ZGd
d�de�ZGdd�dej�ZGdd�d�Zdd�ZGdd�de�ZGdd�dede�ZGdd�de�ZGdd�de�Zeje�Gdd�dej�Zed krrej�dS)!�N)�support)�eq�ne�lt�gt�le�ge)�ABCMetacCs"x|r|||}}qW|S)N�)�a�br
r
�//opt/alt/python35/lib64/python3.5/test_binop.py�gcds	rcCs
t|t�S)N)�
isinstance�int)�xr
r
r
�isintsrcCs1x*tttfD]}t||�rdSqWdS)N�r)r�float�complexr)r�Tr
r
r
�isnumsrcCs
t|t�S)N)r�Rat)rr
r
r
�isRatsrc@s<eZdZddgZdddd�Zdd�Zeed	�Zd
d�Zeed	�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�ZeZdd�Zdd�Zdd�ZeZdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd	S).r�	_Rat__num�	_Rat__denrrcCs�t|�std|��t|�s8td|��|dkrPtd��t||�}t||�|_t||�|_dS)NzRat numerator must be int (%r)z Rat denominator must be int (%r)rzzero denominator)r�	TypeError�ZeroDivisionErrorrrrr)�self�num�den�gr
r
r
�__init__#szRat.__init__cCs|jS)N)r)rr
r
r
�_get_num2szRat._get_numNcCs|jS)N)r)rr
r
r
�_get_den7szRat._get_dencCsd|j|jfS)NzRat(%d, %d))rr)rr
r
r
�__repr__<szRat.__repr__cCstt|��S)N)�strr)rr
r
r
�__str__@szRat.__str__cCs|jd|jS)Ng�?)rr)rr
r
r
�	__float__Dsz
Rat.__float__cCse|jdkrKyt|j�SWn(tk
rJtdt|���YnXtdt|���dS)Nrz%s too large to convert to intzcan't convert %s to int)rrr�
OverflowError�repr�
ValueError)rr
r
r
�__int__Hs
zRat.__int__cCsqt|�rt|�}t|�rSt|j|j|j|j|j|j�St|�rmt|�|StS)N)rrrrrrr�NotImplemented)r�otherr
r
r
�__add__RszRat.__add__cCsqt|�rt|�}t|�rSt|j|j|j|j|j|j�St|�rmt|�|StS)N)rrrrrrrr-)rr.r
r
r
�__sub___szRat.__sub__cCsqt|�rt|�}t|�rSt|j|j|j|j|j|j�St|�rm|t|�StS)N)rrrrrrrr-)rr.r
r
r
�__rsub__jszRat.__rsub__cCsnt|�r-t|j|j|j|j�St|�rPt|j||j�St|�rjt|�|StS)N)rrrrrrrr-)rr.r
r
r
�__mul__us!zRat.__mul__cCsnt|�r-t|j|j|j|j�St|�rPt|j|j|�St|�rjt|�|StS)N)rrrrrrrr-)rr.r
r
r
�__truediv__�s!zRat.__truediv__cCsnt|�r-t|j|j|j|j�St|�rPt||j|j�St|�rj|t|�StS)N)rrrrrrrr-)rr.r
r
r
�__rtruediv__�s!zRat.__rtruediv__cCsCt|�rt|�}nt|�s+tS||}|j|jS)N)rrrr-rr)rr.rr
r
r
�__floordiv__�s
zRat.__floordiv__cCs||}|j|jS)N)rr)rr.rr
r
r
�
__rfloordiv__�s
zRat.__rfloordiv__cCsGt|�rt|�}nt|�s+tS||}||||fS)N)rrrr-)rr.rr
r
r
�
__divmod__�s
zRat.__divmod__cCs8t|�rt|�}nt|�s+tSt||�S)N)rrrr-�divmod)rr.r
r
r
�__rdivmod__�s
zRat.__rdivmod__cCst||�dS)Nr)r8)rr.r
r
r
�__mod__�szRat.__mod__cCst||�dS)Nr)r8)rr.r
r
r
�__rmod__�szRat.__rmod__cCsvt|�r(|jdko'|j|kSt|�rV|j|jkoU|j|jkSt|�rrt|�|kStS)Nr)rrrrrrr-)rr.r
r
r
�__eq__�s"z
Rat.__eq__)�__name__�
__module__�__qualname__�	__slots__r"r#�propertyrr$r r%r'r(r,r/�__radd__r0r1r2�__rmul__r3r4r5r6r7r9r:r;r<r
r
r
r
rs2



		rc@s|eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�RatTestCasecCs[|jtdd�d�|jtdd�d�|jtdd�d�|jtdd�d�|jtdd�d�|jtdd
�d�|jtdd�d�x�tdd	�D]�}x�tdd	�D]z}|jt||�d
k�|jt||�d
k�|jt||�d
k�|jt||�d
k�q�Wq�WdS)N�
�����r�d�ri�������rMi����rMrM)�assertEqualr�range�
assertTrue)r�i�jr
r
r
�test_gcd�szRatTestCase.test_gcdcCs�tdd�}|j|jd�|j|jd�tdd�}|j|jd�|j|jd�tdd�}|j|jd�|j|jd�tdd�}|j|jd�|j|jd�td�}|j|jd�|j|jd�ytdd�}Wntk
r-YnX|jd�x�d	d
dfgidttf	D]u}yt|�}Wntk
r�YnX|jd|�ytd|�}Wntk
r�Yq]X|jd
|�q]WdS)NrErHrG��rrz(Rat(1, 0) didn't raise ZeroDivisionError�0gyzRat(%r) didn't raise TypeErrorz!Rat(1, %r) didn't raise TypeErrori�rMi����rMi����i�)rrNrr rZfail�unittestr)rrZbadr
r
r
�test_constructor�s>

(

zRatTestCase.test_constructorcCs�|jtdd�tdd�d�|jtdd�dtdd��|jdtdd�tdd��|jdtdd�d�|jtdd�dd�dS)NrGrTrrIg�?g�?)rNr)rr
r
r
�test_add�s
&&&zRatTestCase.test_addcCs�|jtdd�tdd�tdd��|jtdd�dtdd��|jdtdd�tdd��|jtdd�dd	�|jdtdd�d	�dS)
NrUrGrI�rErrTg�?g�?)rNr)rr
r
r
�test_subs
/&&zRatTestCase.test_subcCs�|jtdd�tdd�tdd��|jtdd�dd�|jdtdd�d�|jtdd�dd�|jdtdd�d�dS)	NrGrTrIrUrErZg�?g�?)rNr)rr
r
r
�test_mul
s
/zRatTestCase.test_mulcCs�|jtdd�tdd�tdd��|jtdd�dtdd��|jdtd�tdd��|jdtd	d�d
�|jtd	d�dd
�dS)NrErTrIrU��	rGg@rg�?)rNr)rr
r
r
�test_divs
/&#zRatTestCase.test_divcCs~|jtd�td�d�|jtdd�tdd�d�|jtd�dd�|jdtd�d�dS)NrE�rGrT)rNr)rr
r
r
�
test_floordivs &zRatTestCase.test_floordivcCs{|jtd�tdd��|jtd�d�|jdtd��|jtd�d�|jdtd��dS)NrErLrGg$@)rNr)rr
r
r
�test_eqs
zRatTestCase.test_eqcCs�|jtdd�tdd�tdd��|jtdd�dtdd��|jdtd�tdd��|jdtd	d�d
�|jtd	d�dd
�|jtd�d�dS)
NrErTrIrUr]r^rGg@rg�?z1/2g�?)rNr�eval)rr
r
r
�
test_true_div%s/&#zRatTestCase.test_true_divN)r=r>r?rSrXrYr[r\r_rarbrdr
r
r
r
rD�s$rDc@s(eZdZdd�Zdd�ZdS)�OperationLoggercCs
||_dS)N)�logger)rrfr
r
r
r"2szOperationLogger.__init__cGs|j|�dS)N)rf)r�argsr
r
r
�
log_operation4szOperationLogger.log_operationN)r=r>r?r"rhr
r
r
r
re0srecGsZg}g}x$|D]}|j||j��qWy||�Wntk
rUYnX|S)N)�appendr)�op�classes�logZ	instances�cr
r
r
�op_sequence7s

rnc@s4eZdZdd�Zdd�Zdd�ZdS)�AcCs|jd�tS)NzA.__eq__)rhr-)rr.r
r
r
r<Fs
zA.__eq__cCs|jd�tS)NzA.__le__)rhr-)rr.r
r
r
�__le__Is
zA.__le__cCs|jd�tS)NzA.__ge__)rhr-)rr.r
r
r
�__ge__Ls
zA.__ge__N)r=r>r?r<rprqr
r
r
r
roEsroc@s4eZdZdd�Zdd�Zdd�ZdS)�BcCs|jd�tS)NzB.__eq__)rhr-)rr.r
r
r
r<Qs
zB.__eq__cCs|jd�tS)NzB.__le__)rhr-)rr.r
r
r
rpTs
zB.__le__cCs|jd�tS)NzB.__ge__)rhr-)rr.r
r
r
rqWs
zB.__ge__N)r=r>r?r<rprqr
r
r
r
rrPsrr�	metaclassc@s4eZdZdd�Zdd�Zdd�ZdS)�CcCs|jd�tS)NzC.__eq__)rhr-)rr.r
r
r
r<\s
zC.__eq__cCs|jd�tS)NzC.__le__)rhr-)rr.r
r
r
rp_s
zC.__le__cCs|jd�tS)NzC.__ge__)rhr-)rr.r
r
r
rqbs
zC.__ge__N)r=r>r?r<rprqr
r
r
r
rt[srtc@s4eZdZdd�Zdd�Zdd�ZdS)�VcCs|jd�tS)NzV.__eq__)rhr-)rr.r
r
r
r<hs
zV.__eq__cCs|jd�tS)NzV.__le__)rhr-)rr.r
r
r
rpks
zV.__le__cCs|jd�tS)NzV.__ge__)rhr-)rr.r
r
r
rqns
zV.__ge__N)r=r>r?r<rprqr
r
r
r
rufsruc@seZdZdd�ZdS)�OperationOrderTestscCs�|jtttt�ddg�|jtttt�ddg�|jtttt�ddg�|jtttt�ddg�|jtttt�ddg�|jtttt�ddg�|jtttt�ddg�|jtttt�ddg�|jtttt�ddg�|jtttt�d	dg�|jtt	t��|jtttt	�dd
g�|jtttt	�ddg�dS)NzA.__eq__zB.__eq__zC.__eq__zA.__le__zA.__ge__zB.__ge__zB.__le__zC.__ge__zC.__le__zV.__eq__zV.__ge__)
rNrnrrorrrtrrP�
issubclassru)rr
r
r
�test_comparison_ordersus"""""""""""z*OperationOrderTests.test_comparison_ordersN)r=r>r?rxr
r
r
r
rvtsrv�__main__)rWZtestr�operatorrrrrrr�abcr	rrrr�objectrZTestCaserDrernrorrrtru�registerrvr=�mainr
r
r
r
�<module>s&.�j