
    ;e8                     h   	 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                    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                     dS dS ))    N)eqlene)ABCMetac                     	 | r	|| z  | }} | 	|S N )abs     &/usr/lib/python3.11/test/test_binop.pygcdr      s)    ;
 sA1  H    c                 .    	 t          | t                    S r   )
isinstanceintxs    r   isintr      s    7ar   c                 \    	 t           t          t          fD ]}t          | |          r dS dS )N   r   )r   floatcomplexr   )r   Ts     r   isnumr      s>    K%   a 	11	1r   c                 .    	 t          | t                    S r   )r   Ratr   s    r   isRatr      s    Aar   c                       e 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dS )r   	_Rat__num	_Rat__denr   r   c                 2   	 t          |          st          d|z            t          |          st          d|z            |dk    rt          d          t          ||          }t	          ||z            | _        t	          ||z            | _        d S )NzRat numerator must be int (%r)z Rat denominator must be int (%r)r   zzero denominator)r   	TypeErrorZeroDivisionErrorr   r   r   r    )selfnumdengs       r   __init__zRat.__init__"   s    	> Szz 	D<sBCCCSzz 	F>DEEE!88#$6777SMMa[[
a[[


r   c                     	 | j         S r   )r   r$   s    r   _get_numzRat._get_num1       Ezr   Nc                     	 | j         S r   )r    r*   s    r   _get_denzRat._get_den6   r,   r   c                 &    	 d| j         | j        fz  S )NzRat(%d, %d)r   r    r*   s    r   __repr__zRat.__repr__;   s    J
DJ777r   c                 <    	 t          t          |                     S r   )strr   r*   s    r   __str__zRat.__str__?   s    K5;;r   c                 (    	 | j         dz  | j        z  S )N      ?r0   r*   s    r   	__float__zRat.__float__C   s    'z#~dj((r   c                     	 | j         dk    rB	 t          | j                  S # t          $ r  t          dt	          |           z            w xY wt          dt	          |           z            )Nr   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   s}    ::??24:&  2 2 2#$D&*4jj%1 2 2 22 2T$ZZ?@@@s	   " *Ac                 "   	 t          |          rt          |          }t          |          r:t          | j        |j        z  |j        | j        z  z   | j        |j        z            S t          |          rt          |           |z   S t          S r   r   r   r   r   r    r   r   NotImplementedr$   others     r   __add__zRat.__add__Q   s    2<< 	JJE<< 	/tz%+-DJ0FFz%+-/ / /<< 	';;&&r   c                 "   	 t          |          rt          |          }t          |          r:t          | j        |j        z  |j        | j        z  z
  | j        |j        z            S t          |          rt          |           |z
  S t          S r   r>   r@   s     r   __sub__zRat.__sub__^   s    7<< 	JJE<< 	/tz%+-DJ0FFz%+-/ / /<< 	';;&&r   c                 "   	 t          |          rt          |          }t          |          r:t          |j        | j        z  | j        |j        z  z
  | j        |j        z            S t          |          r|t          |           z
  S t          S r   r>   r@   s     r   __rsub__zRat.__rsub__i   s    G<< 	JJE<< 	/u{4:-
5;0FFz%+-/ / /<< 	'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 r   r   r   r   r    r   r   r   r?   r@   s     r   __mul__zRat.__mul__t   s    7<< 	Gtz%+-tz%+/EFFF<< 	5tz%'4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 r   rH   r@   s     r   __truediv__zRat.__truediv__   s    5<< 	Gtz%+-tz%+/EFFF<< 	5tz4:e#34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 r   rH   r@   s     r   __rtruediv__zRat.__rtruediv__   s    E<< 	Gu{4:-u{4:/EFFF<< 	5uTZ'444<< 	'5;;&&r   c                     	 t          |          rt          |          }nt          |          st          S | |z  }|j        |j        z  S r   )r   r   r   r?   r   r    r$   rA   r   s      r   __floordiv__zRat.__floordiv__   sL    <<< 	"JJEEu 	"!!Jw!'!!r   c                 ,    	 || z  }|j         |j        z  S r   r0   rO   s      r   __rfloordiv__zRat.__rfloordiv__   s    L$Jw!'!!r   c                     	 t          |          rt          |          }nt          |          st          S | |z  }|| ||z  z
  fS r   )r   r   r   r?   rO   s      r   
__divmod__zRat.__divmod__   sQ    @<< 	"JJEEu 	"!!%K4%!)#$$r   c                     	 t          |          rt          |          }nt          |          st          S t	          ||           S r   )r   r   r   r?   divmodr@   s     r   __rdivmod__zRat.__rdivmod__   sD    P<< 	"JJEEu 	"!!eT"""r   c                 0    	 t          | |          d         S Nr   rV   r@   s     r   __mod__zRat.__mod__   s    *dE""1%%r   c                 0    	 t          ||           d         S rY   rZ   r@   s     r   __rmod__zRat.__rmod__   s    :eT""1%%r   c                     	 t          |          r| j        dk    o
| j        |k    S t          |          r | j        |j        k    o| j        |j        k    S t	          |          rt          |           |k    S t          S rY   )r   r    r   r   r   r   r?   r@   s     r   __eq__z
Rat.__eq__   s|    ,<< 	;:?:tzU'::<< 	K:,Ju{1JJ<< 	(;;%''r   )r   r   )__name__
__module____qualname__	__slots__r(   r+   propertyr%   r.   r&   r1   r4   r7   r<   rB   __radd__rD   rF   rI   __rmul__rK   rM   rP   rR   rT   rW   r[   r]   r_   r	   r   r   r   r      s       Ck*I! ! ! !   (8T
"
"C   (8T
"
"C8 8 8     ) ) )A A 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
S )RatTestCasec                    |                      t          dd          d           |                      t          dd          d           |                      t          dd          d           |                      t          dd          d           |                      t          d	d          d
           |                      t          dd
          d           |                      t          d	d
          d
           t          dd          D ]}t          dd          D ]}|                     t          ||          dk               |                     t          | |          dk                |                     t          ||           dk               |                     t          | |           dk                d S )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" 	1 	1A1b\\ 1 1Aq		A...QB

Q///Ar

Q///QBa0000	1	1 	1r   c           	      B   t          dd          }|                     |j        d           |                     |j        d           t          dd          }|                     |j        d           |                     |j        d           t          dd          }|                     |j        d           |                     |j        d           t          dd          }|                     |j        d           |                     |j        d           t          d          }|                     |j        d           |                     |j        d	           	 t          d	d
          }|                     d           n# t
          $ r Y nw xY wddddg i d t           t          f	D ]t}	 t          |          }|                     d|z             n# t          $ r Y nw xY w	 t          d	|          }|                     d|z             e# t          $ r Y qw xY wd S )Nrj   rm   rl      irr   rq      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   rt   r%   r&   failr#   unittestr"   )r$   r
   bads      r   test_constructorzRatTestCase.test_constructor   sR   BKK""""""CLL###"""RLL###"""SMM""""""FF""""""	BAq		A II@AAAA ! 	 	 	D	 RRT3@ 	E 	ECBHH 		:S@AAAA    E3KK 		=CDDDD    	E 	Es6   F 
FF-G
G"!G"&H
HHc                    |                      t          dd          t          dd          z   d           |                      t          dd          dz   t          dd                     |                      dt          dd          z   t          dd                     |                      dt          dd          z   d           |                      t          dd          dz   d           d S )Nrl   r{   r   rn   r6         ?rt   r   r*   s    r   test_addzRatTestCase.test_add   s    QSAYY.222QQAq		222SAYYAq		222s1ayy#...QS#.....r   c                    |                      t          dd          t          dd          z
  t          dd                     |                      t          dd          dz
  t          dd                     |                      dt          dd          z
  t          dd                     |                      t          dd          dz
  d	           |                      dt          dd          z
  d	           d S )
Nr|   rl   rn      rj   r   r{   r6         ?r   r*   s    r   test_subzRatTestCase.test_sub  s    QSAYY.B<<<QQAq		222SAYYAq		222QS#...s1ayy#.....r   c                    |                      t          dd          t          dd          z  t          dd                     |                      t          dd          dz  d           |                      dt          dd          z  d           |                      t          dd          dz  d           |                      dt          dd          z  d           d S )	Nrl   r{   rn   r|   rj   r   r   r6   r   r*   s    r   test_mulzRatTestCase.test_mul	  s    QSAYY.B<<<Ra,,,SQZZ,,,Rc)3///s2qzz)3/////r   c                    |                      t          dd          t          dd          z  t          dd                     |                      t          dd          dz  t          dd                     |                      dt          d          z  t          dd                     |                      dt          d	d          z  d
           |                      t          d	d          dz  d
           d S )Nrj   r{   rn   r|      	   rl         @r   r   r   r*   s    r   test_divzRatTestCase.test_div  s    Rc!Qii/R<<<RaR444SVVSAYY///s1ayy#...QS#.....r   c                 n   |                      t          d          t          d          z  d           |                      t          dd          t          dd          z  d           |                      t          d          dz  d           |                      dt          d          z  d           d S )Nrj      rl   r{   r   r*   s    r   test_floordivzRatTestCase.test_floordiv  s    RCFF*A...Rs1ayy0!444RAq)))s1vvq)))))r   c                    |                      t          d          t          dd                     |                      t          d          d           |                      dt          d                     |                      t          d          d           |                      dt          d                     d S )Nrj   rs   rl   g      $@r   r*   s    r   test_eqzRatTestCase.test_eq  s    R#b!**---R"%%%SWW%%%R$'''s2ww'''''r   c                 @   |                      t          dd          t          dd          z  t          dd                     |                      t          dd          dz  t          dd                     |                      dt          d          z  t          dd                     |                      dt          d	d          z  d
           |                      t          d	d          dz  d
           |                      t          d          d           d S )Nrj   r{   rn   r|   r   r   rl   r   r   r   z1/2r   )rt   r   evalr*   s    r   test_true_divzRatTestCase.test_true_div$  s    Rc!Qii/R<<<RaR444SVVSAYY///s1ayy#...QS#...ec*****r   N)r`   ra   rb   ry   r   r   r   r   r   r   r   r   r	   r   r   rh   rh      s        =1 1 1"E "E "EH/ / // / /0 0 0/ / /* * *( ( (+ + + + +r   rh   c                       e Zd Z	 d Zd ZdS )OperationLoggerc                     || _         d S r   logger)r$   r   s     r   r(   zOperationLogger.__init__1  s    r   c                      | j         |  d S r   r   )r$   argss     r   log_operationzOperationLogger.log_operation3  s    Tr   N)r`   ra   rb   r(   r   r	   r   r   r   r   /  s5        8      r   r   c                     	 g }g }|D ]%}|                      ||j                              &	  | |  n# t          $ r Y nw xY w|S r   )appendr"   )opclasseslog	instancescs        r   op_sequencer   6  sx    =
CI ( (3:''''
I   Js   5 
AAc                        e Zd Zd Zd Zd ZdS )Ac                 :    |                      d           t          S )NA.__eq__r   r?   r@   s     r   r_   zA.__eq__E      :&&&r   c                 :    |                      d           t          S )NA.__le__r   r@   s     r   __le__zA.__le__H  r   r   c                 :    |                      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  A                r   r   c                        e Zd Zd Zd Zd ZdS )Bc                 :    |                      d           t          S )NB.__eq__r   r@   s     r   r_   zB.__eq__P  r   r   c                 :    |                      d           t          S )NB.__le__r   r@   s     r   r   zB.__le__S  r   r   c                 :    |                      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dS )Cc                 :    |                      d           t          S )NC.__eq__r   r@   s     r   r_   zC.__eq__[  r   r   c                 :    |                      d           t          S )NC.__le__r   r@   s     r   r   zC.__le__^  r   r   c                 :    |                      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S )Vc                 :    |                      d           t          S )NV.__eq__r   r@   s     r   r_   zV.__eq__g  r   r   c                 :    |                      d           t          S )NzV.__le__r   r@   s     r   r   zV.__le__j  r   r   c                 :    |                      d           t          S )NV.__ge__r   r@   s     r   r   zV.__ge__m  r   r   Nr   r	   r   r   r   r   e  sD                r   r   c                       e Zd Zd ZdS )OperationOrderTestsc                 p   |                      t          t          t          t                    ddg           |                      t          t          t          t                    ddg           |                      t          t          t          t                    ddg           |                      t          t          t          t
                    ddg           |                      t          t          t
          t                    ddg           |                      t          t          t          t                    ddg           |                      t          t          t          t                    ddg           |                      t          t          t          t                    ddg           |                      t          t          t          t
                    ddg           |                      t          t          t
          t                    d	dg           |                     t          t          t                               |                      t          t          t          t                    dd
g           |                      t          t          t          t                    ddg           d S )Nr   r   r   r   r   r   r   r   r   r   r   )
rt   r   r   r   r   r   r   rv   
issubclassr   r*   s    r   test_comparison_ordersz*OperationOrderTests.test_comparison_orderst  s   RA..Z0HIIIRA..Z0HIIIRA..Z0HIIIRA..Z0HIIIRA..Z0HIIIRA..Z0HIIIRA..Z0HIIIRA..Z0HIIIRA..Z0HIIIRA..Z0HIII
1a(()))RA..Z0HIIIRA..Z0HIIIIIr   N)r`   ra   rb   r   r	   r   r   r   r   s  s(        J J J J Jr   r   c                       e Zd Z	 d ZdS )SupEqc                     dS NTr	   r@   s     r   r_   zSupEq.__eq__      tr   Nr`   ra   rb   r_   r	   r   r   r   r     s&        &    r   r   c                       e Zd Z	 dZdS )SNr   r	   r   r   r   r             ,FFFr   r   c                       e Zd ZdS )FN)r`   ra   rb   r	   r   r   r   r     s        11r   r   c                       e Zd Z	 dZdS )XNr   r	   r   r   r   r     r   r   r   c                       e Zd Z	 dZdS )SNN)r`   ra   rb   __ne__r	   r   r   r   r     s        HFFFr   r   c                       e Zd Z	 d ZdZdS )XNc                     dS r   r	   r@   s     r   r_   z	XN.__eq__  r   r   N)r`   ra   rb   r_   r   r	   r   r   r   r     s%        H  FFFr   r   c                       e Zd Z	 d Zd ZdS )FallbackBlockingTestsc                    t                      t                      t                      t                      f\  }}}}|                     ||           |                     ||           |                     ||           |                     ||           |                     t          t          ||           |                     t          t          ||           |                     t          t          ||           d S r   )r   r   r   r   rt   assertRaisesr"   r   )r$   efsr   s        r   test_fallback_rmethod_blockingz4FallbackBlockingTests.test_fallback_rmethod_blocking  s    WWacc133+
1aAAAA)RA...)RA...)RA.....r   c                    t                      t                      t                      }}}|                     ||k               |                     t
          t          ||           |                     t
          t          ||           |                     ||k               |                     t
          t          ||           d S r   )r   r   r   assertFalser   r"   r   )r$   r   snxns       r   test_fallback_ne_blockingz/FallbackBlockingTests.test_fallback_ne_blocking  s    GGRTT244r2a   )RB///)RQ///b!!!)RQ/////r   N)r`   ra   rb   r   r   r	   r   r   r   r     s5        -
/ 
/ 
/0 0 0 0 0r   r   __main__) r   operatorr   r   r   abcr   r   r   r   r   objectr   TestCaserh   r   r   r   r   r   r   registerr   r   r   r   r   r   r   r   r`   mainr	   r   r   <module>r      s_   ?                         g g g g g& g g gRe+ e+ e+ e+ e+(# e+ e+ e+T         	 	 	 	 	 	 	 		 	 	 	 	7 	 	 	 		 	 	 	 	 	 	 	
 
 
 
 
 
 
 
 

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