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_binop.cpython-37.pyc
B

��g�8�@sjdZddlZddlmZmZmZddlmZdd�Zdd�Z	d	d
�Z
dd�ZGd
d�de�Z
Gdd�dej�ZGdd�d�Zdd�ZGdd�de�ZGdd�deed�ZGdd�de�ZGdd�de�Ze�e�Gdd�dej�ZGd d!�d!e�ZGd"d#�d#e�ZGd$d%�d%e�ZGd&d'�d'e�ZGd(d)�d)e�ZGd*d+�d+�ZGd,d-�d-ej�Zed.k�rfe� �dS)/z9Tests for binary operators on subtypes of built-in types.�N)�eq�le�ne)�ABCMetacCsx|r|||}}qW|S)z1Greatest common divisor using Euclid's algorithm.�)�a�brr�+/usr/local/lib/python3.7/test/test_binop.py�gcdsr
cCs
t|t�S)z-Test whether an object is an instance of int.)�
isinstance�int)�xrrr	�isint
srcCs&x tttfD]}t||�rdSqWdS)zATest whether an object is an instance of a built-in numeric type.�r)r�float�complexr)r
�Trrr	�isnums
rcCs
t|t�S)z7Test whether an object is an instance of the Rat class.)r�Rat)r
rrr	�isRatsrc@s�eZdZdZddgZd/dd�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)0rz9Rational number implemented as a normalized pair of ints.�	_Rat__num�	_Rat__denrrcCsbt|�std|��t|�s(td|��|dkr8td��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�ZeroDivisionErrorr
rrr)�self�num�den�grrr	�__init__"s
zRat.__init__cCs|jS)z7Accessor function for read-only 'num' attribute of Rat.)r)rrrr	�_get_num1szRat._get_numNcCs|jS)z7Accessor function for read-only 'den' attribute of Rat.)r)rrrr	�_get_den6szRat._get_dencCsd|j|jfS)z<Convert a Rat to a string resembling a Rat constructor call.zRat(%d, %d))rr)rrrr	�__repr__;szRat.__repr__cCstt|��S)z=Convert a Rat to a string resembling a decimal numeric value.)�strr)rrrr	�__str__?szRat.__str__cCs|jd|jS)zConvert a Rat to a float.g�?)rr)rrrr	�	__float__Csz
Rat.__float__cCsN|jdkr:y
t|j�Stk
r8tdt|���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)rrr�
OverflowError�repr�
ValueError)rrrr	�__int__Gs

zRat.__int__cCsVt|�rt|�}t|�r>t|j|j|j|j|j|j�St|�rRt|�|StS)z$Add two Rats, or a Rat and a number.)rrrrrrr�NotImplemented)r�otherrrr	�__add__QszRat.__add__cCsVt|�rt|�}t|�r>t|j|j|j|j|j|j�St|�rRt|�|StS)z)Subtract two Rats, or a Rat and a number.)rrrrrrrr))rr*rrr	�__sub__^szRat.__sub__cCsVt|�rt|�}t|�r>t|j|j|j|j|j|j�St|�rR|t|�StS)z9Subtract two Rats, or a Rat and a number (reversed args).)rrrrrrrr))rr*rrr	�__rsub__iszRat.__rsub__cCsTt|�r"t|j|j|j|j�St|�r<t|j||j�St|�rPt|�|StS)z)Multiply two Rats, or a Rat and a number.)rrrrrrrr))rr*rrr	�__mul__tszRat.__mul__cCsTt|�r"t|j|j|j|j�St|�r<t|j|j|�St|�rPt|�|StS)z'Divide two Rats, or a Rat and a number.)rrrrrrrr))rr*rrr	�__truediv__�szRat.__truediv__cCsTt|�r"t|j|j|j|j�St|�r<t||j|j�St|�rP|t|�StS)z7Divide two Rats, or a Rat and a number (reversed args).)rrrrrrrr))rr*rrr	�__rtruediv__�szRat.__rtruediv__cCs2t|�rt|�}nt|�stS||}|j|jS)z.Divide two Rats, returning the floored result.)rrrr)rr)rr*r
rrr	�__floordiv__�s
zRat.__floordiv__cCs||}|j|jS)z>Divide two Rats, returning the floored result (reversed args).)rr)rr*r
rrr	�
__rfloordiv__�szRat.__rfloordiv__cCs6t|�rt|�}nt|�stS||}||||fS)z2Divide two Rats, returning quotient and remainder.)rrrr))rr*r
rrr	�
__divmod__�s
zRat.__divmod__cCs(t|�rt|�}nt|�stSt||�S)zBDivide two Rats, returning quotient and remainder (reversed args).)rrrr)�divmod)rr*rrr	�__rdivmod__�s

zRat.__rdivmod__cCst||�dS)zTake one Rat modulo another.r)r4)rr*rrr	�__mod__�szRat.__mod__cCst||�dS)z,Take one Rat modulo another (reversed args).r)r4)rr*rrr	�__rmod__�szRat.__rmod__cCsTt|�r|jdko|j|kSt|�r<|j|jko:|j|jkSt|�rPt|�|kStS)zCompare two Rats for equality.r)rrrrrrr))rr*rrr	�__eq__�sz
Rat.__eq__)rr)�__name__�
__module__�__qualname__�__doc__�	__slots__rr�propertyrr rr!r#r$r(r+�__radd__r,r-r.�__rmul__r/r0r1r2r3r5r6r7r8rrrr	rs4






		rc@sXeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�ZdS)�RatTestCasez3Unit tests for Rat class and its support utilities.cCs|�tdd�d�|�tdd�d�|�tdd�d�|�tdd�d�|�td	d�d
�|�tdd
�d�|�td	d
�d
�x~tdd�D]p}xjtdd�D]\}|�t||�dk�|�t||�dk�|�t||�dk�|�t||�dk�q�Wq�WdS)
N�
�����r�di��������r)�assertEqualr
�range�
assertTrue)r�i�jrrr	�test_gcd�szRatTestCase.test_gcdc	Csvtdd�}|�|jd�|�|jd�tdd�}|�|jd�|�|jd�tdd�}|�|jd�|�|jd�tdd�}|�|jd�|�|jd�td�}|�|jd�|�|jd	�ytd	d
�}Wntk
r�YnX|�d�x�dd
ddgidttf	D]l}yt|�}Wntk
�r(YnX|�d|�ytd	|�}Wntk
�r\YnX|�d|��qWdS)NrBrErD�i�rIi�����rrz(Rat(1, 0) didn't raise ZeroDivisionError�0gyrzRat(%r) didn't raise TypeErrorz!Rat(1, %r) didn't raise TypeError)rrKrrrZfail�unittestr)rrZbadrrr	�test_constructor�s>




zRatTestCase.test_constructorcCs�|�tdd�tdd�d�|�tdd�dtdd��|�dtdd�tdd��|�dtdd�d�|�tdd�dd�dS)NrDrQrrFg�?g�?)rKr)rrrr	�test_add�s
zRatTestCase.test_addcCs�|�tdd�tdd�tdd��|�tdd�dtdd��|�dtdd�tdd��|�tdd�dd	�|�dtdd�d	�dS)
NrRrDrF�rBrrQg�?g�?)rKr)rrrr	�test_subs
"zRatTestCase.test_subcCs~|�tdd�tdd�tdd��|�tdd�dd�|�dtdd�d�|�tdd�dd�|�dtdd�d�dS)	NrDrQrFrRrBrWg�?g�?)rKr)rrrr	�test_mul	s
"zRatTestCase.test_mulcCs�|�tdd�tdd�tdd��|�tdd�dtdd��|�dtd�tdd��|�dtd	d�d
�|�td	d�dd
�dS)NrBrQrFrR��	rDg@rg�?)rKr)rrrr	�test_divs
"zRatTestCase.test_divcCs`|�td�td�d�|�tdd�tdd�d�|�td�dd�|�dtd�d�dS)NrB�rDrQ)rKr)rrrr	�
test_floordivszRatTestCase.test_floordivcCsZ|�td�tdd��|�td�d�|�dtd��|�td�d�|�dtd��dS)NrBrJrDg$@)rKr)rrrr	�test_eqs
zRatTestCase.test_eqcCs�|�tdd�tdd�tdd��|�tdd�dtdd��|�dtd�tdd��|�dtd	d�d
�|�td	d�dd
�|�td�d�dS)
NrBrQrFrRrZr[rDg@rg�?z1/2g�?)rKr�eval)rrrr	�
test_true_div$s"zRatTestCase.test_true_divN)
r9r:r;r<rPrUrVrXrYr\r^r_rarrrr	rA�s$rAc@s eZdZdZdd�Zdd�ZdS)�OperationLoggerz.Base class for classes with operation logging.cCs
||_dS)N)�logger)rrcrrr	r1szOperationLogger.__init__cGs|j|�dS)N)rc)r�argsrrr	�
log_operation3szOperationLogger.log_operationN)r9r:r;r<rrerrrr	rb/srbcGsLg}g}x|D]}|�||j��qWy||�Wntk
rFYnX|S)zvReturn the sequence of operations that results from applying
    the operation `op` to instances of the given classes.)�appendr)�op�classes�logZ	instances�crrr	�op_sequence6s
rkc@s$eZdZdd�Zdd�Zdd�ZdS)�AcCs|�d�tS)NzA.__eq__)rer))rr*rrr	r8Es
zA.__eq__cCs|�d�tS)NzA.__le__)rer))rr*rrr	�__le__Hs
zA.__le__cCs|�d�tS)NzA.__ge__)rer))rr*rrr	�__ge__Ks
zA.__ge__N)r9r:r;r8rmrnrrrr	rlDsrlc@s$eZdZdd�Zdd�Zdd�ZdS)�BcCs|�d�tS)NzB.__eq__)rer))rr*rrr	r8Ps
zB.__eq__cCs|�d�tS)NzB.__le__)rer))rr*rrr	rmSs
zB.__le__cCs|�d�tS)NzB.__ge__)rer))rr*rrr	rnVs
zB.__ge__N)r9r:r;r8rmrnrrrr	roOsro)�	metaclassc@s$eZdZdd�Zdd�Zdd�ZdS)�CcCs|�d�tS)NzC.__eq__)rer))rr*rrr	r8[s
zC.__eq__cCs|�d�tS)NzC.__le__)rer))rr*rrr	rm^s
zC.__le__cCs|�d�tS)NzC.__ge__)rer))rr*rrr	rnas
zC.__ge__N)r9r:r;r8rmrnrrrr	rqZsrqc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�VzVirtual subclass of BcCs|�d�tS)NzV.__eq__)rer))rr*rrr	r8gs
zV.__eq__cCs|�d�tS)NzV.__le__)rer))rr*rrr	rmjs
zV.__le__cCs|�d�tS)NzV.__ge__)rer))rr*rrr	rnms
zV.__ge__N)r9r:r;r<r8rmrnrrrr	rresrrc@seZdZdd�ZdS)�OperationOrderTestscCs4|�tttt�ddg�|�tttt�ddg�|�tttt�ddg�|�tttt�ddg�|�tttt�ddg�|�tttt�ddg�|�tttt�ddg�|�tttt�ddg�|�tttt�ddg�|�tttt�d	dg�|�tt	t��|�tttt	�dd
g�|�tttt	�ddg�dS)NzA.__eq__zB.__eq__zC.__eq__zA.__le__zA.__ge__zB.__ge__zB.__le__zC.__ge__zC.__le__zV.__eq__zV.__ge__)
rKrkrrlrorqrrM�
issubclassrr)rrrr	�test_comparison_orderstsz*OperationOrderTests.test_comparison_ordersN)r9r:r;rurrrr	rsssrsc@seZdZdZdd�ZdS)�SupEqzClass that can test equalitycCsdS)NTr)rr*rrr	r8�szSupEq.__eq__N)r9r:r;r<r8rrrr	rv�srvc@seZdZdZdZdS)�Sz"Subclass of SupEq that should failN)r9r:r;r<r8rrrr	rw�srwc@seZdZdZdS)�Fz'Independent class that should fall backN)r9r:r;r<rrrr	rx�srxc@seZdZdZdZdS)�Xz"Independent class that should failN)r9r:r;r<r8rrrr	ry�sryc@seZdZdZdZdS)�SNz>Subclass of SupEq that can test equality, but not non-equalityN)r9r:r;r<�__ne__rrrr	rz�srzc@seZdZdZdd�ZdZdS)�XNz>Independent class that can test equality, but not non-equalitycCsdS)NTr)rr*rrr	r8�sz	XN.__eq__N)r9r:r;r<r8r{rrrr	r|�sr|c@s eZdZdZdd�Zdd�ZdS)�FallbackBlockingTestsz#Unit tests for None method blockingcCs�t�t�t�t�f\}}}}|�||�|�||�|�||�|�||�|�tt||�|�tt||�|�tt||�dS)N)rvrxrwryrK�assertRaisesrr)r�e�f�sr
rrr	�test_fallback_rmethod_blocking�sz4FallbackBlockingTests.test_fallback_rmethod_blockingcCsft�t�t�}}}|�||k�|�tt||�|�tt||�|�||k�|�tt||�dS)N)rvrzr|ZassertFalser~rr)rrZsnZxnrrr	�test_fallback_ne_blocking�sz/FallbackBlockingTests.test_fallback_ne_blockingN)r9r:r;r<r�r�rrrr	r}�sr}�__main__)!r<rT�operatorrrr�abcrr
rrr�objectrZTestCaserArbrkrlrorqrr�registerrsrvrwrxryrzr|r}r9�mainrrrr	�<module>s6*j