summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_long.py
diff options
context:
space:
mode:
authorFacundo Batista <facundobatista@gmail.com>2008-07-24 18:57:11 (GMT)
committerFacundo Batista <facundobatista@gmail.com>2008-07-24 18:57:11 (GMT)
commit6e6f59b1c9fc01d2cf0404c775214819e6f07b34 (patch)
treeea9e73c3c38651115e4adf5195a5171076482bc8 /Lib/test/test_long.py
parent00c88f090db65fbe782b46e0ac0b1b08dbb42044 (diff)
downloadcpython-6e6f59b1c9fc01d2cf0404c775214819e6f07b34.zip
cpython-6e6f59b1c9fc01d2cf0404c775214819e6f07b34.tar.gz
cpython-6e6f59b1c9fc01d2cf0404c775214819e6f07b34.tar.bz2
Optimization to stop creating new small longs and use the
one previously stored. Issue 2417.
Diffstat (limited to 'Lib/test/test_long.py')
-rw-r--r--Lib/test/test_long.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_long.py b/Lib/test/test_long.py
index b00f736..c475878 100644
--- a/Lib/test/test_long.py
+++ b/Lib/test/test_long.py
@@ -805,6 +805,24 @@ class LongTest(unittest.TestCase):
self.assertRaises(ZeroDivisionError, eval, zero, namespace)
+ def test_small_ints(self):
+ for i in range(-5, 257):
+ self.assertTrue(i is i + 0)
+ self.assertTrue(i is i * 1)
+ self.assertTrue(i is i - 0)
+ self.assertTrue(i is i // 1)
+ self.assertTrue(i is i & -1)
+ self.assertTrue(i is i | 0)
+ self.assertTrue(i is i ^ 0)
+ self.assertTrue(i is ~~i)
+ self.assertTrue(i is i**1)
+ self.assertTrue(i is int(str(i)))
+ self.assertTrue(i is i<<2>>2, str(i))
+ # corner cases
+ i = 1 << 70
+ self.assertTrue(i - i is 0)
+ self.assertTrue(0 * i is 0)
+
def test_main():
support.run_unittest(LongTest)