python (3.12.0)

(root)/
lib/
python3.12/
test/
__pycache__/
test_binop.cpython-312.pyc

͑e8$dZddlZddlmZmZmZddlmZdZdZ	dZ
dZGd	d
eZ
GddejZGd
dZdZGddeZGddeeZGddeZGddeZej-eGddejZGddeZGddeZGdd eZGd!d"eZGd#d$eZGd%d&ZGd'd(ejZed)k(rej@yy)*z9Tests for binary operators on subtypes of built-in types.N)eqlene)ABCMetac|r
||z|}}|r
|S)z1Greatest common divisor using Euclid's algorithm.)abs  C/BuggyBox/python/3.12.0/bootstrap/lib/python3.12/test/test_binop.pygcdrs
sA1Hc"t|tS)z-Test whether an object is an instance of int.)
isinstanceintxs risintr
ar
cLtttfD]}t||syy)zATest whether an object is an instance of a built-in numeric type.r)rfloatcomplexr)rTs  risnumrs*
%
 a
r
c"t|tS)z7Test whether an object is an instance of the Rat class.)rRatrs risRatrrr
ceZdZdZddgZddZdZeedZdZ	ee	dZ
dZd	Zd
Z
dZdZeZd
ZdZdZeZdZdZdZdZdZdZdZdZdZy)rz9Rational number implemented as a normalized pair of ints.	_Rat__num	_Rat__denct|std|zt|std|z|dk(rtdt||}t	||z|_t	||z|_y)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	TypeErrorZeroDivisionErrorrrrr )selfnumdengs    r__init__zRat.__init__"spSz<sBCCSz>DEE!8#$677SMa[
a[
r
c|jS)z7Accessor function for read-only 'num' attribute of Rat.)rr$s r_get_numzRat._get_num1zzr
Nc|jS)z7Accessor function for read-only 'den' attribute of Rat.)r r*s r_get_denzRat._get_den6r,r
c8d|j|jfzS)z<Convert a Rat to a string resembling a Rat constructor call.zRat(%d, %d)rr r*s r__repr__zRat.__repr__;s

DJJ777r
c*tt|S)z=Convert a Rat to a string resembling a decimal numeric value.)strrr*s r__str__zRat.__str__?s5;r
c:|jdz|jzS)zConvert a Rat to a float.?r0r*s r	__float__z
Rat.__float__Cszz#~djj((r
c|jdk(r	t|jStdt	|z#t$rtdt	|zwxYw)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)r rr
OverflowErrorrepr
ValueErrorr*s r__int__zRat.__int__Gsd::?
24::&2T$Z?@@!
2#$D&*4j%122
2s	=!Ac*t|rt|}t|rTt|j|jz|j|jzz|j|jzSt|rt
||zStS)z$Add two Rats, or a Rat and a number.rrrrr rrNotImplementedr$others  r__add__zRat.__add__Qs<JE<tzz%++-DJJ0FFzz%++-/
/<;&&r
c*t|rt|}t|rTt|j|jz|j|jzz
|j|jzSt|rt
||z
StS)z)Subtract two Rats, or a Rat and a number.r>r@s  r__sub__zRat.__sub__^rCr
c*t|rt|}t|rTt|j|jz|j|jzz
|j|jzSt|r|t
|z
StS)z9Subtract two Rats, or a Rat and a number (reversed args).r>r@s  r__rsub__zRat.__rsub__iss<JE<u{{4::-

5;;0FFzz%++-/
/<5;&&r
c&t|r:t|j|jz|j|jzSt	|r#t|j|z|jSt|rt
||zStS)z)Multiply two Rats, or a Rat and a number.rrrr rrrr?r@s  r__mul__zRat.__mul__tsm<tzz%++-tzz%++/EFF<tzz%'44<;u$$r
c&t|r:t|j|jz|j|jzSt	|r#t|j|j|zSt|rt
||zStS)z'Divide two Rats, or a Rat and a number.rIr@s  r__truediv__zRat.__truediv__sm<tzz%++-tzz%++/EFF<tzz4::e#344<;&&r
c&t|r:t|j|jz|j|jzSt	|r#t||jz|jSt|r|t
|zStS)z7Divide two Rats, or a Rat and a number (reversed args).rIr@s  r__rtruediv__zRat.__rtruediv__sm<u{{4::-u{{4::/EFF<uTZZ'44<5;&&r
ct|rt|}nt|stS||z}|j|j
zS)z.Divide two Rats, returning the floored result.)rrrr?rr r$rArs   r__floordiv__zRat.__floordiv__s;<JEu!!Jww!''!!r
c>||z}|j|jzS)z>Divide two Rats, returning the floored result (reversed args).r0rPs   r
__rfloordiv__zRat.__rfloordiv__s$Jww!''!!r
cpt|rt|}nt|stS||z}||||zz
fS)z2Divide two Rats, returning quotient and remainder.)rrrr?rPs   r
__divmod__zRat.__divmod__s<<JEu!!%K4%!)#$$r
cjt|rt|}nt|stSt	||S)zBDivide two Rats, returning quotient and remainder (reversed args).)rrrr?divmodr@s  r__rdivmod__zRat.__rdivmod__s,<JEu!!eT""r
c t||dS)zTake one Rat modulo another.rrWr@s  r__mod__zRat.__mod__sdE"1%%r
c t||dS)z,Take one Rat modulo another (reversed args).rrZr@s  r__rmod__zRat.__rmod__seT"1%%r
ct|r |jdk(xr|j|k(St|r4|j|jk(xr|j|jk(St	|rt||k(StS)zCompare two Rats for equality.r)rr rrrrr?r@s  r__eq__z
Rat.__eq__sm<::?:tzzU'::<::,Ju{{1JJ<;%''r
)rr)__name__
__module____qualname____doc__	__slots__r(r+propertyr%r.r&r1r4r7r<rB__radd__rErGrJ__rmul__rLrNrQrSrUrXr[r]r_rr
rrrsCk*I
!8T
"C8T
"C8 )A	H		H""
%#&&r
rcFeZdZdZdZdZdZdZdZdZ	dZ
d	Zd
Zy)RatTestCasez3Unit tests for Rat class and its support utilities.c|jtddd|jtddd|jtddd|jtddd|jtd	dd
|jtdd
d|jtd	d
d
tddD]}tddD]~}|jt||dkD|jt||dk|jt||dkD|jt||dky)
N
rdr)assertEqualrrange
assertTrue)r$ijs   rtest_gcdzRatTestCase.test_gcds&Ra(Ra(Ra(S"q)S!b)Ra(S"r*q"	1A1b\
1Aq	A
.QB
Q/Ar
Q/QBa0	
1	1r
c	tdd}|j|jd|j|jdtdd}|j|jd|j|jdtdd}|j|jd|j|jdtdd}|j|jd|j|jdtd}|j|jd|j|jd		td	d
}|j	ddd
ddgidttf	D]C}	t|}|j	d|z	td	|}|j	d|zEy#t
$rYewxYw#t$rY>wxYw#t$rYpwxYw)Nrkrnrmirsrrrrz(Rat(1, 0) didn't raise ZeroDivisionError0gyrzRat(%r) didn't raise TypeErrorz!Rat(1, %r) didn't raise TypeError)rrur%r&failr#unittestr")r$r	bads   rtest_constructorzRatTestCase.test_constructorsBK""CL#"RL#"SM""F""	BAq	A
II@ARRT3@	EC
BH		:S@A
E3K		=CD	E	!		



s6G	G)G*	GG	G'&G'*	G65G6cv|jtddtddzd|jtdddztdd|jdtddztdd|jdtddzd|jtdddzdy)Nrmr|rror6?rurr*s rtest_addzRatTestCase.test_addsQSAY.2QQAq	2SAYAq	2s1ay#.QS#.r
c|jtddtddz
tdd|jtdddz
tdd|jdtddz
tdd|jtdddz
d	|jdtddz
d	y)
Nr}rmrorkrr|r6?rr*s rtest_subzRatTestCase.test_subsQSAY.B<QQAq	2SAYAq	2QS#.s1ay#.r
cb|jtddtddztdd|jtdddzd|jdtddzd|jtdddzd|jdtddzdy)	Nrmr|ror}rkrrr6rr*s rtest_mulzRatTestCase.test_mul	sQSAY.B<Ra,SQZ,Rc)3/s2qz)3/r
c|jtddtddztdd|jtdddztdd|jdtdztdd|jdtd	dzd
|jtd	ddzd
y)Nrkr|ror}	rm@rrrr*s rtest_divzRatTestCase.test_divsRc!Qi/R<RaR4SVSAY/s1ay#.QS#.r
c|jtdtdzd|jtddtddzd|jtddzd|jdtdzdy)Nrkrmr|rr*s r
test_floordivzRatTestCase.test_floordivspRCF*A.Rs1ay0!4RAq)s1vq)r
c&|jtdtdd|jtdd|jdtd|jtdd|jdtdy)Nrkrtrmg$@rr*s rtest_eqzRatTestCase.test_eqslR#b!*-R"%SW%R$'s2w'r
c|jtddtddztdd|jtdddztdd|jdtdztdd|jdtd	dzd
|jtd	ddzd
|jtddy)
Nrkr|ror}rrrmrrrz1/2r)rurevalr*s r
test_true_divzRatTestCase.test_true_div$sRc!Qi/R<RaR4SVSAY/s1ay#.QS#.ec*r
N)
r`rarbrcrzrrrrrrrrrr
rriris4=
1"EH//0/*(+r
riceZdZdZdZdZy)OperationLoggerz.Base class for classes with operation logging.c||_yNlogger)r$rs  rr(zOperationLogger.__init__1s	r
c"|j|yrr)r$argss  r
log_operationzOperationLogger.log_operation3sTr
N)r`rarbrcr(rrr
rrr/s8r
rcg}g}|D]#}|j||j%	|||S#t$rY|SwxYw)zvReturn the sequence of operations that results from applying
    the operation `op` to instances of the given classes.)appendr")opclasseslog	instancescs     rop_sequencer6s_
CI
(3::'(

IJ
J
s5	AAceZdZdZdZdZy)Ac0|jdtS)NA.__eq__rr?r@s  rr_zA.__eq__E:&r
c0|jdtS)NA.__le__rr@s  r__le__zA.__le__Hrr
c0|jdtS)NA.__ge__rr@s  r__ge__zA.__ge__Krr
Nr`rarbr_rrrr
rrrDr
rceZdZdZdZdZy)Bc0|jdtS)NB.__eq__rr@s  rr_zB.__eq__Prr
c0|jdtS)NB.__le__rr@s  rrzB.__le__Srr
c0|jdtS)NB.__ge__rr@s  rrzB.__ge__Vrr
Nrrr
rrrOrr
r)	metaclassceZdZdZdZdZy)Cc0|jdtS)NC.__eq__rr@s  rr_zC.__eq__[rr
c0|jdtS)NC.__le__rr@s  rrzC.__le__^rr
c0|jdtS)NC.__ge__rr@s  rrzC.__ge__arr
Nrrr
rrrZrr
rc"eZdZdZdZdZdZy)VzVirtual subclass of Bc0|jdtS)NV.__eq__rr@s  rr_zV.__eq__grr
c0|jdtS)NzV.__le__rr@s  rrzV.__le__jrr
c0|jdtS)NV.__ge__rr@s  rrzV.__ge__mrr
N)r`rarbrcr_rrrr
rrresr
rceZdZdZy)OperationOrderTestscR|jttttddg|jttttddg|jttttddg|jtttt
ddg|jttt
tddg|jttttddg|jttttddg|jttttddg|jtttt
ddg|jttt
td	dg|jttt|jttttdd
g|jttttddgy)Nrrrrrrrrrrr)
rurrrrrrrw
issubclassrr*s rtest_comparison_ordersz*OperationOrderTests.test_comparison_ordersts}RA.Z0HIRA.Z0HIRA.Z0HIRA.Z0HIRA.Z0HIRA.Z0HIRA.Z0HIRA.Z0HIRA.Z0HIRA.Z0HI
1a()RA.Z0HIRA.Z0HIr
N)r`rarbrrr
rrrssJr
rceZdZdZdZy)SupEqzClass that can test equalitycyNTrr@s  rr_zSupEq.__eq__r
Nr`rarbrcr_rr
rrrs
&r
rceZdZdZdZy)Sz"Subclass of SupEq that should failNrrr
rrr
,
Fr
rceZdZdZy)Fz'Independent class that should fall backN)r`rarbrcrr
rrrs1r
rceZdZdZdZy)Xz"Independent class that should failNrrr
rrrrr
rceZdZdZdZy)SNz>Subclass of SupEq that can test equality, but not non-equalityN)r`rarbrc__ne__rr
rrrs
H
Fr
rceZdZdZdZdZy)XNz>Independent class that can test equality, but not non-equalitycyrrr@s  rr_z	XN.__eq__rr
N)r`rarbrcr_rrr
rrrsH
Fr
rceZdZdZdZdZy)FallbackBlockingTestsz#Unit tests for None method blockingcttttf\}}}}|j	|||j	|||j	|||j	|||jtt|||jtt|||jtt||yr)rrrrruassertRaisesr"r)r$efsrs     rtest_fallback_rmethod_blockingz4FallbackBlockingTests.test_fallback_rmethod_blockingsWac13+
1aAAAA)RA.)RA.)RA.r
c8ttt}}}|j||k7|j	t
t|||j	t
t|||j||k7|j	t
t||yr)rrrassertFalserr"r)r$rsnxns    rtest_fallback_ne_blockingz/FallbackBlockingTests.test_fallback_ne_blockingsuGRT24r2a )RB/)RQ/b!)RQ/r
N)r`rarbrcrrrr
rrrs-
/0r
r__main__)!rcroperatorrrrabcrrrrrobjectrTestCaserirrrrrrregisterrrrrrrrrr`mainrr
r<module>rs ?

g&gRe+(##e+T			7			



1
J(++J&F
220H--0.zHMMOr