annotate Lib/test/test_long_future.py @ 58925:eecf1bef052d 2.6

Merged revisions 78207 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line #7930: fix stripid ........
author Ezio Melotti <ezio.melotti@gmail.com>
date Tue, 16 Feb 2010 23:29:44 +0000
parents 4b9fa8092e82
children 19964944cc01 606a45dbd10c
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
41392
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
6 import unittest
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
7 from test.test_support import run_unittest
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
8
41392
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
9 class TrueDivisionTests(unittest.TestCase):
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
10 def test(self):
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
11 huge = 1L << 40000
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
12 mhuge = -huge
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
13 self.assertEqual(huge / huge, 1.0)
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
14 self.assertEqual(mhuge / mhuge, 1.0)
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
15 self.assertEqual(huge / mhuge, -1.0)
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
16 self.assertEqual(mhuge / huge, -1.0)
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
17 self.assertEqual(1 / huge, 0.0)
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
18 self.assertEqual(1L / huge, 0.0)
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
19 self.assertEqual(1 / mhuge, 0.0)
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
20 self.assertEqual(1L / mhuge, 0.0)
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
21 self.assertEqual((666 * huge + (huge >> 1)) / huge, 666.5)
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
22 self.assertEqual((666 * mhuge + (mhuge >> 1)) / mhuge, 666.5)
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
23 self.assertEqual((666 * huge + (huge >> 1)) / mhuge, -666.5)
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
24 self.assertEqual((666 * mhuge + (mhuge >> 1)) / huge, -666.5)
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
25 self.assertEqual(huge / (huge << 1), 0.5)
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
26 self.assertEqual((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
41392
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
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
41392
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
30 for overflow in ["float(huge)", "float(mhuge)",
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
31 "huge / 1", "huge / 2L", "huge / -1", "huge / -2L",
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
32 "mhuge / 100", "mhuge / 100L"]:
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
33 # XXX(cwinter) this test doesn't pass when converted to
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
34 # use assertRaises.
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
35 try:
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
36 eval(overflow, namespace)
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
37 self.fail("expected OverflowError from %r" % overflow)
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
38 except OverflowError:
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
39 pass
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
40
41392
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
41 for underflow in ["1 / huge", "2L / huge", "-1 / huge", "-2L / huge",
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
42 "100 / mhuge", "100L / mhuge"]:
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
43 result = eval(underflow, namespace)
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
44 self.assertEqual(result, 0.0,
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
45 "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
46
41392
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
47 for zero in ["huge / 0", "huge / 0L", "mhuge / 0", "mhuge / 0L"]:
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
48 self.assertRaises(ZeroDivisionError, eval, zero, namespace)
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
49
19678
82db9a9006ac Fixed a typo and added more tests.
Tim Peters <tim.peters@gmail.com>
parents: 19677
diff changeset
50
41392
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
51 def test_main():
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
52 run_unittest(TrueDivisionTests)
41532
4b9fa8092e82 Whitespace normalization. Ugh, we really need to do this more often.
Neal Norwitz <nnorwitz@gmail.com>
parents: 41392
diff changeset
53
41392
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
54 if __name__ == "__main__":
9a50e2b6b685 Convert test_long_future to use unittest.
Collin Winter <collinw@gmail.com>
parents: 24364
diff changeset
55 test_main()