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_binop.cpython-35.opt-1.pyc



��Yf3�@s|dZddlZddlmZddlmZmZmZmZm	Z	m
Z
ddlmZdd�Z
dd	�Zd
d�Zdd
�ZGdd�de�ZGdd�dej�ZGdd�d�Zdd�ZGdd�de�ZGdd�dede�ZGdd�de�ZGdd�de�Zeje�Gdd �d ej�Zed!krxej�dS)"z9Tests for binary operators on subtypes of built-in types.�N)�support)�eq�ne�lt�gt�le�ge)�ABCMetacCs"x|r|||}}qW|S)z1Greatest common divisor using Euclid's algorithm.�)�a�br
r
�4/opt/alt/python35/lib64/python3.5/test/test_binop.py�gcds	rcCs
t|t�S)z-Test whether an object is an instance of int.)�
isinstance�int)�xr
r
r
�isintsrcCs1x*tttfD]}t||�rdSqWdS)zATest whether an object is an instance of a built-in numeric type.�r)r�float�complexr)r�Tr
r
r
�isnumsrcCs
t|t�S)z6Test wheter an object is an instance of the Rat class.)r�Rat)rr
r
r
�isRatsrc@sBeZdZdZddgZdddd�Zdd	�Zeed
�Zdd�Z	ee	d
�Z
d
d�Zdd�Zdd�Z
dd�Zdd�ZeZdd�Zdd�Zdd�ZeZdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd
S)/rz9Rational number implemented as a normalized pair of ints.�	_Rat__num�	_Rat__denrrcCs�t|�std|��t|�s8td|��|dkrPtd��t||�}t||�|_t||�|_dS)z[Constructor: Rat([num[, den]]).

        The arguments must be ints, and default to (0, 1).zRat numerator must be int (%r)z Rat denominator must be int (%r)rzzero denominatorN)r�	TypeError�ZeroDivisionErrorrrrr)�self�num�den�gr
r
r
�__init__#szRat.__init__cCs|jS)z7Accessor function for read-only 'num' attribute of Rat.)r)rr
r
r
�_get_num2szRat._get_numNcCs|jS)z7Accessor function for read-only 'den' attribute of Rat.)r)rr
r
r
�_get_den7szRat._get_dencCsd|j|jfS)z<Convert a Rat to a string resembling a Rat constructor call.zRat(%d, %d))rr)rr
r
r
�__repr__<szRat.__repr__cCstt|��S)z=Convert a Rat to a string resembling a decimal numeric value.)�strr)rr
r
r
�__str__@szRat.__str__cCs|jd|jS)zConvert a Rat to a float.g�?)rr)rr
r
r
�	__float__Dsz
Rat.__float__cCse|jdkrKyt|j�SWn(tk
rJtdt|���YnXtdt|���dS)z,Convert a Rat to an int; self.den must be 1.rz%s too large to convert to intzcan't convert %s to intN)rrr�
OverflowError�repr�
ValueError)rr
r
r
�__int__Hs
zRat.__int__cCsqt|�rt|�}t|�rSt|j|j|j|j|j|j�St|�rmt|�|StS)z$Add two Rats, or a Rat and a number.)rrrrrrr�NotImplemented)r�otherr
r
r
�__add__RszRat.__add__cCsqt|�rt|�}t|�rSt|j|j|j|j|j|j�St|�rmt|�|StS)z)Subtract two Rats, or a Rat and a number.)rrrrrrrr-)rr.r
r
r
�__sub___szRat.__sub__cCsqt|�rt|�}t|�rSt|j|j|j|j|j|j�St|�rm|t|�StS)z9Subtract two Rats, or a Rat and a number (reversed args).)rrrrrrrr-)rr.r
r
r
�__rsub__jszRat.__rsub__cCsnt|�r-t|j|j|j|j�St|�rPt|j||j�St|�rjt|�|StS)z)Multiply two Rats, or a Rat and a number.)rrrrrrrr-)rr.r
r
r
�__mul__us!zRat.__mul__cCsnt|�r-t|j|j|j|j�St|�rPt|j|j|�St|�rjt|�|StS)z'Divide two Rats, or a Rat and a number.)rrrrrrrr-)rr.r
r
r
�__truediv__�s!zRat.__truediv__cCsnt|�r-t|j|j|j|j�St|�rPt||j|j�St|�rj|t|�StS)z7Divide two Rats, or a Rat and a number (reversed args).)rrrrrrrr-)rr.r
r
r
�__rtruediv__�s!zRat.__rtruediv__cCsCt|�rt|�}nt|�s+tS||}|j|jS)z.Divide two Rats, returning the floored result.)rrrr-rr)rr.rr
r
r
�__floordiv__�s
zRat.__floordiv__cCs||}|j|jS)z>Divide two Rats, returning the floored result (reversed args).)rr)rr.rr
r
r
�
__rfloordiv__�s
zRat.__rfloordiv__cCsGt|�rt|�}nt|�s+tS||}||||fS)z2Divide two Rats, returning quotient and remainder.)rrrr-)rr.rr
r
r
�
__divmod__�s
zRat.__divmod__cCs8t|�rt|�}nt|�s+tSt||�S)zBDivide two Rats, returning quotient and remainder (reversed args).)rrrr-�divmod)rr.r
r
r
�__rdivmod__�s
zRat.__rdivmod__cCst||�dS)zTake one Rat modulo another.r)r8)rr.r
r
r
�__mod__�szRat.__mod__cCst||�dS)z,Take one Rat modulo another (reversed args).r)r8)rr.r
r
r
�__rmod__�szRat.__rmod__cCsvt|�r(|jdko'|j|kSt|�rV|j|jkoU|j|jkSt|�rrt|�|kStS)zCompare two Rats for equality.r)rrrrrrr-)rr.r
r
r
�__eq__�s"z
Rat.__eq__)�__name__�
__module__�__qualname__�__doc__�	__slots__r"r#�propertyrr$r r%r'r(r,r/�__radd__r0r1r2�__rmul__r3r4r5r6r7r9r:r;r<r
r
r
r
rs4



		rc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�ZdS)�RatTestCasez3Unit tests for Rat class and its support utilities.cCs[|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�������rNi����rNrN)�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)NrFrIrH��rrz(Rat(1, 0) didn't raise ZeroDivisionError�0gyzRat(%r) didn't raise TypeErrorz!Rat(1, %r) didn't raise TypeErrori�rNi����rNi����i�)rrOrr rZfail�unittestr)rrZbadr
r
r
�test_constructor�s>

(

zRatTestCase.test_constructorcCs�|jtdd�tdd�d�|jtdd�dtdd��|jdtdd�tdd��|jdtdd�d�|jtdd�dd�dS)NrHrUrrJg�?g�?)rOr)rr
r
r
�test_add�s
&&&zRatTestCase.test_addcCs�|jtdd�tdd�tdd��|jtdd�dtdd��|jdtdd�tdd��|jtdd�dd	�|jdtdd�d	�dS)
NrVrHrJ�rFrrUg�?g�?)rOr)rr
r
r
�test_subs
/&&zRatTestCase.test_subcCs�|jtdd�tdd�tdd��|jtdd�dd�|jdtdd�d�|jtdd�dd�|jdtdd�d�dS)	NrHrUrJrVrFr[g�?g�?)rOr)rr
r
r
�test_mul
s
/zRatTestCase.test_mulcCs�|jtdd�tdd�tdd��|jtdd�dtdd��|jdtd�tdd��|jdtd	d�d
�|jtd	d�dd
�dS)NrFrUrJrV��	rHg@rg�?)rOr)rr
r
r
�test_divs
/&#zRatTestCase.test_divcCs~|jtd�td�d�|jtdd�tdd�d�|jtd�dd�|jdtd�d�dS)NrF�rHrU)rOr)rr
r
r
�
test_floordivs &zRatTestCase.test_floordivcCs{|jtd�tdd��|jtd�d�|jdtd��|jtd�d�|jdtd��dS)NrFrMrHg$@)rOr)rr
r
r
�test_eqs
zRatTestCase.test_eqcCs�|jtdd�tdd�tdd��|jtdd�dtdd��|jdtd�tdd��|jdtd	d�d
�|jtd	d�dd
�|jtd�d�dS)
NrFrUrJrVr^r_rHg@rg�?z1/2g�?)rOr�eval)rr
r
r
�
test_true_div%s/&#zRatTestCase.test_true_divN)
r=r>r?r@rTrYrZr\r]r`rbrcrer
r
r
r
rE�s$rEc@s.eZdZdZdd�Zdd�ZdS)�OperationLoggerz.Base class for classes with operation logging.cCs
||_dS)N)�logger)rrgr
r
r
r"2szOperationLogger.__init__cGs|j|�dS)N)rg)r�argsr
r
r
�
log_operation4szOperationLogger.log_operationN)r=r>r?r@r"rir
r
r
r
rf0srfcGsZg}g}x$|D]}|j||j��qWy||�Wntk
rUYnX|S)zvReturn the sequence of operations that results from applying
    the operation `op` to instances of the given classes.)�appendr)�op�classes�logZ	instances�cr
r
r
�op_sequence7s

roc@s4eZdZdd�Zdd�Zdd�ZdS)�AcCs|jd�tS)NzA.__eq__)rir-)rr.r
r
r
r<Fs
zA.__eq__cCs|jd�tS)NzA.__le__)rir-)rr.r
r
r
�__le__Is
zA.__le__cCs|jd�tS)NzA.__ge__)rir-)rr.r
r
r
�__ge__Ls
zA.__ge__N)r=r>r?r<rqrrr
r
r
r
rpEsrpc@s4eZdZdd�Zdd�Zdd�ZdS)�BcCs|jd�tS)NzB.__eq__)rir-)rr.r
r
r
r<Qs
zB.__eq__cCs|jd�tS)NzB.__le__)rir-)rr.r
r
r
rqTs
zB.__le__cCs|jd�tS)NzB.__ge__)rir-)rr.r
r
r
rrWs
zB.__ge__N)r=r>r?r<rqrrr
r
r
r
rsPsrs�	metaclassc@s4eZdZdd�Zdd�Zdd�ZdS)�CcCs|jd�tS)NzC.__eq__)rir-)rr.r
r
r
r<\s
zC.__eq__cCs|jd�tS)NzC.__le__)rir-)rr.r
r
r
rq_s
zC.__le__cCs|jd�tS)NzC.__ge__)rir-)rr.r
r
r
rrbs
zC.__ge__N)r=r>r?r<rqrrr
r
r
r
ru[sruc@s:eZdZdZdd�Zdd�Zdd�ZdS)	�VzVirtual subclass of BcCs|jd�tS)NzV.__eq__)rir-)rr.r
r
r
r<hs
zV.__eq__cCs|jd�tS)NzV.__le__)rir-)rr.r
r
r
rqks
zV.__le__cCs|jd�tS)NzV.__ge__)rir-)rr.r
r
r
rrns
zV.__ge__N)r=r>r?r@r<rqrrr
r
r
r
rvfsrvc@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__)
rOrorrprsrurrQ�
issubclassrv)rr
r
r
�test_comparison_ordersus"""""""""""z*OperationOrderTests.test_comparison_ordersN)r=r>r?ryr
r
r
r
rwtsrw�__main__)r@rXZtestr�operatorrrrrrr�abcr	rrrr�objectrZTestCaserErfrorprsrurv�registerrwr=�mainr
r
r
r
�<module>s(.�j