
    <e                        d dl Z d dlmZ d dlZd dlZd dlZd dlZej        j        Z	de	z  Z
e
dz
  ZdZdZd dde
e
dz	  ddgZd	Z ede	z            D ]Ze                    edz
             edz  Z [ed
 eD             d eD             z   z  Zej        j        Zej        j        Zej        j        Zej        j        Zdez  deez
  dz
  z  z
  Zd Zd Z G d de j                  Z e!dk    r e j"                     dS dS )    N)support      F      l   UU*UU* l   *UU*UU
    c                     g | ]}| S  r
   .0xs     %/usr/lib/python3.11/test/test_long.py
<listcomp>r      s       1QB       c                     g | ]}| S r
   r
   r   s     r   r   r      s    #8#8#81QB#8#8#8r   c                    	 t           j        j        dz   }t           j        j        |z
  }d|z  }g d}| dk    rdS | dk     rt	          |             S |                                 |z
  }|dk     r| | z  n| |z	  t          | d|z   z            z  }|||dz           z  }|||k    z   |k    rt          d          t          j	        t          |          |          S )	Nr   r   )r   r   r   r   r   r   r           r      z%integer too large to convert to float)sys
float_infomant_digmax_expint_to_float
bit_lengthboolOverflowErrormathldexpfloat)n	PRECISION	SHIFT_MAXQ_MAXROUND_HALF_TO_EVEN_CORRECTIONshiftqs          r   r   r   '   s    '!+I&2INE$?$?$?! 	Avvs	
QaR     LLNNY&EqyyeVqEzT!en:L5M5M&MA 	&q1u	--A U
i''CDDD :eAhh&&&r   c                 z   	 | |z  dk     }t          |           t          |          }} |st          d          | t          |z  k    rt          d          |                                 |                                z
  }|dk    r| d|z  |z  k    s|dk     r| d| z  z  |k    r|dz  }t          |t                    t          z
  }| t          | d          z  |t          |d          z  }} t          | |          \  }}d|z  |k    sd|z  |k    r|dz  dk    r|dz  }t          j
        ||          }|r| n|S )Nr   zdivision by zeroz)int/int too large to represent as a floatr   r   )absZeroDivisionErrorDBL_MIN_OVERFLOWr   r   maxDBL_MIN_EXPDBL_MANT_DIGdivmodr   r    )abnegativedexpr(   rresults           r   truedivr8   U   sV   7sQwHq663q66qA  4 2333q   GHHH 	
'AAvv!q!tax--1q55QQBY!^^	Q a


,CSD!a3sA;;.qA!Q<<DAq 	sQww!A#((q1uzz	QZ3F*F77F*r   c                      e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zej        d             Zd Zd Zd Zd Zd Zd Zd Zd Zd=dZej        d             Zd Zd Z ej!        d             Z"ej!         ej#        e$j%        dz   d d!"          d#                         Z&d$ Z'ej!         ej#        e$j%        d%z   d&d!"          d'                         Z(d( Z)d) Z*d* Z+d+ Z,d, Z-d- Z.ej!        d.             Z/ej!        d/             Z0ej!        d0             Z1d1 Z2d2 Z3d3 Z4d4 Z5d5 Z6d6 Z7ej!        d7             Z8d8 Z9d9 Z:d: Z;d; Z<d<S )>LongTestc                 f   |                      |d           |t          z  }|t          z
  dz   }d}d}t          t          j                    t          dz  z            dz  }||k     r|dz	  dz   }t	          |||z
            }|                     d|cxk    o
t          k    nc            ||z   }||z  }|dz  r|d|z  dz
  z  }t          t          j                    t          dz  z            }||k     |                     ||cxk    o|k    nc            t          j                    dk     r| }|S )Nr   r   r         ?)assertGreaterSHIFTintrandommin
assertTrue)selfndigitsnbits_hinbits_loanswernbitsr6   bitss           r   getranzLongTest.getran{   s[   7A&&&U?e#a'519-..2hFa<DtX-..DOOA........///DLEt^F1u 4AI?3FMOOuqy122A h 	E5555X5555666=??S  WFr   c                     d}t          |           D ]'}|t          z  t          j        dt                    z  }(t          j                    dk     r| }|S )Nr   r<   )ranger>   r@   randintMASK)rD   rG   is      r   getran2zLongTest.getran2   sW    w 	A 	AAo4)@)@@FF=??S  WFr   c                    | j         }|                     ||          5  t          ||          \  }}||z  ||z  }}||z  ||z  }	} |||	d            |||d            |||d            ||||z  |z   d           |dk    r%|                     d|cxk    o|k     nc d           n$|                     ||cxk     odk    nc d           d d d            d S # 1 swxY w Y   d S )Nr   yzmultiplication does not commutez(divmod returns different quotient than /z#divmod returns different mod than %zx != q*y + r after divmodr   zbad mod from divmod)assertEqualsubTestr0   rB   )
rC   r   rS   eqr(   r6   q2r2pabpbas
             r   check_divisionzLongTest.check_division   s   \\A\## 	C 	C!Q<<DAqT1Q3BsAaCCBsC:;;;Bq"@AAABq";<<<Bq!A#'67771uuQ







,ABBBBA







,ABBB	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	Cs   B1CC!$C!c                    t          t          dt          dz                       t          t          t          t          dz                       z   }|                    t          dz             |D ]I}|                     |          }|D ]/}|                     |          pd}|                     ||           0J|                     dd           |                     dd           |                     dd	           |                     d
d           |                     dd           |                     dd           |                     dd           |                     dd           |                     dd           |                     dd           |                     dd           |                     dd           d S )Nr         l   !Us/w3al   ZW3al   +Q@{dB]OlNl   OOlNl   teo%gqCgx<l   &ghrsGl   Q5K4+o-bkl   C4+o-bkl   .#wflD&I-Xl   ZnSu9bl   cv<Il   rdFBu'pl   PhbIi|$l   1m{Wqi8l   s~5^Fiy+l   'H
<{Cl   `<{Cl   ED_5(Nl   oybal   =2zz6 l   9tm)listrL   	MAXDIGITSKARATSUBA_CUTOFFappendrJ   r[   )rC   digitslenxr   lenyrS   s         r   test_divisionzLongTest.test_division   s   eAy{++,,tE:J6F6K5M 5M 0N 0N N&*+++ 	* 	*DD!!A * *KK%%*##Aq))))* 	8/	1 	1 	1@)	+ 	+ 	+@)	+ 	+ 	+A3	5 	5 	5 	@2	4 	4 	4@3	5 	5 	5 	NI666/;;;.	:::.???.???,n=====r   c                     t          t          dd                    t          t          t          t          dz                       z   }|                    t          dz  t          dz  g           d |D             }|D ]}d|z  dz
  }|D ]r}||k     r	|                     ||          5  d|z  dz
  }||z  }d||z   z  d|z  z
  d|z  z
  dz   }|                     ||           d d d            n# 1 swxY w Y   sd S )Nr      
   d   c                 "    g | ]}|t           z  S r
   )r>   )r   digits     r   r   z+LongTest.test_karatsuba.<locals>.<listcomp>   s    222%222r   )abitsbbits)r_   rL   ra   extendrU   rT   )	rC   rc   rI   rm   r1   rn   r2   r   rS   s	            r   test_karatsubazLongTest.test_karatsuba   s   eAqkk""T%0@0@20E+G +G &H &H H'",.>.DEFFF226222  	+ 	+Eeq A 
+ 
+5==\\U\;; + +eq(AAA.u*&u*& A $$Q***+ + + + + + + + + + + + + + +
+	+ 	+s   *;C11C58C5c                    | j         }|                     |          5   ||dz  d            ||dz  |            ||dz  |            ||dz  |            ||dz  d            ||dz  |             |||              |||z  |            |||z  |            |||z  d            ||| z  d            ||| z  d            ||| z  d            || d| z               || |dz
              d d d            n# 1 swxY w Y   t          dt          z            D ]}d|z  }|                     |||          5   |||z  |z	  |            |||z  ||z	              |||z  ||z              ||| z  ||z	  |z              ||| z  ||dz
   z             d d d            n# 1 swxY w Y   d S )N)r   r   r   r   r   )r   r"   p2)rT   rU   rL   r>   )rC   r   rV   r"   rr   s        r   check_bitop_identities_1z!LongTest.check_bitop_identities_1   s   \\A\ 	 	Bq1uaLLLBq1uaLLLBq1uaLLLBq2vqMMMBq2vrNNNBq2vrNNNBqA2#JJJBq1uaLLLBq1uaLLLBq1uaLLLBqA2vqMMMBqA2vrNNNBqA2vrNNNBr1r6NNNBrQqS6NNN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	  qw 	+ 	+AaBQ2.. + +16Q;"""17AF###1r616"""1s7AFaK(((1s7A"q&	M***+ + + + + + + + + + + + + + +	+ 	+s%   C)DDDA$GG	G	c                    | j         }|                     ||          5   |||z  ||z              |||z  ||z              |||z  ||z              |||z  |z  |            |||z  | | z               |||z  | | z               |||z  ||z  ||z   z              |||z  || z  | |z  z              |||z  ||z  | | z  z             d d d            d S # 1 swxY w Y   d S )NrR   rT   rU   )rC   r   rS   rV   s       r   check_bitop_identities_2z!LongTest.check_bitop_identities_2  s   \\A\## 		+ 		+Bq1ua!eBq1ua!eBq1ua!eBq1uqy!Bq1uaRj!!!Bq1uaRj!!!Bq1uq1u!a%()))Bq1uqA2v1"q&)***Bq1uq1u!qb)***		+ 		+ 		+ 		+ 		+ 		+ 		+ 		+ 		+ 		+ 		+ 		+ 		+ 		+ 		+ 		+ 		+ 		+s   C C,,C03C0c                 r   | j         }|                     |||          5   |||z  |z  |||z  z              |||z  |z  |||z  z              |||z  |z  |||z  z              ||||z  z  ||z  ||z  z              ||||z  z  ||z  ||z  z             d d d            d S # 1 swxY w Y   d S )N)r   rS   zru   )rC   r   rS   rx   rV   s        r   check_bitop_identities_3z!LongTest.check_bitop_identities_3  s:   \\Aa\(( 	/ 	/BA{AQK(((BA{AQK(((BA{AQK(((BqAE{QUq1u-...BqAE{QUq1u-...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/s   A?B,,B03B0c           
         t           D ]}|                     |           t          dt          dz             }|D ]}|                     |          }|                     |           |D ]]}|                     |          }|                     ||           |                     |||                     ||z   dz                       ^d S )Nr   r   )specialrs   rL   r`   rJ   rv   ry   )rC   r   rc   rd   re   rS   s         r   test_bitop_identitieszLongTest.test_bitop_identities  s     	- 	-A))!,,,,q)A+&& 	S 	SDD!!A))!,,, S SKK%%--a333--aDKKq@P4Q4QRRRRS	S 	Sr   c                 4   g }d}|dk     rd| }}|r7t          ||          \  }}|                    t          |                     |7|                                 |pdg}dd |         ddddd|         z   d                    d	 |D                       z   S )
Nr   r   -0b0o 0x)r      ri      c              3   &   K   | ]}d |         V  dS )0123456789abcdefNr
   )r   rO   s     r   	<genexpr>z'LongTest.slow_format.<locals>.<genexpr>1  s(      ==)!,======r   )r0   rb   r?   reversejoin)rC   r   baserc   signr6   s         r   slow_formatzLongTest.slow_format%  s    q55!!D 	"!T??DAqMM#a&&!!!  	" 	A35D5zDbd33D9:ww==f=====> 	>r   c                    dt           fdt          fdt          fdt          fdt          ffD ]\  }} ||          }|                     ||j                  5  |                     ||          }|                     ||           d d d            n# 1 swxY w Y   |                     |          5  |                     t          |d          |           d d d            n# 1 swxY w Y   d S )Nr   r   ri   r   )r   mapper)gotr   )
binoctstrreprhexrU   __name__r   rT   r?   )rC   r   r   r   r   expecteds         r   check_format_1zLongTest.check_format_13  sm   Hq#hS	B:CyP 	1 	1LD&&))C&/:: 0 0++At44  h///0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 #&& 1 1  S!a0001 1 1 1 1 1 1 1 1 1 1 1 1 1 1	1 	1s$   -BB	B	1%C""C&	)C&	c                     t           D ]}|                     |           t          d          D ]G}t          dt          dz             D ],}|                     |          }|                     |           -Hd S )Nri   r   )r{   r   rL   r`   rJ   )rC   r   rO   rd   s       r   test_formatzLongTest.test_format<  s     	# 	#A""""r 	' 	'Aa1-- ' 'KK%%##A&&&&'	' 	'r   c                    ddddz  fg}|D ]_\  }}dD ]W}dD ]R}||z   |z   }|}|dk    r|t           ur| }	 |                     t          |          |           C# t           $ r Y Ow xY wX`|                     t           t          d           |                     t           t          d	           |                     t           t          d
           |                     t           t          d           |                     t           t          dd           |                     t           t          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d          d           |                     t          dd          d           |                     t          dd          d           |                     t          d d          d           |                     t           t          d!d           |                     t           t          d"d           d#d$d%d&d'd(d)d*d+d,dz  d,dz   g}|D ]$}	|                     t           t          d-|	           %|                     t           t          d.           d S )/N)100000000000000000000l      Fx:^V e10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ri   rj   )r   +r~   )r    	z  		  r~   123L123l0Lz-37L0x32Lr   1L      +   000r   0o123S   0x123i#  0b100r   z	 0O123   z 0X123  z 0B100 0z+0z-00008z-012395is        i   l                    l         l        r   42u   こんにちは)
ValueErrorrT   r?   assertRaises)
rC   LLsvr   prefixssvvinvalid_basesr   s
             r   	test_longzLongTest.test_longD  s~    'C(
  
	 
	DAq$ 	 	7  F$*BBs{{q
':':R((R"5555%   	 	*c6222*c6222*c4000*c6222*c7B777*c4444T2+++ 	UA***Wa"---Wa#...Wa!,,,[!,,b111Z++S111Y**A...S!a(((T1q)))T1q)))T1q)))*c4333*c9a888 !5&(!5&(S&1c6'
 " 	; 	;Dj#tT:::: 	*c+KLLLLLs   #A
A'	&A'	c                 H    G d d          }|                      t          t           |                        G d d          }|                     t                    5  |                     t           |                      d           d d d            d S # 1 swxY w Y   d S )Nc                       e Zd Zd ZdS )*LongTest.test_conversion.<locals>.JustLongc                     dS N*   r
   rC   s    r   __long__z3LongTest.test_conversion.<locals>.JustLong.__long__      rr   N)r   
__module____qualname__r   r
   r   r   JustLongr     s#            r   r   c                       e Zd Zd Zd ZdS )+LongTest.test_conversion.<locals>.LongTruncc                     dS r   r
   r   s    r   r   z4LongTest.test_conversion.<locals>.LongTrunc.__long__  r   r   c                     dS )N  r
   r   s    r   	__trunc__z5LongTest.test_conversion.<locals>.LongTrunc.__trunc__  s    tr   N)r   r   r   r   r   r
   r   r   	LongTruncr     s2              r   r   r   )r   	TypeErrorr?   assertWarnsDeprecationWarningrT   )rC   r   r   s      r   test_conversionzLongTest.test_conversion}  s   	 	 	 	 	 	 	 	 	)S((**555	 	 	 	 	 	 	 	 011 	5 	5S--t444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5s   ,BBBc                     	 t          |          }n# t          $ r d}Y nw xY w	 t          |          }n# t          $ r d}Y nw xY wd                    |||          }|                     |||           d S )NoverflowzAError in conversion of integer {} to float.  Got {}, expected {}.)r!   r   r   formatrT   )rC   r"   actualr   msgs        r   check_float_conversionzLongTest.check_float_conversion  s    	 1XXFF 	  	  	 FFF	 	"#AHH 	" 	" 	"!HHH	"&&,fQ&A&A 	3/////s    !!5 AAc                    g d}|D ]J}|                      t          |          |           |                      t          |           |            KdD ]Y\  }}t          d          D ]D}|                      t          t          d|z  d|z   z                      d|z  d|z   z             EZdD ]Y\  }}t          d          D ]D}|                      t          t          d|z  d|z   z                      d|z  d|z   z             EZt          t                    }dt
          z  }||z   dz  }|                      t          |          t                     |                      t          |dz             t                     |                      t          |dz
            t                     |                     t          t          |           |                      t          d|z
            t                      |                     t          t          |            |                     t          t          |dz
             |                     t          t          |           |                     t          t          |dz              |                     t          t          d|z  dz
             |                     t          t          d|z             |                     t          t          ||z             t          d	          D ]}d|z  d
z  dz   }d|z  dz  }|                      t          t          |                    |           d|z  d
z  }d|z  dz  }|                      t          t          |                    |           |dz
  ||dz   |dz
  ||dz   |dz
  ||dz   d|z  dz
  d|z  ||z  g}|                    |           t          dd          D ]3}t          dd          D ] }|	                    d|dz   z  |z              !4|D ]-}	| 
                    |	           | 
                    |	            .d S )N)r   r   r   l    l    l                       l   l             l         )r   r   )r   r   r^   r   r   r   rh   r   )   r   r   r   r   r   r   ))r   r   r   )r   r   r   r   r   )r   r   r   )r   r   )	   r   )ri   r   )      )r   r   )   r   )r]   r   )r   r   r   r   rj   l         r   r      5   )rT   r!   rL   r?   DBL_MAXDBL_MAX_EXPr   r   ro   rb   r   )
rC   exact_valuesr   rS   pint_dbl_max	top_powerhalfwaytest_valuesvalues
             r   test_float_conversionzLongTest.test_float_conversion  sp   	" 	" 	"  	, 	,AU1XXq)))UA2YY++++ M 	M 	MDAq2YY M M  U1a4q>%:%:!;!;QT57^LLLLM3 	M 	MDAq 2YY M M  U1a4q>%:%:!;!;QT57^LLLLM 'll{N	*Q.{++W555{1}--w777wqy))7333-888qy))G8444-999-	!<<<-	:::-	!<<<-)A>>>-)<<<-	)0CDDDs 	/ 	/A1	"Q&A1	"ASq]]A...1	"A1uASq]]A....
 M;AAIw!aKIaKiKM1Y;	)(;	
 	<(((r1 	2 	2A4%% 2 2""1qt9q=11112  	0 	0E''...''////	0 	0r   c                 L   dD ]2}|                      t          t          |                    |           3d}ddz  }| }|||t          d}dD ]$}|                     t
          t          ||           %|                     t          |          t          |          d           d S )N)g             r         ?       @X  123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345r   i0u  )hugemhugeshuger   )$float(huge)float(mhuge)zcomplex(huge)zcomplex(mhuge)zcomplex(huge, 1)zcomplex(mhuge, 1)zcomplex(1, huge)zcomplex(1, mhuge)z	1. + hugez	huge + 1.z
1. + mhugez
mhuge + 1.z	1. - hugez	huge - 1.z
1. - mhugez
mhuge - 1.z	1. * hugez	huge * 1.z
1. * mhugez
mhuge * 1.z
1. // hugez
huge // 1.z1. // mhugezmhuge // 1.z	1. / hugez	huge / 1.z
1. / mhugez
mhuge / 1.z
1. ** hugez
huge ** 1.z1. ** mhugezmhuge ** 1.zmath.sin(huge)zmath.sin(mhuge)zmath.sqrt(huge)zmath.sqrt(mhuge)z(float(shuge) should not equal int(shuge))rT   r!   r?   r   r   r   evalassertNotEqual)rC   r   r   r   r   	namespacetests          r   test_float_overflowzLongTest.test_float_overflow  s    * 	/ 	/AU3q66]]A....Ez!EE4PP	 	D 	DD  mT4CCCC 	E%LL#e**6	8 	8 	8 	8 	8r   c                    t          j        t           j                  }t          t	          d                    g dz   D ]`}d|z  }t          j        |          }|                     ||           ||z  }t          j        |          }|                     ||           addz   ddfD ]N}|                     t          t           j        |           |                     t          t           j        |           Od S )Nri   )rj     '  r   r	  r   r   )	r   log10er_   rL   assertAlmostEquallogr   r   )rC   LOG10Er5   r   r
  r   r  bads           r   	test_logszLongTest.test_logs  s    DF##b		??%7%7%77 		2 		2C#IEJu%%E""5#... V|H(5//C""31111%Z="a' 	; 	;Cj$(C888j$*c::::	; 	;r   c                   
 | j         } G 
fdd          
g d}dD ]X}|                    |dz
  |dz
  ||dz   |dz   t          |dz
            t          |          t          |dz             g           Y|                    ddd	t          j        t          t          j                  g           t          d
          }|                    ddd	ddz  |dz
  ||dz   g           |                    d |D                        |D ]} 
|          }|D ]} 
|          }||k    ||k     z
  }|                     |||          5  ||k    ||k     z
  }	 |||	            |||k    |dk                |||k    |dk                |||k     |dk                 |||k    |dk                |||k    |dk                |||k    |dk               d d d            n# 1 swxY w Y   ܌d S )Nc                   >    e Zd Zd Z fdZd Zd Zd Zd Zd Z	dS )	)LongTest.test_mixed_compares.<locals>.Ratc                    t          |t                    r|| _        d| _        d S t          |t                    rt          j        t          |                    \  }}d}d}|r8t          j        ||          }t          |          }||z  |z  }||z  }||z  }|8|dk    r||z  }d}n|}d| z  }|dk     r| }|| _        || _        d S t          d|z            )Nr      r   zcan't deal with %r)

isinstancer?   r"   r4   r!   r   frexpr*   r    r   )	rC   r   fr  CHUNKtoprl   r"   r4   s	            r   __init__z2LongTest.test_mixed_compares.<locals>.Rat.__init__  s   eS)) %B"DFDFFFu-- "B:c%jj11DAq EC # Jq%00 #A"e|u4U
U
  # Avv1H!GqyyBDFDFFF $$85$@AAAr   c                     t          |          s |          }| j        |j        z  | j        |j        z  }}||k    ||k     z
  S )N)r  r"   r4   )rC   otherr   rS   Rats       r   _cmp__z0LongTest.test_mixed_compares.<locals>.Rat._cmp__G  sP    !%-- 'CJJEv'%')91A!a%((r   c                 4    |                      |          dk    S Nr   r  rC   r  s     r   __eq__z0LongTest.test_mixed_compares.<locals>.Rat.__eq__L      {{5))Q..r   c                 4    |                      |          dk    S r!  r"  r#  s     r   __ge__z0LongTest.test_mixed_compares.<locals>.Rat.__ge__N  r%  r   c                 4    |                      |          dk    S r!  r"  r#  s     r   __gt__z0LongTest.test_mixed_compares.<locals>.Rat.__gt__P      {{5))A--r   c                 4    |                      |          dk    S r!  r"  r#  s     r   __le__z0LongTest.test_mixed_compares.<locals>.Rat.__le__R  r%  r   c                 4    |                      |          dk     S r!  r"  r#  s     r   __lt__z0LongTest.test_mixed_compares.<locals>.Rat.__lt__T  r*  r   N)
r   r   r   r  r  r$  r'  r)  r,  r.  )r  s   r   r  r    s        &B &B &BP) ) ) ) )
/ / // / /. . ./ / /. . . . .r   r  )r   gMbP?gGz?r   g      ?g@xDZbti)g      Bg      Cg      @Cr   g333333?r   r   r   r/  i N  c                     g | ]}| S r
   r
   r   s     r   r   z0LongTest.test_mixed_compares.<locals>.<listcomp>b  s    (((Qqb(((r   )r   rS   Rcmp)rT   ro   r?   r   maxsizer!   rU   )rC   rV   casestr   RxrS   Ryr1  xycmpr  s             @r   test_mixed_compareszLongTest.test_mixed_compares  s   7	. 7	. 7	. 7	. 7	. 7	. 7	. 7	. 7	. 7	.r 877 + 	7 	7ALL!c'1s7Aq3wCac((CFFC!HH6 7 7 7 7aAs{E#+,>,>?@@@ JJaAqEz1Q31Q37888((%((())) 	* 	*AQB * *SVVRBG,\\A\66 * *Uq1u-EBtUOOOBqAvtqy)))BqAvtqy)))Bq1udQh'''BqAvtqy)))Bq1udQh'''BqAvtqy)))* * * * * * * * * * * * * * **	* 	*s   BG&&G*-G*c           
      z   |                      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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d          d           |                      t          dd          d           |                      t          dd          d           |                      t          dd          d           |                      t          d d          d           |                      t          d d          d           |                      t          t          d!d"          d          d!           |                      t          t          d!d"          d          d#           |                      t          t          d!d"           d          d$           |                      t          t          d!d"           d          d%           |                     t          t          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d0          d1           |                      t          dd0          d.           |                      t          dd2          d3           |                      t          dd2          d.           |                     t          t          d&d4           |                      t          d&d5          d6           |                      t          dd7          d8           |                      t          d d7          d9           |                      t          dd7          d:           |                      t          dd7          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          t          d&dA           |                      t          dBdC          dD           |                     t          t          ddE           |                     t          t          ddF           |                     t          t          ddG           |                     t          t          ddH           |                     t          dIt          ddJ           |                     t          dIt          ddK           |                     t          dIt          ddL           |                     t          dIt          ddM           |                     t          dNt          ddO           |                     t          dPt          ddQ           dR t          t          dS          t          dT          dz             D             dU t          t          dV          t          dW          dz             D             z   D ]}|dXvr|                     t          t          dY|           |                     t          t          d|           |                     t          t          d|           |                     t          t          dZd[z  |           |                     t          t          dZd[z   |           d\D ]F}d]D ]A}|                      t          ||          t          t          |          |                     BGd S )^Ni[r4   	123456789,z123,456,789_123_456_789r   r~   1r   z-1z-3z  1z -1z+3z +1z 3r   z 1r^   r   3Xi  4d2i.z-4d28xz     4d2z    -4d2ber   BEz-bez-BEIz,x_x	4996_02d2_X	4996_02D2o2322z-2322z-oz oz 2322z+oz+2322z,o_o111_4540_1322r2   11z-1110011010010z-10011010010z-bz bz 10011010010z+bz+10011010010z,b90  _b11_0000_0011_1001z1.3_cz,cz+czCannot specify bothz_,z,_z_,dz,_dzCannot specify ',' with 's'z,szCannot specify '_' with 's'_sc                 ,    g | ]}t          |          S r
   chrr   s     r   r   z+LongTest.test__format__.<locals>.<listcomp>      IIISVVIIIr   r1   rx   c                 ,    g | ]}t          |          S r
   rW  r   s     r   r   z+LongTest.test__format__.<locals>.<listcomp>  rY  r   AZzbcdoxXeEfFgGn%r   r   rj   zeEfFgG%)r   r   r   rj   rF  i.i)	rT   r   r?   r   r   assertRaisesRegexrL   ordr!   )rC   format_specr   s      r   test__format__zLongTest.test__format__r  sy	   	3//===	3//===	3//???	3//??? 	3---C$///4%000D))51114%000D))51114%000D))51113...C$/// 	3---3---c**E222s++V444d++Z888t,,j999c**E222s++V444C$///C$///D"s33T:::D"s33T:::T244e<<<T244e<<<*fj$???
D11;???
D11;??? 	3---C$///c**F333s++W555d++V444t,,g666d++W555t,,g666d++W555t,,g666*fj$???
D11?CCC 	3...C%000c**M:::s++^<<<d++];;;t,,n===d++^<<<t,,n===d++^<<<t,,n===*fj$???t,,.ABBB 	*fa777*fa666*fa666*fa666 	z+@&!TRRRz+@&!TRRRz+@&!USSSz+@&!USSSz+H&RSUYZZZz+H&RSUYZZZ JIU3s88SXXaZ-H-HIIIIIU3s88SXXaZ-H-HIIIJ 	N 	NK"222!!*faEEE!!*faEEE!!*fb+FFF!!*fafkJJJ!!*f3iMMM % 	D 	DKG D D  {!;!;!'ek!B!BD D D DD	D 	Dr   c                    |                      t          t          t          d                     |                      t          t          t          d                     |                      t          t          t          d                     d S )Ninfz-infnan)r   r   r?   r!   r   r   s    r   test_nan_infzLongTest.test_nan_inf  sb    -eEll;;;-eFmm<<<*c5<<88888r   c                    |                      t                    5  ddz  }d d d            n# 1 swxY w Y   |                     dd           |                     dd           |                     dd           |                     dd           |                     dd           |                     dd           |                     dd           |                     dd           d S )Nr   r   r^   r   rC  r   r+   rT   rC   r<  s     r   test_mod_divisionzLongTest.test_mod_division  s-   011 	 	AA	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	!$$$1%%%2&&&B'''###!$$$!$$$1%%%%%   -11c                 *   ddz  }| }|                      ||z  d           |                      ||z  d           |                      ||z  d           |                      ||z  d           |                      d|z  d           |                      d|z  d           |                      d|z  d           |                      d|z  d           |                      d|z  |dz	  z   |z  d           |                      d|z  |dz	  z   |z  d           |                      d|z  |dz	  z   |z  d           |                      d|z  |dz	  z   |z  d           |                      ||dz  z  d	           |                      d
|z  |z  d
           ||d}dD ]$}|                     t          t          ||           %dD ],}t          ||          }|                      |dd|z             -dD ]$}|                     t          t          ||           %d S )Nr   i@  r   r   r   i  g     Ԅ@g     Ԅr<   i@B )r   r   )r   r  zhuge / 1zhuge / 2z	huge / -1z	huge / -2zmhuge / 100zmhuge / 200)z1 / hugez2 / hugez	-1 / hugez	-2 / hugez100 / mhugez200 / mhugezexpected underflow to 0 from %r)zhuge / 0z	mhuge / 0)rT   r   r   r  r+   )rC   r   r   r  r   	underflowr7   zeros           r   test_true_divisionzLongTest.test_true_division  s   Ezc***,,,t,,,t,,,T3'''T3'''UC(((UC(((#*	2d:EBBB#+!4=uEEE#*	2e;VDDD#+!4<fEEE+S111'D.D0':::!E22	7 	H 	HH mT8YGGGG7 	L 	LI)Y//FVS>JL L L L . 	H 	HD/tYGGGG	H 	Hr   c                    |                      t                    5  ddz  }d d d            n# 1 swxY w Y   |                     dd           |                     dd           |                     dd           |                     dd           |                     dd           |                     dd           |                     dd           |                     dd           |                     dd           |                     dd           |                     dd           |                     dd           d S )Nr   r   r   r^   r   r   rh  ri  s     r   test_floordivzLongTest.test_floordiv  s   011 	 	QA	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	###"%%%"%%%1%%%A&&&2&&&2&&&!$$$A&&&2&&&2&&&!$$$$$rk  Tc           
         	 |r8t          t          |          t          |                    dt          z  k     rd S 	 t          t	          ||                    }n# t
          $ r d}Y nt          $ r d}Y nw xY w	 t          ||z            }n# t
          $ r d}Y nt          $ r d}Y nw xY w|                     ||d                    ||||                     d S )Nr   r   zerodivisionz7Incorrectly rounded division {}/{}: expected {}, got {})	r-   r*   r/   r   r8   r   r+   rT   r   )rC   r1   r2   
skip_smallr   r   s         r   check_truedivzLongTest.check_truediv  s/   	3  	#c!ffc!ff--<??F	&GAqMM**HH 	" 	" 	"!HHH  	& 	& 	&%HHH	&	!q1u++CC 	 	 	CCC  	! 	! 	! CCC	! 	3 )//5vaHc/J/J	L 	L 	L 	L 	Ls/   A A7)A76A7;B B*B*)B*c                 	   |                      dd           |                      dd           |                      dd           |                      dd           |                      dd           |                      ddt          z  z  d           |                      dd	dt          t          z
  z  z             |                      ddd
z  z  d           |                      ddddz  z             dt          t          t          t          t          z
  f}|D ]}t	          |dz
  |dz             D ]}|                      ddt          |d          z  z  ddt          | d          z  z             |                      ddt          |d          z  z  ddt          | d          z  z             ddddddd
z  dddddddz   fD ]X}t	          dd          D ]E}|                      |t          z  |z   |           |                      |t          z  |z   |            FYt	          d          D ]=}|                      dt          z  dz   dz  ddz  z  d|z  z   dt          z  dz             >|                      dd           |                      d d!           t	          d"          D ]@}|                      d|dz   z  d|z             |                      d|z  d|dz   z             Addd#dd$d%dd&ddd
z  dddddddz   fD ]9}t	          dd          D ]&}|                      dt          z  |z  |z   |           ':t	          d'd(          D ]}|                      |dd)z             d*dd
z  dd"z  fD ]}t	          d"          D ]}t          j        d|          }t          j        |d|z  dz             }	|                      ||	           |                      | |	           |                      ||	            |                      | |	            t	          d+          D ]}
t          j        d"          }t          j        dd"          }t          j        d|z            }t          j        dd|z            }|                      ||           |                      ||            |                      | |           |                      | |            d S ),N{   r   i8r^   rC  ige~ r   rQ  iNF rj   í l       90r   Q   r   i0& iC r      r   r   ii)   2   ri         i
  l   E,J_   l     Jb   r  r   r   r       i   i4  l    d(	 r	  )	ru  r   r/   r.   rL   r-   r,   r@   	randrange)rC   basesr   r5   mr"   rO   Mr1   r2   r<  a_bitsb_bitsr   rS   s                  r   $test_correctly_rounded_true_divisionz-LongTest.test_correctly_rounded_true_division9  s    	3"""4###1a   1b!!!1a   ;K7???5&1|k/I+J"JKKK5C<///;ae444 L+kL8: 	P 	PDTBYr	22 P P""5CQKK#7q#sdA,,9NOOO""5CQKK#7q#sdA,,9NOOOOP
 Q2uafb"c6BF74 	? 	?A3^^ ? ?""1%5#5#91===""1%5#5#9A2>>>>?
 s 	2 	2A <! 3U:1c6AAqDHl?502 2 2 2 	1d### 	02GHHHt 	1 	1ArAaCy"a%000r1ub1Q3i0000 Q1aRUAsFb"c6BF74 	= 	=A3^^ = =""1l?1#4q#8!<<<<= sB 	+ 	+Aq!T'**** "c'2t8, 	+ 	+A4[[ + +$Q**$Q!A..""1a(((""A2q)))""1qb)))""A2r****+ u 	' 	'A%d++F%a..F F++A AvI..Aq!$$$q1"%%%r1%%%rA2&&&&	' 	'r   c                    |                      t                    5  ddz   d d d            n# 1 swxY w Y   |                      t                    5  dddz   z   d d d            n# 1 swxY w Y   |                      t                    5  ddz	   d d d            n# 1 swxY w Y   |                      t                    5  dddz   z	   d d d            d S # 1 swxY w Y   d S )Nr   rC  r   r  )r   r   r   s    r   test_negative_shift_countz"LongTest.test_negative_shift_count  s   z** 	 	"HH	 	 	 	 	 	 	 	 	 	 	 	 	 	 	z** 	 	AI,	 	 	 	 	 	 	 	 	 	 	 	 	 	 	z** 	 	"HH	 	 	 	 	 	 	 	 	 	 	 	 	 	 	z** 	 	AI,	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	sB   -11
A((A,/A,BB#&B#
CC"Cc                 |   |                      dd           |                      dd           |                     t                    5  ddz   d d d            n# 1 swxY w Y   |                      dddz  z  d           |                     t                    5  dddz   z   d d d            d S # 1 swxY w Y   d S )Nr   r   r   r  )rT   r   r   r   s    r   test_lshift_of_zerozLongTest.test_lshift_of_zero  sH   ###!$$$z** 	 	GG	 	 	 	 	 	 	 	 	 	 	 	 	 	 	qDy)1---z** 	 	19	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s$   AA A
B11B58B5c                     |                      dt          j        z  d           |                      dt          j        dz   z  d           d S )Nr   r   rT   r   r2  r   s    r   test_huge_lshift_of_zeroz!LongTest.test_huge_lshift_of_zero  sH    
 	ck)1---s{Q/33333r   r  g?F)memusedry_runc                 r    |                      dt          j        dz   z  ddz  t          j        z             d S )Nr   r  r  )rC   sizes     r   test_huge_lshiftzLongTest.test_huge_lshift  s7     	s{T12AI4LMMMMMr   c                 J   ddz  }|                      d|z	  d           |                      d|z	  d           |                      d|z	  d           |                      d|z	  d           |                      d	d
z  |z	  d           |                      d	d
z   |z	  d           d S )Nr   r  r   r   ir   ic  ir   r   rT   )rC   
huge_shifts     r   test_huge_rshiftzLongTest.test_huge_rshift  s    $Y
z)1---#*,b111+Q///%J.333C:-q111!S&J.33333r     g?c                     ddz  dz   t           j        z  }|                     |t           j        dz   z	  ddz  dz              |                     |t           j        dz   z	  d           d S )Nr   r  r   i  rh   r  r   )r   r2  rT   )rC   r  r   s      r   test_huge_rshift_of_hugez!LongTest.test_huge_rshift_of_huge  si     cRCK/#+/2Q#XNCCC#+"45q99999r   c                 x   |                      dd           |                      dd           |                      dd           |                      dd           |                      dd           |                      dd           |                      dd           |                      dd           |                      ddz  d	z	  dd
z             |                      ddz   d	z	  dd
z              |                      ddz  d	z   d	z	  dd
z             |                      ddz  d	z    d	z	  dd
z   d	z
             d S )Nr   iii1  iir   r   r      r  r   s    r   test_small_rshiftzLongTest.test_small_rshift  sV   "%%%S)))"%%%S)))C(((t,,,C(((t,,,C1af---!S&A3w///!S&1**AsF3331c6A:!+afWq[99999r   c                    |                      dd           |                      dd           |                      dd           |                      dd           |                      ddz  dz	  ddz             |                      ddz   dz	  ddz              |                      dt          t          z  z
  t          z	  t                      |                      t          dz
  t          t          z  z
  t          z	  t                      d S )	Nr   r   r   rC  r   r   w   r   )rT   BASEr>   r   s    r   test_medium_rshiftzLongTest.test_medium_rshift  s    !$$$R(((A&&&r***C1af---!S&A3w/// 	!d4i-E1D5999$(T$Y.584%@@@@@r   c                 6   |                      dd           |                      dd           |                      dd           |                      dd           |                      ddz  dz	  ddz             |                      ddz   dz	  ddz              d S )Nr   r   r   r   r  `   r  r   s    r   test_big_rshiftzLongTest.test_big_rshift  s    1%%%b)))Q'''+++C2q"u---!S&BB/////r   c                 6   |                      dd           |                      dd           |                      dd           |                      dd           |                      ddz  dz  ddz             |                      ddz   dz  ddz              d S )	NT   iib  ir   r  r   r   r  r   s    r   test_small_lshiftzLongTest.test_small_lshift  s    "%%%S)))4(((e,,,C1af---!S&A3w/////r   c                     |                      dd           |                      dd           |                      dd           |                      dd           d S )Ni T  i i  i <r  r   s    r   test_medium_lshiftzLongTest.test_medium_lshift  s`    %(((V,,,F+++w/////r   c                 6   |                      dd           |                      dd           |                      dd           |                      dd           |                      ddz  dz  ddz             |                      ddz   dz  ddz              d S )	Nl        l     l       l    r   r   r     r  r   s    r   test_big_lshiftzLongTest.test_big_lshift  s    :...k222\222666C2q#v...!S&BC00000r   c                     ddz  }| dz   }|dz   }|                      ||z   d           |                      ||z
  d           d S )Nr   rj   r   )assertIs)rC   r1   r2   cs       r   #test_small_ints_in_huge_calculationz,LongTest.test_small_ints_in_huge_calculation  sU    HBFEa!eQa!eQr   c                 d   |                      t          ddd          d           |                      dd           d\  }}}|                      ||z  |z  d           |                      t          ddd          d           |                      dd           d	\  }}}|                      ||z  |z  d           |                      t          dd
dd
z  dz
            d           |                      dd
z  dd
z  dz
  z  d           dd
dd
z  dz
  }}}|                      ||z  |z  d           d S )Nri   r^     r   )ri   r^   r     r   r   )r   r  r   rj   )r  pow)rC   r1   r   r  s       r   test_pow_uses_cached_small_intsz(LongTest.test_pow_uses_cached_small_ints  s;   c"aooq)))mQ'''1aa1fqj!$$$c!R--q111-q111$1aa1fqj!$$$c!S!S&1*--q111a3h!s(Q,/333S!S&1*a1a1fqj!$$$$$r   c                    ddz  }|                      |dz   |z  d           |                      |dz   |z  d           |                      ||dz  z  d           |                      ||dz  z  d           t          d|z  dz   |          \  }}|                      |d           |                      |d           t          d|z  dz   |          \  }}|                      |d           |                      |d           t          d| z  dz
  |           \  }}|                      |d           |                      |d           t          d|z  dz
  |           \  }}|                      |d           |                      |d           d S )	Nri   rj   r   r   r   r^   r   rC  )r  r0   )rC   bigr(   r6   s       r   "test_divmod_uses_cached_small_intsz+LongTest.test_divmod_uses_cached_small_ints  s   CisQw#oq)))sQw3&***ccQh'+++ccRi("---a#gk3''1aab3hnc**1aaaC4j1nsd++1aaa#gkC4((1aar   c           	         t          dd          D ]=}|                     ||dz              |                     ||dz             |                     ||dz
             |                     ||dz             |                     ||dz             |                     ||dz             |                     ||dz             |                     ||             |                     ||dz             |                     |t          t          |                               |                     ||dz  dz	  t          |                     ?d}|                     ||z
  d           |                     d|z  d           d S )Nrz    r   r   r   r   l            )rL   r  r?   r   )rC   rO   s     r   test_small_intszLongTest.test_small_ints1  ss   r3 	. 	.AMM!QU###MM!QU###MM!QU###MM!Q!V$$$MM!QV$$$MM!QU###MM!QU###MM!qbS!!!MM!QT"""MM!SQ[[)))MM!QT1Wc!ff----a!eQa!eQr   c                    d}t          dd          D ]}|                                }|                     |t          t	          |                              d                               |dk    r:|                     d|dz
  z  t          |          cxk    od|z  k     nc            n|                     |d           |dk    rb|                     |dt          j	        t          j
        t          |                    t          j
        d          z  |z             z              |                     d                                d           |                     d                                d           |                     d                                d           |                     d                                d           |                     d	                                d           d
D ]}d|z  }|                     |dz
                                  |           |                     d|z
                                  |           |                     |                                |dz              |                     |                                 |dz              |                     |dz                                   |dz              |                     | dz
                                  |dz              d S )Ng|=ii  z-0br   r   r   r   r   )r   r^   r   r   ry  r  r  !   ?   @      )rL   r   rT   lenr   lstriprB   r*   r   floorr  )rC   tinyr   krO   r1   s         r   test_bit_lengthzLongTest.test_bit_lengthC  s   vu%% 	> 	>AAQCFFMM%$8$8 9 9:::AvvAaCCFF 9 9 9 9QT 9 9 9 9::::  A&&&Avv
   A
Q((!4t;)= )= %= > > > 	!))1---!))1---"**A...!))1---"**A...< 	7 	7A1Aac--//333ac--//333a^^--qs333qb__..!444ac--//1555qbd..00!A#6666	7 	7r   c                 .   t          dd          D ]J}|                     |                                t          |                              d                     KdD ]}d|z  }|                     |                                d           |                     |dz
                                  |           |                     |dz                                  d           |                     |dz
  d	z                                  |d
z
             d S )Nir  r>  )ri   ry  r  r  A   i  iZ i r   r   r  r   i  r   )rL   rT   	bit_countr   count)rC   r1   r5   s      r   test_bit_countzLongTest.test_bit_counte  s   ud## 	? 	?AQ[[]]CFFLL,=,=>>>>= 	C 	CC3AQ[[]]A...a!e..00#666a"f//111555q1um6688#'BBBB	C 	Cr   c                    i ddddddddddddddd	dd
ddddddddddddddddddddd}t          ddd          D ]r}|                                D ][\  }}t          ||z   d          }||z   }|                     ||           |                     t          |          t                     \s|                     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 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.d          d0           |                     t          d.d*          d1           |                     t          d.d2          d3           |                     t          d.d4          d5           |                     t          d.d6          d7           |                     t          d.d8          d9           |                     t          d.d:          d;           |                     t          d.d<          d=           |                     t          d.d>          d?           |                     t          d.d@          d           |                     t          d.dA          d           |                     t          d.dB          d           t          dd"          D ]^}t          d|z  dCz   d*          }d|z  dDz   }|                     ||           |                     t          |          t                     _t          d          D ]w}t          d"          D ]e}	t          j        dEdF          }
t          |
|          }|                     ||
           |                     t          |          t                     fxdGdHdIdJdd"z  dd"z  fD ]&}|                     t          dK|          dK           't          d"          D ]d}	t          j        dEdF          }
t          |
          }|                     ||
           |                     t          |          t                     edL}|D ]$}| 	                    t          t          d|           %d S )MNr   r   r   r^   r   rh   r   ri   r   r   r   r   r   r   r]   r   r  r   )ry        ii  r   ijr   i8ikr]  iii1   r|  3   rj         r  r~     i,  iԡ rC  i i i l   ! l   ! l   ~! l    ! r   l   ! rz  l   `! il    ! rg  l    '! il    z+ il    v|o r}  l    ,Gx iiiiF i ir	  r   r   r   r   i{ )brianr   y                )rL   itemsroundrT   r  typer?   r@   r  r   r   )rC   	test_dictoffsetr  r   r   r   expectr"   rO   r   huge_nbad_exponentsr  s                 r   
test_roundzLongTest.test_roundp  s   8Qq 8!A 8q 8Aa 81 8a 8r8R8!"28'(8-/846r8;=b8BDR8IKB88r8&(RB8 8 8	 D#r** 	. 	.F!)) . .1AfHb))V8  h///d3ii----	. 	tR$///tR$///sB...sB+++sB+++r2***q"q)))q"q)))r2***r2***r2,,,sB---sB---sB---sB---vr**F333vr**F333{B//==={B//==={B//==={B//==={B//==={B//==={B//==={B//==={B//==={C00+>>>{C00!444{C00!444{D111555 r3 	* 	*AA++CUV^FS&)))MM$s))S)))) q 	. 	.A3ZZ . .$VU33Aqkk  a(((d3ii----	.
 uguafb#gE 	> 	>FU7F33W==== s 	* 	*A //A((CS!$$$MM$s))S)))) + 	6 	6Ai15555	6 	6r   c                     d= fd	}i ddddddd	d
dddddddddddddddddddddd d!d"d#d$} ||d%d&'           i ddddddd	d
dddddddd(dd)dddddd*dddd+dd,d!d-d#d.} ||d/d&'           dddddddd0d1d2d3
} ||d%d'           dddddd*dd+d1d4d3
} ||d/d'                                 t          dj        dd%d'                                 t          dj        dd%d&'                                 t          dj        dd/d'                                 t          dj        dd/d&'                                 t          dj        d5d%d'                                 t          dj        d5d/d'                                d                    dd%          d6                                d                    d7d%          d8                                d                    d7d%          d9                                d                    d7d%d&'          d:                                 t          dj        dd%            G d; d<t                    }                     d                    d |d%                    d                                d                    d |d/                    d6           d S )>NFc           	         d	d}|                                  D ]Z\  }}	                     |                    t          |          ||          |           n7# t          $ r*}t          d                    |||                    |d }~ww xY wt          |          dk    rg|dk    ra|s_	                     |                                |           n5# t          $ r(}t          d                    |                    |d }~ww xY w	                      ||t          |          ||          |           %# t          $ r*}t          d                    |||                    |d }~ww xY wd S )
NFc                      |dk    rt          |          }n"|dk    rt          t          |                    }t           fd|D                       S )Nlittler  c              3   .   K   | ]}|d z  z	  dz  V  dS )r      Nr
   )r   rO   r"   s     r   r   zSLongTest.test_to_bytes.<locals>.check.<locals>.equivalent_python.<locals>.<genexpr>  s0      >>1a1Q3h$.>>>>>>r   )rL   reversedbytes)r"   length	byteordersignedorders   `    r   equivalent_pythonz@LongTest.test_to_bytes.<locals>.check.<locals>.equivalent_python  s\    ((!&MMEE%''$U6]]33E>>>>>>>>>>r   r  z4failed to convert {} with byteorder={} and signed={}r   r  +failed to convert {} with default argumentszmCode equivalent from docs is not equivalent for conversion of {0} with byteorder byteorder={1} and signed={2}F)r  rT   to_bytesr  	ExceptionAssertionErrorr   testsr  r  r  r  r   errrC   s          r   checkz%LongTest.test_to_bytes.<locals>.check  s    ? ? ? ? #(++-- O OhC$$c(mmYvNN " " " " ! C C C(Ni88: :?BCC x==A%%)u*<*<V*<4(((CCCC$ 4 4 4,I#VD\\+ +0344

O$$)) #h--6K K K    
 ! O O O(%%+VD)V%D%DF F LOOO3O OsG   9A
B%%B

B.(C
D	!#DD	0D??
E3	%E..E3r       r      r         r         r                    r                   s                        r  Tr                               r              )
r   r   r  r   r  r  r     r          r   r   rh   s       s        s   c                       e Zd ZdS )&LongTest.test_to_bytes.<locals>.SubStrNr   r   r   r
   r   r   SubStrr  :          Dr   r!  r  )r   r   r  rT   r   )rC   r  tests1tests2tests3tests4r!  s   `      r   test_to_byteszLongTest.test_to_bytes  s   %	O %	O %	O %	O %	O %	OP
w
w
 
 '	

 '
 +
 
 
 +
 +
 
 
 ;
 O
 ?
  O!
" o#
& 	feD))))
w
w
 
 '	

 '
 +
 
 
 +
 +
 
 
 ;
 K
 ?
  O!
" o#
& 	fht,,,, "
 
 	feE**** "
 
 	fhu-----#E%PPP-#E$OOO-#HUSSS-#HTRRR-"5OOO-"8ERRR!a//555!a//1HIII!a//1HIII"q%==0	2 	2 	2-!q%@@@	 	 	 	 	S 	 	 	!a77AAA!a)9)9::C@@@@@r   c                     dM fd	}i ddddddddd	dd
ddddddddddddddddddddddd d!d"d#d$d%} ||d&d'(           i ddddddddd	dd
dddddddddddd)dd*dddddd	ddd d!d"d#d$d+} ||d,d'(           ddddd-ddd d.d"d/d0} ||d&d(           ddddd-ddd d.d"d/d1} ||d,d(            G d2 d3t                     }                     t          |                    dd&                    |                                |                    dd&          d                                t          |                    dd&d(                    |                                |                    dd&d(          d                                t          |                    dd,                    |                                |                    dd,          d                                t          |                    dd,d(                    |                                |                    dd,d(          d                                t                               g d4d&d'(          d#                                t                               d4d&d'(          d#                                t                               t          d5          d&d'(          d#                                t                               t          d5          d&d'(          d#                                t                               t          j        d6d5          d&d'(          d#                                t                               t          d5          d&d'(          d#                                t          t           j        dgd&                                t          t           j        dgd7                                t          t           j        dgd8                                t          t           j        d9d&                                t          t           j        d:d&                                t          t           j        dd&                                t          t           j        dd&d'                                t          |j        d9d&                                t          |j        d:d&                                t          |j        dd&                                t          t           j        dd&d'            G d; d<t                     }|                    dd&          }                     t          |          |                                |d=            G d> d?t                     }	|	                    dd&          }                     t          |          |	                                |d                                t          |d@dA          dB            G dC dD          }
 G dE dF          } G dG dH          } G dI dJ          }                     t                                |
                      d                                t          t           j         |                                            t          t           j         |                                            t          t           j         |                        G dK dLt                    }                     t                               d |d&                    d                                t                               d |d,                    d           d S )NNFc           	         dd}|                                  D ]7\  }}	                     t                              |||          |           n7# t          $ r*}t          d                    |||                    |d }~ww xY w|dk    rg|se	                     t                              |          |           n5# t          $ r(}t          d                    |                    |d }~ww xY w	                      ||||          |           # t          $ r*}t          d                    |||                    |d }~ww xY wd S )	NFc                    |dk    rt          |           }n"|dk    rt          t          |                     }t          d t          |          D                       }|r%|r#|d         dz  r|ddt	          |          z  z  z  }|S )Nr  r  c              3   ,   K   | ]\  }}||d z  z  V  dS )r   Nr
   )r   rO   r2   s      r   r   zULongTest.test_from_bytes.<locals>.check.<locals>.equivalent_python.<locals>.<genexpr>G  s.      GGTQQqSGGGGGGr   r   r   r   r   )r_   r  sum	enumerater  )
byte_arrayr  r  little_orderedr"   s        r   r  zBLongTest.test_from_bytes.<locals>.check.<locals>.equivalent_pythonA  s    ((%)*%5%5NN%''%)(:*>*>%?%?NGGY~-F-FGGGGG 4n 4.2Dt2K 4aN 3 3333Ar   r  z6failed to convert {} with byteorder={!r} and signed={}r  r  zeCode equivalent from docs is not equivalent for conversion of {0} with byteorder={1!r} and signed={2}r  )r  rT   r?   
from_bytesr  r  r   r  s          r   r  z'LongTest.test_from_bytes.<locals>.check@  s   
 
 
 
 #(++-- C ChC$$tYvFF " " " " ! C C C(Pi88: :?BCC %%f%4((NN400$& & & & % 4 4 4,I#VD\\+ +0344
	C$$))$	&III     ! C C C(Pi88: : @CCC5C CsG   1A
B%BB.C
C4#C//C48"D
E&%EEr   r   r  s     r  r   r  r  r   r  r  r  r  r   r  r  r  r  r   r  r  r  r  r  r  r  r  r  r	  r  r
  r  r  r  )r  r  r  r  r  Tr  r  r  )r  r  r  r  r  r   r  r  )r   r  r  r  r  r  r  r	  r  r  r  )r   r  r  r  r  r  r  r  r  r  r  c                       e Zd ZdS )'LongTest.test_from_bytes.<locals>.myintNr   r
   r   r   myintr2    r"  r   r3  )r  r   r   r  Bzbig zlittle r    c                       e Zd Zd ZdS )(LongTest.test_from_bytes.<locals>.myint2c                 >    t                               | |dz             S )Nr   )r?   __new__)clsr   s     r   r9  z0LongTest.test_from_bytes.<locals>.myint2.__new__  s    {{3	222r   Nr   r   r   r9  r
   r   r   myint2r7    s#        3 3 3 3 3r   r<  r   c                       e Zd Zd ZdS )(LongTest.test_from_bytes.<locals>.myint3c                     d| _         d S )Nbar)foo)rC   r   s     r   r  z1LongTest.test_from_bytes.<locals>.myint3.__init__  s     r   N)r   r   r   r  r
   r   r   myint3r>    s#        ! ! ! ! !r   rB  rA  noner@  c                       e Zd Zd ZdS ),LongTest.test_from_bytes.<locals>.ValidBytesc                     dS )Nr  r
   r   s    r   	__bytes__z6LongTest.test_from_bytes.<locals>.ValidBytes.__bytes__  s    wr   Nr   r   r   rG  r
   r   r   
ValidBytesrE    s#            r   rI  c                       e Zd Zd ZdS ).LongTest.test_from_bytes.<locals>.InvalidBytesc                     dS )Nabcr
   r   s    r   rG  z8LongTest.test_from_bytes.<locals>.InvalidBytes.__bytes__  s    ur   NrH  r
   r   r   InvalidBytesrK    s#            r   rN  c                       e Zd ZdS ).LongTest.test_from_bytes.<locals>.MissingBytesNr   r
   r   r   MissingBytesrP    s          r   rQ  c                       e Zd Zd ZdS ).LongTest.test_from_bytes.<locals>.RaisingBytesc                     ddz   d S )Nr   r   r
   r   s    r   rG  z8LongTest.test_from_bytes.<locals>.RaisingBytes.__bytes__  s    Ar   NrH  r
   r   r   RaisingBytesrS    s#            r   rU  c                       e Zd ZdS )(LongTest.test_from_bytes.<locals>.SubStrNr   r
   r   r   r!  rW    r"  r   r!  r  )r?   r  r  r0  rT   	bytearrayarray
memoryviewr   r   r   getattrr+   r   )rC   r  r#  r$  r%  r&  r3  r<  rO   rB  rI  rN  rQ  rU  r!  s   `              r   test_from_byteszLongTest.test_from_bytes?  s	   +	C +	C +	C +	C +	C +	C\

Q
 
 Q	

 
 R
 
 T
 T
 
 S
 
 
 
 
  !
" #
$  "#%+
 
 
. 	feD))))

Q
 
 Q	

 
 R
 
 T
 T
 
 S
 
 
 
 
  !
" #
$  "#%+
 
 
. 	fht,,,, "
 
 	feE**** "
 
 	fhu----	 	 	 	 	C 	 	 	 	d5++GU;;<<eDDD))'5991===!!'5!??@@%	I 	I 	I))'5)GGKKKd5++GX>>??GGG))'8<<a@@@d5++Xe , - - . ./4	6 	6 	6))'8E)JJANNNNN;;;dN;;V	E 	E 	ENN;dN;;V	E 	E 	Eo&&d ( < <=C	E 	E 	Eo&&d ( < <=C	E 	E 	EK_--uT ( C CDJ	L 	L 	L''t ( = =>D	F 	F 	F*cnseUCCC*cnqc9EEE*cnqc<HHH)S^R???)S^VUCCC)S^Q>>>)S^QtDDD)U%5r5AAA)U%5vuEEE)U%5q%@@@)S^QtDDD	3 	3 	3 	3 	3S 	3 	3 	3 gu--d1ggv&&&A	! 	! 	! 	! 	!S 	! 	! 	! gu--d1ggv&&&AE622E:::	 	 	 	 	 	 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	

55q999)S^\\^^DDD)S^\\^^DDD+S^\\^^LLL	 	 	 	 	S 	 	 	VVE]];;Q???1A1ABBAFFFFFr   c                     t          dd          D ]I}|                    dd          }|                     t                              |d          |           Jd S )Nrz  r  r   Tr  )rL   r  r  r?   r0  )rC   rO   r2   s      r   test_from_bytes_smallzLongTest.test_from_bytes_small  sa     r3 	= 	=A

1T
**AMM#..4.88!<<<<	= 	=r   c                      G d dt                     fdt          d          D             }t          t           |          D ]}|                     |d           d S )Nc                       e Zd ZddZdS )<LongTest.test_access_to_nonexistent_digit_0.<locals>.Integerr   c                 J    t                               | |          }d|_        |S )NrA  )r?   r9  rA  )r:  r   rC   s      r   r9  zDLongTest.test_access_to_nonexistent_digit_0.<locals>.Integer.__new__  s!    {{3.. r   Nr   r;  r
   r   r   Integerra    s(             r   rd  c                 &    g | ]} d           S rc  r
   )r   rO   rd  s     r   r   z?LongTest.test_access_to_nonexistent_digit_0.<locals>.<listcomp>  s!    4441GGAJJ444r   r  r   )r?   rL   maprT   )rC   integersr"   rd  s      @r   "test_access_to_nonexistent_digit_0z+LongTest.test_access_to_nonexistent_digit_0  s    	 	 	 	 	c 	 	 	 5444d444S(## 	# 	#AQ""""	# 	#r   c                     dD ]]}dD ]X}|                      t          ||z            t                     |                      t          ||z	            t                     Y^d S )N)TF)r   r   )rT   r  r?   )rC   r   r'   s      r   test_shift_boolzLongTest.test_shift_bool"  sv    " 	< 	<E < <  eun!5!5s;;;  eun!5!5s;;;;<	< 	<r   c           
          G d dt                     }ddddt          j        dz   dd |d	          g}|D ]}|                                \  }}|                     ||ft          |          df           |                     t          |          t                      |                     t          |          t                      d S )
Nc                       e Zd ZdS )-LongTest.test_as_integer_ratio.<locals>.myintNr   r
   r   r   r3  rm  *  r"  r   r3  ri   r   r}  r   TFr   )r?   r   r2  as_integer_ratiorT   r  )rC   r3  r  r   	numeratordenominators         r   test_as_integer_ratiozLongTest.test_as_integer_ratio)  s    	 	 	 	 	C 	 	 	QQaueeBiiH 	5 	5E%*%;%;%=%="I{i5E

AGGGT)__c222T+..4444		5 	5r   c           	          t          dd          D ]d}d|z  dz
  }|                     ||          5  |                     |dz  dd|z  z  d|dz   z  z
  dz              d d d            n# 1 swxY w Y   ed S )Nr   i  )bitlenr"   r   )rL   rU   rT   )rC   rs  r"   s      r   test_squarezLongTest.test_square3  s    
 Asmm 	C 	CFf!AVq11 C C  A1v:&1!+<=AC C CC C C C C C C C C C C C C C C	C 	Cs   ,A**A.	1A.	N)T)=r   r   r   rJ   rP   r[   rf   rp   rs   rv   ry   r|   r   r   r   r   r   r   r   requires_IEEE_754r   r  r  r8  ra  re  rj  ro  rq  ru  r  r  r  cpython_onlyr  
bigmemtestr   r2  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r'  r\  r^  rh  rj  rq  rt  r
   r   r   r:   r:   s   sJ         0  C C C#> #> #>N+ + +.+ + +6+ + +/ / /
S 
S 
S> > >1 1 1' ' '6M 6M 6Mr5 5 5"0 0 0" C0 C0 C0J8 8 8>; ; ;$Z* Z* Z*x_D _D _DB9 9 9
& & & H  H  HD% % %&L L L L< Y' Y' Y'v     4 4 4 Wd*8UKKKN N LK N4 4 4 Wc)$FFF: : GF :
: : : 
A 
A 
A0 0 00 0 00 0 01 1 1       % % %    0     $ 7  7  7D	C 	C 	CH6 H6 H6TCA CA CAJLG LG LG\ = = =# # #< < <5 5 5
C 
C 
C 
C 
Cr   r:   __main__)#unittestr  r   r   r@   r   rY  int_infobits_per_digitr>   r  rN   ra   r`   r{   rr   rL   rO   rb   r   r-   r   r   r   min_expr.   r   r/   r,   r   r8   TestCaser:   r   mainr
   r   r   <module>r     s          



    	#Ezax  	 aD$!)%79K
L	qw  ANN26	qBB      #8#8#8#8#88 8
.
n$n$~&k>Al(BQ(F$GG *' *' *'\+ + +<JC JC JC JC JCx  JC JC JCX. zHMOOOOO r   