summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-08-23 22:56:21 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-08-23 22:56:21 (GMT)
commit26c7fa355a129778d21a8cf973f852dd592b792b (patch)
treea80a3c0f55eccb796fad11fe78244538c136a0e8
parent96685bfbf0e954febd4f873721d3db5d03cb2d99 (diff)
downloadcpython-26c7fa355a129778d21a8cf973f852dd592b792b.zip
cpython-26c7fa355a129778d21a8cf973f852dd592b792b.tar.gz
cpython-26c7fa355a129778d21a8cf973f852dd592b792b.tar.bz2
SF bug [#454456] int overflow code needs tests.
Added tests for boundary cases in magical PEP 237 int->long auto-overflow, but nothing here addresses the rest of the bug report so left it open.
-rw-r--r--Lib/test/test_long.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/Lib/test/test_long.py b/Lib/test/test_long.py
index 8cbdde5..60adb74 100644
--- a/Lib/test/test_long.py
+++ b/Lib/test/test_long.py
@@ -255,9 +255,70 @@ def test_misc(maxdigits=MAXDIGITS):
except:
raise TestFailed, "int(long(-sys.maxint-1) - 1) didn't overflow"
+# ----------------------------------- tests of auto int->long conversion
+
+def test_auto_overflow():
+ import math, sys
+
+ if verbose:
+ print "auto-convert int->long on overflow"
+
+ special = [0, 1, 2, 3, sys.maxint-1, sys.maxint, sys.maxint+1]
+ sqrt = int(math.sqrt(sys.maxint))
+ special.extend([sqrt-1, sqrt, sqrt+1])
+ special.extend([-i for i in special])
+
+ def checkit(*args):
+ # Heavy use of nested scopes here!
+ verify(got == expected, "for %r expected %r got %r" %
+ (args, expected, got))
+
+ for x in special:
+ longx = long(x)
+
+ expected = -longx
+ got = -x
+ checkit('-', x)
+
+ for y in special:
+ longy = long(y)
+
+ expected = longx + longy
+ got = x + y
+ checkit(x, '+', y)
+
+ expected = longx - longy
+ got = x - y
+ checkit(x, '-', y)
+
+ expected = longx * longy
+ got = x * y
+ checkit(x, '*', y)
+
+ if y:
+ expected = longx / longy
+ got = x / y
+ checkit(x, '/', y)
+
+ expected = divmod(longx, longy)
+ got = divmod(longx, longy)
+ checkit(x, 'divmod', y)
+
+ if abs(y) < 5 and not (x == 0 and y < 0):
+ expected = longx ** longy
+ got = x ** y
+ checkit(x, '**', y)
+
+ for z in special:
+ if z != 0:
+ expected = pow(longx, longy, long(z))
+ got = pow(x, y, z)
+ checkit('pow', x, y, '%', z)
+
# ---------------------------------------------------------------- do it
test_division()
test_bitop_identities()
test_format()
test_misc()
+test_auto_overflow()