Uname: Linux web3.us.cloudlogin.co 5.10.226-xeon-hst #2 SMP Fri Sep 13 12:28:44 UTC 2024 x86_64
Software: Apache
PHP version: 8.1.31 [ PHP INFO ] PHP os: Linux
Server Ip: 162.210.96.117
Your Ip: 18.118.216.112
User: edustar (269686) | Group: tty (888)
Safe Mode: OFF
Disable Function:
NONE

name : test_binop.cpython-310.pyc
o

`b�8�@sldZddlZddlmZmZmZddlmZdd�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.kr�e� �dSdS)/z9Tests for binary operators on subtypes of built-in types.�N)�eq�le�ne)�ABCMetacCs|r|||}}|s|S)z1Greatest common divisor using Euclid's algorithm.�)�a�brr�8/usr/local/python-3.10/lib/python3.10/test/test_binop.py�gcds�r
cC�
t|t�S)z-Test whether an object is an instance of int.)�
isinstance�int��xrrr	�isint
�
rcCs$tttfD]
}t||�rdSqdS)zATest whether an object is an instance of a built-in numeric type.�r)r
�float�complexr)r�Trrr	�isnums

�rcCr)z7Test whether an object is an instance of the Rat class.)r�Ratrrrr	�isRatrrc@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|�s
td|��t|�std|��|dkrtd��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__cC�|jS)z7Accessor function for read-only 'num' attribute of Rat.)r�rrrr	�_get_num1�zRat._get_numNcCr")z7Accessor function for read-only 'den' attribute of Rat.)rr#rrr	�_get_den6r%zRat._get_dencCsd|j|jfS)z<Convert a Rat to a string resembling a Rat constructor call.zRat(%d, %d)�rrr#rrr	�__repr__;�zRat.__repr__cCstt|��S)z=Convert a Rat to a string resembling a decimal numeric value.)�strrr#rrr	�__str__?szRat.__str__cCs|jd|jS)zConvert a Rat to a float.��?r'r#rrr	�	__float__Cr)z
Rat.__float__cCsF|jdkrzt|j�WStytdt|���wtdt|���)z,Convert a Rat to an int; self.den must be 1.rz%s too large to convert to intzcan't convert %s to int)rr
r�
OverflowError�repr�
ValueErrorr#rrr	�__int__Gs
��zRat.__int__cCsVt|�rt|�}t|�rt|j|j|j|j|j|j�St|�r)t|�|StS)z$Add two Rats, or a Rat and a number.�rrrrrrr�NotImplemented�r�otherrrr	�__add__Q�
�zRat.__add__cCsVt|�rt|�}t|�rt|j|j|j|j|j|j�St|�r)t|�|StS)z)Subtract two Rats, or a Rat and a number.r2r4rrr	�__sub__^r7zRat.__sub__cCsVt|�rt|�}t|�rt|j|j|j|j|j|j�St|�r)|t|�StS)z9Subtract two Rats, or a Rat and a number (reversed args).r2r4rrr	�__rsub__ir7zRat.__rsub__cCsTt|�rt|j|j|j|j�St|�rt|j||j�St|�r(t|�|StS)z)Multiply two Rats, or a Rat and a number.�rrrrrrrr3r4rrr	�__mul__t�zRat.__mul__cCsTt|�rt|j|j|j|j�St|�rt|j|j|�St|�r(t|�|StS)z'Divide two Rats, or a Rat and a number.r:r4rrr	�__truediv__�r<zRat.__truediv__cCsTt|�rt|j|j|j|j�St|�rt||j|j�St|�r(|t|�StS)z7Divide two Rats, or a Rat and a number (reversed args).r:r4rrr	�__rtruediv__�r<zRat.__rtruediv__cCs2t|�r	t|�}nt|�stS||}|j|jS)z.Divide two Rats, returning the floored result.)rrrr3rr�rr5rrrr	�__floordiv__�s
zRat.__floordiv__cCs||}|j|jS)z>Divide two Rats, returning the floored result (reversed args).r'r?rrr	�
__rfloordiv__�szRat.__rfloordiv__cCs6t|�r	t|�}nt|�stS||}||||fS)z2Divide two Rats, returning quotient and remainder.)rrrr3r?rrr	�
__divmod__�s
zRat.__divmod__cCs(t|�r	t|�}nt|�stSt||�S)zBDivide two Rats, returning quotient and remainder (reversed args).)rrrr3�divmodr4rrr	�__rdivmod__�s


zRat.__rdivmod__cCst||�dS)zTake one Rat modulo another.r�rCr4rrr	�__mod__��zRat.__mod__cCst||�dS)z,Take one Rat modulo another (reversed args).rrEr4rrr	�__rmod__�rGzRat.__rmod__cCsTt|�r|jdko
|j|kSt|�r|j|jko|j|jkSt|�r(t|�|kStS)zCompare two Rats for equality.r)rrrrrrr3r4rrr	�__eq__�sz
Rat.__eq__)rr)�__name__�
__module__�__qualname__�__doc__�	__slots__r!r$�propertyrr&rr(r+r-r1r6�__radd__r8r9r;�__rmul__r=r>r@rArBrDrFrHrIrrrr	rs6






		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
�tdd�D]6}tdd�D].}|�t||�dk�|�t||�dk�|�t||�dk�|�t||�dk�qKqDdS)
N�
�����r�d�������r)�assertEqualr
�range�
assertTrue)r�i�jrrr	�test_gcd�s��zRatTestCase.test_gcdc	Csftdd�}|�|jd�|�|jd�tdd�}|�|jd�|�|jd�tdd�}|�|jd�|�|jd�tdd�}|�|jd�|�|jd�td�}|�|jd�|�|jd	�ztd	d
�}Wn	tynYnw|�d�dd
ddgidttf	D]1}zt|�}Wn	ty�Ynw|�d|�ztd	|�}Wn	ty�Yqw|�d|�qdS)NrSrVrU�i�r[rZ�rrz(Rat(1, 0) didn't raise ZeroDivisionError�0gyrzRat(%r) didn't raise TypeErrorz!Rat(1, %r) didn't raise TypeError)rr]rrrZfail�unittestr)rrZbadrrr	�test_constructor�sF



�
���zRatTestCase.test_constructorcCs�|�tdd�tdd�d�|�tdd�dtdd��|�dtdd�tdd��|�dtdd�d�|�tdd�dd�dS)NrUrcrrWr,��?�r]rr#rrr	�test_add�s
zRatTestCase.test_addcCs�|�tdd�tdd�tdd��|�tdd�dtdd��|�dtdd�tdd��|�tdd�dd	�|�dtdd�d	�dS)
NrdrUrW�rSrrcr,��?rir#rrr	�test_subs
"zRatTestCase.test_subcCs~|�tdd�tdd�tdd��|�tdd�dd�|�dtdd�d�|�tdd�dd�|�dtdd�d�dS)	NrUrcrWrdrSrkrlr,rir#rrr	�test_mul	s
"zRatTestCase.test_mulcCs�|�tdd�tdd�tdd��|�tdd�dtdd��|�dtd�tdd��|�dtd	d�d
�|�td	d�dd
�dS)NrSrcrWrd��	rU�@rrhrir#rrr	�test_divs
"zRatTestCase.test_divcCs`|�td�td�d�|�tdd�tdd�d�|�td�dd�|�dtd�d�dS)NrS�rUrcrir#rrr	�
test_floordivszRatTestCase.test_floordivcCsZ|�td�tdd��|�td�d�|�dtd��|�td�d�|�dtd��dS)NrSr\rUg$@rir#rrr	�test_eqs
zRatTestCase.test_eqcCs�|�tdd�tdd�tdd��|�tdd�dtdd��|�dtd�tdd��|�dtd	d�d
�|�td	d�dd
�|�td�d�dS)
NrSrcrWrdrorprUrqrrhz1/2rl)r]r�evalr#rrr	�
test_true_div$s"zRatTestCase.test_true_divN)
rJrKrLrMrbrgrjrmrnrrrtrurwrrrr	rR�s$rRc@� eZdZdZdd�Zdd�ZdS)�OperationLoggerz.Base class for classes with operation logging.cCs
||_dS�N��logger)rr|rrr	r!1s
zOperationLogger.__init__cGs|j|�dSrzr{)r�argsrrr	�
log_operation3szOperationLogger.log_operationN)rJrKrLrMr!r~rrrr	ry/srycGsFg}g}|D]
}|�||j��qz||�W|Sty"Y|Sw)zvReturn the sequence of operations that results from applying
    the operation `op` to instances of the given classes.)�appendr)�opZclasses�logZ	instances�crrr	�op_sequence6s
��r�c@�$eZdZdd�Zdd�Zdd�ZdS)�AcC�|�d�tS)N�A.__eq__�r~r3r4rrr	rIE�
r�cCr�)N�A.__le__r�r4rrr	�__le__Hr�r�cCr�)N�A.__ge__r�r4rrr	�__ge__Kr�r�N�rJrKrLrIr�r�rrrr	r�D�r�c@r�)�BcCr�)N�B.__eq__r�r4rrr	rIPr�r�cCr�)N�B.__le__r�r4rrr	r�Sr�r�cCr�)N�B.__ge__r�r4rrr	r�Vr�r�Nr�rrrr	r�Or�r�)�	metaclassc@r�)�CcCr�)N�C.__eq__r�r4rrr	rI[r�r�cCr�)N�C.__le__r�r4rrr	r�^r�r�cCr�)N�C.__ge__r�r4rrr	r�ar�r�Nr�rrrr	r�Zr�r�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�VzVirtual subclass of BcCr�)N�V.__eq__r�r4rrr	rIgr�r�cCr�)N�V.__le__r�r4rrr	r�jr�r�cCr�)N�V.__ge__r�r4rrr	r�mr�r�N)rJrKrLrMrIr�r�rrrr	r�es
r�c@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)Nr�r�r�r�r�r�r�r�r�r�r�)
r]r�rr�r�r�rr_�
issubclassr�r#rrr	�test_comparison_orderstsz*OperationOrderTests.test_comparison_ordersN)rJrKrLr�rrrr	r�ssr�c@seZdZdZdd�ZdS)�SupEqzClass that can test equalitycC�dS�NTrr4rrr	rI��zSupEq.__eq__N�rJrKrLrMrIrrrr	r��sr�c@�eZdZdZdZdS)�Sz"Subclass of SupEq that should failNr�rrrr	r���r�c@seZdZdZdS)�Fz'Independent class that should fall backN)rJrKrLrMrrrr	r��sr�c@r�)�Xz"Independent class that should failNr�rrrr	r��r�r�c@r�)�SNz>Subclass of SupEq that can test equality, but not non-equalityN)rJrKrLrM�__ne__rrrr	r��r�r�c@seZdZdZdd�ZdZdS)�XNz>Independent class that can test equality, but not non-equalitycCr�r�rr4rrr	rI�r�z	XN.__eq__N)rJrKrLrMrIr�rrrr	r��sr�c@rx)�FallbackBlockingTestsz#Unit tests for None method blockingcCs�t�t�t�t�f\}}}}|�||�|�||�|�||�|�||�|�tt||�|�tt||�|�tt||�dSrz)r�r�r�r�r]�assertRaisesrr)r�e�f�srrrr	�test_fallback_rmethod_blocking�sz4FallbackBlockingTests.test_fallback_rmethod_blockingcCsft�t�t�}}}|�||k�|�tt||�|�tt||�|�||k�|�tt||�dSrz)r�r�r�ZassertFalser�rr)rr�ZsnZxnrrr	�test_fallback_ne_blocking�sz/FallbackBlockingTests.test_fallback_ne_blockingN)rJrKrLrMr�r�rrrr	r��sr��__main__)!rMrf�operatorrrr�abcrr
rrr�objectrZTestCaserRryr�r�r�r�r��registerr�r�r�r�r�r�r�r�rJ�mainrrrr	�<module>s:*j
�
© 2025 GrazzMean