summaryrefslogtreecommitdiffstats
path: root/Lib
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
parent69cec0412cbea658670c894c95becc807588a9c7 (diff)
downloadcpython-875d4c099bae13a5d82bc9a2efd970473a65ec20.zip
cpython-875d4c099bae13a5d82bc9a2efd970473a65ec20.tar.gz
cpython-875d4c099bae13a5d82bc9a2efd970473a65ec20.tar.bz2
move test_long_future into test_long
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_long.py35
-rw-r--r--Lib/test/test_long_future.py55
2 files changed, 35 insertions, 55 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)
diff --git a/Lib/test/test_long_future.py b/Lib/test/test_long_future.py
deleted file mode 100644
index 428b03a..0000000
--- a/Lib/test/test_long_future.py
+++ /dev/null
@@ -1,55 +0,0 @@
-from __future__ import division
-# When true division is the default, get rid of this and add it to
-# test_long.py instead. In the meantime, it's too obscure to try to
-# trick just part of test_long into using future division.
-
-import unittest
-from test.support import run_unittest
-
-class TrueDivisionTests(unittest.TestCase):
- def test(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"]:
- # XXX(cwinter) this test doesn't pass when converted to
- # use assertRaises.
- try:
- eval(overflow, namespace)
- self.fail("expected OverflowError from %r" % overflow)
- except OverflowError:
- pass
-
- 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():
- run_unittest(TrueDivisionTests)
-
-if __name__ == "__main__":
- test_main()