
    <e                        d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlm	Z
 ej        j        Zej        j        Z G d de          Z G d de j                  Z G d d	e j                  Zed
k    r e j                     dS dS )    N)Decimal)Fractionc                   \     e Zd ZdZ fdZeZd ZeZed             Z	ed             Z
 xZS )DummyIntegralzADummy Integral class to test conversion of the Rational to float.c                 `    t          t                                          |                    S N)r   super__mul__)selfother	__class__s     ./usr/lib/python3.11/test/test_numeric_tower.pyr
   zDummyIntegral.__mul__   s!    UWW__U33444    c                     t           S r   )NotImplementedr   r   s     r   __truediv__zDummyIntegral.__truediv__   s    r   c                      t          |           S r   r   r   s    r   	numeratorzDummyIntegral.numerator   s    T"""r   c                      t          d          S )N   r   r   s    r   denominatorzDummyIntegral.denominator!   s    Qr   )__name__
__module____qualname____doc__r
   __rmul__r   __rtruediv__propertyr   r   __classcell__)r   s   @r   r   r      s        KK5 5 5 5 5H  L# # X#     X         r   r   c                   >    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	S )
HashTestc                     |                      t          |          t          |          d                    ||                     |                      ||           d S )Nz&got different hashes for {!r} and {!r})assertEqualhashformat)r   xys      r   check_equal_hashzHashTest.check_equal_hash'   s\    a$q''AHHANN	P 	P 	PAr   c                 ^    |                      dd           |                      dd           d S )NFr   Tr   )r+   r   s    r   
test_boolszHashTest.test_bools-   s4    eQ'''dA&&&&&r   c                 v   t          dd          D ]k}|                     |t          |                     |                     |t          |                     |                     |t	          |                     lt          d          D ]}d|z  dz
  }|t          t          |                    k    rH|                     |t          |                     |                     | t          |                      |                     |t          |                     |                     |t	          |                     |                     | t          |                      |                     | t	          |                      d|z  }|                     |t          |                     |                     | t          |                      |                     |t          |                     |                     |t	          |                     |                     | t          |                      |                     | t	          |                      t          d          D ]}t          j        d          }t          j        d|z   d|z            }|                     |t          |                     |                     |t	          |                     |t          t          |                    k    r#|                     |t          |                     d S )Ni  d      r   i,  
   )ranger+   floatDFintrandom	randrange)r   in_es        r   test_integerszHashTest.test_integers1   s    ud## 	+ 	+A!!!U1XX...!!!QqTT***!!!QqTT**** s 	- 	-A1qACaMM!!%%aq222%%qb588)444!!!QqTT***!!!QqTT***!!1"aee,,,!!1"aee,,,1A!!!U1XX...!!1"uQxxi000!!!QqTT***!!!QqTT***!!1"aee,,,!!1"aee,,,, t 	3 	3A %%A "a%Q//A!!!QqTT***!!!QqTT***CaMM!!%%aq222	3 	3r   c                 L   |                      dd           |                      dt          d                     |                      dt          d                     |                      dt          d                     |                      dt          d                     |                      t          d          t          d                     |                      t          d          t          d                     t	          d          D ]}t          j                    t          j        t          j                    dz  d	z
            z  }|                      |t          j        |                     |                      |t          j        |                     d S )
N               r   z-0.0inf-infr/   g      i@g      Y@)	r+   r5   r6   r4   r3   r8   mathexp
from_float)r   r<   r)   s      r   test_binary_floatszHashTest.test_binary_floatsW   sZ    	c4((( 	c1Q44(((dAaDD)))dAfII...c1Q44((( 	eEllAeHH555eFmmQvYY777t 	6 	6A$(6=??5+@5+H"I"IIA!!!Q\!__555!!!Q\!__5555	6 	6r   c           
          ddddddt          d          t          d          g}d	D ]+}|D ]&}|                     |t          ||                     ',d S )
Nr@   rA         ?g      g      ?g    rB   rC   )rA   r@   )r4   r+   complex)r   test_valueszerovalues       r   test_complexzHashTest.test_complexl   s     D#tWgU||U6]]4  	C 	CD$ C C%%eWUD-A-ABBBBC	C 	Cr   c                 8   g d}|D ]2}|                      t          |          t          d                     3|                      t          d          t          d                     |                      t          d          t          d                     |                      t          d          t          d                     |                      t          d          t          d                     |                      t          d	          t          d
                     |                      t          d          t          d
                     |                      t          d          t          d
                     |                      t          d          t          d
                     |                      t          d          t          d
                     |                      t          d          t          d
                     d S )N)0z-0z0.0z-0.0e10z000e-10r   z1.00r   z1.00000z-1.00z-1.00000123e2i0  1230e112300z12300.0z12300.00z	12300.000)r+   r5   )r   zerosrL   s      r   test_decimalszHashTest.test_decimalsw   s    988 	1 	1D!!!D''1Q440000aii1...a	llAaDD111ajj!B%%000a
mmQrUU333ajj!E((333akk1U88444ajj!E((333a	llAeHH555a
mmQuXX666annahh77777r   c           	         |                      t          t          dt                              t                     |                      t          t          ddt          z                      t                      |                      t          t          dt          z  d                    d           |                      t          t          t           d                    d           t          t          d          t          d          d          |                     t          fd	           |                      t                    d
           d S )Nr   rQ         r   r1   F)
_normalizec                  "     j          j        z  S r   )r   r   )r)   s   r   <lambda>z)HashTest.test_fractions.<locals>.<lambda>   s    Q[-F r   g      ?)	r&   r'   r6   _PyHASH_MODULUS_PyHASH_INFr   assertRaises	TypeErrorr4   )r   r)   s    @r   test_fractionszHashTest.test_fractions   s    	a?3344kBBBaAo$56677+FFFa/ 115566:::a 0!4455q999
 mAa 0 0UCCC)%F%F%F%FGGGq3'''''r   c                 ~     G d d          }d |            h}|                      t          |          d           d S )Nc                       e Zd Zd Zd ZdS )6HashTest.test_hash_normalization.<locals>.HalibutProxyc                      t          d          S Nhalibut)r'   r   s    r   __hash__z?HashTest.test_hash_normalization.<locals>.HalibutProxy.__hash__   s    I&r   c                     |dk    S rf    r   s     r   __eq__z=HashTest.test_hash_normalization.<locals>.HalibutProxy.__eq__   s    	))r   N)r   r   r   rh   rk   rj   r   r   HalibutProxyrd      s2        ' ' '* * * * *r   rl   rg   r   )r&   len)r   rl   r)   s      r   test_hash_normalizationz HashTest.test_hash_normalization   s^    	* 	* 	* 	* 	* 	* 	* 	* 'Q#####r   N)r   r   r   r+   r-   r>   rG   rN   rV   ra   rn   rj   r   r   r$   r$   &   s          ' ' '$3 $3 $3L6 6 6*	C 	C 	C8 8 8$( ( ($ $ $ $ $r   r$   c                       e Zd Zd Zd ZdS )ComparisonTestc                 N   t          d          t          d          dt          dd          dddd	d
t          d          t          d          t          d          t          dd          t          d          t          dd          t          dd          dt          d          g}t          |          D ]m\  }}||dz   d          D ]Z}|                     ||           |                     ||           |                     ||           |                     ||           [nd S )NrC   z-1e425000000girY   gQ	r@   g      Tz1.2z1.3z1.4i_5 i z1.414213562373095048801688724iC i; i:iJ gvܼ5Jiinfinityr   )r4   r5   r6   	enumerate
assertLessassertLessEqualassertGreaterassertGreaterEqual)r   rK   r:   firstseconds        r   test_mixed_comparisonsz%ComparisonTest.test_mixed_comparisons   s7   
 &MMnc1IIeHHeHH%LLff-..feijMM%( "+.. 	7 	7HAu%acdd+ 7 7v...$$UF333""65111''6666	7	7 	7r   c                 l   d}d}ddt          d          t          d          t          d          fD ].}|                     ||           |                     ||           /ddt          d          t          d          t          d          fD ]Z}|                     ||           |                     ||           |                     ||           |                     ||           [ddt          d          t          d          t          d          ddt          d          t          d          t          d          |fD ]m}t
          j        t
          j        t
          j        t
          j	        fD ]<}| 
                    t          |||           | 
                    t          |||           =nd S )Ny      ?        yQ	@r   rI   r1   g       @)r6   r5   rJ   r&   assertNotEqualoperatorleltgegtr_   r`   )r   zwvops        r   rN   zComparisonTest.test_complex   s    C1qttWQZZ/ 	# 	#AQ"""Q""""C1qttWQZZ/ 	& 	&A1%%%1%%%1%%%1%%%%S!A$$!gajjS!A$$!gajj!5 	7 	7Ak8;X[H 7 7!!)RA666!!)RA66667	7 	7r   N)r   r   r   r{   rN   rj   r   r   rp   rp      s2        7 7 7>7 7 7 7 7r   rp   __main__)unittestr8   rD   sysr~   decimalr   r5   	fractionsr   r6   	hash_infomodulusr]   rB   r^   r7   r   TestCaser$   rp   r   mainrj   r   r   <module>r      s"      



              # # # # # # -'m         C      (E$ E$ E$ E$ E$x  E$ E$ E$N57 57 57 57 57X& 57 57 57p zHMOOOOO r   