PyXR

c:\python24\lib \ test \ test_long_future.py



0001 from __future__ import division
0002 # When true division is the default, get rid of this and add it to
0003 # test_long.py instead.  In the meantime, it's too obscure to try to
0004 # trick just part of test_long into using future division.
0005 
0006 from test.test_support import TestFailed, verify, verbose
0007 
0008 def test_true_division():
0009     if verbose:
0010         print "long true division"
0011     huge = 1L << 40000
0012     mhuge = -huge
0013     verify(huge / huge == 1.0)
0014     verify(mhuge / mhuge == 1.0)
0015     verify(huge / mhuge == -1.0)
0016     verify(mhuge / huge == -1.0)
0017     verify(1 / huge == 0.0)
0018     verify(1L / huge == 0.0)
0019     verify(1 / mhuge == 0.0)
0020     verify(1L / mhuge == 0.0)
0021     verify((666 * huge + (huge >> 1)) / huge == 666.5)
0022     verify((666 * mhuge + (mhuge >> 1)) / mhuge == 666.5)
0023     verify((666 * huge + (huge >> 1)) / mhuge == -666.5)
0024     verify((666 * mhuge + (mhuge >> 1)) / huge == -666.5)
0025     verify(huge / (huge << 1) == 0.5)
0026     verify((1000000 * huge) / huge == 1000000)
0027 
0028     namespace = {'huge': huge, 'mhuge': mhuge}
0029 
0030     for overflow in ["float(huge)", "float(mhuge)",
0031                      "huge / 1", "huge / 2L", "huge / -1", "huge / -2L",
0032                      "mhuge / 100", "mhuge / 100L"]:
0033         try:
0034             eval(overflow, namespace)
0035         except OverflowError:
0036             pass
0037         else:
0038             raise TestFailed("expected OverflowError from %r" % overflow)
0039 
0040     for underflow in ["1 / huge", "2L / huge", "-1 / huge", "-2L / huge",
0041                      "100 / mhuge", "100L / mhuge"]:
0042         result = eval(underflow, namespace)
0043         if result != 0.0:
0044             raise TestFailed("expected underflow to 0 from %r" % underflow)
0045 
0046     for zero in ["huge / 0", "huge / 0L",
0047                  "mhuge / 0", "mhuge / 0L"]:
0048         try:
0049             eval(zero, namespace)
0050         except ZeroDivisionError:
0051             pass
0052         else:
0053             raise TestFailed("expected ZeroDivisionError from %r" % zero)
0054 
0055 test_true_division()
0056 

Generated by PyXR 0.9.4
SourceForge.net Logo