From 875d4c099bae13a5d82bc9a2efd970473a65ec20 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sun, 13 Jul 2008 17:44:16 +0000 Subject: [PATCH] move test_long_future into test_long --- Lib/test/test_long.py | 35 +++++++++++++++++++++++ Lib/test/test_long_future.py | 55 ------------------------------------ 2 files changed, 35 insertions(+), 55 deletions(-) delete mode 100644 Lib/test/test_long_future.py diff --git a/Lib/test/test_long.py b/Lib/test/test_long.py index 21881c97c9f..b00f7360646 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 428b03aeb49..00000000000 --- 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()