[Python-checkins] CVS: python/dist/src/Lib/test test_types.py,1.21,1.22

Tim Peters tim_one@users.sourceforge.net
Tue, 04 Dec 2001 15:05:12 -0800


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv31267/python/Lib/test

Modified Files:
	test_types.py 
Log Message:
SF bug #488480: integer multiply to return -max_int-1.
int_mul():  new and vastly simpler overflow checking.  Whether it's
faster or slower will likely vary across platforms, favoring boxes
with fast floating point.  OTOH, we no longer have to worry about
people shipping broken LONG_BIT definitions <0.9 wink>.


Index: test_types.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_types.py,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** test_types.py	2001/06/26 20:09:28	1.21
--- test_types.py	2001/12/04 23:05:10	1.22
***************
*** 72,75 ****
--- 72,101 ----
  if not (xsize*ysize*zsize == zsize*xsize*ysize == 338912):
      raise TestFailed, 'int mul commutativity'
+ # And another.
+ m = -sys.maxint - 1
+ for divisor in 1, 2, 4, 8, 16, 32:
+     j = m / divisor
+     prod = divisor * j
+     if prod != m:
+         raise TestFailed, "%r * %r == %r != %r" % (divisor, j, prod, m)
+     if type(prod) is not int:
+         raise TestFailed, ("expected type(prod) to be int, not %r" %
+                            type(prod))
+ # Check for expected * overflow to long.
+ for divisor in 1, 2, 4, 8, 16, 32:
+     j = m / divisor - 1
+     prod = divisor * j
+     if type(prod) is not long:
+         raise TestFailed, ("expected type(%r) to be long, not %r" %
+                            (prod, type(prod)))
+ # Check for expected * overflow to long.
+ m = sys.maxint
+ for divisor in 1, 2, 4, 8, 16, 32:
+     j = m / divisor + 1
+     prod = divisor * j
+     if type(prod) is not long:
+         raise TestFailed, ("expected type(%r) to be long, not %r" %
+                            (prod, type(prod)))
+ 
  print '6.4.2 Long integers'
  if 12L + 24L != 36L: raise TestFailed, 'long op'