diff options
author | Collin Winter <collinw@gmail.com> | 2007-04-05 20:05:07 (GMT) |
---|---|---|
committer | Collin Winter <collinw@gmail.com> | 2007-04-05 20:05:07 (GMT) |
commit | fe712fb9cacc9d04d80853ae3cd6e134a04610f1 (patch) | |
tree | 8158186535bc986c03e9d6cd4c6b6ca5e73b9cb8 | |
parent | 7a3d41f4ca7a94267063ee50250ed5199ba8daf5 (diff) | |
download | cpython-fe712fb9cacc9d04d80853ae3cd6e134a04610f1.zip cpython-fe712fb9cacc9d04d80853ae3cd6e134a04610f1.tar.gz cpython-fe712fb9cacc9d04d80853ae3cd6e134a04610f1.tar.bz2 |
Convert test_long_future to use unittest.
-rw-r--r-- | Lib/test/test_long_future.py | 100 |
1 files changed, 50 insertions, 50 deletions
diff --git a/Lib/test/test_long_future.py b/Lib/test/test_long_future.py index 074c148..b62048a 100644 --- a/Lib/test/test_long_future.py +++ b/Lib/test/test_long_future.py @@ -3,53 +3,53 @@ from __future__ import division # test_long.py instead. In the meantime, it's too obscure to try to # trick just part of test_long into using future division. -from test.test_support import TestFailed, verify, verbose - -def test_true_division(): - if verbose: - print "long true division" - huge = 1L << 40000 - mhuge = -huge - verify(huge / huge == 1.0) - verify(mhuge / mhuge == 1.0) - verify(huge / mhuge == -1.0) - verify(mhuge / huge == -1.0) - verify(1 / huge == 0.0) - verify(1L / huge == 0.0) - verify(1 / mhuge == 0.0) - verify(1L / mhuge == 0.0) - verify((666 * huge + (huge >> 1)) / huge == 666.5) - verify((666 * mhuge + (mhuge >> 1)) / mhuge == 666.5) - verify((666 * huge + (huge >> 1)) / mhuge == -666.5) - verify((666 * mhuge + (mhuge >> 1)) / huge == -666.5) - verify(huge / (huge << 1) == 0.5) - verify((1000000 * huge) / huge == 1000000) - - namespace = {'huge': huge, 'mhuge': mhuge} - - for overflow in ["float(huge)", "float(mhuge)", - "huge / 1", "huge / 2L", "huge / -1", "huge / -2L", - "mhuge / 100", "mhuge / 100L"]: - try: - eval(overflow, namespace) - except OverflowError: - pass - else: - raise TestFailed("expected OverflowError from %r" % overflow) - - for underflow in ["1 / huge", "2L / huge", "-1 / huge", "-2L / huge", - "100 / mhuge", "100L / mhuge"]: - result = eval(underflow, namespace) - if result != 0.0: - raise TestFailed("expected underflow to 0 from %r" % underflow) - - for zero in ["huge / 0", "huge / 0L", - "mhuge / 0", "mhuge / 0L"]: - try: - eval(zero, namespace) - except ZeroDivisionError: - pass - else: - raise TestFailed("expected ZeroDivisionError from %r" % zero) - -test_true_division() +import unittest +from test.test_support import run_unittest + +class TrueDivisionTests(unittest.TestCase): + def test(self): + huge = 1L << 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(1L / huge, 0.0) + self.assertEqual(1 / mhuge, 0.0) + self.assertEqual(1L / 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 / 2L", "huge / -1", "huge / -2L", + "mhuge / 100", "mhuge / 100L"]: + # 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", "2L / huge", "-1 / huge", "-2L / huge", + "100 / mhuge", "100L / mhuge"]: + result = eval(underflow, namespace) + self.assertEqual(result, 0.0, + "expected underflow to 0 from %r" % underflow) + + for zero in ["huge / 0", "huge / 0L", "mhuge / 0", "mhuge / 0L"]: + self.assertRaises(ZeroDivisionError, eval, zero, namespace) + + +def test_main(): + run_unittest(TrueDivisionTests) + +if __name__ == "__main__": + test_main() |