diff options
author | 4kir4 <4kir4.1i@gmail.com> | 2017-03-20 06:44:46 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2017-03-20 06:44:46 (GMT) |
commit | e46fb8611867fa3b407a813f53137929b7cb4a10 (patch) | |
tree | 9165a0264f38ddfd82cce4080b190f1b5225e95d /Lib/test/test_range.py | |
parent | 64508780d72769e4c7afc67a511c057261c578f6 (diff) | |
download | cpython-e46fb8611867fa3b407a813f53137929b7cb4a10.zip cpython-e46fb8611867fa3b407a813f53137929b7cb4a10.tar.gz cpython-e46fb8611867fa3b407a813f53137929b7cb4a10.tar.bz2 |
bpo-28876: bool of large range raises OverflowError (#699)
Diffstat (limited to 'Lib/test/test_range.py')
-rw-r--r-- | Lib/test/test_range.py | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/Lib/test/test_range.py b/Lib/test/test_range.py index 3675f25..ce15847 100644 --- a/Lib/test/test_range.py +++ b/Lib/test/test_range.py @@ -98,20 +98,24 @@ class RangeTest(unittest.TestCase): x = range(10**20+10, 10**20, 3) self.assertEqual(len(x), 0) self.assertEqual(len(list(x)), 0) + self.assertFalse(x) x = range(10**20, 10**20+10, -3) self.assertEqual(len(x), 0) self.assertEqual(len(list(x)), 0) + self.assertFalse(x) x = range(10**20+10, 10**20, -3) self.assertEqual(len(x), 4) self.assertEqual(len(list(x)), 4) + self.assertTrue(x) # Now test range() with longs - self.assertEqual(list(range(-2**100)), []) - self.assertEqual(list(range(0, -2**100)), []) - self.assertEqual(list(range(0, 2**100, -1)), []) - self.assertEqual(list(range(0, 2**100, -1)), []) + for x in [range(-2**100), + range(0, -2**100), + range(0, 2**100, -1)]: + self.assertEqual(list(x), []) + self.assertFalse(x) a = int(10 * sys.maxsize) b = int(100 * sys.maxsize) @@ -152,6 +156,7 @@ class RangeTest(unittest.TestCase): step = x[1] - x[0] length = 1 + ((x[-1] - x[0]) // step) return length + a = -sys.maxsize b = sys.maxsize expected_len = b - a @@ -159,6 +164,7 @@ class RangeTest(unittest.TestCase): self.assertIn(a, x) self.assertNotIn(b, x) self.assertRaises(OverflowError, len, x) + self.assertTrue(x) self.assertEqual(_range_len(x), expected_len) self.assertEqual(x[0], a) idx = sys.maxsize+1 @@ -176,6 +182,7 @@ class RangeTest(unittest.TestCase): self.assertIn(a, x) self.assertNotIn(b, x) self.assertRaises(OverflowError, len, x) + self.assertTrue(x) self.assertEqual(_range_len(x), expected_len) self.assertEqual(x[0], a) idx = sys.maxsize+1 @@ -194,6 +201,7 @@ class RangeTest(unittest.TestCase): self.assertIn(a, x) self.assertNotIn(b, x) self.assertRaises(OverflowError, len, x) + self.assertTrue(x) self.assertEqual(_range_len(x), expected_len) self.assertEqual(x[0], a) idx = sys.maxsize+1 @@ -212,6 +220,7 @@ class RangeTest(unittest.TestCase): self.assertIn(a, x) self.assertNotIn(b, x) self.assertRaises(OverflowError, len, x) + self.assertTrue(x) self.assertEqual(_range_len(x), expected_len) self.assertEqual(x[0], a) idx = sys.maxsize+1 |