mò
­fIc           @   s÷  d  k  l Z l Z l Z l Z d k l Z d k l Z l Z d Z	 d e	 Z
 e
 d Z d Z d Z e e d d d e
 e
 d ?g ƒ Z e i d ƒ e i d	 ƒ d
 Z x3 e d e	 ƒ D]! Z e i e d ƒ e d >Z q¸ W[ e e d „  e ƒ e d „  e ƒ Z d „  Z d „  Z d „  Z d „  Z e d „ Z d „  Z d „  Z d „  Z d „  Z e d „ Z d „  Z d „  Z  e d „ Z! e d „ Z" d „  Z# d „  Z$ d „  Z% d „  Z& e ƒ  e ƒ  e ƒ  e! ƒ  e" ƒ  e# ƒ  e$ ƒ  e% ƒ  e& ƒ  d S(    (   s   verifys   verboses
   TestFaileds   fcmp(   s   join(   s   randoms   randinti   i   i   iF   i    l   UUª*UUª* l   ª*UUª*UU
 l    c         C   s   |  S(   N(   t   x(   R    (    (    t+   /mit/python/lib/python2.4/test/test_long.pyt   <lambda>   s    c         C   s   |  S(   N(   R    (   R    (    (    R   R      s    c         G   s*   |  p t t t t | ƒ d ƒ ‚ n d  S(   Nt    (   t   okt
   TestFailedt   joint   mapt   strt   args(   R   R	   (    (    R   t   check"   s    c         C   s2  t  |  d j ƒ |  t } | t d } d } d } t t ƒ  t d ƒ d B} x  | | j  o’ | d ?d } t | | | ƒ } t  d | j o
 t j n ƒ | | } | | >} | d @o | d | >d B} n t t ƒ  t d ƒ } qR Wt  | | j o
 | j n ƒ t ƒ  d j  o | } n | S(   Ni    i   l    i   f0.5(   t   verifyt   ndigitst   SHIFTt   nbits_hit   nbits_lot   answert   nbitst   intt   randomt   rt   bitst   min(   R   R   R   R   R   R   R   (    (    R   t   getran,   s(    
 !

!c         C   sS   d } x+ t |  ƒ D] } | t >t d t ƒ B} q Wt ƒ  d j  o | } n | S(   Nl    i    f0.5(   R   t   rangeR   t   iR   t   randintt   MASKR   (   R   R   R   (    (    R   t   getran2D   s     c         C   s  t  |  | ƒ \ } } |  | |  | } } |  | | |  } } t	 | | j d |  | ƒ t	 | | j d |  | ƒ t	 | | j d |  | ƒ t	 |  | | | j d |  | ƒ | d j o. t	 d | j o
 | j  n d |  | ƒ n+ t	 | | j  o
 d j n d |  | ƒ d  S(   Ns#   multiplication does not commute fors,   divmod returns different quotient than / fors'   divmod returns different mod than % fors   x != q*y + r after divmod oni    s   bad mod from divmod on(
   t   divmodR    t   yt   qR   t   q2t   r2t   pabt   pbaR
   (   R    R   R    R!   R   R"   R   R#   (    (    R   t   test_division_2N   s    !.c         C   s—   t  o	 d GHn t d |  d ƒ t t t d ƒ } | i t d ƒ xK | D]C } t | ƒ } x. | D]& } t | ƒ p d } t | | ƒ qe WqL Wd  S(   Ns   long / * % divmodi   i   i   l    (   t   verboseR   t	   maxdigitst   KARATSUBA_CUTOFFt   digitst   appendt   lenxR   R    t   lenyR   R$   (   R&   R(   R   R    R+   R*   (    (    R   t   test_division[   s    	  c    
   
   C   s  t  o	 d GHn t d d ƒ t t t d ƒ }  |  i t d t d g ƒ g  } |  D] } | | t qV ~ }	 x |	 D]• } d | >d } x~ |	 D]v } | | j  o q’ n d | >d } | | } d | | >d | >d | >d } t | | j d | d | | | ƒ q’ Wqw Wd  S(	   Nt	   Karatsubai   i   i
   id   l    s   bad result fort   *(   R%   R   R'   R(   t   extendt   _[1]t   digitR   R   t   abitst   at   bbitst   bR    R   R
   (
   R(   R3   R1   R5   R4   R2   R0   R   R    R   (    (    R   t   test_karatsubah   s     	 %  
"c         C   s[  t  |  d @d j d |  ƒ t  |  d B|  j d |  ƒ t  |  d A|  j d |  ƒ t  |  d @|  j d |  ƒ t  |  d Bd j d |  ƒ t  |  d A|  j d |  ƒ t  |  |  j d	 |  ƒ t  |  |  @|  j d
 |  ƒ t  |  |  B|  j d |  ƒ t  |  |  Ad j d |  ƒ t  |  |  @d j d |  ƒ t  |  |  Bd j d |  ƒ t  |  |  Ad j d |  ƒ t  |  d |  j o |  d j n d |  ƒ xÎ t d t ƒ D]¼ } d | } t  |  | >| ?|  j d |  | ƒ t  |  | |  | ?j d |  | | ƒ t  |  | |  | >j d |  | | ƒ t  |  | @|  | ?| >j o |  | d @j n d |  | | ƒ q—Wd  S(   Ni    s   x & 0 != 0 fors   x | 0 != x fors   x ^ 0 != x foriÿÿÿÿs   x & -1 != x fors   x | -1 != -1 fors   x ^ -1 != ~x fors   x != ~~x fors   x & x != x fors   x | x != x fors   x ^ x != 0 fors   x & ~x != 0 fors   x | ~x != -1 fors   x ^ ~x != -1 fori   s   not -x == 1 + ~x == ~(x-1) fori   l    s   x << n >> n != x fors   x // p2 != x >> n for x n p2s   x * p2 != x << n for x n p2s6   not x & -p2 == x >> n << n == x & ~(p2 - 1) for x n p2(   R
   R    R   R   t   nt   p2(   R    R8   R7   (    (    R   t   test_bitop_identities_1‚   s.    2 
!$$3c         C   sP  t  |  | @| |  @j d |  | ƒ t  |  | B| |  Bj d |  | ƒ t  |  | A| |  Aj d |  | ƒ t  |  | A|  A| j d |  | ƒ t  |  | @|  | Bj d |  | ƒ t  |  | B|  | @j d |  | ƒ t  |  | A|  | B|  | @@j d |  | ƒ t  |  | A|  | @|  | @Bj d |  | ƒ t  |  | A|  | B|  | B@j d	 |  | ƒ d  S(
   Ns   x & y != y & x fors   x | y != y | x fors   x ^ y != y ^ x fors   x ^ y ^ x != y fors   x & y != ~(~x | ~y) fors   x | y != ~(~x & ~y) fors   x ^ y != (x | y) & ~(x & y) fors    x ^ y == (x & ~y) | (~x & y) fors    x ^ y == (x | y) & (~x | ~y) for(   R
   R    R   (   R    R   (    (    R   t   test_bitop_identities_2š   s    !!!!$$c         C   sè   t  |  | @| @|  | | @@j d |  | | ƒ t  |  | B| B|  | | BBj d |  | | ƒ t  |  | A| A|  | | AAj d |  | | ƒ t  |  | | B@|  | @|  | @Bj d |  | | ƒ t  |  | | @B|  | B|  | B@j d |  | | ƒ d  S(   Ns   (x & y) & z != x & (y & z) fors   (x | y) | z != x | (y | z) fors   (x ^ y) ^ z != x ^ (y ^ z) fors$   x & (y | z) != (x & y) | (x & z) fors$   x | (y & z) != (x | y) & (x | z) for(   R
   R    R   t   z(   R    R   R;   (    (    R   t   test_bitop_identities_3¨   s      c         C   s±   t  o	 d GHn x t D] } t | ƒ q Wt d |  d ƒ } xl | D]d } t | ƒ } t | ƒ xE | D]= } t | ƒ } t | | ƒ t | | t | | d ƒ ƒ qh WqE Wd  S(   Ns   long bit-operation identitiesi   i   (   R%   t   specialR    R9   R   R&   R(   R*   R   R+   R   R:   R<   (   R&   R(   R   R    R+   R*   (    (    R   t   test_bitop_identities´   s    	  
 c         C   sß   |  | f d j o d Sn g  } d } |  d j  o d |  } }  n x4 |  o, t |  | ƒ \ }  } | i t | ƒ ƒ qI W| i ƒ  | p d g } d |  h  d d <d d <d	 d
 <| t	 t
 d „  | ƒ d ƒ d S(   Ni    i   t   0Li   t   -t   0i
   t    i   t   0xc         C   s   d |  S(   Nt   0123456789ABCDEF(   R   (   R   (    (    R   R   Ó   s    t   L(   i    i   (   R    t   baseR(   t   signR   R   R)   R   t   reverseR   R   (   R    RF   R(   RG   R   (    (    R   t   slow_formatÄ   s     
c      
   C   sð   d k  l } x• d t f d t f d t f f D]r \ } } | |  ƒ } t	 |  | ƒ } t | | j | i d | d | d |  ƒ t | | d ƒ |  j d	 | |  ƒ q/ Wt |  ƒ } t	 |  d ƒ d
  } t | | j | i d | d | d |  ƒ d  S(   N(   s   atoli   i
   i   t   returneds   but expectedt   fori    s   atol("%s", 0) !=iÿÿÿÿ(   t   stringt   atolt   octt   reprt   hexRF   t   mapperR    t   gotRI   t   expectedR
   t   __name__R   (   R    RQ   RF   RM   RR   RS   (    (    R   t   test_format_1Ö   s    " 'c         C   sz   t  o	 d GHn x t D] } t | ƒ q WxH t d ƒ D]: } x1 t d |  d ƒ D] } t | ƒ } t | ƒ qR Wq8 Wd  S(   Ns   long str/hex/oct/atoli
   i   (	   R%   R=   R    RU   R   R   R&   R*   R   (   R&   R   R    R*   (    (    R   t   test_formatå   s    	   c   	      C   s:  t  o	 d GHn d  k } | i } | d } t | ƒ } t | ƒ } t | | j d ƒ t | | j d ƒ t	 | ƒ } y t | | j d ƒ Wn t j
 o t d ‚ n Xt | t	 ƒ p t d ƒ ‚ n t	 | ƒ } y t | | j d ƒ Wn t j
 o t d	 ‚ n Xt | t	 ƒ p t d
 ƒ ‚ n | d } y t	 | ƒ } Wn t j
 o t d ‚ n Xt | t ƒ p t d ƒ ‚ n | d } y t	 | ƒ } Wn t j
 o t d ‚ n Xt | t ƒ p t d ƒ ‚ n d t f d „  ƒ  Y} | d d >ƒ } t	 | ƒ } t | ƒ t j	 o t d ƒ ‚ n d  S(   Ns   long miscellaneous operationsi   s   long(sys.maxint) != sys.maxints$   long(-sys.maxint-1) != -sys.maxint-1s3   converting sys.maxint to long and back to int failss!   int(long(sys.maxint)) overflowed!s.   int(long(sys.maxint)) should have returned ints6   converting -sys.maxint-1 to long and back to int failss$   int(long(-sys.maxint-1)) overflowed!s1   int(long(-sys.maxint-1)) should have returned ints*   int(long(sys.maxint) + 1) mustn't overflows3   int(long(sys.maxint) + 1) should have returned longs-   int(long(-sys.maxint-1) - 1) mustn't overflows6   int(long(-sys.maxint-1) - 1) should have returned longt   long2c           B   s   t  Z RS(   N(   RT   t
   __module__(    (    (    R   RW   "  s   l    id   s<   overflowing int conversion must return long not long subtype(   R%   t   syst   maxintt   hugepost   hugenegt   longt   hugepos_aslongt   hugeneg_aslongR
   R   R    t   OverflowErrorR   t
   isinstanceR   RW   t   type(	   R&   R[   R^   RW   RY   R\   R_   R   R    (    (    R   t	   test_miscñ   sZ    			

c             s  d  k  } d  k } t o	 d GHn d d d d | i d | i | i d g } t | i | i ƒ ƒ } | i | d | | d g ƒ | i g  }
 | D] }	 |
 |	 q• ~
 ƒ ‡  ‡ d †  } xZ| D]R} t | ƒ } | ‰  | ‰ | d | ƒ x"| D]} t | ƒ }  | |  ‰  | | ‰ | | d | ƒ | |  ‰  | | ‰ | | d | ƒ | |  ‰  | | ‰ | | d	 | ƒ | oz | |  ‰  | | ‰ | | d
 | ƒ | |  ‰  | | ‰ | | d | ƒ t | |  ƒ ‰  t | |  ƒ ‰ | | d | ƒ n t | ƒ d j  o| d j o
 | d j  oí | |  ‰  | | ‰ | | d | ƒ xÆ | D]º } | d j o§ | d j oD t | |  t | ƒ ƒ ‰  t | | | ƒ ‰ | d | | d | ƒ q	y t | |  t | ƒ ƒ Wn t j
 o q	Xt d | |  t | ƒ f f ƒ ‚ qOqOWq÷ q÷ WqÃ Wd  S(   Ns"   auto-convert int->long on overflowi    i   i   i   c             s$   t  ˆ ˆ  j d |  ˆ  ˆ f ƒ d  S(   Ns   for %r expected %r got %r(   R   RR   RS   R	   (   R	   (   RS   RR   (    R   t   checkit5  s    R@   t   +R.   t   /s   //R   i   s   **t   powt   %s"   pow%r should have raised TypeError(   t   mathRY   R%   RZ   R=   R   t   sqrtR/   R0   R   Rd   R    R]   t   longxRS   RR   R   t   longyR   t   absR;   Rg   t	   TypeErrorR   (   Rl   Rk   R=   Rj   RS   Ri   Rd   RR   RY   R   R0   R   R    R;   (    (   RS   RR   R   t   test_auto_overflow*  sh    	,)  









.

 c       &   C   sr  d  k  } t o	 d GHn x* d7 D]" } t t t | ƒ ƒ | j ƒ q  Wd d } d	 d
 >}  |  } h  d |  <d | <d | <d | <} xà 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 d1 d2 d3 d4 g& D]f } y t | | ƒ Wn t j
 o n Xt d5 | ƒ ‚ t | ƒ t | ƒ j o t d6 ƒ ‚ qqWd  S(8   Ns   long->float overflowf-2.0f-1.0f0.0f1.0f2.0t   12345ix   l    i0u  t   huget   mhuget   shugeRi   s   float(huge)s   float(mhuge)s   complex(huge)s   complex(mhuge)s   complex(huge, 1)s   complex(mhuge, 1)s   complex(1, huge)s   complex(1, mhuge)s	   1. + huges	   huge + 1.s
   1. + mhuges
   mhuge + 1.s	   1. - huges	   huge - 1.s
   1. - mhuges
   mhuge - 1.s	   1. * huges	   huge * 1.s
   1. * mhuges
   mhuge * 1.s
   1. // huges
   huge // 1.s   1. // mhuges   mhuge // 1.s	   1. / huges	   huge / 1.s
   1. / mhuges
   mhuge / 1.s
   1. ** huges
   huge ** 1.s   1. ** mhuges   mhuge ** 1.s   math.sin(huge)s   math.sin(mhuge)s   math.sqrt(huge)s   math.sqrt(mhuge)s   math.floor(huge)s   math.floor(mhuge)s   expected OverflowError from %ss(   float(shuge) should not equal int(shuge)(   f-2.0f-1.0f0.0f1.0f2.0(   Ri   R%   R    R   t   floatR]   Rs   Rq   Rr   t	   namespacet   testt   evalR`   R   R   (   Rq   Ru   Rr   Rv   R    Ri   Rs   (    (    R   t   test_float_overflows  s&    		  

*y c          C   s<  d  k  } t o	 d GHn | i | i ƒ }  x… t d ƒ d d d g D]j } d | } | i | ƒ } t t	 | | ƒ d j ƒ | |  } | i | ƒ } t t	 | | ƒ d j ƒ qE Wx‚ d d >d d	 f D]l } y | i | ƒ t d
 ƒ ‚ Wn t j
 o n Xy | i | ƒ t d ƒ ‚ WqÈ t j
 o qÈ XqÈ Wd  S(   Ns   log and log10i
   id   iè  i'  i    l    lÿÿÿÿ l    s"   expected ValueError from log(<= 0)s$   expected ValueError from log10(<= 0)(   Ri   R%   t   log10t   et   LOG10ER   t   expt   valueR   t   fcmpRS   t   logt   badR   t
   ValueError(   R{   R€   R}   R|   RS   Ry   Ri   R   (    (    R   t	   test_logsœ  s0    		 

 c             s#  d  k  ‰ d  k } t o	 d GHn d f  ‡  ‡ d †  ƒ  Y‰  d d d d d d	 d
 g }
 xr d d d d d d f D]U } |
 i | d | d | | d | d t | d ƒ t | ƒ t | d ƒ g ƒ qr W|
 i d d d | i t	 | i ƒ g ƒ t d
 ƒ } |
 i d d d d d >| d | | d g ƒ |
 i g  }  |
 D] }	 |  |	 q>~  ƒ xÆ|
 D]¾}	 ˆ  |	 ƒ } x©|
 D]¡} ˆ  | ƒ } t | | ƒ } t |	 | ƒ } | | j o  t d |	 | | | f ƒ ‚ n |	 | j | d j j o t d |	 | | f ƒ ‚ n |	 | j | d j j o t d |	 | | f ƒ ‚ n |	 | j  | d j  j o t d |	 | | f ƒ ‚ n |	 | j | d j j o t d |	 | | f ƒ ‚ n |	 | j | d j j o t d |	 | | f ƒ ‚ n |	 | j | d j j o t d |	 | | f ƒ ‚ qvqvWq]Wd  S(   Ns   mixed comparisonst   Ratc              s    t  Z ‡ d †  Z ‡  d †  Z RS(   Nc   	         s¹  t  | t t f ƒ o | |  _ d |  _ nŠt  | t ƒ oiˆ  i	 t
 | ƒ ƒ \ } } | d j p% d | j o
 d j  n p t ‚ d } d } x‰ | o ˆ  i | | ƒ } t | ƒ } | | ?d j p t ‚ | | >| B} | | 8} d | j o
 d j  n p t ‚ | | 8} q˜ W| d j o | | >} d } n | } d | >} | d j  o | } n | |  _ | |  _ t | ƒ t | ƒ | j p t ‚ n t d t ƒ ‚ d  S(   Ni   i    f0.5f1.0i   f0.0s   can't deal with %r(   Ra   R}   R   R]   t   selfR7   t   dRt   Ri   t   frexpRm   t   fRz   t   AssertionErrort   CHUNKt   topt   ldexpR1   Rn   t   val(	   R„   R}   R1   Rz   R…   R‡   R7   RŠ   R‰   (   Ri   (    R   t   __init__Ë  s8    	2 
%

		(c            sA   t  | ˆ  ƒ p ˆ  | ƒ } n t |  i | i |  i | i ƒ S(   N(   Ra   t   otherRƒ   t   cmpR„   R7   R…   (   R„   RŽ   (   Rƒ   (    R   t   __cmp__õ  s    (   RT   RX   R   R   (    (   Rƒ   Ri   (    R   Rƒ   Ê  s   *i    f0.001f0.98999999999999999f1.0f1.5f1e+20f9.9999999999999997e+199f2.0i0   i2   i5   f0.29999999999999999i   i   l    l    l    i N  s   %r %r %d %ds   %r == %r %ds   %r != %r %ds
   %r < %r %ds   %r <= %r %ds
   %r > %r %ds   %r >= %r %d(   Ri   RY   R%   Rƒ   t   casest   tR/   R]   RZ   Rt   R0   R    t   RxR   t   RyR   t   Rcmpt   xycmpR   (   R0   R•   R“   R”   R–   RY   Rƒ   R’   R   R    R‘   Ri   (    (   Rƒ   Ri   R   t   test_mixed_compares¾  sF    			0 S(.)   N('   t   test.test_supportR   R%   R   R~   RL   R   R   R   R   t   BASER   R'   t	   MAXDIGITSR   R]   R=   R)   R8   R   R   R
   R   R   R$   R,   R6   R9   R:   R<   R>   RI   RU   RV   Rc   Ro   Rx   R‚   R—   (!   RV   R%   R:   R   R   R6   R—   R$   Rx   R
   R=   R9   Ro   R   R   R<   R   R   R>   Rš   R,   R   R™   R'   R   RI   R8   R   R   R‚   R~   Rc   RU   (    (    R   t   ?   sX   

" &	
		
							9	I	)	"	_