[Python-checkins] python/dist/src/Lib/test test_long.py,1.19,1.20

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
2002年8月13日 14:06:57 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv21095/python/Lib/test
Modified Files:
	test_long.py 
Log Message:
Added a test specifically to tickle Karatsuba; it costs no appreciable
runtime.
Index: test_long.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_long.py,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** test_long.py	13 Aug 2002 02:24:25 -0000	1.19
--- test_long.py	13 Aug 2002 21:06:55 -0000	1.20
***************
*** 100,104 ****
--- 100,129 ----
 y = getran(leny) or 1L
 test_division_2(x, y)
+ # ------------------------------------------------------------ karatsuba
+ 
+ def test_karatsuba():
 
+ if verbose:
+ print "Karatsuba"
+ 
+ digits = range(1, 5) + range(KARATSUBA_CUTOFF, KARATSUBA_CUTOFF + 10)
+ digits.extend([KARATSUBA_CUTOFF * 10, KARATSUBA_CUTOFF * 100])
+ 
+ bits = [digit * SHIFT for digit in digits]
+ 
+ # Test products of long strings of 1 bits -- (2**x-1)*(2**y-1) ==
+ # 2**(x+y) - 2**x - 2**y + 1, so the proper result is easy to check.
+ for abits in bits:
+ a = (1L << abits) - 1
+ for bbits in bits:
+ if bbits < abits:
+ continue
+ b = (1L << bbits) - 1
+ x = a * b
+ y = ((1L << (abits + bbits)) -
+ (1L << abits) -
+ (1L << bbits) +
+ 1)
+ check(x == y, "bad result for", a, "*", b, x, y)
 # -------------------------------------------------------------- ~ & | ^
 
***************
*** 404,407 ****
--- 429,433 ----
 
 test_division()
+ test_karatsuba()
 test_bitop_identities()
 test_format()

AltStyle によって変換されたページ (->オリジナル) /