diff options
author | cinap_lenrek <cinap_lenrek@localhost> | 2011-05-03 11:25:13 +0000 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@localhost> | 2011-05-03 11:25:13 +0000 |
commit | 458120dd40db6b4df55a4e96b650e16798ef06a0 (patch) | |
tree | 8f82685be24fef97e715c6f5ca4c68d34d5074ee /sys/lib/python/test/test_long_future.py | |
parent | 3a742c699f6806c1145aea5149bf15de15a0afd7 (diff) |
add hg and python
Diffstat (limited to 'sys/lib/python/test/test_long_future.py')
-rw-r--r-- | sys/lib/python/test/test_long_future.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/sys/lib/python/test/test_long_future.py b/sys/lib/python/test/test_long_future.py new file mode 100644 index 000000000..074c1489f --- /dev/null +++ b/sys/lib/python/test/test_long_future.py @@ -0,0 +1,55 @@ +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. + +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() |