annotate Lib/test/test_long_future.py @ 40775:4cdf21a0dbbc

Fix most trivially-findable print statements. There's one major and one minor category still unfixed: doctests are the major category (and I hope to be able to augment the refactoring tool to refactor bona fide doctests soon); other code generating print statements in strings is the minor category. (Oh, and I don't know if the compiler package works.)
author Guido van Rossum <guido@python.org>
date Fri, 09 Feb 2007 05:37:30 +0000
parents 1c26505c1de6
children 06145fbc7ab9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19677
91533675d6cb Change long/long true division to return as many good bits as it can;
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
1 from __future__ import division
91533675d6cb Change long/long true division to return as many good bits as it can;
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
2 # When true division is the default, get rid of this and add it to
91533675d6cb Change long/long true division to return as many good bits as it can;
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
3 # test_long.py instead. In the meantime, it's too obscure to try to
91533675d6cb Change long/long true division to return as many good bits as it can;
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
4 # trick just part of test_long into using future division.
91533675d6cb Change long/long true division to return as many good bits as it can;
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
5
24364
aa0d2d51fbde Get rid of relative imports in all unittests. Now anything that
Barry Warsaw <barry@python.org>
parents: 19792
diff changeset
6 from test.test_support import TestFailed, verify, verbose
19677
91533675d6cb Change long/long true division to return as many good bits as it can;
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
7
91533675d6cb Change long/long true division to return as many good bits as it can;
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
8 def test_true_division():
91533675d6cb Change long/long true division to return as many good bits as it can;
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
9 if verbose:
40775
4cdf21a0dbbc Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents: 40644
diff changeset
10 print("long true division")
40644
1c26505c1de6 Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
11 huge = 1 << 40000
19677
91533675d6cb Change long/long true division to return as many good bits as it can;
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
12 mhuge = -huge
91533675d6cb Change long/long true division to return as many good bits as it can;
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
13 verify(huge / huge == 1.0)
91533675d6cb Change long/long true division to return as many good bits as it can;
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
14 verify(mhuge / mhuge == 1.0)
91533675d6cb Change long/long true division to return as many good bits as it can;
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
15 verify(huge / mhuge == -1.0)
91533675d6cb Change long/long true division to return as many good bits as it can;
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
16 verify(mhuge / huge == -1.0)
91533675d6cb Change long/long true division to return as many good bits as it can;
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
17 verify(1 / huge == 0.0)
40644
1c26505c1de6 Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
18 verify(1 / huge == 0.0)
19677
91533675d6cb Change long/long true division to return as many good bits as it can;
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
19 verify(1 / mhuge == 0.0)
40644
1c26505c1de6 Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
20 verify(1 / mhuge == 0.0)
19677
91533675d6cb Change long/long true division to return as many good bits as it can;
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
21 verify((666 * huge + (huge >> 1)) / huge == 666.5)
91533675d6cb Change long/long true division to return as many good bits as it can;
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
22 verify((666 * mhuge + (mhuge >> 1)) / mhuge == 666.5)
91533675d6cb Change long/long true division to return as many good bits as it can;
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
23 verify((666 * huge + (huge >> 1)) / mhuge == -666.5)
91533675d6cb Change long/long true division to return as many good bits as it can;
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
24 verify((666 * mhuge + (mhuge >> 1)) / huge == -666.5)
91533675d6cb Change long/long true division to return as many good bits as it can;
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
25 verify(huge / (huge << 1) == 0.5)
19678
82db9a9006ac Fixed a typo and added more tests.
Tim Peters <tim.peters@gmail.com>
parents: 19677
diff changeset
26 verify((1000000 * huge) / huge == 1000000)
19677
91533675d6cb Change long/long true division to return as many good bits as it can;
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
27
91533675d6cb Change long/long true division to return as many good bits as it can;
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
28 namespace = {'huge': huge, 'mhuge': mhuge}
19678
82db9a9006ac Fixed a typo and added more tests.
Tim Peters <tim.peters@gmail.com>
parents: 19677
diff changeset
29
19677
91533675d6cb Change long/long true division to return as many good bits as it can;
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
30 for overflow in ["float(huge)", "float(mhuge)",
40644
1c26505c1de6 Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
31 "huge / 1", "huge / 2", "huge / -1", "huge / -2",
1c26505c1de6 Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
32 "mhuge / 100", "mhuge / 100"]:
19677
91533675d6cb Change long/long true division to return as many good bits as it can;
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
33 try:
91533675d6cb Change long/long true division to return as many good bits as it can;
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
34 eval(overflow, namespace)
91533675d6cb Change long/long true division to return as many good bits as it can;
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
35 except OverflowError:
91533675d6cb Change long/long true division to return as many good bits as it can;
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
36 pass
91533675d6cb Change long/long true division to return as many good bits as it can;
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
37 else:
91533675d6cb Change long/long true division to return as many good bits as it can;
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
38 raise TestFailed("expected OverflowError from %r" % overflow)
91533675d6cb Change long/long true division to return as many good bits as it can;
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
39
40644
1c26505c1de6 Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
40 for underflow in ["1 / huge", "2 / huge", "-1 / huge", "-2 / huge",
1c26505c1de6 Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
41 "100 / mhuge", "100 / mhuge"]:
19789
94e141e20d61 Added some underflow-to-0.0 long/long true division tests.
Tim Peters <tim.peters@gmail.com>
parents: 19678
diff changeset
42 result = eval(underflow, namespace)
94e141e20d61 Added some underflow-to-0.0 long/long true division tests.
Tim Peters <tim.peters@gmail.com>
parents: 19678
diff changeset
43 if result != 0.0:
19792
b35a2bf0c980 Fix typo in error reporting. This doesn't need to go into the release
Tim Peters <tim.peters@gmail.com>
parents: 19789
diff changeset
44 raise TestFailed("expected underflow to 0 from %r" % underflow)
19789
94e141e20d61 Added some underflow-to-0.0 long/long true division tests.
Tim Peters <tim.peters@gmail.com>
parents: 19678
diff changeset
45
40644
1c26505c1de6 Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
46 for zero in ["huge / 0", "huge / 0",
1c26505c1de6 Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
47 "mhuge / 0", "mhuge / 0"]:
19678
82db9a9006ac Fixed a typo and added more tests.
Tim Peters <tim.peters@gmail.com>
parents: 19677
diff changeset
48 try:
82db9a9006ac Fixed a typo and added more tests.
Tim Peters <tim.peters@gmail.com>
parents: 19677
diff changeset
49 eval(zero, namespace)
82db9a9006ac Fixed a typo and added more tests.
Tim Peters <tim.peters@gmail.com>
parents: 19677
diff changeset
50 except ZeroDivisionError:
82db9a9006ac Fixed a typo and added more tests.
Tim Peters <tim.peters@gmail.com>
parents: 19677
diff changeset
51 pass
82db9a9006ac Fixed a typo and added more tests.
Tim Peters <tim.peters@gmail.com>
parents: 19677
diff changeset
52 else:
82db9a9006ac Fixed a typo and added more tests.
Tim Peters <tim.peters@gmail.com>
parents: 19677
diff changeset
53 raise TestFailed("expected ZeroDivisionError from %r" % zero)
82db9a9006ac Fixed a typo and added more tests.
Tim Peters <tim.peters@gmail.com>
parents: 19677
diff changeset
54
19677
91533675d6cb Change long/long true division to return as many good bits as it can;
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
55 test_true_division()