u]y SrSSKrSSKJrJrJr SSKJr SrSr Sr Sr "S S \ 5r "S S \R5r"S S5rSr"SS\5r"SS\\S9r"SS\5r"SS\5r\R-\5 "SS\R5r"SS\ 5r"SS\5r"SS \ 5r"S!S"\ 5r"S#S$\5r"S%S&5r"S'S(\R5r\S):Xa\R@"5 gg)*z9Tests for binary operators on subtypes of built-in types.N)eqlene)ABCMetac0U(aX-UpU(aMU$)z1Greatest common divisor using Euclid's algorithm.)abs 6/opt/alt/python313/lib64/python3.13/test/test_binop.pygcdr s sA1 ! Hc"[U[5$)z-Test whether an object is an instance of int.) isinstanceintxs r isintr  a r cX[[[4Hn[X5(dM g g)zATest whether an object is an instance of a built-in numeric type.r)rfloatcomplexr)rTs r isnumrs& %  a  ! r c"[U[5$)z7Test whether an object is an instance of the Rat class.)rRatrs r isRatrrr c\rSrSrSrSS/rSSjrSr\"\S5r Sr \"\ S5r S r S r S rS rS r\rSrSrSr\rSrSrSrSrSrSrSrSrSrSrg)rz9Rational number implemented as a normalized pair of ints. _Rat__num _Rat__denc[U5(d[SU-5e[U5(d[SU-5eUS:Xa [S5e[X!5n[ X-5Ul[ X#-5Ulg)zSConstructor: 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 rr r!)selfnumdengs r __init__ Rat.__init__"snSzzDE E !8#$67 7 M[ [ r cUR$)z7Accessor function for read-only 'num' attribute of Rat.)r r%s r _get_num Rat._get_num1 zzr NcUR$)z7Accessor function for read-only 'den' attribute of Rat.)r!r,s r _get_den Rat._get_den6r/r c8SURUR4-$)z"A cH[U5(a [U5n[U5(aT[URUR-URUR--URUR-5$[ U5(a[ U5U-$[$)z$Add two Rats, or a Rat and a number.rrrr r!rrNotImplementedr%others r __add__ Rat.__add__Qy <<JE <<tzz%++- DJJ0FFzz%++-/ / <<;& &r cH[U5(a [U5n[U5(aT[URUR-URUR-- URUR-5$[ U5(a[ U5U- $[$)z)Subtract two Rats, or a Rat and a number.rFrHs r __sub__ Rat.__sub__^rLr cH[U5(a [U5n[U5(aT[URUR-URUR-- URUR-5$[ U5(aU[ U5- $[$)z9Subtract two Rats, or a Rat and a number (reversed args).rFrHs r __rsub__ Rat.__rsub__isy <<JE <<u{{4::- 5;;0FFzz%++-/ / <<5;& &r cD[U5(a:[URUR-URUR-5$[ U5(a#[URU-UR5$[ U5(a[ U5U-$[$)z)Multiply two Rats, or a Rat and a number.rrr r!rrrrGrHs r __mul__ Rat.__mul__tss <<tzz%++-tzz%++/EF F <<tzz%'4 4 <<;u$ $r cD[U5(a:[URUR-URUR-5$[ U5(a#[URURU-5$[ U5(a[ U5U- $[$)z'Divide two Rats, or a Rat and a number.rTrHs r __truediv__Rat.__truediv__ss <<tzz%++-tzz%++/EF F <<tzz4::e#34 4 <<;& &r cB[U5(a:[URUR-URUR-5$[ U5(a"[XR-UR5$[ U5(aU[ U5- $[$)z7Divide two Rats, or a Rat and a number (reversed args).rTrHs r __rtruediv__Rat.__rtruediv__sq <<u{{4::-u{{4::/EF F <<uZZ'4 4 <<5;& &r c[U5(a [U5nO[U5(d[$X- nURUR -$)z.Divide two Rats, returning the floored result.)rrrrGr r!r%rIrs r __floordiv__Rat.__floordiv__s= <<JEu! ! Jww!''!!r c<X- nURUR-$)z>Divide two Rats, returning the floored result (reversed args).r4r^s r __rfloordiv__Rat.__rfloordiv__s Jww!''!!r c~[U5(a [U5nO[U5(d[$X-nX X-- 4$)z2Divide two Rats, returning quotient and remainder.)rrrrGr^s r __divmod__Rat.__divmod__s: <<JEu! ! K%)#$$r c|[U5(a [U5nO[U5(d[$[ X5$)zBDivide two Rats, returning quotient and remainder (reversed args).)rrrrGdivmodrHs r __rdivmod__Rat.__rdivmod__s. <<JEu! !e""r c[X5S$)zTake one Rat modulo another.rrhrHs r __mod__ Rat.__mod__sd"1%%r c[X5S$)z,Take one Rat modulo another (reversed args).rrlrHs r __rmod__ Rat.__rmod__se"1%%r cF[U5(a%URS:H=(a URU:H$[U5(a9URUR:H=(a URUR:H$[ U5(a[ U5U:H$[ $)zCompare two Rats for equality.r)rr!r rrrrGrHs r __eq__ Rat.__eq__ss <<::?:tzzU': : <<::,Ju{{1J J <<;%' 'r )__den__num)rr) __name__ __module__ __qualname____firstlineno____doc__ __slots__r)r-propertyr&r1r'r5r9r=rCrJ__radd__rNrQrU__rmul__rXr[r_rbrerirmrprs__static_attributes__rr r rrsCk*I ! 8T "C 8T "C8 )A H  H"" %#&&r rcN\rSrSrSrSrSrSrSrSr Sr S r S r S r S rg ) RatTestCasez3Unit tests for Rat class and its support utilities.cUR[SS5S5 UR[SS5S5 UR[SS5S5 UR[SS5S5 UR[S S5S 5 UR[SS 5S5 UR[S S 5S 5 [SS 5Hn[SS 5H}nUR[X5S :5 UR[U*U5S :5 UR[X*5S :5 UR[U*U*5S :5 M M g) N  rdr) assertEqualr range assertTrue)r%ijs r test_gcdRatTestCase.test_gcds Ra( Ra( Ra( S"q) S!b) Ra( S"r*q"A1b\A A .QB Q/Ar Q/QB a0 "r c [SS5nURURS5 URURS5 [SS5nURURS5 URURS5 [SS5nURURS5 URURS5 [SS5nURURS5 URURS5 [S5nURURS5 URURS 5 [S S 5nUR S 5 S S SS/0S[[ 4 HDn[U5nUR SU-5 [S U5nUR SU-5 MF g![ a Nhf=f![a NBf=f![a Mvf=f)Nrrrirrrrz(Rat(1, 0) didn't raise ZeroDivisionError0gyrzRat(%r) didn't raise TypeErrorz!Rat(1, %r) didn't raise TypeError)rrr&r'failr$unittestr#)r%r bads r test_constructorRatTestCase.test_constructors BK " " CL # " RL # " SM " " F " " BAq A II@ ARRT3@C BH :S@A E3K =CDA !        s6 G G) G. GG G+*G+. G<;G<cvUR[SS5[SS5-S5 UR[SS5S-[SS55 URS[SS5-[SS55 URS[SS5-S5 UR[SS5S-S5 g)Nrrrrr<?rrr,s r test_addRatTestCase.test_adds QSAY.2 QQAq 2 SAYAq 2 s1ay#. QS#.r cUR[SS5[SS5- [SS55 UR[SS5S- [SS55 URS[SS5- [SS55 UR[SS5S- S 5 URS[SS5- S 5 g) Nrrrrrrr<?rr,s r test_subRatTestCase.test_subs QSAY.B < QQAq 2 SAYAq 2 QS#. s1ay#.r cbUR[SS5[SS5-[SS55 UR[SS5S-S5 URS[SS5-S5 UR[SS5S-S5 URS[SS5-S5 g) Nrrrrrrrr<rr,s r test_mulRatTestCase.test_mul s QSAY.B < Ra, SQZ, Rc)3/ s2qz)3/r cUR[SS5[SS5- [SS55 UR[SS5S- [SS55 URS[S5- [SS55 URS[S S5-S 5 UR[S S5S-S 5 g) Nrrrr r@rrrr,s r test_divRatTestCase.test_divs Rc!Qi/R< RaR4 SVSAY/ s1ay#. QS#.r cUR[S5[S5-S5 UR[SS5[SS5-S5 UR[S5S-S5 URS[S5-S5 g)Nrrrrr,s r test_floordivRatTestCase.test_floordivsp RCF*A. Rs1ay0!4 RAq) s1vq)r c&UR[S5[SS55 UR[S5S5 URS[S55 UR[S5S5 URS[S55 g)Nrrrg$@rr,s r test_eqRatTestCase.test_eqsl R#b!*- R"% SW% R$' s2w'r cUR[SS5[SS5- [SS55 UR[SS5S- [SS55 URS[S5- [SS55 URS[S S5-S 5 UR[S S5S-S 5 UR[S 5S 5 g) Nrrrrrrrrrrz1/2r)rrevalr,s r test_true_divRatTestCase.test_true_div$s Rc!Qi/R< RaR4 SVSAY/ s1ay#. QS#. ec*r rN)rwrxryrzr{rrrrrrrrrrrr r rrs4= 1"EH//0/* (+r rc$\rSrSrSrSrSrSrg)OperationLoggeri/z.Base class for classes with operation logging.cXlgNlogger)r%rs r r)OperationLogger.__init__1s r c"UR"U6 grr)r%argss r log_operationOperationLogger.log_operation3s Tr rN)rwrxryrzr{r)rrrr r rr/s8r rc/n/nUH$nURU"UR55 M& U"U6 U$![a U$f=f)zrReturn the sequence of operations that results from applying the operation `op` to instances of the given classes.)appendr#)opclasseslog instancescs r op_sequencer6sZ CI 3::'  I J   J s7 AAc&\rSrSrSrSrSrSrg)AiDc0URS5 [$)NA.__eq__rrGrHs r rsA.__eq__E :&r c0URS5 [$)NA.__le__rrHs r __le__A.__le__Hrr c0URS5 [$)NA.__ge__rrHs r __ge__A.__ge__Krr rNrwrxryrzrsrrrrr r rrDr rc&\rSrSrSrSrSrSrg)BiOc0URS5 [$)NB.__eq__rrHs r rsB.__eq__Prr c0URS5 [$)NB.__le__rrHs r rB.__le__Srr c0URS5 [$)NB.__ge__rrHs r rB.__ge__Vrr rNrrr r rrOrr r) metaclassc&\rSrSrSrSrSrSrg)CiZc0URS5 [$)NC.__eq__rrHs r rsC.__eq__[rr c0URS5 [$)NC.__le__rrHs r rC.__le__^rr c0URS5 [$)NC.__ge__rrHs r rC.__ge__arr rNrrr r rrZrr rc*\rSrSrSrSrSrSrSrg)ViezVirtual subclass of Bc0URS5 [$)NV.__eq__rrHs r rsV.__eq__grr c0URS5 [$)NzV.__le__rrHs r rV.__le__jrr c0URS5 [$)NV.__ge__rrHs r rV.__ge__mrr rN) rwrxryrzr{rsrrrrr r rresr rc\rSrSrSrSrg)OperationOrderTestsiscRUR[[[[5SS/5 UR[[[[5SS/5 UR[[[[5SS/5 UR[[[[ 5SS/5 UR[[[ [5SS/5 UR[[ [[5SS/5 UR[[ [[5SS/5 UR[[ [[5SS/5 UR[[ [[ 5SS/5 UR[[ [ [5S S/5 UR[[[55 UR[[[[5SS /5 UR[[ [[5SS /5 g) Nrrrrrrrrrrr) rrrrrrrr issubclassrr,s r test_comparison_orders*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 rN)rwrxryrzrrrr r rrssJr rc\rSrSrSrSrSrg)SupEqizClass that can test equalitycgNTrrHs r rs SupEq.__eq__r rNrwrxryrzr{rsrrr r r r s &r r c\rSrSrSrSrSrg)Siz"Subclass of SupEq that should failNrrrr r rr , Fr rc\rSrSrSrSrg)Fiz'Independent class that should fall backrN)rwrxryrzr{rrr r rrs1r rc\rSrSrSrSrSrg)Xiz"Independent class that should failNrrrr r rrrr rc\rSrSrSrSrSrg)SNiz>Subclass of SupEq that can test equality, but not non-equalityNr)rwrxryrzr{__ne__rrr r rrs H Fr rc"\rSrSrSrSrSrSrg)XNiz>Independent class that can test equality, but not non-equalitycgr rrHs r rs XN.__eq__r r Nr)rwrxryrzr{rsrrrr r rrsH Fr rc$\rSrSrSrSrSrSrg)FallbackBlockingTestsiz#Unit tests for None method blockingc[5[5[5[54upp4UR X5 UR X5 UR X!5 UR X5 UR [ [XA5 UR [ [X5 UR [ [X15 gr)r rrrr assertRaisesr#r)r%efsrs r test_fallback_rmethod_blocking4FallbackBlockingTests.test_fallback_rmethod_blockingsWac13+ a     )R. )R. )R.r c,[5[5[5p2nURX:g5 UR [ [ X5 UR [ [ X!5 URX:g5 UR [ [ X15 gr)r rr assertFalser r#r)r%r!snxns r test_fallback_ne_blocking/FallbackBlockingTests.test_fallback_ne_blockingsiGRT24r   )R/ )R/ ! )R/r rN)rwrxryrzr{r$r*rrr r rrs- /0r r__main__)!r{roperatorrrrabcrr rrrobjectrTestCaserrrrrrrregisterrr rrrrrrrwmainrr r r3s?  g&gRe+(##e+T    7      1 J(++J&F 22 0H--0. z MMOr