<s> import unittest <EOL> import sys <EOL> import random <EOL> import math <EOL> from test import test_int , test_support <EOL> class Frm ( object ) : <EOL> def __init__ ( self , format , * args ) : <EOL> self . format = format <EOL> self . args = args <EOL> def __str__ ( self ) : <EOL> return self . format % self . args <EOL> SHIFT = sys . long_info . bits_per_digit <EOL> BASE = <NUM_LIT:2> ** SHIFT <EOL> MASK = BASE - <NUM_LIT:1> <EOL> KARATSUBA_CUTOFF = <NUM_LIT> <EOL> MAXDIGITS = <NUM_LIT:15> <EOL> special = map ( long , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , BASE , BASE >> <NUM_LIT:1> ] ) <EOL> special . append ( <NUM_LIT> L ) <EOL> special . append ( <NUM_LIT> L ) <EOL> p2 = <NUM_LIT:4> L <EOL> for i in range ( <NUM_LIT:2> * SHIFT ) : <EOL> special . append ( p2 - <NUM_LIT:1> ) <EOL> p2 = p2 << <NUM_LIT:1> <EOL> del p2 <EOL> special = special + map ( lambda x : ~ x , special ) + map ( lambda x : - x , special ) <EOL> L = [ <EOL> ( '<STR_LIT:0>' , <NUM_LIT:0> ) , <EOL> ( '<STR_LIT:1>' , <NUM_LIT:1> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:9> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:10> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT:100>' , <NUM_LIT:100> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( repr ( sys . maxint ) , sys . maxint ) , <EOL> ( '<STR_LIT>' , ValueError ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:1> ) , <EOL> ( '<STR_LIT>' , ValueError ) , <EOL> ( '<STR_LIT>' , ValueError ) , <EOL> ( '<STR_LIT:U+0020>' , ValueError ) , <EOL> ( '<STR_LIT>' , ValueError ) <EOL> ] <EOL> if test_support . have_unicode : <EOL> L += [ <EOL> ( unicode ( '<STR_LIT:0>' ) , <NUM_LIT:0> ) , <EOL> ( unicode ( '<STR_LIT:1>' ) , <NUM_LIT:1> ) , <EOL> ( unicode ( '<STR_LIT>' ) , <NUM_LIT:9> ) , <EOL> ( unicode ( '<STR_LIT>' ) , <NUM_LIT:10> ) , <EOL> ( unicode ( '<STR_LIT>' ) , <NUM_LIT> ) , <EOL> ( unicode ( '<STR_LIT:100>' ) , <NUM_LIT:100> ) , <EOL> ( unicode ( '<STR_LIT>' ) , <NUM_LIT> ) , <EOL> ( unicode ( '<STR_LIT>' ) , <NUM_LIT> ) , <EOL> ( unicode ( '<STR_LIT>' , '<STR_LIT>' ) , <NUM_LIT> ) , <EOL> ( unicode ( '<STR_LIT>' ) , <NUM_LIT> ) , <EOL> ( unicode ( '<STR_LIT>' ) , ValueError ) , <EOL> ( unicode ( '<STR_LIT>' ) , <NUM_LIT:1> ) , <EOL> ( unicode ( '<STR_LIT>' ) , ValueError ) , <EOL> ( unicode ( '<STR_LIT>' ) , ValueError ) , <EOL> ( unicode ( '<STR_LIT:U+0020>' ) , ValueError ) , <EOL> ( unicode ( '<STR_LIT>' ) , ValueError ) , <EOL> ( unichr ( <NUM_LIT> ) , ValueError ) , <EOL> ] <EOL> class LongTest ( test_int . IntLongCommonTests , unittest . TestCase ) : <EOL> ntype = long <EOL> def getran ( self , ndigits ) : <EOL> self . assertGreater ( ndigits , <NUM_LIT:0> ) <EOL> nbits_hi = ndigits * SHIFT <EOL> nbits_lo = nbits_hi - SHIFT + <NUM_LIT:1> <EOL> answer = <NUM_LIT:0> L <EOL> nbits = <NUM_LIT:0> <EOL> r = int ( random . random ( ) * ( SHIFT * <NUM_LIT:2> ) ) | <NUM_LIT:1> <EOL> while nbits < nbits_lo : <EOL> bits = ( r >> <NUM_LIT:1> ) + <NUM_LIT:1> <EOL> bits = min ( bits , nbits_hi - nbits ) <EOL> self . assertTrue ( <NUM_LIT:1> <= bits <= SHIFT ) <EOL> nbits = nbits + bits <EOL> answer = answer << bits <EOL> if r & <NUM_LIT:1> : <EOL> answer = answer | ( ( <NUM_LIT:1> << bits ) - <NUM_LIT:1> ) <EOL> r = int ( random . random ( ) * ( SHIFT * <NUM_LIT:2> ) ) <EOL> self . assertTrue ( nbits_lo <= nbits <= nbits_hi ) <EOL> if random . random ( ) < <NUM_LIT:0.5> : <EOL> answer = - answer <EOL> return answer <EOL> def getran2 ( ndigits ) : <EOL> answer = <NUM_LIT:0> L <EOL> for i in xrange ( ndigits ) : <EOL> answer = ( answer << SHIFT ) | random . randint ( <NUM_LIT:0> , MASK ) <EOL> if random . random ( ) < <NUM_LIT:0.5> : <EOL> answer = - answer <EOL> return answer <EOL> def check_division ( self , x , y ) : <EOL> eq = self . assertEqual <EOL> q , r = divmod ( x , y ) <EOL> q2 , r2 = x // y , x % y <EOL> pab , pba = x * y , y * x <EOL> eq ( pab , pba , Frm ( "<STR_LIT>" , x , y ) ) <EOL> eq ( q , q2 , Frm ( "<STR_LIT>" , x , y ) ) <EOL> eq ( r , r2 , Frm ( "<STR_LIT>" , x , y ) ) <EOL> eq ( x , q * y + r , Frm ( "<STR_LIT>" , x , y ) ) <EOL> if y > <NUM_LIT:0> : <EOL> self . assertTrue ( <NUM_LIT:0> <= r < y , Frm ( "<STR_LIT>" , x , y ) ) <EOL> else : <EOL> self . assertTrue ( y < r <= <NUM_LIT:0> , Frm ( "<STR_LIT>" , x , y ) ) <EOL> def test_division ( self ) : <EOL> digits = range ( <NUM_LIT:1> , MAXDIGITS + <NUM_LIT:1> ) + range ( KARATSUBA_CUTOFF , <EOL> KARATSUBA_CUTOFF + <NUM_LIT> ) <EOL> digits . append ( KARATSUBA_CUTOFF * <NUM_LIT:3> ) <EOL> for lenx in digits : <EOL> x = self . getran ( lenx ) <EOL> for leny in digits : <EOL> y = self . getran ( leny ) or <NUM_LIT:1> L <EOL> self . check_division ( x , y ) <EOL> self . check_division ( <NUM_LIT> L , <EOL> <NUM_LIT> L ) <EOL> self . check_division ( <NUM_LIT> L , <EOL> <NUM_LIT> L ) <EOL> self . check_division ( <NUM_LIT> L , <EOL> <NUM_LIT> L ) <EOL> self . check_division ( <NUM_LIT> L , <EOL> <NUM_LIT> L ) <EOL> self . check_division ( <NUM_LIT> L , <EOL> <NUM_LIT> L ) <EOL> self . check_division ( <NUM_LIT> L , <EOL> <NUM_LIT> L ) <EOL> self . check_division ( <NUM_LIT> L , <NUM_LIT> L ) <EOL> self . check_division ( <NUM_LIT> L , <NUM_LIT> L ) <EOL> self . check_division ( <NUM_LIT> L , <NUM_LIT> L ) <EOL> self . check_division ( <NUM_LIT> L , <NUM_LIT> L ) <EOL> self . check_division ( <NUM_LIT> L , <NUM_LIT> L ) <EOL> self . check_division ( <NUM_LIT> L , <NUM_LIT> L ) <EOL> def test_karatsuba ( self ) : <EOL> digits = range ( <NUM_LIT:1> , <NUM_LIT:5> ) + range ( KARATSUBA_CUTOFF , KARATSUBA_CUTOFF + <NUM_LIT:10> ) <EOL> digits . extend ( [ KARATSUBA_CUTOFF * <NUM_LIT:10> , KARATSUBA_CUTOFF * <NUM_LIT:100> ] ) <EOL> bits = [ digit * SHIFT for digit in digits ] <EOL> for abits in bits : <EOL> a = ( <NUM_LIT:1> L << abits ) - <NUM_LIT:1> <EOL> for bbits in bits : <EOL> if bbits < abits : <EOL> continue <EOL> b = ( <NUM_LIT:1> L << bbits ) - <NUM_LIT:1> <EOL> x = a * b <EOL> y = ( ( <NUM_LIT:1> L << ( abits + bbits ) ) - <EOL> ( <NUM_LIT:1> L << abits ) - <EOL> ( <NUM_LIT:1> L << bbits ) + <EOL> <NUM_LIT:1> ) <EOL> self . assertEqual ( x , y , <EOL> Frm ( "<STR_LIT>" , a , b , x , y ) ) <EOL> def check_bitop_identities_1 ( self , x ) : <EOL> eq = self . assertEqual <EOL> eq ( x & <NUM_LIT:0> , <NUM_LIT:0> , Frm ( "<STR_LIT>" , x ) ) <EOL> eq ( x | <NUM_LIT:0> , x , Frm ( "<STR_LIT>" , x ) ) <EOL> eq ( x ^ <NUM_LIT:0> , x , Frm ( "<STR_LIT>" , x ) ) <EOL> eq ( x & - <NUM_LIT:1> , x , Frm ( "<STR_LIT>" , x ) ) <EOL> eq ( x | - <NUM_LIT:1> , - <NUM_LIT:1> , Frm ( "<STR_LIT>" , x ) ) <EOL> eq ( x ^ - <NUM_LIT:1> , ~ x , Frm ( "<STR_LIT>" , x ) ) <EOL> eq ( x , ~ ~ x , Frm ( "<STR_LIT>" , x ) ) <EOL> eq ( x & x , x , Frm ( "<STR_LIT>" , x ) ) <EOL> eq ( x | x , x , Frm ( "<STR_LIT>" , x ) ) <EOL> eq ( x ^ x , <NUM_LIT:0> , Frm ( "<STR_LIT>" , x ) ) <EOL> eq ( x & ~ x , <NUM_LIT:0> , Frm ( "<STR_LIT>" , x ) ) <EOL> eq ( x | ~ x , - <NUM_LIT:1> , Frm ( "<STR_LIT>" , x ) ) <EOL> eq ( x ^ ~ x , - <NUM_LIT:1> , Frm ( "<STR_LIT>" , x ) ) <EOL> eq ( - x , <NUM_LIT:1> + ~ x , Frm ( "<STR_LIT>" , x ) ) <EOL> eq ( - x , ~ ( x - <NUM_LIT:1> ) , Frm ( "<STR_LIT>" , x ) ) <EOL> for n in xrange ( <NUM_LIT:2> * SHIFT ) : <EOL> p2 = <NUM_LIT:2> L ** n <EOL> eq ( x << n >> n , x , <EOL> Frm ( "<STR_LIT>" , ( x , n ) ) ) <EOL> eq ( x // p2 , x >> n , <EOL> Frm ( "<STR_LIT>" , ( x , n , p2 ) ) ) <EOL> eq ( x * p2 , x << n , <EOL> Frm ( "<STR_LIT>" , ( x , n , p2 ) ) ) <EOL> eq ( x & - p2 , x >> n << n , <EOL> Frm ( "<STR_LIT>" , ( x , n , p2 ) ) ) <EOL> eq ( x & - p2 , x & ~ ( p2 - <NUM_LIT:1> ) , <EOL> Frm ( "<STR_LIT>" , ( x , n , p2 ) ) ) <EOL> def check_bitop_identities_2 ( self , x , y ) : <EOL> eq = self . assertEqual <EOL> eq ( x & y , y & x , Frm ( "<STR_LIT>" , ( x , y ) ) ) <EOL> eq ( x | y , y | x , Frm ( "<STR_LIT>" , ( x , y ) ) ) <EOL> eq ( x ^ y , y ^ x , Frm ( "<STR_LIT>" , ( x , y ) ) ) <EOL> eq ( x ^ y ^ x , y , Frm ( "<STR_LIT>" , ( x , y ) ) ) <EOL> eq ( x & y , ~ ( ~ x | ~ y ) , Frm ( "<STR_LIT>" , ( x , y ) ) ) <EOL> eq ( x | y , ~ ( ~ x & ~ y ) , Frm ( "<STR_LIT>" , ( x , y ) ) ) <EOL> eq ( x ^ y , ( x | y ) & ~ ( x & y ) , <EOL> Frm ( "<STR_LIT>" , ( x , y ) ) ) <EOL> eq ( x ^ y , ( x & ~ y ) | ( ~ x & y ) , <EOL> Frm ( "<STR_LIT>" , ( x , y ) ) ) <EOL> eq ( x ^ y , ( x | y ) & ( ~ x | ~ y ) , <EOL> Frm ( "<STR_LIT>" , ( x , y ) ) ) <EOL> def check_bitop_identities_3 ( self , x , y , z ) : <EOL> eq = self . assertEqual <EOL> eq ( ( x & y ) & z , x & ( y & z ) , <EOL> Frm ( "<STR_LIT>" , ( x , y , z ) ) ) <EOL> eq ( ( x | y ) | z , x | ( y | z ) , <EOL> Frm ( "<STR_LIT>" , ( x , y , z ) ) ) <EOL> eq ( ( x ^ y ) ^ z , x ^ ( y ^ z ) , <EOL> Frm ( "<STR_LIT>" , ( x , y , z ) ) ) <EOL> eq ( x & ( y | z ) , ( x & y ) | ( x & z ) , <EOL> Frm ( "<STR_LIT>" , ( x , y , z ) ) ) <EOL> eq ( x | ( y & z ) , ( x | y ) & ( x | z ) , <EOL> Frm ( "<STR_LIT>" , ( x , y , z ) ) ) <EOL> def test_bitop_identities ( self ) : <EOL> for x in special : <EOL> self . check_bitop_identities_1 ( x ) <EOL> digits = xrange ( <NUM_LIT:1> , MAXDIGITS + <NUM_LIT:1> ) <EOL> for lenx in digits : <EOL> x = self . getran ( lenx ) <EOL> self . check_bitop_identities_1 ( x ) <EOL> for leny in digits : <EOL> y = self . getran ( leny ) <EOL> self . check_bitop_identities_2 ( x , y ) <EOL> self . check_bitop_identities_3 ( x , y , self . getran ( ( lenx + leny ) // <NUM_LIT:2> ) ) <EOL> def slow_format ( self , x , base ) : <EOL> if ( x , base ) == ( <NUM_LIT:0> , <NUM_LIT:8> ) : <EOL> return "<STR_LIT>" <EOL> digits = [ ] <EOL> sign = <NUM_LIT:0> <EOL> if x < <NUM_LIT:0> : <EOL> sign , x = <NUM_LIT:1> , - x <EOL> while x : <EOL> x , r = divmod ( x , base ) <EOL> digits . append ( int ( r ) ) <EOL> digits . reverse ( ) <EOL> digits = digits or [ <NUM_LIT:0> ] <EOL> return '<STR_LIT:->' [ : sign ] + { <NUM_LIT:8> : '<STR_LIT:0>' , <NUM_LIT:10> : '<STR_LIT>' , <NUM_LIT:16> : '<STR_LIT>' } [ base ] + "<STR_LIT>" . join ( map ( lambda i : "<STR_LIT>" [ i ] , digits ) ) + "<STR_LIT:L>" <EOL> def check_format_1 ( self , x ) : <EOL> for base , mapper in ( <NUM_LIT:8> , oct ) , ( <NUM_LIT:10> , repr ) , ( <NUM_LIT:16> , hex ) : <EOL> got = mapper ( x ) <EOL> expected = self . slow_format ( x , base ) <EOL> msg = Frm ( "<STR_LIT>" , <EOL> mapper . __name__ , got , expected , x ) <EOL> self . assertEqual ( got , expected , msg ) <EOL> self . assertEqual ( long ( got , <NUM_LIT:0> ) , x , Frm ( '<STR_LIT>' , got , x ) ) <EOL> got = str ( x ) <EOL> expected = self . slow_format ( x , <NUM_LIT:10> ) [ : - <NUM_LIT:1> ] <EOL> msg = Frm ( "<STR_LIT>" , <EOL> mapper . __name__ , got , expected , x ) <EOL> self . assertEqual ( got , expected , msg ) <EOL> def test_format ( self ) : <EOL> for x in special : <EOL> self . check_format_1 ( x ) <EOL> for i in xrange ( <NUM_LIT:10> ) : <EOL> for lenx in xrange ( <NUM_LIT:1> , MAXDIGITS + <NUM_LIT:1> ) : <EOL> x = self . getran ( lenx ) <EOL> self . check_format_1 ( x ) <EOL> def test_long ( self ) : <EOL> self . assertEqual ( long ( <NUM_LIT> ) , <NUM_LIT> L ) <EOL> self . assertEqual ( long ( <NUM_LIT> ) , <NUM_LIT:3> L ) <EOL> self . assertEqual ( long ( <NUM_LIT> L ) , <NUM_LIT> L ) <EOL> self . assertEqual ( type ( long ( <NUM_LIT> ) ) , long ) <EOL> self . assertEqual ( type ( long ( <NUM_LIT> ) ) , long ) <EOL> self . assertEqual ( type ( long ( <NUM_LIT> L ) ) , long ) <EOL> self . assertEqual ( long ( - <NUM_LIT> ) , - <NUM_LIT:3> L ) <EOL> self . assertEqual ( long ( <NUM_LIT> ) , <NUM_LIT:3> L ) <EOL> self . assertEqual ( long ( - <NUM_LIT> ) , - <NUM_LIT:3> L ) <EOL> self . assertEqual ( long ( <NUM_LIT> ) , <NUM_LIT:3> L ) <EOL> self . assertEqual ( long ( - <NUM_LIT> ) , - <NUM_LIT:3> L ) <EOL> self . assertEqual ( long ( "<STR_LIT>" ) , - <NUM_LIT:3> L ) <EOL> self . assertEqual ( long ( "<STR_LIT>" , <NUM_LIT:2> ) , <NUM_LIT:2> L ) <EOL> self . assertEqual ( long ( "<STR_LIT>" , <NUM_LIT:8> ) , <NUM_LIT:8> L ) <EOL> self . assertEqual ( long ( "<STR_LIT>" , <NUM_LIT:16> ) , <NUM_LIT:16> L ) <EOL> if test_support . have_unicode : <EOL> self . assertEqual ( long ( unicode ( "<STR_LIT>" ) ) , - <NUM_LIT:3> L ) <EOL> self . assertEqual ( long ( "<STR_LIT>" , <NUM_LIT:16> ) , <NUM_LIT:16> L ) <EOL> if test_support . have_unicode : <EOL> self . assertEqual ( long ( unicode ( "<STR_LIT>" ) , <NUM_LIT:16> ) , <NUM_LIT:16> L ) <EOL> LL = [ <EOL> ( '<STR_LIT:1>' + '<STR_LIT:0>' * <NUM_LIT:20> , <NUM_LIT:10> L ** <NUM_LIT:20> ) , <EOL> ( '<STR_LIT:1>' + '<STR_LIT:0>' * <NUM_LIT:100> , <NUM_LIT:10> L ** <NUM_LIT:100> ) <EOL> ] <EOL> L2 = L [ : ] <EOL> if test_support . have_unicode : <EOL> L2 += [ <EOL> ( unicode ( '<STR_LIT:1>' ) + unicode ( '<STR_LIT:0>' ) * <NUM_LIT:20> , <NUM_LIT:10> L ** <NUM_LIT:20> ) , <EOL> ( unicode ( '<STR_LIT:1>' ) + unicode ( '<STR_LIT:0>' ) * <NUM_LIT:100> , <NUM_LIT:10> L ** <NUM_LIT:100> ) , <EOL> ] <EOL> for s , v in L2 + LL : <EOL> for sign in "<STR_LIT>" , "<STR_LIT:+>" , "<STR_LIT:->" : <EOL> for prefix in "<STR_LIT>" , "<STR_LIT:U+0020>" , "<STR_LIT:\t>" , "<STR_LIT>" : <EOL> ss = prefix + sign + s <EOL> vv = v <EOL> if sign == "<STR_LIT:->" and v is not ValueError : <EOL> vv = - v <EOL> try : <EOL> self . assertEqual ( long ( ss ) , long ( vv ) ) <EOL> except v : <EOL> pass <EOL> self . assertRaises ( ValueError , long , '<STR_LIT>' ) <EOL> self . assertRaises ( ValueError , long , '<STR_LIT>' , <NUM_LIT> ) <EOL> self . assertRaises ( TypeError , long , <NUM_LIT:1> , <NUM_LIT:12> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:0> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:0> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:0> ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:0> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:0> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:0> ) , <NUM_LIT:4> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:0> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:0> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:0> ) , <NUM_LIT:4> ) <EOL> self . assertEqual ( long ( '<STR_LIT:0>' , <NUM_LIT:0> ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:0> ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:0> ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:0> ) , <NUM_LIT:0> ) <EOL> self . assertRaises ( ValueError , long , '<STR_LIT>' , <NUM_LIT:0> ) <EOL> self . assertRaises ( ValueError , long , '<STR_LIT>' , <NUM_LIT:0> ) <EOL> self . assertRaises ( ValueError , long , '<STR_LIT>' , <NUM_LIT:10> ) <EOL> self . assertRaises ( ValueError , long , '<STR_LIT>' , <NUM_LIT:20> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:2> ) , <EOL> <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:3> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:4> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:5> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:6> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:7> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:8> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:9> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:10> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:11> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:12> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:15> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:16> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:20> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:30> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:32> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:2> ) , <EOL> <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:3> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:4> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:5> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:6> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:7> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:8> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:9> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:10> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:11> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:12> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:15> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:16> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:20> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:30> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT:32> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( long ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> def test_conversion ( self ) : <EOL> class ClassicMissingMethods : <EOL> pass <EOL> self . assertRaises ( AttributeError , long , ClassicMissingMethods ( ) ) <EOL> class MissingMethods ( object ) : <EOL> pass <EOL> self . assertRaises ( TypeError , long , MissingMethods ( ) ) <EOL> class Foo0 : <EOL> def __long__ ( self ) : <EOL> return <NUM_LIT> L <EOL> class Foo1 ( object ) : <EOL> def __long__ ( self ) : <EOL> return <NUM_LIT> L <EOL> class Foo2 ( long ) : <EOL> def __long__ ( self ) : <EOL> return <NUM_LIT> L <EOL> class Foo3 ( long ) : <EOL> def __long__ ( self ) : <EOL> return self <EOL> class Foo4 ( long ) : <EOL> def __long__ ( self ) : <EOL> return <NUM_LIT> <EOL> class Foo5 ( long ) : <EOL> def __long__ ( self ) : <EOL> return <NUM_LIT> <EOL> self . assertEqual ( long ( Foo0 ( ) ) , <NUM_LIT> L ) <EOL> self . assertEqual ( long ( Foo1 ( ) ) , <NUM_LIT> L ) <EOL> self . assertEqual ( long ( Foo2 ( ) ) , <NUM_LIT> L ) <EOL> self . assertEqual ( long ( Foo3 ( ) ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( long ( Foo4 ( ) ) , <NUM_LIT> ) <EOL> self . assertRaises ( TypeError , long , Foo5 ( ) ) <EOL> class Classic : <EOL> pass <EOL> for base in ( object , Classic ) : <EOL> class LongOverridesTrunc ( base ) : <EOL> def __long__ ( self ) : <EOL> return <NUM_LIT> <EOL> def __trunc__ ( self ) : <EOL> return - <NUM_LIT:12> <EOL> self . assertEqual ( long ( LongOverridesTrunc ( ) ) , <NUM_LIT> ) <EOL> class JustTrunc ( base ) : <EOL> def __trunc__ ( self ) : <EOL> return <NUM_LIT> <EOL> self . assertEqual ( long ( JustTrunc ( ) ) , <NUM_LIT> ) <EOL> for trunc_result_base in ( object , Classic ) : <EOL> class Integral ( trunc_result_base ) : <EOL> def __int__ ( self ) : <EOL> return <NUM_LIT> <EOL> class TruncReturnsNonLong ( base ) : <EOL> def __trunc__ ( self ) : <EOL> return Integral ( ) <EOL> self . assertEqual ( long ( TruncReturnsNonLong ( ) ) , <NUM_LIT> ) <EOL> class NonIntegral ( trunc_result_base ) : <EOL> def __trunc__ ( self ) : <EOL> return NonIntegral ( ) <EOL> class TruncReturnsNonIntegral ( base ) : <EOL> def __trunc__ ( self ) : <EOL> return NonIntegral ( ) <EOL> try : <EOL> long ( TruncReturnsNonIntegral ( ) ) <EOL> except TypeError as e : <EOL> self . assertEqual ( str ( e ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" % <EOL> ( ( base , trunc_result_base ) , ) ) <EOL> def test_misc ( self ) : <EOL> hugepos = sys . maxint <EOL> hugeneg = - hugepos - <NUM_LIT:1> <EOL> hugepos_aslong = long ( hugepos ) <EOL> hugeneg_aslong = long ( hugeneg ) <EOL> self . assertEqual ( hugepos , hugepos_aslong , "<STR_LIT>" ) <EOL> self . assertEqual ( hugeneg , hugeneg_aslong , <EOL> "<STR_LIT>" ) <EOL> x = int ( hugepos_aslong ) <EOL> try : <EOL> self . assertEqual ( x , hugepos , <EOL> "<STR_LIT>" ) <EOL> except OverflowError : <EOL> self . fail ( "<STR_LIT>" ) <EOL> if not isinstance ( x , int ) : <EOL> self . fail ( "<STR_LIT>" ) <EOL> x = int ( hugeneg_aslong ) <EOL> try : <EOL> self . assertEqual ( x , hugeneg , <EOL> "<STR_LIT>" ) <EOL> except OverflowError : <EOL> self . fail ( "<STR_LIT>" ) <EOL> if not isinstance ( x , int ) : <EOL> self . fail ( "<STR_LIT>" ) <EOL> x = hugepos_aslong + <NUM_LIT:1> <EOL> try : <EOL> y = int ( x ) <EOL> except OverflowError : <EOL> self . fail ( "<STR_LIT>" ) <EOL> self . assertIsInstance ( y , long , <EOL> "<STR_LIT>" ) <EOL> x = hugeneg_aslong - <NUM_LIT:1> <EOL> try : <EOL> y = int ( x ) <EOL> except OverflowError : <EOL> self . fail ( "<STR_LIT>" ) <EOL> self . assertIsInstance ( y , long , <EOL> "<STR_LIT>" ) <EOL> class long2 ( long ) : <EOL> pass <EOL> x = long2 ( <NUM_LIT:1> L << <NUM_LIT:100> ) <EOL> y = int ( x ) <EOL> self . assertIs ( type ( y ) , long , <EOL> "<STR_LIT>" ) <EOL> class X ( object ) : <EOL> def __getslice__ ( self , i , j ) : <EOL> return i , j <EOL> with test_support . check_py3k_warnings ( ) : <EOL> self . assertEqual ( X ( ) [ - <NUM_LIT:5> L : <NUM_LIT:7> L ] , ( - <NUM_LIT:5> , <NUM_LIT:7> ) ) <EOL> slicemin , slicemax = X ( ) [ - <NUM_LIT:2> L ** <NUM_LIT:100> : <NUM_LIT:2> L ** <NUM_LIT:100> ] <EOL> self . assertEqual ( X ( ) [ slicemin : slicemax ] , ( slicemin , slicemax ) ) <EOL> def test_issue9869 ( self ) : <EOL> class BadLong ( object ) : <EOL> def __long__ ( self ) : <EOL> return <NUM_LIT> <EOL> class MyLong ( long ) : <EOL> pass <EOL> x = MyLong ( BadLong ( ) ) <EOL> self . assertIsInstance ( x , long ) <EOL> self . assertEqual ( x , <NUM_LIT> ) <EOL> def test_auto_overflow ( self ) : <EOL> special = [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , sys . maxint - <NUM_LIT:1> , sys . maxint , sys . maxint + <NUM_LIT:1> ] <EOL> sqrt = int ( math . sqrt ( sys . maxint ) ) <EOL> special . extend ( [ sqrt - <NUM_LIT:1> , sqrt , sqrt + <NUM_LIT:1> ] ) <EOL> special . extend ( [ - i for i in special ] ) <EOL> def checkit ( * args ) : <EOL> self . assertEqual ( got , expected , <EOL> Frm ( "<STR_LIT>" , args , expected , got ) ) <EOL> for x in special : <EOL> longx = long ( x ) <EOL> expected = - longx <EOL> got = - x <EOL> checkit ( '<STR_LIT:->' , x ) <EOL> for y in special : <EOL> longy = long ( y ) <EOL> expected = longx + longy <EOL> got = x + y <EOL> checkit ( x , '<STR_LIT:+>' , y ) <EOL> expected = longx - longy <EOL> got = x - y <EOL> checkit ( x , '<STR_LIT:->' , y ) <EOL> expected = longx * longy <EOL> got = x * y <EOL> checkit ( x , '<STR_LIT:*>' , y ) <EOL> if y : <EOL> with test_support . check_py3k_warnings ( ) : <EOL> expected = longx / longy <EOL> got = x / y <EOL> checkit ( x , '<STR_LIT:/>' , y ) <EOL> expected = longx // longy <EOL> got = x // y <EOL> checkit ( x , '<STR_LIT>' , y ) <EOL> expected = divmod ( longx , longy ) <EOL> got = divmod ( longx , longy ) <EOL> checkit ( x , '<STR_LIT>' , y ) <EOL> if abs ( y ) < <NUM_LIT:5> and not ( x == <NUM_LIT:0> and y < <NUM_LIT:0> ) : <EOL> expected = longx ** longy <EOL> got = x ** y <EOL> checkit ( x , '<STR_LIT>' , y ) <EOL> for z in special : <EOL> if z != <NUM_LIT:0> : <EOL> if y >= <NUM_LIT:0> : <EOL> expected = pow ( longx , longy , long ( z ) ) <EOL> got = pow ( x , y , z ) <EOL> checkit ( '<STR_LIT>' , x , y , '<STR_LIT:%>' , z ) <EOL> else : <EOL> self . assertRaises ( TypeError , pow , longx , longy , long ( z ) ) <EOL> @ unittest . skipUnless ( float . __getformat__ ( "<STR_LIT>" ) . startswith ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" ) <EOL> def test_float_conversion ( self ) : <EOL> import sys <EOL> DBL_MAX = sys . float_info . max <EOL> DBL_MAX_EXP = sys . float_info . max_exp <EOL> DBL_MANT_DIG = sys . float_info . mant_dig <EOL> exact_values = [ <NUM_LIT:0> L , <NUM_LIT:1> L , <NUM_LIT:2> L , <EOL> long ( <NUM_LIT:2> ** <NUM_LIT> - <NUM_LIT:3> ) , <EOL> long ( <NUM_LIT:2> ** <NUM_LIT> - <NUM_LIT:2> ) , <EOL> long ( <NUM_LIT:2> ** <NUM_LIT> - <NUM_LIT:1> ) , <EOL> long ( <NUM_LIT:2> ** <NUM_LIT> ) , <EOL> long ( <NUM_LIT:2> ** <NUM_LIT> + <NUM_LIT:2> ) , <EOL> long ( <NUM_LIT:2> ** <NUM_LIT> - <NUM_LIT:4> ) , <EOL> long ( <NUM_LIT:2> ** <NUM_LIT> - <NUM_LIT:2> ) , <EOL> long ( <NUM_LIT:2> ** <NUM_LIT> ) , <EOL> long ( <NUM_LIT:2> ** <NUM_LIT> + <NUM_LIT:4> ) ] <EOL> for x in exact_values : <EOL> self . assertEqual ( long ( float ( x ) ) , x ) <EOL> self . assertEqual ( long ( float ( - x ) ) , - x ) <EOL> for x , y in [ ( <NUM_LIT:1> , <NUM_LIT:0> ) , ( <NUM_LIT:2> , <NUM_LIT:2> ) , ( <NUM_LIT:3> , <NUM_LIT:4> ) , ( <NUM_LIT:4> , <NUM_LIT:4> ) , ( <NUM_LIT:5> , <NUM_LIT:4> ) , ( <NUM_LIT:6> , <NUM_LIT:6> ) , ( <NUM_LIT:7> , <NUM_LIT:8> ) ] : <EOL> for p in xrange ( <NUM_LIT:15> ) : <EOL> self . assertEqual ( long ( float ( <NUM_LIT:2> L ** p * ( <NUM_LIT:2> ** <NUM_LIT> + x ) ) ) , <NUM_LIT:2> L ** p * ( <NUM_LIT:2> ** <NUM_LIT> + y ) ) <EOL> for x , y in [ ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , <NUM_LIT:0> ) , ( <NUM_LIT:2> , <NUM_LIT:0> ) , ( <NUM_LIT:3> , <NUM_LIT:4> ) , ( <NUM_LIT:4> , <NUM_LIT:4> ) , ( <NUM_LIT:5> , <NUM_LIT:4> ) , ( <NUM_LIT:6> , <NUM_LIT:8> ) , <EOL> ( <NUM_LIT:7> , <NUM_LIT:8> ) , ( <NUM_LIT:8> , <NUM_LIT:8> ) , ( <NUM_LIT:9> , <NUM_LIT:8> ) , ( <NUM_LIT:10> , <NUM_LIT:8> ) , ( <NUM_LIT:11> , <NUM_LIT:12> ) , ( <NUM_LIT:12> , <NUM_LIT:12> ) , <EOL> ( <NUM_LIT> , <NUM_LIT:12> ) , ( <NUM_LIT> , <NUM_LIT:16> ) , ( <NUM_LIT:15> , <NUM_LIT:16> ) ] : <EOL> for p in xrange ( <NUM_LIT:15> ) : <EOL> self . assertEqual ( long ( float ( <NUM_LIT:2> L ** p * ( <NUM_LIT:2> ** <NUM_LIT> + x ) ) ) , <NUM_LIT:2> L ** p * ( <NUM_LIT:2> ** <NUM_LIT> + y ) ) <EOL> long_dbl_max = long ( DBL_MAX ) <EOL> top_power = <NUM_LIT:2> ** DBL_MAX_EXP <EOL> halfway = ( long_dbl_max + top_power ) // <NUM_LIT:2> <EOL> self . assertEqual ( float ( long_dbl_max ) , DBL_MAX ) <EOL> self . assertEqual ( float ( long_dbl_max + <NUM_LIT:1> ) , DBL_MAX ) <EOL> self . assertEqual ( float ( halfway - <NUM_LIT:1> ) , DBL_MAX ) <EOL> self . assertRaises ( OverflowError , float , halfway ) <EOL> self . assertEqual ( float ( <NUM_LIT:1> - halfway ) , - DBL_MAX ) <EOL> self . assertRaises ( OverflowError , float , - halfway ) <EOL> self . assertRaises ( OverflowError , float , top_power - <NUM_LIT:1> ) <EOL> self . assertRaises ( OverflowError , float , top_power ) <EOL> self . assertRaises ( OverflowError , float , top_power + <NUM_LIT:1> ) <EOL> self . assertRaises ( OverflowError , float , <NUM_LIT:2> * top_power - <NUM_LIT:1> ) <EOL> self . assertRaises ( OverflowError , float , <NUM_LIT:2> * top_power ) <EOL> self . assertRaises ( OverflowError , float , top_power * top_power ) <EOL> for p in xrange ( <NUM_LIT:100> ) : <EOL> x = long ( <NUM_LIT:2> ** p * ( <NUM_LIT:2> ** <NUM_LIT> + <NUM_LIT:1> ) + <NUM_LIT:1> ) <EOL> y = long ( <NUM_LIT:2> ** p * ( <NUM_LIT:2> ** <NUM_LIT> + <NUM_LIT:2> ) ) <EOL> self . assertEqual ( long ( float ( x ) ) , y ) <EOL> x = long ( <NUM_LIT:2> ** p * ( <NUM_LIT:2> ** <NUM_LIT> + <NUM_LIT:1> ) ) <EOL> y = long ( <NUM_LIT:2> ** p * <NUM_LIT:2> ** <NUM_LIT> ) <EOL> self . assertEqual ( long ( float ( x ) ) , y ) <EOL> def test_float_overflow ( self ) : <EOL> for x in - <NUM_LIT> , - <NUM_LIT:1.0> , <NUM_LIT:0.0> , <NUM_LIT:1.0> , <NUM_LIT> : <EOL> self . assertEqual ( float ( long ( x ) ) , x ) <EOL> shuge = '<STR_LIT>' * <NUM_LIT> <EOL> huge = <NUM_LIT:1> L << <NUM_LIT> <EOL> mhuge = - huge <EOL> namespace = { '<STR_LIT>' : huge , '<STR_LIT>' : mhuge , '<STR_LIT>' : shuge , '<STR_LIT>' : math } <EOL> for test in [ "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ] : <EOL> self . assertRaises ( OverflowError , eval , test , namespace ) <EOL> self . assertNotEqual ( float ( shuge ) , int ( shuge ) , <EOL> "<STR_LIT>" ) <EOL> def test_logs ( self ) : <EOL> LOG10E = math . log10 ( math . e ) <EOL> for exp in range ( <NUM_LIT:10> ) + [ <NUM_LIT:100> , <NUM_LIT:1000> , <NUM_LIT> ] : <EOL> value = <NUM_LIT:10> ** exp <EOL> log10 = math . log10 ( value ) <EOL> self . assertAlmostEqual ( log10 , exp ) <EOL> expected = exp / LOG10E <EOL> log = math . log ( value ) <EOL> self . assertAlmostEqual ( log , expected ) <EOL> for bad in - ( <NUM_LIT:1> L << <NUM_LIT> ) , - <NUM_LIT:2> L , <NUM_LIT:0> L : <EOL> self . assertRaises ( ValueError , math . log , bad ) <EOL> self . assertRaises ( ValueError , math . log10 , bad ) <EOL> def test_mixed_compares ( self ) : <EOL> eq = self . assertEqual <EOL> class Rat : <EOL> def __init__ ( self , value ) : <EOL> if isinstance ( value , ( int , long ) ) : <EOL> self . n = value <EOL> self . d = <NUM_LIT:1> <EOL> elif isinstance ( value , float ) : <EOL> f , e = math . frexp ( abs ( value ) ) <EOL> assert f == <NUM_LIT:0> or <NUM_LIT:0.5> <= f < <NUM_LIT:1.0> <EOL> CHUNK = <NUM_LIT> <EOL> top = <NUM_LIT:0> <EOL> while f : <EOL> f = math . ldexp ( f , CHUNK ) <EOL> digit = int ( f ) <EOL> assert digit >> CHUNK == <NUM_LIT:0> <EOL> top = ( top << CHUNK ) | digit <EOL> f -= digit <EOL> assert <NUM_LIT:0.0> <= f < <NUM_LIT:1.0> <EOL> e -= CHUNK <EOL> if e >= <NUM_LIT:0> : <EOL> n = top << e <EOL> d = <NUM_LIT:1> <EOL> else : <EOL> n = top <EOL> d = <NUM_LIT:1> << - e <EOL> if value < <NUM_LIT:0> : <EOL> n = - n <EOL> self . n = n <EOL> self . d = d <EOL> assert float ( n ) / float ( d ) == value <EOL> else : <EOL> raise TypeError ( "<STR_LIT>" % value ) <EOL> def __cmp__ ( self , other ) : <EOL> if not isinstance ( other , Rat ) : <EOL> other = Rat ( other ) <EOL> return cmp ( self . n * other . d , self . d * other . n ) <EOL> cases = [ <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1.0> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> for t in <NUM_LIT> ** <NUM_LIT> , <NUM_LIT> ** <NUM_LIT:50> , <NUM_LIT> ** <NUM_LIT> : <EOL> cases . extend ( [ t - <NUM_LIT:1.0> , t - <NUM_LIT> , t , t + <NUM_LIT> , t + <NUM_LIT:1.0> , <EOL> long ( t - <NUM_LIT:1> ) , long ( t ) , long ( t + <NUM_LIT:1> ) ] ) <EOL> cases . extend ( [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , sys . maxint , float ( sys . maxint ) ] ) <EOL> t = long ( <NUM_LIT> ) <EOL> cases . extend ( [ <NUM_LIT:0> L , <NUM_LIT:1> L , <NUM_LIT:2> L , <NUM_LIT:1> L << <NUM_LIT> , t - <NUM_LIT:1> , t , t + <NUM_LIT:1> ] ) <EOL> cases . extend ( [ - x for x in cases ] ) <EOL> for x in cases : <EOL> Rx = Rat ( x ) <EOL> for y in cases : <EOL> Ry = Rat ( y ) <EOL> Rcmp = cmp ( Rx , Ry ) <EOL> xycmp = cmp ( x , y ) <EOL> eq ( Rcmp , xycmp , Frm ( "<STR_LIT>" , x , y , Rcmp , xycmp ) ) <EOL> eq ( x == y , Rcmp == <NUM_LIT:0> , Frm ( "<STR_LIT>" , x , y , Rcmp ) ) <EOL> eq ( x != y , Rcmp != <NUM_LIT:0> , Frm ( "<STR_LIT>" , x , y , Rcmp ) ) <EOL> eq ( x < y , Rcmp < <NUM_LIT:0> , Frm ( "<STR_LIT>" , x , y , Rcmp ) ) <EOL> eq ( x <= y , Rcmp <= <NUM_LIT:0> , Frm ( "<STR_LIT>" , x , y , Rcmp ) ) <EOL> eq ( x > y , Rcmp > <NUM_LIT:0> , Frm ( "<STR_LIT>" , x , y , Rcmp ) ) <EOL> eq ( x >= y , Rcmp >= <NUM_LIT:0> , Frm ( "<STR_LIT>" , x , y , Rcmp ) ) <EOL> def test_nan_inf ( self ) : <EOL> self . assertRaises ( OverflowError , long , float ( '<STR_LIT>' ) ) <EOL> self . assertRaises ( OverflowError , long , float ( '<STR_LIT>' ) ) <EOL> self . assertRaises ( ValueError , long , float ( '<STR_LIT>' ) ) <EOL> def test_bit_length ( self ) : <EOL> tiny = <NUM_LIT> <EOL> for x in xrange ( - <NUM_LIT> , <NUM_LIT> ) : <EOL> x = long ( x ) <EOL> k = x . bit_length ( ) <EOL> self . assertEqual ( k , len ( bin ( x ) . lstrip ( '<STR_LIT>' ) ) ) <EOL> if x != <NUM_LIT:0> : <EOL> self . assertTrue ( <NUM_LIT:2> ** ( k - <NUM_LIT:1> ) <= abs ( x ) < <NUM_LIT:2> ** k ) <EOL> else : <EOL> self . assertEqual ( k , <NUM_LIT:0> ) <EOL> if x != <NUM_LIT:0> : <EOL> self . assertEqual ( k , <NUM_LIT:1> + math . floor ( <EOL> math . log ( abs ( x ) ) / math . log ( <NUM_LIT:2> ) + tiny ) ) <EOL> self . assertEqual ( ( <NUM_LIT:0> L ) . bit_length ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( ( <NUM_LIT:1> L ) . bit_length ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( ( - <NUM_LIT:1> L ) . bit_length ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( ( <NUM_LIT:2> L ) . bit_length ( ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( ( - <NUM_LIT:2> L ) . bit_length ( ) , <NUM_LIT:2> ) <EOL> for i in [ <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:15> , <NUM_LIT:16> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:32> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:64> , <NUM_LIT> ] : <EOL> a = <NUM_LIT:2> L ** i <EOL> self . assertEqual ( ( a - <NUM_LIT:1> ) . bit_length ( ) , i ) <EOL> self . assertEqual ( ( <NUM_LIT:1> - a ) . bit_length ( ) , i ) <EOL> self . assertEqual ( ( a ) . bit_length ( ) , i + <NUM_LIT:1> ) <EOL> self . assertEqual ( ( - a ) . bit_length ( ) , i + <NUM_LIT:1> ) <EOL> self . assertEqual ( ( a + <NUM_LIT:1> ) . bit_length ( ) , i + <NUM_LIT:1> ) <EOL> self . assertEqual ( ( - a - <NUM_LIT:1> ) . bit_length ( ) , i + <NUM_LIT:1> ) <EOL> def test_main ( ) : <EOL> test_support . run_unittest ( LongTest ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test_main ( ) </s>
