
    daf8                     $   d Z ddlZddlmZmZmZ ddlmZ d Zd Z	d Z
d Z G d	 d
e      Z G d dej                        Z G d d      Zd Z G d de      Z G d dee      Z G d de      Z G d de      Zej-                  e        G d dej                        Z G d de      Z G d de      Z G d d e      Z G d! d"e      Z G d# d$e      Z G d% d&      Z G d' d(ej                        Zed)k(  r ej@                          yy)*z9Tests for binary operators on subtypes of built-in types.    N)eqlene)ABCMetac                     | r
|| z  | }} | r
|S )z1Greatest common divisor using Euclid's algorithm. )abs     */root/Python-3.12.4/Lib/test/test_binop.pygcdr      s    
sA1 H    c                 "    t        | t              S )z-Test whether an object is an instance of int.)
isinstanceintxs    r   isintr          ar   c                 L    t         t        t        fD ]  }t        | |      s y y)zATest whether an object is an instance of a built-in numeric type.   r   )r   floatcomplexr   )r   Ts     r   isnumr      s*    %  a r   c                 "    t        | t              S )z7Test whether an object is an instance of the Rat class.)r   Ratr   s    r   isRatr      r   r   c                       e Zd ZdZddgZddZd Z eed      Zd Z	 ee	d      Z
d Zd	 Zd
 Zd Zd ZeZd Zd Zd ZeZd Zd Zd Zd Zd Zd Zd Zd Zd Zy)r   z9Rational number implemented as a normalized pair of ints.	_Rat__num	_Rat__denc                     t        |      st        d|z        t        |      st        d|z        |dk(  rt        d      t        ||      }t	        ||z        | _        t	        ||z        | _        y)z[Constructor: Rat([num[, den]]).

        The arguments must be ints, and default to (0, 1).zRat numerator must be int (%r)z Rat denominator must be int (%r)r   zzero denominatorN)r   	TypeErrorZeroDivisionErrorr   r   r   r    )selfnumdengs       r   __init__zRat.__init__"   sp     Sz<sBCCSz>DEE!8#$677SMa[
a[
r   c                     | j                   S )z7Accessor function for read-only 'num' attribute of Rat.)r   r$   s    r   _get_numzRat._get_num1       zzr   Nc                     | j                   S )z7Accessor function for read-only 'den' attribute of Rat.)r    r*   s    r   _get_denzRat._get_den6   r,   r   c                 8    d| j                   | j                  fz  S )z<Convert a Rat to a string resembling a Rat constructor call.zRat(%d, %d)r   r    r*   s    r   __repr__zRat.__repr__;   s    

DJJ777r   c                 *    t        t        |             S )z=Convert a Rat to a string resembling a decimal numeric value.)strr   r*   s    r   __str__zRat.__str__?   s    5;r   c                 :    | j                   dz  | j                  z  S )zConvert a Rat to a float.      ?r0   r*   s    r   	__float__zRat.__float__C   s    zz#~djj((r   c                     | j                   dk(  r	 t        | j                        S t        dt	        |       z        # t        $ r t        dt	        |       z        w xY w)z,Convert a Rat to an int; self.den must be 1.r   z%s too large to convert to intzcan't convert %s to int)r    r   r   OverflowErrorrepr
ValueErrorr*   s    r   __int__zRat.__int__G   sd    ::?24::& 2T$Z?@@ ! 2#$D&*4j%1 2 22s	   = !Ac                 *   t        |      rt        |      }t        |      rTt        | j                  |j                  z  |j                  | j                  z  z   | j                  |j                  z        S t        |      rt        |       |z   S t        S )z$Add two Rats, or a Rat and a number.r   r   r   r   r    r   r   NotImplementedr$   others     r   __add__zRat.__add__Q   s    <JE<tzz%++-DJJ0FFzz%++-/ /<;&&r   c                 *   t        |      rt        |      }t        |      rTt        | j                  |j                  z  |j                  | j                  z  z
  | j                  |j                  z        S t        |      rt        |       |z
  S t        S )z)Subtract two Rats, or a Rat and a number.r>   r@   s     r   __sub__zRat.__sub__^   rC   r   c                 *   t        |      rt        |      }t        |      rTt        |j                  | j                  z  | j                  |j                  z  z
  | j                  |j                  z        S t        |      r|t        |       z
  S t        S )z9Subtract two Rats, or a Rat and a number (reversed args).r>   r@   s     r   __rsub__zRat.__rsub__i   ss    <JE<u{{4::-

5;;0FFzz%++-/ /<5;&&r   c                 &   t        |      r:t        | j                  |j                  z  | j                  |j                  z        S t	        |      r#t        | j                  |z  | j                        S t        |      rt        |       |z  S t        S )z)Multiply two Rats, or a Rat and a number.r   r   r   r    r   r   r   r?   r@   s     r   __mul__zRat.__mul__t   sm    <tzz%++-tzz%++/EFF<tzz%'44<;u$$r   c                 &   t        |      r:t        | j                  |j                  z  | j                  |j                  z        S t	        |      r#t        | j                  | j                  |z        S t        |      rt        |       |z  S t        S )z'Divide two Rats, or a Rat and a number.rI   r@   s     r   __truediv__zRat.__truediv__   sm    <tzz%++-tzz%++/EFF<tzz4::e#344<;&&r   c                 &   t        |      r:t        |j                  | j                  z  |j                  | j                  z        S t	        |      r#t        || j                  z  | j                        S t        |      r|t        |       z  S t        S )z7Divide two Rats, or a Rat and a number (reversed args).rI   r@   s     r   __rtruediv__zRat.__rtruediv__   sm    <u{{4::-u{{4::/EFF<uTZZ'44<5;&&r   c                     t        |      rt        |      }nt        |      st        S | |z  }|j                  |j
                  z  S )z.Divide two Rats, returning the floored result.)r   r   r   r?   r   r    r$   rA   r   s      r   __floordiv__zRat.__floordiv__   s;    <JEu!!Jww!''!!r   c                 >    || z  }|j                   |j                  z  S )z>Divide two Rats, returning the floored result (reversed args).r0   rP   s      r   __rfloordiv__zRat.__rfloordiv__   s    $Jww!''!!r   c                 p    t        |      rt        |      }nt        |      st        S | |z  }|| ||z  z
  fS )z2Divide two Rats, returning quotient and remainder.)r   r   r   r?   rP   s      r   
__divmod__zRat.__divmod__   s<    <JEu!!%K4%!)#$$r   c                 j    t        |      rt        |      }nt        |      st        S t	        ||       S )zBDivide two Rats, returning quotient and remainder (reversed args).)r   r   r   r?   divmodr@   s     r   __rdivmod__zRat.__rdivmod__   s,    <JEu!!eT""r   c                      t        | |      d   S )zTake one Rat modulo another.r   rW   r@   s     r   __mod__zRat.__mod__   s    dE"1%%r   c                      t        ||       d   S )z,Take one Rat modulo another (reversed args).r   rZ   r@   s     r   __rmod__zRat.__rmod__   s    eT"1%%r   c                    t        |      r | j                  dk(  xr | j                  |k(  S t        |      r4| j                  |j                  k(  xr | j                  |j                  k(  S t	        |      rt        |       |k(  S t        S )zCompare two Rats for equality.r   )r   r    r   r   r   r   r?   r@   s     r   __eq__z
Rat.__eq__   sm    <::?:tzzU'::<::,Ju{{1JJ<;%''r   )r   r   )__name__
__module____qualname____doc__	__slots__r(   r+   propertyr%   r.   r&   r1   r4   r7   r<   rB   __radd__rE   rG   rJ   __rmul__rL   rN   rQ   rS   rU   rX   r[   r]   r_   r   r   r   r   r      s    Ck*I! 8T
"C 8T
"C8 )A	 H		 H""
%#&&r   r   c                   F    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)RatTestCasez3Unit tests for Rat class and its support utilities.c                    | j                  t        dd      d       | j                  t        dd      d       | j                  t        dd      d       | j                  t        dd      d       | j                  t        d	d      d
       | j                  t        dd
      d       | j                  t        d	d
      d
       t        dd      D ]  }t        dd      D ]~  }| j                  t        ||      dkD         | j                  t        | |      dk         | j                  t        ||       dkD         | j                  t        | |       dk           y )N
                  r   d      r   )assertEqualr   range
assertTrue)r$   ijs      r   test_gcdzRatTestCase.test_gcd   s&   Ra(Ra(Ra(S"q)S!b)Ra(S"r*q" 	1A1b\ 1Aq	A.QB
Q/Ar
Q/QBa0	1	1r   c           	         t        dd      }| j                  |j                  d       | j                  |j                  d       t        dd      }| j                  |j                  d       | j                  |j                  d       t        dd      }| j                  |j                  d       | j                  |j                  d       t        dd      }| j                  |j                  d       | j                  |j                  d       t        d      }| j                  |j                  d       | j                  |j                  d	       	 t        d	d
      }| j	                  d       ddddg i d t         t        f	D ]C  }	 t        |      }| j	                  d|z         	 t        d	|      }| j	                  d|z         E y # t
        $ r Y ew xY w# t        $ r Y >w xY w# t        $ r Y pw xY w)Nrk   rn   rm      irs   rr      r   r   z(Rat(1, 0) didn't raise ZeroDivisionError0g        y                r   zRat(%r) didn't raise TypeErrorz!Rat(1, %r) didn't raise TypeError)r   ru   r%   r&   failr#   unittestr"   )r$   r	   bads      r   test_constructorzRatTestCase.test_constructor   s   BK""CL#"RL#"SM""F""	BAq	A II@ARRT3@ 	ECBH 		:S@AE3K 		=CD	E	 ! 		    s6   G 	G)G*	GG	G'&G'*	G65G6c                 v   | j                  t        dd      t        dd      z   d       | j                  t        dd      dz   t        dd             | j                  dt        dd      z   t        dd             | j                  dt        dd      z   d       | j                  t        dd      dz   d       y )Nrm   r|   r   ro   r6         ?ru   r   r*   s    r   test_addzRatTestCase.test_add   s    QSAY.2QQAq	2SAYAq	2s1ay#.QS#.r   c                    | j                  t        dd      t        dd      z
  t        dd             | j                  t        dd      dz
  t        dd             | j                  dt        dd      z
  t        dd             | j                  t        dd      dz
  d	       | j                  dt        dd      z
  d	       y )
Nr}   rm   ro      rk   r   r|   r6         ?r   r*   s    r   test_subzRatTestCase.test_sub  s    QSAY.B<QQAq	2SAYAq	2QS#.s1ay#.r   c                 b   | j                  t        dd      t        dd      z  t        dd             | j                  t        dd      dz  d       | j                  dt        dd      z  d       | j                  t        dd      dz  d       | j                  dt        dd      z  d       y )	Nrm   r|   ro   r}   rk   r   r   r6   r   r*   s    r   test_mulzRatTestCase.test_mul	  s    QSAY.B<Ra,SQZ,Rc)3/s2qz)3/r   c                    | j                  t        dd      t        dd      z  t        dd             | j                  t        dd      dz  t        dd             | j                  dt        d      z  t        dd             | j                  dt        d	d      z  d
       | j                  t        d	d      dz  d
       y )Nrk   r|   ro   r}      	   rm         @r   r   r   r*   s    r   test_divzRatTestCase.test_div  s    Rc!Qi/R<RaR4SVSAY/s1ay#.QS#.r   c                    | j                  t        d      t        d      z  d       | j                  t        dd      t        dd      z  d       | j                  t        d      dz  d       | j                  dt        d      z  d       y )Nrk      rm   r|   r   r*   s    r   test_floordivzRatTestCase.test_floordiv  sp    RCF*A.Rs1ay0!4RAq)s1vq)r   c                 &   | j                  t        d      t        dd             | j                  t        d      d       | j                  dt        d             | j                  t        d      d       | j                  dt        d             y )Nrk   rt   rm   g      $@r   r*   s    r   test_eqzRatTestCase.test_eq  sl    R#b!*-R"%SW%R$'s2w'r   c                    | j                  t        dd      t        dd      z  t        dd             | j                  t        dd      dz  t        dd             | j                  dt        d      z  t        dd             | j                  dt        d	d      z  d
       | j                  t        d	d      dz  d
       | j                  t        d      d       y )Nrk   r|   ro   r}   r   r   rm   r   r   r   z1/2r   )ru   r   evalr*   s    r   test_true_divzRatTestCase.test_true_div$  s    Rc!Qi/R<RaR4SVSAY/s1ay#.QS#.ec*r   N)r`   ra   rb   rc   rz   r   r   r   r   r   r   r   r   r   r   r   ri   ri      s4    =1"EH//0/*(+r   ri   c                       e Zd ZdZd Zd Zy)OperationLoggerz.Base class for classes with operation logging.c                     || _         y Nlogger)r$   r   s     r   r(   zOperationLogger.__init__1  s	    r   c                 "     | j                   |  y r   r   )r$   argss     r   log_operationzOperationLogger.log_operation3  s    Tr   N)r`   ra   rb   rc   r(   r   r   r   r   r   r   /  s    8r   r   c                     g }g }|D ]#  }|j                   ||j                                % 	  | |  |S # t        $ r Y |S w xY w)zvReturn the sequence of operations that results from applying
    the operation `op` to instances of the given classes.)appendr"   )opclasseslog	instancescs        r   op_sequencer   6  s_     CI (3::'(
I J  Js   5 	AAc                       e Zd Zd Zd Zd Zy)Ac                 0    | j                  d       t        S )NA.__eq__r   r?   r@   s     r   r_   zA.__eq__E      :&r   c                 0    | j                  d       t        S )NA.__le__r   r@   s     r   __le__zA.__le__H  r   r   c                 0    | j                  d       t        S )NA.__ge__r   r@   s     r   __ge__zA.__ge__K  r   r   Nr`   ra   rb   r_   r   r   r   r   r   r   r   D      r   r   c                       e Zd Zd Zd Zd Zy)Bc                 0    | j                  d       t        S )NB.__eq__r   r@   s     r   r_   zB.__eq__P  r   r   c                 0    | j                  d       t        S )NB.__le__r   r@   s     r   r   zB.__le__S  r   r   c                 0    | j                  d       t        S )NB.__ge__r   r@   s     r   r   zB.__ge__V  r   r   Nr   r   r   r   r   r   O  r   r   r   )	metaclassc                       e Zd Zd Zd Zd Zy)Cc                 0    | j                  d       t        S )NC.__eq__r   r@   s     r   r_   zC.__eq__[  r   r   c                 0    | j                  d       t        S )NC.__le__r   r@   s     r   r   zC.__le__^  r   r   c                 0    | j                  d       t        S )NC.__ge__r   r@   s     r   r   zC.__ge__a  r   r   Nr   r   r   r   r   r   Z  r   r   r   c                   "    e Zd ZdZd Zd Zd Zy)VzVirtual subclass of Bc                 0    | j                  d       t        S )NV.__eq__r   r@   s     r   r_   zV.__eq__g  r   r   c                 0    | j                  d       t        S )NzV.__le__r   r@   s     r   r   zV.__le__j  r   r   c                 0    | j                  d       t        S )NV.__ge__r   r@   s     r   r   zV.__ge__m  r   r   N)r`   ra   rb   rc   r_   r   r   r   r   r   r   r   e  s    r   r   c                       e Zd Zd Zy)OperationOrderTestsc                 R   | j                  t        t        t        t              ddg       | j                  t        t        t        t              ddg       | j                  t        t        t        t              ddg       | j                  t        t        t        t
              ddg       | j                  t        t        t
        t              ddg       | j                  t        t        t        t              ddg       | j                  t        t        t        t              ddg       | j                  t        t        t        t              ddg       | j                  t        t        t        t
              ddg       | j                  t        t        t
        t              d	dg       | j                  t        t        t                     | j                  t        t        t        t              dd
g       | j                  t        t        t        t              ddg       y )Nr   r   r   r   r   r   r   r   r   r   r   )
ru   r   r   r   r   r   r   rw   
issubclassr   r*   s    r   test_comparison_ordersz*OperationOrderTests.test_comparison_orderst  s}   RA.Z0HIRA.Z0HIRA.Z0HIRA.Z0HIRA.Z0HIRA.Z0HIRA.Z0HIRA.Z0HIRA.Z0HIRA.Z0HI
1a()RA.Z0HIRA.Z0HIr   N)r`   ra   rb   r   r   r   r   r   r   s  s    Jr   r   c                       e Zd ZdZd Zy)SupEqzClass that can test equalityc                      yNTr   r@   s     r   r_   zSupEq.__eq__      r   Nr`   ra   rb   rc   r_   r   r   r   r   r     s
    &r   r   c                       e Zd ZdZdZy)Sz"Subclass of SupEq that should failNr   r   r   r   r   r     
    ,Fr   r   c                       e Zd ZdZy)Fz'Independent class that should fall backN)r`   ra   rb   rc   r   r   r   r   r     s    1r   r   c                       e Zd ZdZdZy)Xz"Independent class that should failNr   r   r   r   r   r     r   r   r   c                       e Zd ZdZdZy)SNz>Subclass of SupEq that can test equality, but not non-equalityN)r`   ra   rb   rc   __ne__r   r   r   r   r     s
    HFr   r   c                       e Zd ZdZd ZdZy)XNz>Independent class that can test equality, but not non-equalityc                      yr   r   r@   s     r   r_   z	XN.__eq__  r   r   N)r`   ra   rb   rc   r_   r   r   r   r   r   r     s    HFr   r   c                       e Zd ZdZd Zd Zy)FallbackBlockingTestsz#Unit tests for None method blockingc                    t               t               t               t               f\  }}}}| j	                  ||       | j	                  ||       | j	                  ||       | j	                  ||       | j                  t        t        ||       | j                  t        t        ||       | j                  t        t        ||       y r   )r   r   r   r   ru   assertRaisesr"   r   )r$   efsr   s        r   test_fallback_rmethod_blockingz4FallbackBlockingTests.test_fallback_rmethod_blocking  s    Wac13+
1aAAAA)RA.)RA.)RA.r   c                 8   t               t               t               }}}| j                  ||k7         | j	                  t
        t        ||       | j	                  t
        t        ||       | j                  ||k7         | j	                  t
        t        ||       y r   )r   r   r   assertFalser   r"   r   )r$   r   snxns       r   test_fallback_ne_blockingz/FallbackBlockingTests.test_fallback_ne_blocking  su    GRT24r2a )RB/)RQ/b!)RQ/r   N)r`   ra   rb   rc   r   r   r   r   r   r   r     s    -
/0r   r   __main__)!rc   r   operatorr   r   r   abcr   r   r   r   r   objectr   TestCaseri   r   r   r   r   r   r   registerr   r   r   r   r   r   r   r   r`   mainr   r   r   <module>r      s    ?    g& gRe+(## e+T 	 		7 		 	
 
 

1J(++ J&F 
 2 2   0H-- 0. zHMMO r   