summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_builtin.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2003-04-11 18:43:06 (GMT)
committerGuido van Rossum <guido@python.org>2003-04-11 18:43:06 (GMT)
commitefbbb1c60237a9a2997dc4b1ab213e4c6f0da824 (patch)
treec2fd52c7be4ed7015749f88056e8f6c558419f8f /Lib/test/test_builtin.py
parenta1ce93f87cb221be9a7466c2f9d2b7dc494f458d (diff)
downloadcpython-efbbb1c60237a9a2997dc4b1ab213e4c6f0da824.zip
cpython-efbbb1c60237a9a2997dc4b1ab213e4c6f0da824.tar.gz
cpython-efbbb1c60237a9a2997dc4b1ab213e4c6f0da824.tar.bz2
Patch by Chad Netzer (with significant change):
- range() now works even if the arguments are longs with magnitude larger than sys.maxint, as long as the total length of the sequence fits. E.g., range(2**100, 2**101, 2**100) is the following list: [1267650600228229401496703205376L]. (SF patch #707427.)
Diffstat (limited to 'Lib/test/test_builtin.py')
-rw-r--r--Lib/test/test_builtin.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index af497a0..5912e85 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -6,6 +6,8 @@ from test.test_support import fcmp, have_unicode, TESTFN, unlink
import sys, warnings, cStringIO
warnings.filterwarnings("ignore", "hex../oct.. of negative int",
FutureWarning, __name__)
+warnings.filterwarnings("ignore", "integer argument expected",
+ DeprecationWarning, "unittest")
class Squares:
@@ -925,10 +927,43 @@ class BuiltinTest(unittest.TestCase):
self.assertEqual(range(1, 10, 3), [1, 4, 7])
self.assertEqual(range(5, -5, -3), [5, 2, -1, -4])
+ # Now test range() with longs
+ self.assertEqual(range(-2**100), [])
+ self.assertEqual(range(0, -2**100), [])
+ self.assertEqual(range(0, 2**100, -1), [])
+ self.assertEqual(range(0, 2**100, -1), [])
+
+ a = long(10 * sys.maxint)
+ b = long(100 * sys.maxint)
+ c = long(50 * sys.maxint)
+
+ self.assertEqual(range(a, a+2), [a, a+1])
+ self.assertEqual(range(a+2, a, -1L), [a+2, a+1])
+ self.assertEqual(range(a+4, a, -2), [a+4, a+2])
+
+ seq = range(a, b, c)
+ self.assert_(a in seq)
+ self.assert_(b not in seq)
+ self.assertEqual(len(seq), 2)
+
+ seq = range(b, a, -c)
+ self.assert_(b in seq)
+ self.assert_(a not in seq)
+ self.assertEqual(len(seq), 2)
+
+ seq = range(-a, -b, -c)
+ self.assert_(-a in seq)
+ self.assert_(-b not in seq)
+ self.assertEqual(len(seq), 2)
+
self.assertRaises(TypeError, range)
self.assertRaises(TypeError, range, 1, 2, 3, 4)
self.assertRaises(ValueError, range, 1, 2, 0)
+ # Reject floats when it would require PyLongs to represent.
+ # (smaller floats still accepted, but deprecated)
+ self.assertRaises(ValueError, range, 1e100, 1e101, 1e101)
+
def test_input_and_raw_input(self):
self.write_testfile()
fp = open(TESTFN, 'r')