summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_long.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2008-07-13 17:44:16 (GMT)
committerBenjamin Peterson <benjamin@python.org>2008-07-13 17:44:16 (GMT)
commit875d4c099bae13a5d82bc9a2efd970473a65ec20 (patch)
tree60bf9b8225340f10bfbee8184093915ae03941fb /Lib/test/test_long.py
parent69cec0412cbea658670c894c95becc807588a9c7 (diff)
downloadcpython-875d4c099bae13a5d82bc9a2efd970473a65ec20.zip
cpython-875d4c099bae13a5d82bc9a2efd970473a65ec20.tar.gz
cpython-875d4c099bae13a5d82bc9a2efd970473a65ec20.tar.bz2
move test_long_future into test_long
Diffstat (limited to 'Lib/test/test_long.py')
-rw-r--r--Lib/test/test_long.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/Lib/test/test_long.py b/Lib/test/test_long.py
index 21881c9..b00f736 100644
--- a/Lib/test/test_long.py
+++ b/Lib/test/test_long.py
@@ -770,6 +770,41 @@ class LongTest(unittest.TestCase):
self.assertRaises(OverflowError, int, float('inf'))
self.assertRaises(OverflowError, int, float('nan'))
+ def test_true_division(self):
+ huge = 1 << 40000
+ mhuge = -huge
+ self.assertEqual(huge / huge, 1.0)
+ self.assertEqual(mhuge / mhuge, 1.0)
+ self.assertEqual(huge / mhuge, -1.0)
+ self.assertEqual(mhuge / huge, -1.0)
+ self.assertEqual(1 / huge, 0.0)
+ self.assertEqual(1 / huge, 0.0)
+ self.assertEqual(1 / mhuge, 0.0)
+ self.assertEqual(1 / mhuge, 0.0)
+ self.assertEqual((666 * huge + (huge >> 1)) / huge, 666.5)
+ self.assertEqual((666 * mhuge + (mhuge >> 1)) / mhuge, 666.5)
+ self.assertEqual((666 * huge + (huge >> 1)) / mhuge, -666.5)
+ self.assertEqual((666 * mhuge + (mhuge >> 1)) / huge, -666.5)
+ self.assertEqual(huge / (huge << 1), 0.5)
+ self.assertEqual((1000000 * huge) / huge, 1000000)
+
+ namespace = {'huge': huge, 'mhuge': mhuge}
+
+ for overflow in ["float(huge)", "float(mhuge)",
+ "huge / 1", "huge / 2", "huge / -1", "huge / -2",
+ "mhuge / 100", "mhuge / 200"]:
+ self.assertRaises(OverflowError, eval, overflow, namespace)
+
+ for underflow in ["1 / huge", "2 / huge", "-1 / huge", "-2 / huge",
+ "100 / mhuge", "200 / mhuge"]:
+ result = eval(underflow, namespace)
+ self.assertEqual(result, 0.0,
+ "expected underflow to 0 from %r" % underflow)
+
+ for zero in ["huge / 0", "mhuge / 0"]:
+ self.assertRaises(ZeroDivisionError, eval, zero, namespace)
+
+
def test_main():
support.run_unittest(LongTest)