annotate Lib/test/test_math.py @ 57303:4aa4c19dfaed legacy-trunk

#1757126: fix typo with the cyrillic_asian alias
author Philip Jenvey <pjenvey@underboss.org>
date Tue, 17 Nov 2009 02:42:26 +0000
parents 624f81b5ec24
children cb22eaee86c9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3950
75d016c97d1c Added test for math module
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 # Python test set -- math module
75d016c97d1c Added test for math module
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 # XXXX Should not do tests around zero only
75d016c97d1c Added test for math module
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
4 from test.test_support import run_unittest, verbose
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
5 import unittest
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
6 import math
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
7 import os
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
8 import sys
47529
6428c4f1ae09 Issue #2138: Add math.factorial().
Raymond Hettinger <python@rcn.com>
parents: 47382
diff changeset
9 import random
56268
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
10 import struct
3950
75d016c97d1c Added test for math module
Guido van Rossum <guido@python.org>
parents:
diff changeset
11
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
12 eps = 1E-05
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
13 NAN = float('nan')
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
14 INF = float('inf')
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
15 NINF = float('-inf')
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
16
56089
f2555ad5fe09 Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
17 # decorator for skipping tests on non-IEEE 754 platforms
f2555ad5fe09 Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
18 requires_IEEE_754 = unittest.skipUnless(
f2555ad5fe09 Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
19 float.__getformat__("double").startswith("IEEE"),
f2555ad5fe09 Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
20 "test requires IEEE 754 doubles")
f2555ad5fe09 Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
21
53350
133c66027f33 Issue #5593: Use more robust test for double-rounding in test_fsum.
Mark Dickinson <dickinsm@gmail.com>
parents: 48110
diff changeset
22 # detect evidence of double-rounding: fsum is not always correctly
133c66027f33 Issue #5593: Use more robust test for double-rounding in test_fsum.
Mark Dickinson <dickinsm@gmail.com>
parents: 48110
diff changeset
23 # rounded on machines that suffer from double rounding.
133c66027f33 Issue #5593: Use more robust test for double-rounding in test_fsum.
Mark Dickinson <dickinsm@gmail.com>
parents: 48110
diff changeset
24 x, y = 1e16, 2.9999 # use temporary values to defeat peephole optimizer
133c66027f33 Issue #5593: Use more robust test for double-rounding in test_fsum.
Mark Dickinson <dickinsm@gmail.com>
parents: 48110
diff changeset
25 HAVE_DOUBLE_ROUNDING = (x + y == 1e16 + 4)
133c66027f33 Issue #5593: Use more robust test for double-rounding in test_fsum.
Mark Dickinson <dickinsm@gmail.com>
parents: 48110
diff changeset
26
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
27 # locate file with test values
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
28 if __name__ == '__main__':
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
29 file = sys.argv[0]
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
30 else:
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
31 file = __file__
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
32 test_dir = os.path.dirname(file) or os.curdir
56268
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
33 math_testcases = os.path.join(test_dir, 'math_testcases.txt')
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
34 test_file = os.path.join(test_dir, 'cmath_testcases.txt')
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
35
56268
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
36 def to_ulps(x):
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
37 """Convert a non-NaN float x to an integer, in such a way that
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
38 adjacent floats are converted to adjacent integers. Then
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
39 abs(ulps(x) - ulps(y)) gives the difference in ulps between two
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
40 floats.
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
41
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
42 The results from this function will only make sense on platforms
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
43 where C doubles are represented in IEEE 754 binary64 format.
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
44
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
45 """
56556
624f81b5ec24 test_math ulp computation was wrong on big-endian systems
Mark Dickinson <dickinsm@gmail.com>
parents: 56307
diff changeset
46 n = struct.unpack('<q', struct.pack('<d', x))[0]
56268
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
47 if n < 0:
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
48 n = ~(n+2**63)
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
49 return n
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
50
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
51
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
52 def parse_mtestfile(fname):
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
53 """Parse a file with test values
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
54
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
55 -- starts a comment
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
56 blank lines, or lines containing only a comment, are ignored
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
57 other lines are expected to have the form
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
58 id fn arg -> expected [flag]*
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
59
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
60 """
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
61 with open(fname) as fp:
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
62 for line in fp:
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
63 # strip comments, and skip blank lines
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
64 if '--' in line:
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
65 line = line[:line.index('--')]
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
66 if not line.strip():
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
67 continue
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
68
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
69 lhs, rhs = line.split('->')
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
70 id, fn, arg = lhs.split()
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
71 rhs_pieces = rhs.split()
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
72 exp = rhs_pieces[0]
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
73 flags = rhs_pieces[1:]
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
74
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
75 yield (id, fn, float(arg), float(exp), flags)
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
76
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
77 def parse_testfile(fname):
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
78 """Parse a file with test values
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
79
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
80 Empty lines or lines starting with -- are ignored
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
81 yields id, fn, arg_real, arg_imag, exp_real, exp_imag
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
82 """
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
83 with open(fname) as fp:
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
84 for line in fp:
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
85 # skip comment lines and blank lines
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
86 if line.startswith('--') or not line.strip():
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
87 continue
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
88
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
89 lhs, rhs = line.split('->')
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
90 id, fn, arg_real, arg_imag = lhs.split()
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
91 rhs_pieces = rhs.split()
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
92 exp_real, exp_imag = rhs_pieces[0], rhs_pieces[1]
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
93 flags = rhs_pieces[2:]
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
94
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
95 yield (id, fn,
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
96 float(arg_real), float(arg_imag),
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
97 float(exp_real), float(exp_imag),
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
98 flags
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
99 )
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
100
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
101 class MathTests(unittest.TestCase):
3950
75d016c97d1c Added test for math module
Guido van Rossum <guido@python.org>
parents:
diff changeset
102
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
103 def ftest(self, name, value, expected):
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
104 if abs(value-expected) > eps:
42380
0546c115a9cf Make test_math error messages more meaningful for small discrepancies in results
Nick Coghlan <ncoghlan@gmail.com>
parents: 42370
diff changeset
105 # Use %r instead of %f so the error message
0546c115a9cf Make test_math error messages more meaningful for small discrepancies in results
Nick Coghlan <ncoghlan@gmail.com>
parents: 42370
diff changeset
106 # displays full precision. Otherwise discrepancies
0546c115a9cf Make test_math error messages more meaningful for small discrepancies in results
Nick Coghlan <ncoghlan@gmail.com>
parents: 42370
diff changeset
107 # in the last few bits will lead to very confusing
0546c115a9cf Make test_math error messages more meaningful for small discrepancies in results
Nick Coghlan <ncoghlan@gmail.com>
parents: 42370
diff changeset
108 # error messages
0546c115a9cf Make test_math error messages more meaningful for small discrepancies in results
Nick Coghlan <ncoghlan@gmail.com>
parents: 42370
diff changeset
109 self.fail('%s returned %r, expected %r' %
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
110 (name, value, expected))
3950
75d016c97d1c Added test for math module
Guido van Rossum <guido@python.org>
parents:
diff changeset
111
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
112 def testConstants(self):
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
113 self.ftest('pi', math.pi, 3.1415926)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
114 self.ftest('e', math.e, 2.7182818)
3950
75d016c97d1c Added test for math module
Guido van Rossum <guido@python.org>
parents:
diff changeset
115
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
116 def testAcos(self):
40270
1715e6a0aee9 Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents: 40219
diff changeset
117 self.assertRaises(TypeError, math.acos)
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
118 self.ftest('acos(-1)', math.acos(-1), math.pi)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
119 self.ftest('acos(0)', math.acos(0), math.pi/2)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
120 self.ftest('acos(1)', math.acos(1), 0)
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
121 self.assertRaises(ValueError, math.acos, INF)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
122 self.assertRaises(ValueError, math.acos, NINF)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
123 self.assertTrue(math.isnan(math.acos(NAN)))
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
124
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
125 def testAcosh(self):
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
126 self.assertRaises(TypeError, math.acosh)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
127 self.ftest('acosh(1)', math.acosh(1), 0)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
128 self.ftest('acosh(2)', math.acosh(2), 1.3169578969248168)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
129 self.assertRaises(ValueError, math.acosh, 0)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
130 self.assertRaises(ValueError, math.acosh, -1)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
131 self.assertEquals(math.acosh(INF), INF)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
132 self.assertRaises(ValueError, math.acosh, NINF)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
133 self.assertTrue(math.isnan(math.acosh(NAN)))
3950
75d016c97d1c Added test for math module
Guido van Rossum <guido@python.org>
parents:
diff changeset
134
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
135 def testAsin(self):
40270
1715e6a0aee9 Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents: 40219
diff changeset
136 self.assertRaises(TypeError, math.asin)
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
137 self.ftest('asin(-1)', math.asin(-1), -math.pi/2)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
138 self.ftest('asin(0)', math.asin(0), 0)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
139 self.ftest('asin(1)', math.asin(1), math.pi/2)
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
140 self.assertRaises(ValueError, math.asin, INF)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
141 self.assertRaises(ValueError, math.asin, NINF)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
142 self.assertTrue(math.isnan(math.asin(NAN)))
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
143
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
144 def testAsinh(self):
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
145 self.assertRaises(TypeError, math.asinh)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
146 self.ftest('asinh(0)', math.asinh(0), 0)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
147 self.ftest('asinh(1)', math.asinh(1), 0.88137358701954305)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
148 self.ftest('asinh(-1)', math.asinh(-1), -0.88137358701954305)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
149 self.assertEquals(math.asinh(INF), INF)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
150 self.assertEquals(math.asinh(NINF), NINF)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
151 self.assertTrue(math.isnan(math.asinh(NAN)))
3950
75d016c97d1c Added test for math module
Guido van Rossum <guido@python.org>
parents:
diff changeset
152
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
153 def testAtan(self):
40270
1715e6a0aee9 Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents: 40219
diff changeset
154 self.assertRaises(TypeError, math.atan)
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
155 self.ftest('atan(-1)', math.atan(-1), -math.pi/4)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
156 self.ftest('atan(0)', math.atan(0), 0)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
157 self.ftest('atan(1)', math.atan(1), math.pi/4)
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
158 self.ftest('atan(inf)', math.atan(INF), math.pi/2)
46486
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
159 self.ftest('atan(-inf)', math.atan(NINF), -math.pi/2)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
160 self.assertTrue(math.isnan(math.atan(NAN)))
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
161
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
162 def testAtanh(self):
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
163 self.assertRaises(TypeError, math.atan)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
164 self.ftest('atanh(0)', math.atanh(0), 0)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
165 self.ftest('atanh(0.5)', math.atanh(0.5), 0.54930614433405489)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
166 self.ftest('atanh(-0.5)', math.atanh(-0.5), -0.54930614433405489)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
167 self.assertRaises(ValueError, math.atanh, 1)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
168 self.assertRaises(ValueError, math.atanh, -1)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
169 self.assertRaises(ValueError, math.atanh, INF)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
170 self.assertRaises(ValueError, math.atanh, NINF)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
171 self.assertTrue(math.isnan(math.atanh(NAN)))
3950
75d016c97d1c Added test for math module
Guido van Rossum <guido@python.org>
parents:
diff changeset
172
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
173 def testAtan2(self):
40270
1715e6a0aee9 Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents: 40219
diff changeset
174 self.assertRaises(TypeError, math.atan2)
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
175 self.ftest('atan2(-1, 0)', math.atan2(-1, 0), -math.pi/2)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
176 self.ftest('atan2(-1, 1)', math.atan2(-1, 1), -math.pi/4)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
177 self.ftest('atan2(0, 1)', math.atan2(0, 1), 0)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
178 self.ftest('atan2(1, 1)', math.atan2(1, 1), math.pi/4)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
179 self.ftest('atan2(1, 0)', math.atan2(1, 0), math.pi/2)
3950
75d016c97d1c Added test for math module
Guido van Rossum <guido@python.org>
parents:
diff changeset
180
46504
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
181 # math.atan2(0, x)
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
182 self.ftest('atan2(0., -inf)', math.atan2(0., NINF), math.pi)
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
183 self.ftest('atan2(0., -2.3)', math.atan2(0., -2.3), math.pi)
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
184 self.ftest('atan2(0., -0.)', math.atan2(0., -0.), math.pi)
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
185 self.assertEqual(math.atan2(0., 0.), 0.)
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
186 self.assertEqual(math.atan2(0., 2.3), 0.)
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
187 self.assertEqual(math.atan2(0., INF), 0.)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
188 self.assertTrue(math.isnan(math.atan2(0., NAN)))
46504
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
189 # math.atan2(-0, x)
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
190 self.ftest('atan2(-0., -inf)', math.atan2(-0., NINF), -math.pi)
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
191 self.ftest('atan2(-0., -2.3)', math.atan2(-0., -2.3), -math.pi)
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
192 self.ftest('atan2(-0., -0.)', math.atan2(-0., -0.), -math.pi)
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
193 self.assertEqual(math.atan2(-0., 0.), -0.)
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
194 self.assertEqual(math.atan2(-0., 2.3), -0.)
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
195 self.assertEqual(math.atan2(-0., INF), -0.)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
196 self.assertTrue(math.isnan(math.atan2(-0., NAN)))
46504
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
197 # math.atan2(INF, x)
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
198 self.ftest('atan2(inf, -inf)', math.atan2(INF, NINF), math.pi*3/4)
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
199 self.ftest('atan2(inf, -2.3)', math.atan2(INF, -2.3), math.pi/2)
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
200 self.ftest('atan2(inf, -0.)', math.atan2(INF, -0.0), math.pi/2)
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
201 self.ftest('atan2(inf, 0.)', math.atan2(INF, 0.0), math.pi/2)
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
202 self.ftest('atan2(inf, 2.3)', math.atan2(INF, 2.3), math.pi/2)
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
203 self.ftest('atan2(inf, inf)', math.atan2(INF, INF), math.pi/4)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
204 self.assertTrue(math.isnan(math.atan2(INF, NAN)))
46504
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
205 # math.atan2(NINF, x)
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
206 self.ftest('atan2(-inf, -inf)', math.atan2(NINF, NINF), -math.pi*3/4)
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
207 self.ftest('atan2(-inf, -2.3)', math.atan2(NINF, -2.3), -math.pi/2)
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
208 self.ftest('atan2(-inf, -0.)', math.atan2(NINF, -0.0), -math.pi/2)
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
209 self.ftest('atan2(-inf, 0.)', math.atan2(NINF, 0.0), -math.pi/2)
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
210 self.ftest('atan2(-inf, 2.3)', math.atan2(NINF, 2.3), -math.pi/2)
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
211 self.ftest('atan2(-inf, inf)', math.atan2(NINF, INF), -math.pi/4)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
212 self.assertTrue(math.isnan(math.atan2(NINF, NAN)))
46504
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
213 # math.atan2(+finite, x)
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
214 self.ftest('atan2(2.3, -inf)', math.atan2(2.3, NINF), math.pi)
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
215 self.ftest('atan2(2.3, -0.)', math.atan2(2.3, -0.), math.pi/2)
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
216 self.ftest('atan2(2.3, 0.)', math.atan2(2.3, 0.), math.pi/2)
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
217 self.assertEqual(math.atan2(2.3, INF), 0.)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
218 self.assertTrue(math.isnan(math.atan2(2.3, NAN)))
46504
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
219 # math.atan2(-finite, x)
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
220 self.ftest('atan2(-2.3, -inf)', math.atan2(-2.3, NINF), -math.pi)
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
221 self.ftest('atan2(-2.3, -0.)', math.atan2(-2.3, -0.), -math.pi/2)
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
222 self.ftest('atan2(-2.3, 0.)', math.atan2(-2.3, 0.), -math.pi/2)
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
223 self.assertEqual(math.atan2(-2.3, INF), -0.)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
224 self.assertTrue(math.isnan(math.atan2(-2.3, NAN)))
46504
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
225 # math.atan2(NAN, x)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
226 self.assertTrue(math.isnan(math.atan2(NAN, NINF)))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
227 self.assertTrue(math.isnan(math.atan2(NAN, -2.3)))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
228 self.assertTrue(math.isnan(math.atan2(NAN, -0.)))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
229 self.assertTrue(math.isnan(math.atan2(NAN, 0.)))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
230 self.assertTrue(math.isnan(math.atan2(NAN, 2.3)))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
231 self.assertTrue(math.isnan(math.atan2(NAN, INF)))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
232 self.assertTrue(math.isnan(math.atan2(NAN, NAN)))
46504
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
233
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
234 def testCeil(self):
40270
1715e6a0aee9 Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents: 40219
diff changeset
235 self.assertRaises(TypeError, math.ceil)
44465
77c37e32fe35 Make math.{floor,ceil}({int,long}) return float again for backwards
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44440
diff changeset
236 # These types will be int in py3k.
77c37e32fe35 Make math.{floor,ceil}({int,long}) return float again for backwards
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44440
diff changeset
237 self.assertEquals(float, type(math.ceil(1)))
77c37e32fe35 Make math.{floor,ceil}({int,long}) return float again for backwards
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44440
diff changeset
238 self.assertEquals(float, type(math.ceil(1L)))
77c37e32fe35 Make math.{floor,ceil}({int,long}) return float again for backwards
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44440
diff changeset
239 self.assertEquals(float, type(math.ceil(1.0)))
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
240 self.ftest('ceil(0.5)', math.ceil(0.5), 1)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
241 self.ftest('ceil(1.0)', math.ceil(1.0), 1)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
242 self.ftest('ceil(1.5)', math.ceil(1.5), 2)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
243 self.ftest('ceil(-0.5)', math.ceil(-0.5), 0)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
244 self.ftest('ceil(-1.0)', math.ceil(-1.0), -1)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
245 self.ftest('ceil(-1.5)', math.ceil(-1.5), -1)
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
246 self.assertEquals(math.ceil(INF), INF)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
247 self.assertEquals(math.ceil(NINF), NINF)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
248 self.assertTrue(math.isnan(math.ceil(NAN)))
3950
75d016c97d1c Added test for math module
Guido van Rossum <guido@python.org>
parents:
diff changeset
249
44432
4f9723d9ca32 Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 42380
diff changeset
250 class TestCeil(object):
44488
94eeaeeb3ce9 Continue rolling back pep-3141 changes that changed behavior from 2.5. This
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44465
diff changeset
251 def __float__(self):
94eeaeeb3ce9 Continue rolling back pep-3141 changes that changed behavior from 2.5. This
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44465
diff changeset
252 return 41.3
44432
4f9723d9ca32 Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 42380
diff changeset
253 class TestNoCeil(object):
4f9723d9ca32 Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 42380
diff changeset
254 pass
4f9723d9ca32 Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 42380
diff changeset
255 self.ftest('ceil(TestCeil())', math.ceil(TestCeil()), 42)
4f9723d9ca32 Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 42380
diff changeset
256 self.assertRaises(TypeError, math.ceil, TestNoCeil())
4f9723d9ca32 Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 42380
diff changeset
257
4f9723d9ca32 Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 42380
diff changeset
258 t = TestNoCeil()
4f9723d9ca32 Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 42380
diff changeset
259 t.__ceil__ = lambda *args: args
4f9723d9ca32 Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 42380
diff changeset
260 self.assertRaises(TypeError, math.ceil, t)
4f9723d9ca32 Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 42380
diff changeset
261 self.assertRaises(TypeError, math.ceil, t, 0)
4f9723d9ca32 Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 42380
diff changeset
262
56089
f2555ad5fe09 Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
263 @requires_IEEE_754
f2555ad5fe09 Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
264 def testCopysign(self):
f2555ad5fe09 Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
265 self.assertRaises(TypeError, math.copysign)
f2555ad5fe09 Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
266 # copysign should let us distinguish signs of zeros
f2555ad5fe09 Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
267 self.assertEquals(copysign(1., 0.), 1.)
f2555ad5fe09 Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
268 self.assertEquals(copysign(1., -0.), -1.)
f2555ad5fe09 Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
269 self.assertEquals(copysign(INF, 0.), INF)
f2555ad5fe09 Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
270 self.assertEquals(copysign(INF, -0.), NINF)
f2555ad5fe09 Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
271 self.assertEquals(copysign(NINF, 0.), INF)
f2555ad5fe09 Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
272 self.assertEquals(copysign(NINF, -0.), NINF)
f2555ad5fe09 Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
273 # and of infinities
f2555ad5fe09 Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
274 self.assertEquals(copysign(1., INF), 1.)
f2555ad5fe09 Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
275 self.assertEquals(copysign(1., NINF), -1.)
f2555ad5fe09 Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
276 self.assertEquals(copysign(INF, INF), INF)
f2555ad5fe09 Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
277 self.assertEquals(copysign(INF, NINF), NINF)
f2555ad5fe09 Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
278 self.assertEquals(copysign(NINF, INF), INF)
f2555ad5fe09 Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
279 self.assertEquals(copysign(NINF, NINF), NINF)
f2555ad5fe09 Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
280 self.assertTrue(math.isnan(copysign(NAN, 1.)))
f2555ad5fe09 Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
281 self.assertTrue(math.isnan(copysign(NAN, INF)))
f2555ad5fe09 Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
282 self.assertTrue(math.isnan(copysign(NAN, NINF)))
f2555ad5fe09 Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
283 self.assertTrue(math.isnan(copysign(NAN, NAN)))
f2555ad5fe09 Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
284 # copysign(INF, NAN) may be INF or it may be NINF, since
f2555ad5fe09 Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
285 # we don't know whether the sign bit of NAN is set on any
f2555ad5fe09 Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
286 # given platform.
f2555ad5fe09 Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
287 self.assertTrue(math.isinf(copysign(INF, NAN)))
f2555ad5fe09 Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
288 # similarly, copysign(2., NAN) could be 2. or -2.
f2555ad5fe09 Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
289 self.assertEquals(abs(copysign(2., NAN)), 2.)
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
290
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
291 def testCos(self):
40270
1715e6a0aee9 Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents: 40219
diff changeset
292 self.assertRaises(TypeError, math.cos)
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
293 self.ftest('cos(-pi/2)', math.cos(-math.pi/2), 0)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
294 self.ftest('cos(0)', math.cos(0), 1)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
295 self.ftest('cos(pi/2)', math.cos(math.pi/2), 0)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
296 self.ftest('cos(pi)', math.cos(math.pi), -1)
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
297 try:
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
298 self.assertTrue(math.isnan(math.cos(INF)))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
299 self.assertTrue(math.isnan(math.cos(NINF)))
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
300 except ValueError:
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
301 self.assertRaises(ValueError, math.cos, INF)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
302 self.assertRaises(ValueError, math.cos, NINF)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
303 self.assertTrue(math.isnan(math.cos(NAN)))
3950
75d016c97d1c Added test for math module
Guido van Rossum <guido@python.org>
parents:
diff changeset
304
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
305 def testCosh(self):
40270
1715e6a0aee9 Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents: 40219
diff changeset
306 self.assertRaises(TypeError, math.cosh)
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
307 self.ftest('cosh(0)', math.cosh(0), 1)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
308 self.ftest('cosh(2)-2*cosh(1)**2', math.cosh(2)-2*math.cosh(1)**2, -1) # Thanks to Lambert
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
309 self.assertEquals(math.cosh(INF), INF)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
310 self.assertEquals(math.cosh(NINF), INF)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
311 self.assertTrue(math.isnan(math.cosh(NAN)))
3950
75d016c97d1c Added test for math module
Guido van Rossum <guido@python.org>
parents:
diff changeset
312
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
313 def testDegrees(self):
40270
1715e6a0aee9 Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents: 40219
diff changeset
314 self.assertRaises(TypeError, math.degrees)
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
315 self.ftest('degrees(pi)', math.degrees(math.pi), 180.0)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
316 self.ftest('degrees(pi/2)', math.degrees(math.pi/2), 90.0)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
317 self.ftest('degrees(-pi/4)', math.degrees(-math.pi/4), -45.0)
23426
1157281f00a0 Adds tests for degrees() and radians() functions added to mathmodule.
Raymond Hettinger <python@rcn.com>
parents: 19750
diff changeset
318
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
319 def testExp(self):
40270
1715e6a0aee9 Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents: 40219
diff changeset
320 self.assertRaises(TypeError, math.exp)
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
321 self.ftest('exp(-1)', math.exp(-1), 1/math.e)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
322 self.ftest('exp(0)', math.exp(0), 1)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
323 self.ftest('exp(1)', math.exp(1), math.e)
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
324 self.assertEquals(math.exp(INF), INF)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
325 self.assertEquals(math.exp(NINF), 0.)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
326 self.assertTrue(math.isnan(math.exp(NAN)))
3950
75d016c97d1c Added test for math module
Guido van Rossum <guido@python.org>
parents:
diff changeset
327
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
328 def testFabs(self):
40270
1715e6a0aee9 Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents: 40219
diff changeset
329 self.assertRaises(TypeError, math.fabs)
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
330 self.ftest('fabs(-1)', math.fabs(-1), 1)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
331 self.ftest('fabs(0)', math.fabs(0), 0)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
332 self.ftest('fabs(1)', math.fabs(1), 1)
3950
75d016c97d1c Added test for math module
Guido van Rossum <guido@python.org>
parents:
diff changeset
333
47529
6428c4f1ae09 Issue #2138: Add math.factorial().
Raymond Hettinger <python@rcn.com>
parents: 47382
diff changeset
334 def testFactorial(self):
6428c4f1ae09 Issue #2138: Add math.factorial().
Raymond Hettinger <python@rcn.com>
parents: 47382
diff changeset
335 def fact(n):
6428c4f1ae09 Issue #2138: Add math.factorial().
Raymond Hettinger <python@rcn.com>
parents: 47382
diff changeset
336 result = 1
6428c4f1ae09 Issue #2138: Add math.factorial().
Raymond Hettinger <python@rcn.com>
parents: 47382
diff changeset
337 for i in range(1, int(n)+1):
6428c4f1ae09 Issue #2138: Add math.factorial().
Raymond Hettinger <python@rcn.com>
parents: 47382
diff changeset
338 result *= i
6428c4f1ae09 Issue #2138: Add math.factorial().
Raymond Hettinger <python@rcn.com>
parents: 47382
diff changeset
339 return result
6428c4f1ae09 Issue #2138: Add math.factorial().
Raymond Hettinger <python@rcn.com>
parents: 47382
diff changeset
340 values = range(10) + [50, 100, 500]
6428c4f1ae09 Issue #2138: Add math.factorial().
Raymond Hettinger <python@rcn.com>
parents: 47382
diff changeset
341 random.shuffle(values)
6428c4f1ae09 Issue #2138: Add math.factorial().
Raymond Hettinger <python@rcn.com>
parents: 47382
diff changeset
342 for x in range(10):
6428c4f1ae09 Issue #2138: Add math.factorial().
Raymond Hettinger <python@rcn.com>
parents: 47382
diff changeset
343 for cast in (int, long, float):
6428c4f1ae09 Issue #2138: Add math.factorial().
Raymond Hettinger <python@rcn.com>
parents: 47382
diff changeset
344 self.assertEqual(math.factorial(cast(x)), fact(x), (x, fact(x), math.factorial(x)))
6428c4f1ae09 Issue #2138: Add math.factorial().
Raymond Hettinger <python@rcn.com>
parents: 47382
diff changeset
345 self.assertRaises(ValueError, math.factorial, -1)
6428c4f1ae09 Issue #2138: Add math.factorial().
Raymond Hettinger <python@rcn.com>
parents: 47382
diff changeset
346 self.assertRaises(ValueError, math.factorial, math.pi)
6428c4f1ae09 Issue #2138: Add math.factorial().
Raymond Hettinger <python@rcn.com>
parents: 47382
diff changeset
347
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
348 def testFloor(self):
40270
1715e6a0aee9 Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents: 40219
diff changeset
349 self.assertRaises(TypeError, math.floor)
44465
77c37e32fe35 Make math.{floor,ceil}({int,long}) return float again for backwards
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44440
diff changeset
350 # These types will be int in py3k.
77c37e32fe35 Make math.{floor,ceil}({int,long}) return float again for backwards
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44440
diff changeset
351 self.assertEquals(float, type(math.floor(1)))
77c37e32fe35 Make math.{floor,ceil}({int,long}) return float again for backwards
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44440
diff changeset
352 self.assertEquals(float, type(math.floor(1L)))
77c37e32fe35 Make math.{floor,ceil}({int,long}) return float again for backwards
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44440
diff changeset
353 self.assertEquals(float, type(math.floor(1.0)))
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
354 self.ftest('floor(0.5)', math.floor(0.5), 0)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
355 self.ftest('floor(1.0)', math.floor(1.0), 1)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
356 self.ftest('floor(1.5)', math.floor(1.5), 1)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
357 self.ftest('floor(-0.5)', math.floor(-0.5), -1)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
358 self.ftest('floor(-1.0)', math.floor(-1.0), -1)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
359 self.ftest('floor(-1.5)', math.floor(-1.5), -2)
42370
64903ff76ede Add explicit test for a misbehaving math.floor
Nick Coghlan <ncoghlan@gmail.com>
parents: 40284
diff changeset
360 # pow() relies on floor() to check for integers
64903ff76ede Add explicit test for a misbehaving math.floor
Nick Coghlan <ncoghlan@gmail.com>
parents: 40284
diff changeset
361 # This fails on some platforms - so check it here
64903ff76ede Add explicit test for a misbehaving math.floor
Nick Coghlan <ncoghlan@gmail.com>
parents: 40284
diff changeset
362 self.ftest('floor(1.23e167)', math.floor(1.23e167), 1.23e167)
64903ff76ede Add explicit test for a misbehaving math.floor
Nick Coghlan <ncoghlan@gmail.com>
parents: 40284
diff changeset
363 self.ftest('floor(-1.23e167)', math.floor(-1.23e167), -1.23e167)
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
364 self.assertEquals(math.ceil(INF), INF)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
365 self.assertEquals(math.ceil(NINF), NINF)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
366 self.assertTrue(math.isnan(math.floor(NAN)))
3950
75d016c97d1c Added test for math module
Guido van Rossum <guido@python.org>
parents:
diff changeset
367
44432
4f9723d9ca32 Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 42380
diff changeset
368 class TestFloor(object):
44488
94eeaeeb3ce9 Continue rolling back pep-3141 changes that changed behavior from 2.5. This
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44465
diff changeset
369 def __float__(self):
94eeaeeb3ce9 Continue rolling back pep-3141 changes that changed behavior from 2.5. This
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44465
diff changeset
370 return 42.3
44432
4f9723d9ca32 Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 42380
diff changeset
371 class TestNoFloor(object):
4f9723d9ca32 Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 42380
diff changeset
372 pass
4f9723d9ca32 Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 42380
diff changeset
373 self.ftest('floor(TestFloor())', math.floor(TestFloor()), 42)
4f9723d9ca32 Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 42380
diff changeset
374 self.assertRaises(TypeError, math.floor, TestNoFloor())
4f9723d9ca32 Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 42380
diff changeset
375
4f9723d9ca32 Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 42380
diff changeset
376 t = TestNoFloor()
4f9723d9ca32 Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 42380
diff changeset
377 t.__floor__ = lambda *args: args
4f9723d9ca32 Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 42380
diff changeset
378 self.assertRaises(TypeError, math.floor, t)
4f9723d9ca32 Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 42380
diff changeset
379 self.assertRaises(TypeError, math.floor, t, 0)
4f9723d9ca32 Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 42380
diff changeset
380
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
381 def testFmod(self):
40270
1715e6a0aee9 Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents: 40219
diff changeset
382 self.assertRaises(TypeError, math.fmod)
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
383 self.ftest('fmod(10,1)', math.fmod(10,1), 0)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
384 self.ftest('fmod(10,0.5)', math.fmod(10,0.5), 0)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
385 self.ftest('fmod(10,1.5)', math.fmod(10,1.5), 1)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
386 self.ftest('fmod(-10,1)', math.fmod(-10,1), 0)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
387 self.ftest('fmod(-10,0.5)', math.fmod(-10,0.5), 0)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
388 self.ftest('fmod(-10,1.5)', math.fmod(-10,1.5), -1)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
389 self.assertTrue(math.isnan(math.fmod(NAN, 1.)))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
390 self.assertTrue(math.isnan(math.fmod(1., NAN)))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
391 self.assertTrue(math.isnan(math.fmod(NAN, NAN)))
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
392 self.assertRaises(ValueError, math.fmod, 1., 0.)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
393 self.assertRaises(ValueError, math.fmod, INF, 1.)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
394 self.assertRaises(ValueError, math.fmod, NINF, 1.)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
395 self.assertRaises(ValueError, math.fmod, INF, 0.)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
396 self.assertEquals(math.fmod(3.0, INF), 3.0)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
397 self.assertEquals(math.fmod(-3.0, INF), -3.0)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
398 self.assertEquals(math.fmod(3.0, NINF), 3.0)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
399 self.assertEquals(math.fmod(-3.0, NINF), -3.0)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
400 self.assertEquals(math.fmod(0.0, 3.0), 0.0)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
401 self.assertEquals(math.fmod(0.0, NINF), 0.0)
3950
75d016c97d1c Added test for math module
Guido van Rossum <guido@python.org>
parents:
diff changeset
402
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
403 def testFrexp(self):
40270
1715e6a0aee9 Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents: 40219
diff changeset
404 self.assertRaises(TypeError, math.frexp)
1715e6a0aee9 Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents: 40219
diff changeset
405
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
406 def testfrexp(name, (mant, exp), (emant, eexp)):
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
407 if abs(mant-emant) > eps or exp != eexp:
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
408 self.fail('%s returned %r, expected %r'%\
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
409 (name, (mant, exp), (emant,eexp)))
3950
75d016c97d1c Added test for math module
Guido van Rossum <guido@python.org>
parents:
diff changeset
410
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
411 testfrexp('frexp(-1)', math.frexp(-1), (-0.5, 1))
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
412 testfrexp('frexp(0)', math.frexp(0), (0, 0))
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
413 testfrexp('frexp(1)', math.frexp(1), (0.5, 1))
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
414 testfrexp('frexp(2)', math.frexp(2), (0.5, 2))
3950
75d016c97d1c Added test for math module
Guido van Rossum <guido@python.org>
parents:
diff changeset
415
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
416 self.assertEquals(math.frexp(INF)[0], INF)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
417 self.assertEquals(math.frexp(NINF)[0], NINF)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
418 self.assertTrue(math.isnan(math.frexp(NAN)[0]))
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
419
56089
f2555ad5fe09 Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
420 @requires_IEEE_754
53351
32226776f866 Remove unnecessary double negative
Mark Dickinson <dickinsm@gmail.com>
parents: 53350
diff changeset
421 @unittest.skipIf(HAVE_DOUBLE_ROUNDING,
53350
133c66027f33 Issue #5593: Use more robust test for double-rounding in test_fsum.
Mark Dickinson <dickinsm@gmail.com>
parents: 48110
diff changeset
422 "fsum is not exact on machines with double rounding")
48110
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
423 def testFsum(self):
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
424 # math.fsum relies on exact rounding for correct operation.
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
425 # There's a known problem with IA32 floating-point that causes
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
426 # inexact rounding in some situations, and will cause the
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
427 # math.fsum tests below to fail; see issue #2937. On non IEEE
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
428 # 754 platforms, and on IEEE 754 platforms that exhibit the
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
429 # problem described in issue #2937, we simply skip the whole
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
430 # test.
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
431
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
432 # Python version of math.fsum, for comparison. Uses a
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
433 # different algorithm based on frexp, ldexp and integer
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
434 # arithmetic.
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
435 from sys import float_info
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
436 mant_dig = float_info.mant_dig
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
437 etiny = float_info.min_exp - mant_dig
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
438
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
439 def msum(iterable):
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
440 """Full precision summation. Compute sum(iterable) without any
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
441 intermediate accumulation of error. Based on the 'lsum' function
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
442 at http://code.activestate.com/recipes/393090/
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
443
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
444 """
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
445 tmant, texp = 0, 0
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
446 for x in iterable:
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
447 mant, exp = math.frexp(x)
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
448 mant, exp = int(math.ldexp(mant, mant_dig)), exp - mant_dig
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
449 if texp > exp:
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
450 tmant <<= texp-exp
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
451 texp = exp
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
452 else:
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
453 mant <<= exp-texp
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
454 tmant += mant
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
455 # Round tmant * 2**texp to a float. The original recipe
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
456 # used float(str(tmant)) * 2.0**texp for this, but that's
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
457 # a little unsafe because str -> float conversion can't be
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
458 # relied upon to do correct rounding on all platforms.
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
459 tail = max(len(bin(abs(tmant)))-2 - mant_dig, etiny - texp)
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
460 if tail > 0:
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
461 h = 1 << (tail-1)
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
462 tmant = tmant // (2*h) + bool(tmant & h and tmant & 3*h-1)
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
463 texp += tail
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
464 return math.ldexp(tmant, texp)
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
465
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
466 test_values = [
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
467 ([], 0.0),
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
468 ([0.0], 0.0),
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
469 ([1e100, 1.0, -1e100, 1e-100, 1e50, -1.0, -1e50], 1e-100),
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
470 ([2.0**53, -0.5, -2.0**-54], 2.0**53-1.0),
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
471 ([2.0**53, 1.0, 2.0**-100], 2.0**53+2.0),
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
472 ([2.0**53+10.0, 1.0, 2.0**-100], 2.0**53+12.0),
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
473 ([2.0**53-4.0, 0.5, 2.0**-54], 2.0**53-3.0),
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
474 ([1./n for n in range(1, 1001)],
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
475 float.fromhex('0x1.df11f45f4e61ap+2')),
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
476 ([(-1.)**n/n for n in range(1, 1001)],
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
477 float.fromhex('-0x1.62a2af1bd3624p-1')),
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
478 ([1.7**(i+1)-1.7**i for i in range(1000)] + [-1.7**1000], -1.0),
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
479 ([1e16, 1., 1e-16], 10000000000000002.0),
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
480 ([1e16-2., 1.-2.**-53, -(1e16-2.), -(1.-2.**-53)], 0.0),
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
481 # exercise code for resizing partials array
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
482 ([2.**n - 2.**(n+50) + 2.**(n+52) for n in range(-1074, 972, 2)] +
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
483 [-2.**1022],
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
484 float.fromhex('0x1.5555555555555p+970')),
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
485 ]
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
486
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
487 for i, (vals, expected) in enumerate(test_values):
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
488 try:
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
489 actual = math.fsum(vals)
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
490 except OverflowError:
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
491 self.fail("test %d failed: got OverflowError, expected %r "
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
492 "for math.fsum(%.100r)" % (i, expected, vals))
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
493 except ValueError:
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
494 self.fail("test %d failed: got ValueError, expected %r "
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
495 "for math.fsum(%.100r)" % (i, expected, vals))
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
496 self.assertEqual(actual, expected)
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
497
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
498 from random import random, gauss, shuffle
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
499 for j in xrange(1000):
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
500 vals = [7, 1e100, -7, -1e100, -9e-20, 8e-20] * 10
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
501 s = 0
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
502 for i in xrange(200):
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
503 v = gauss(0, random()) ** 7 - s
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
504 s += v
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
505 vals.append(v)
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
506 shuffle(vals)
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
507
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
508 s = msum(vals)
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
509 self.assertEqual(msum(vals), math.fsum(vals))
347603f794d1 Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 48101
diff changeset
510
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
511 def testHypot(self):
40270
1715e6a0aee9 Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents: 40219
diff changeset
512 self.assertRaises(TypeError, math.hypot)
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
513 self.ftest('hypot(0,0)', math.hypot(0,0), 0)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
514 self.ftest('hypot(3,4)', math.hypot(3,4), 5)
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
515 self.assertEqual(math.hypot(NAN, INF), INF)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
516 self.assertEqual(math.hypot(INF, NAN), INF)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
517 self.assertEqual(math.hypot(NAN, NINF), INF)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
518 self.assertEqual(math.hypot(NINF, NAN), INF)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
519 self.assertTrue(math.isnan(math.hypot(1.0, NAN)))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
520 self.assertTrue(math.isnan(math.hypot(NAN, -2.0)))
3950
75d016c97d1c Added test for math module
Guido van Rossum <guido@python.org>
parents:
diff changeset
521
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
522 def testLdexp(self):
40270
1715e6a0aee9 Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents: 40219
diff changeset
523 self.assertRaises(TypeError, math.ldexp)
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
524 self.ftest('ldexp(0,1)', math.ldexp(0,1), 0)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
525 self.ftest('ldexp(1,1)', math.ldexp(1,1), 2)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
526 self.ftest('ldexp(1,-1)', math.ldexp(1,-1), 0.5)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
527 self.ftest('ldexp(-1,1)', math.ldexp(-1,1), -2)
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
528 self.assertRaises(OverflowError, math.ldexp, 1., 1000000)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
529 self.assertRaises(OverflowError, math.ldexp, -1., 1000000)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
530 self.assertEquals(math.ldexp(1., -1000000), 0.)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
531 self.assertEquals(math.ldexp(-1., -1000000), -0.)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
532 self.assertEquals(math.ldexp(INF, 30), INF)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
533 self.assertEquals(math.ldexp(NINF, -213), NINF)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
534 self.assertTrue(math.isnan(math.ldexp(NAN, 0)))
3950
75d016c97d1c Added test for math module
Guido van Rossum <guido@python.org>
parents:
diff changeset
535
46797
fd0b894bc90c Issue #2487. math.ldexp(x, n) raised OverflowError when n was large and
Mark Dickinson <dickinsm@gmail.com>
parents: 46504
diff changeset
536 # large second argument
fd0b894bc90c Issue #2487. math.ldexp(x, n) raised OverflowError when n was large and
Mark Dickinson <dickinsm@gmail.com>
parents: 46504
diff changeset
537 for n in [10**5, 10L**5, 10**10, 10L**10, 10**20, 10**40]:
fd0b894bc90c Issue #2487. math.ldexp(x, n) raised OverflowError when n was large and
Mark Dickinson <dickinsm@gmail.com>
parents: 46504
diff changeset
538 self.assertEquals(math.ldexp(INF, -n), INF)
fd0b894bc90c Issue #2487. math.ldexp(x, n) raised OverflowError when n was large and
Mark Dickinson <dickinsm@gmail.com>
parents: 46504
diff changeset
539 self.assertEquals(math.ldexp(NINF, -n), NINF)
fd0b894bc90c Issue #2487. math.ldexp(x, n) raised OverflowError when n was large and
Mark Dickinson <dickinsm@gmail.com>
parents: 46504
diff changeset
540 self.assertEquals(math.ldexp(1., -n), 0.)
fd0b894bc90c Issue #2487. math.ldexp(x, n) raised OverflowError when n was large and
Mark Dickinson <dickinsm@gmail.com>
parents: 46504
diff changeset
541 self.assertEquals(math.ldexp(-1., -n), -0.)
fd0b894bc90c Issue #2487. math.ldexp(x, n) raised OverflowError when n was large and
Mark Dickinson <dickinsm@gmail.com>
parents: 46504
diff changeset
542 self.assertEquals(math.ldexp(0., -n), 0.)
fd0b894bc90c Issue #2487. math.ldexp(x, n) raised OverflowError when n was large and
Mark Dickinson <dickinsm@gmail.com>
parents: 46504
diff changeset
543 self.assertEquals(math.ldexp(-0., -n), -0.)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
544 self.assertTrue(math.isnan(math.ldexp(NAN, -n)))
46797
fd0b894bc90c Issue #2487. math.ldexp(x, n) raised OverflowError when n was large and
Mark Dickinson <dickinsm@gmail.com>
parents: 46504
diff changeset
545
fd0b894bc90c Issue #2487. math.ldexp(x, n) raised OverflowError when n was large and
Mark Dickinson <dickinsm@gmail.com>
parents: 46504
diff changeset
546 self.assertRaises(OverflowError, math.ldexp, 1., n)
fd0b894bc90c Issue #2487. math.ldexp(x, n) raised OverflowError when n was large and
Mark Dickinson <dickinsm@gmail.com>
parents: 46504
diff changeset
547 self.assertRaises(OverflowError, math.ldexp, -1., n)
fd0b894bc90c Issue #2487. math.ldexp(x, n) raised OverflowError when n was large and
Mark Dickinson <dickinsm@gmail.com>
parents: 46504
diff changeset
548 self.assertEquals(math.ldexp(0., n), 0.)
fd0b894bc90c Issue #2487. math.ldexp(x, n) raised OverflowError when n was large and
Mark Dickinson <dickinsm@gmail.com>
parents: 46504
diff changeset
549 self.assertEquals(math.ldexp(-0., n), -0.)
fd0b894bc90c Issue #2487. math.ldexp(x, n) raised OverflowError when n was large and
Mark Dickinson <dickinsm@gmail.com>
parents: 46504
diff changeset
550 self.assertEquals(math.ldexp(INF, n), INF)
fd0b894bc90c Issue #2487. math.ldexp(x, n) raised OverflowError when n was large and
Mark Dickinson <dickinsm@gmail.com>
parents: 46504
diff changeset
551 self.assertEquals(math.ldexp(NINF, n), NINF)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
552 self.assertTrue(math.isnan(math.ldexp(NAN, n)))
46797
fd0b894bc90c Issue #2487. math.ldexp(x, n) raised OverflowError when n was large and
Mark Dickinson <dickinsm@gmail.com>
parents: 46504
diff changeset
553
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
554 def testLog(self):
40270
1715e6a0aee9 Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents: 40219
diff changeset
555 self.assertRaises(TypeError, math.log)
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
556 self.ftest('log(1/e)', math.log(1/math.e), -1)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
557 self.ftest('log(1)', math.log(1), 0)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
558 self.ftest('log(e)', math.log(math.e), 1)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
559 self.ftest('log(32,2)', math.log(32,2), 5)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
560 self.ftest('log(10**40, 10)', math.log(10**40, 10), 40)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
561 self.ftest('log(10**40, 10**20)', math.log(10**40, 10**20), 2)
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
562 self.assertEquals(math.log(INF), INF)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
563 self.assertRaises(ValueError, math.log, NINF)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
564 self.assertTrue(math.isnan(math.log(NAN)))
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
565
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
566 def testLog1p(self):
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
567 self.assertRaises(TypeError, math.log1p)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
568 self.ftest('log1p(1/e -1)', math.log1p(1/math.e-1), -1)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
569 self.ftest('log1p(0)', math.log1p(0), 0)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
570 self.ftest('log1p(e-1)', math.log1p(math.e-1), 1)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
571 self.ftest('log1p(1)', math.log1p(1), math.log(2))
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
572 self.assertEquals(math.log1p(INF), INF)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
573 self.assertRaises(ValueError, math.log1p, NINF)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
574 self.assertTrue(math.isnan(math.log1p(NAN)))
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
575 n= 2**90
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
576 self.assertAlmostEquals(math.log1p(n), 62.383246250395075)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
577 self.assertAlmostEquals(math.log1p(n), math.log1p(float(n)))
3950
75d016c97d1c Added test for math module
Guido van Rossum <guido@python.org>
parents:
diff changeset
578
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
579 def testLog10(self):
40270
1715e6a0aee9 Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents: 40219
diff changeset
580 self.assertRaises(TypeError, math.log10)
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
581 self.ftest('log10(0.1)', math.log10(0.1), -1)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
582 self.ftest('log10(1)', math.log10(1), 0)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
583 self.ftest('log10(10)', math.log10(10), 1)
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
584 self.assertEquals(math.log(INF), INF)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
585 self.assertRaises(ValueError, math.log10, NINF)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
586 self.assertTrue(math.isnan(math.log10(NAN)))
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
587
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
588 def testModf(self):
40270
1715e6a0aee9 Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents: 40219
diff changeset
589 self.assertRaises(TypeError, math.modf)
1715e6a0aee9 Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents: 40219
diff changeset
590
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
591 def testmodf(name, (v1, v2), (e1, e2)):
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
592 if abs(v1-e1) > eps or abs(v2-e2):
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
593 self.fail('%s returned %r, expected %r'%\
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
594 (name, (v1,v2), (e1,e2)))
3950
75d016c97d1c Added test for math module
Guido van Rossum <guido@python.org>
parents:
diff changeset
595
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
596 testmodf('modf(1.5)', math.modf(1.5), (0.5, 1.0))
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
597 testmodf('modf(-1.5)', math.modf(-1.5), (-0.5, -1.0))
40284
ff678669aa6e Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 40270
diff changeset
598
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
599 self.assertEquals(math.modf(INF), (0.0, INF))
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
600 self.assertEquals(math.modf(NINF), (-0.0, NINF))
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
601
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
602 modf_nan = math.modf(NAN)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
603 self.assertTrue(math.isnan(modf_nan[0]))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
604 self.assertTrue(math.isnan(modf_nan[1]))
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
605
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
606 def testPow(self):
40270
1715e6a0aee9 Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents: 40219
diff changeset
607 self.assertRaises(TypeError, math.pow)
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
608 self.ftest('pow(0,1)', math.pow(0,1), 0)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
609 self.ftest('pow(1,0)', math.pow(1,0), 1)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
610 self.ftest('pow(2,1)', math.pow(2,1), 2)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
611 self.ftest('pow(2,-1)', math.pow(2,-1), 0.5)
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
612 self.assertEqual(math.pow(INF, 1), INF)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
613 self.assertEqual(math.pow(NINF, 1), NINF)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
614 self.assertEqual((math.pow(1, INF)), 1.)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
615 self.assertEqual((math.pow(1, NINF)), 1.)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
616 self.assertTrue(math.isnan(math.pow(NAN, 1)))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
617 self.assertTrue(math.isnan(math.pow(2, NAN)))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
618 self.assertTrue(math.isnan(math.pow(0, NAN)))
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
619 self.assertEqual(math.pow(1, NAN), 1)
46486
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
620
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
621 # pow(0., x)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
622 self.assertEqual(math.pow(0., INF), 0.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
623 self.assertEqual(math.pow(0., 3.), 0.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
624 self.assertEqual(math.pow(0., 2.3), 0.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
625 self.assertEqual(math.pow(0., 2.), 0.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
626 self.assertEqual(math.pow(0., 0.), 1.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
627 self.assertEqual(math.pow(0., -0.), 1.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
628 self.assertRaises(ValueError, math.pow, 0., -2.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
629 self.assertRaises(ValueError, math.pow, 0., -2.3)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
630 self.assertRaises(ValueError, math.pow, 0., -3.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
631 self.assertRaises(ValueError, math.pow, 0., NINF)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
632 self.assertTrue(math.isnan(math.pow(0., NAN)))
46486
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
633
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
634 # pow(INF, x)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
635 self.assertEqual(math.pow(INF, INF), INF)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
636 self.assertEqual(math.pow(INF, 3.), INF)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
637 self.assertEqual(math.pow(INF, 2.3), INF)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
638 self.assertEqual(math.pow(INF, 2.), INF)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
639 self.assertEqual(math.pow(INF, 0.), 1.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
640 self.assertEqual(math.pow(INF, -0.), 1.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
641 self.assertEqual(math.pow(INF, -2.), 0.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
642 self.assertEqual(math.pow(INF, -2.3), 0.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
643 self.assertEqual(math.pow(INF, -3.), 0.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
644 self.assertEqual(math.pow(INF, NINF), 0.)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
645 self.assertTrue(math.isnan(math.pow(INF, NAN)))
46486
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
646
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
647 # pow(-0., x)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
648 self.assertEqual(math.pow(-0., INF), 0.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
649 self.assertEqual(math.pow(-0., 3.), -0.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
650 self.assertEqual(math.pow(-0., 2.3), 0.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
651 self.assertEqual(math.pow(-0., 2.), 0.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
652 self.assertEqual(math.pow(-0., 0.), 1.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
653 self.assertEqual(math.pow(-0., -0.), 1.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
654 self.assertRaises(ValueError, math.pow, -0., -2.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
655 self.assertRaises(ValueError, math.pow, -0., -2.3)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
656 self.assertRaises(ValueError, math.pow, -0., -3.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
657 self.assertRaises(ValueError, math.pow, -0., NINF)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
658 self.assertTrue(math.isnan(math.pow(-0., NAN)))
46486
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
659
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
660 # pow(NINF, x)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
661 self.assertEqual(math.pow(NINF, INF), INF)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
662 self.assertEqual(math.pow(NINF, 3.), NINF)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
663 self.assertEqual(math.pow(NINF, 2.3), INF)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
664 self.assertEqual(math.pow(NINF, 2.), INF)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
665 self.assertEqual(math.pow(NINF, 0.), 1.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
666 self.assertEqual(math.pow(NINF, -0.), 1.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
667 self.assertEqual(math.pow(NINF, -2.), 0.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
668 self.assertEqual(math.pow(NINF, -2.3), 0.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
669 self.assertEqual(math.pow(NINF, -3.), -0.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
670 self.assertEqual(math.pow(NINF, NINF), 0.)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
671 self.assertTrue(math.isnan(math.pow(NINF, NAN)))
46486
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
672
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
673 # pow(-1, x)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
674 self.assertEqual(math.pow(-1., INF), 1.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
675 self.assertEqual(math.pow(-1., 3.), -1.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
676 self.assertRaises(ValueError, math.pow, -1., 2.3)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
677 self.assertEqual(math.pow(-1., 2.), 1.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
678 self.assertEqual(math.pow(-1., 0.), 1.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
679 self.assertEqual(math.pow(-1., -0.), 1.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
680 self.assertEqual(math.pow(-1., -2.), 1.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
681 self.assertRaises(ValueError, math.pow, -1., -2.3)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
682 self.assertEqual(math.pow(-1., -3.), -1.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
683 self.assertEqual(math.pow(-1., NINF), 1.)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
684 self.assertTrue(math.isnan(math.pow(-1., NAN)))
46486
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
685
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
686 # pow(1, x)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
687 self.assertEqual(math.pow(1., INF), 1.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
688 self.assertEqual(math.pow(1., 3.), 1.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
689 self.assertEqual(math.pow(1., 2.3), 1.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
690 self.assertEqual(math.pow(1., 2.), 1.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
691 self.assertEqual(math.pow(1., 0.), 1.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
692 self.assertEqual(math.pow(1., -0.), 1.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
693 self.assertEqual(math.pow(1., -2.), 1.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
694 self.assertEqual(math.pow(1., -2.3), 1.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
695 self.assertEqual(math.pow(1., -3.), 1.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
696 self.assertEqual(math.pow(1., NINF), 1.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
697 self.assertEqual(math.pow(1., NAN), 1.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
698
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
699 # pow(x, 0) should be 1 for any x
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
700 self.assertEqual(math.pow(2.3, 0.), 1.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
701 self.assertEqual(math.pow(-2.3, 0.), 1.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
702 self.assertEqual(math.pow(NAN, 0.), 1.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
703 self.assertEqual(math.pow(2.3, -0.), 1.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
704 self.assertEqual(math.pow(-2.3, -0.), 1.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
705 self.assertEqual(math.pow(NAN, -0.), 1.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
706
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
707 # pow(x, y) is invalid if x is negative and y is not integral
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
708 self.assertRaises(ValueError, math.pow, -1., 2.3)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
709 self.assertRaises(ValueError, math.pow, -15., -3.1)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
710
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
711 # pow(x, NINF)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
712 self.assertEqual(math.pow(1.9, NINF), 0.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
713 self.assertEqual(math.pow(1.1, NINF), 0.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
714 self.assertEqual(math.pow(0.9, NINF), INF)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
715 self.assertEqual(math.pow(0.1, NINF), INF)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
716 self.assertEqual(math.pow(-0.1, NINF), INF)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
717 self.assertEqual(math.pow(-0.9, NINF), INF)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
718 self.assertEqual(math.pow(-1.1, NINF), 0.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
719 self.assertEqual(math.pow(-1.9, NINF), 0.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
720
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
721 # pow(x, INF)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
722 self.assertEqual(math.pow(1.9, INF), INF)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
723 self.assertEqual(math.pow(1.1, INF), INF)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
724 self.assertEqual(math.pow(0.9, INF), 0.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
725 self.assertEqual(math.pow(0.1, INF), 0.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
726 self.assertEqual(math.pow(-0.1, INF), 0.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
727 self.assertEqual(math.pow(-0.9, INF), 0.)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
728 self.assertEqual(math.pow(-1.1, INF), INF)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
729 self.assertEqual(math.pow(-1.9, INF), INF)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
730
46500
a20def0101de Yet more explicit special case handling to make
Mark Dickinson <dickinsm@gmail.com>
parents: 46498
diff changeset
731 # pow(x, y) should work for x negative, y an integer
a20def0101de Yet more explicit special case handling to make
Mark Dickinson <dickinsm@gmail.com>
parents: 46498
diff changeset
732 self.ftest('(-2.)**3.', math.pow(-2.0, 3.0), -8.0)
a20def0101de Yet more explicit special case handling to make
Mark Dickinson <dickinsm@gmail.com>
parents: 46498
diff changeset
733 self.ftest('(-2.)**2.', math.pow(-2.0, 2.0), 4.0)
a20def0101de Yet more explicit special case handling to make
Mark Dickinson <dickinsm@gmail.com>
parents: 46498
diff changeset
734 self.ftest('(-2.)**1.', math.pow(-2.0, 1.0), -2.0)
a20def0101de Yet more explicit special case handling to make
Mark Dickinson <dickinsm@gmail.com>
parents: 46498
diff changeset
735 self.ftest('(-2.)**0.', math.pow(-2.0, 0.0), 1.0)
a20def0101de Yet more explicit special case handling to make
Mark Dickinson <dickinsm@gmail.com>
parents: 46498
diff changeset
736 self.ftest('(-2.)**-0.', math.pow(-2.0, -0.0), 1.0)
a20def0101de Yet more explicit special case handling to make
Mark Dickinson <dickinsm@gmail.com>
parents: 46498
diff changeset
737 self.ftest('(-2.)**-1.', math.pow(-2.0, -1.0), -0.5)
a20def0101de Yet more explicit special case handling to make
Mark Dickinson <dickinsm@gmail.com>
parents: 46498
diff changeset
738 self.ftest('(-2.)**-2.', math.pow(-2.0, -2.0), 0.25)
a20def0101de Yet more explicit special case handling to make
Mark Dickinson <dickinsm@gmail.com>
parents: 46498
diff changeset
739 self.ftest('(-2.)**-3.', math.pow(-2.0, -3.0), -0.125)
a20def0101de Yet more explicit special case handling to make
Mark Dickinson <dickinsm@gmail.com>
parents: 46498
diff changeset
740 self.assertRaises(ValueError, math.pow, -2.0, -0.5)
a20def0101de Yet more explicit special case handling to make
Mark Dickinson <dickinsm@gmail.com>
parents: 46498
diff changeset
741 self.assertRaises(ValueError, math.pow, -2.0, 0.5)
a20def0101de Yet more explicit special case handling to make
Mark Dickinson <dickinsm@gmail.com>
parents: 46498
diff changeset
742
46486
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
743 # the following tests have been commented out since they don't
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
744 # really belong here: the implementation of ** for floats is
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
745 # independent of the implemention of math.pow
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
746 #self.assertEqual(1**NAN, 1)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
747 #self.assertEqual(1**INF, 1)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
748 #self.assertEqual(1**NINF, 1)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
749 #self.assertEqual(1**0, 1)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
750 #self.assertEqual(1.**NAN, 1)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
751 #self.assertEqual(1.**INF, 1)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
752 #self.assertEqual(1.**NINF, 1)
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
753 #self.assertEqual(1.**0, 1)
3950
75d016c97d1c Added test for math module
Guido van Rossum <guido@python.org>
parents:
diff changeset
754
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
755 def testRadians(self):
40270
1715e6a0aee9 Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents: 40219
diff changeset
756 self.assertRaises(TypeError, math.radians)
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
757 self.ftest('radians(180)', math.radians(180), math.pi)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
758 self.ftest('radians(90)', math.radians(90), math.pi/2)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
759 self.ftest('radians(-45)', math.radians(-45), -math.pi/4)
3950
75d016c97d1c Added test for math module
Guido van Rossum <guido@python.org>
parents:
diff changeset
760
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
761 def testSin(self):
40270
1715e6a0aee9 Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents: 40219
diff changeset
762 self.assertRaises(TypeError, math.sin)
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
763 self.ftest('sin(0)', math.sin(0), 0)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
764 self.ftest('sin(pi/2)', math.sin(math.pi/2), 1)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
765 self.ftest('sin(-pi/2)', math.sin(-math.pi/2), -1)
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
766 try:
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
767 self.assertTrue(math.isnan(math.sin(INF)))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
768 self.assertTrue(math.isnan(math.sin(NINF)))
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
769 except ValueError:
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
770 self.assertRaises(ValueError, math.sin, INF)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
771 self.assertRaises(ValueError, math.sin, NINF)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
772 self.assertTrue(math.isnan(math.sin(NAN)))
23426
1157281f00a0 Adds tests for degrees() and radians() functions added to mathmodule.
Raymond Hettinger <python@rcn.com>
parents: 19750
diff changeset
773
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
774 def testSinh(self):
40270
1715e6a0aee9 Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents: 40219
diff changeset
775 self.assertRaises(TypeError, math.sinh)
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
776 self.ftest('sinh(0)', math.sinh(0), 0)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
777 self.ftest('sinh(1)**2-cosh(1)**2', math.sinh(1)**2-math.cosh(1)**2, -1)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
778 self.ftest('sinh(1)+sinh(-1)', math.sinh(1)+math.sinh(-1), 0)
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
779 self.assertEquals(math.sinh(INF), INF)
46486
82d85a05923b Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents: 46473
diff changeset
780 self.assertEquals(math.sinh(NINF), NINF)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
781 self.assertTrue(math.isnan(math.sinh(NAN)))
3950
75d016c97d1c Added test for math module
Guido van Rossum <guido@python.org>
parents:
diff changeset
782
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
783 def testSqrt(self):
40270
1715e6a0aee9 Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents: 40219
diff changeset
784 self.assertRaises(TypeError, math.sqrt)
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
785 self.ftest('sqrt(0)', math.sqrt(0), 0)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
786 self.ftest('sqrt(1)', math.sqrt(1), 1)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
787 self.ftest('sqrt(4)', math.sqrt(4), 2)
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
788 self.assertEquals(math.sqrt(INF), INF)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
789 self.assertRaises(ValueError, math.sqrt, NINF)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
790 self.assertTrue(math.isnan(math.sqrt(NAN)))
3950
75d016c97d1c Added test for math module
Guido van Rossum <guido@python.org>
parents:
diff changeset
791
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
792 def testTan(self):
40270
1715e6a0aee9 Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents: 40219
diff changeset
793 self.assertRaises(TypeError, math.tan)
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
794 self.ftest('tan(0)', math.tan(0), 0)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
795 self.ftest('tan(pi/4)', math.tan(math.pi/4), 1)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
796 self.ftest('tan(-pi/4)', math.tan(-math.pi/4), -1)
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
797 try:
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
798 self.assertTrue(math.isnan(math.tan(INF)))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
799 self.assertTrue(math.isnan(math.tan(NINF)))
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
800 except:
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
801 self.assertRaises(ValueError, math.tan, INF)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
802 self.assertRaises(ValueError, math.tan, NINF)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
803 self.assertTrue(math.isnan(math.tan(NAN)))
3950
75d016c97d1c Added test for math module
Guido van Rossum <guido@python.org>
parents:
diff changeset
804
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
805 def testTanh(self):
40270
1715e6a0aee9 Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents: 40219
diff changeset
806 self.assertRaises(TypeError, math.tanh)
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
807 self.ftest('tanh(0)', math.tanh(0), 0)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
808 self.ftest('tanh(1)+tanh(-1)', math.tanh(1)+math.tanh(-1), 0)
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
809 self.ftest('tanh(inf)', math.tanh(INF), 1)
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
810 self.ftest('tanh(-inf)', math.tanh(NINF), -1)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
811 self.assertTrue(math.isnan(math.tanh(NAN)))
46504
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
812 # check that tanh(-0.) == -0. on IEEE 754 systems
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
813 if float.__getformat__("double").startswith("IEEE"):
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
814 self.assertEqual(math.tanh(-0.), -0.)
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
815 self.assertEqual(math.copysign(1., math.tanh(-0.)),
60f4456fa338 Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents: 46500
diff changeset
816 math.copysign(1., -0.))
3950
75d016c97d1c Added test for math module
Guido van Rossum <guido@python.org>
parents:
diff changeset
817
45079
492b302aded6 Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44488
diff changeset
818 def test_trunc(self):
492b302aded6 Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44488
diff changeset
819 self.assertEqual(math.trunc(1), 1)
492b302aded6 Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44488
diff changeset
820 self.assertEqual(math.trunc(-1), -1)
492b302aded6 Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44488
diff changeset
821 self.assertEqual(type(math.trunc(1)), int)
492b302aded6 Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44488
diff changeset
822 self.assertEqual(type(math.trunc(1.5)), int)
492b302aded6 Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44488
diff changeset
823 self.assertEqual(math.trunc(1.5), 1)
492b302aded6 Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44488
diff changeset
824 self.assertEqual(math.trunc(-1.5), -1)
492b302aded6 Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44488
diff changeset
825 self.assertEqual(math.trunc(1.999999), 1)
492b302aded6 Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44488
diff changeset
826 self.assertEqual(math.trunc(-1.999999), -1)
492b302aded6 Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44488
diff changeset
827 self.assertEqual(math.trunc(-0.999999), -0)
492b302aded6 Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44488
diff changeset
828 self.assertEqual(math.trunc(-100.999), -100)
492b302aded6 Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44488
diff changeset
829
492b302aded6 Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44488
diff changeset
830 class TestTrunc(object):
492b302aded6 Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44488
diff changeset
831 def __trunc__(self):
492b302aded6 Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44488
diff changeset
832 return 23
492b302aded6 Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44488
diff changeset
833
492b302aded6 Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44488
diff changeset
834 class TestNoTrunc(object):
492b302aded6 Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44488
diff changeset
835 pass
492b302aded6 Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44488
diff changeset
836
492b302aded6 Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44488
diff changeset
837 self.assertEqual(math.trunc(TestTrunc()), 23)
492b302aded6 Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44488
diff changeset
838
492b302aded6 Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44488
diff changeset
839 self.assertRaises(TypeError, math.trunc)
492b302aded6 Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44488
diff changeset
840 self.assertRaises(TypeError, math.trunc, 1, 2)
492b302aded6 Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44488
diff changeset
841 # XXX: This is not ideal, but see the comment in math_trunc().
492b302aded6 Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44488
diff changeset
842 self.assertRaises(AttributeError, math.trunc, TestNoTrunc())
492b302aded6 Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44488
diff changeset
843
492b302aded6 Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44488
diff changeset
844 t = TestNoTrunc()
492b302aded6 Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44488
diff changeset
845 t.__trunc__ = lambda *args: args
492b302aded6 Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44488
diff changeset
846 self.assertEquals((), math.trunc(t))
492b302aded6 Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44488
diff changeset
847 self.assertRaises(TypeError, math.trunc, t, 0)
492b302aded6 Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 44488
diff changeset
848
44440
6208b17d0dbe Added copysign(x, y) function to the math module
Christian Heimes <christian@cheimes.de>
parents: 44437
diff changeset
849 def testCopysign(self):
6208b17d0dbe Added copysign(x, y) function to the math module
Christian Heimes <christian@cheimes.de>
parents: 44437
diff changeset
850 self.assertEqual(math.copysign(1, 42), 1.0)
6208b17d0dbe Added copysign(x, y) function to the math module
Christian Heimes <christian@cheimes.de>
parents: 44437
diff changeset
851 self.assertEqual(math.copysign(0., 42), 0.0)
6208b17d0dbe Added copysign(x, y) function to the math module
Christian Heimes <christian@cheimes.de>
parents: 44437
diff changeset
852 self.assertEqual(math.copysign(1., -42), -1.0)
6208b17d0dbe Added copysign(x, y) function to the math module
Christian Heimes <christian@cheimes.de>
parents: 44437
diff changeset
853 self.assertEqual(math.copysign(3, 0.), 3.0)
6208b17d0dbe Added copysign(x, y) function to the math module
Christian Heimes <christian@cheimes.de>
parents: 44437
diff changeset
854 self.assertEqual(math.copysign(4., -0.), -4.0)
6208b17d0dbe Added copysign(x, y) function to the math module
Christian Heimes <christian@cheimes.de>
parents: 44437
diff changeset
855
44437
968bda81e6c8 Added math.isinf() and math.isnan()
Christian Heimes <christian@cheimes.de>
parents: 44432
diff changeset
856 def testIsnan(self):
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
857 self.assertTrue(math.isnan(float("nan")))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
858 self.assertTrue(math.isnan(float("inf")* 0.))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
859 self.assertFalse(math.isnan(float("inf")))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
860 self.assertFalse(math.isnan(0.))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
861 self.assertFalse(math.isnan(1.))
44437
968bda81e6c8 Added math.isinf() and math.isnan()
Christian Heimes <christian@cheimes.de>
parents: 44432
diff changeset
862
968bda81e6c8 Added math.isinf() and math.isnan()
Christian Heimes <christian@cheimes.de>
parents: 44432
diff changeset
863 def testIsinf(self):
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
864 self.assertTrue(math.isinf(float("inf")))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
865 self.assertTrue(math.isinf(float("-inf")))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
866 self.assertTrue(math.isinf(1E400))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
867 self.assertTrue(math.isinf(-1E400))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
868 self.assertFalse(math.isinf(float("nan")))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
869 self.assertFalse(math.isinf(0.))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53351
diff changeset
870 self.assertFalse(math.isinf(1.))
44437
968bda81e6c8 Added math.isinf() and math.isnan()
Christian Heimes <christian@cheimes.de>
parents: 44432
diff changeset
871
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
872 # RED_FLAG 16-Oct-2000 Tim
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
873 # While 2.0 is more consistent about exceptions than previous releases, it
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
874 # still fails this part of the test on some platforms. For now, we only
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
875 # *run* test_exceptions() in verbose mode, so that this isn't normally
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
876 # tested.
15170
09c7ac188ce2 Stop raising OverflowError on underflows reported by libm (errno==ERANGE and
Tim Peters <tim.peters@gmail.com>
parents: 13912
diff changeset
877
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
878 if verbose:
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
879 def test_exceptions(self):
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
880 try:
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
881 x = math.exp(-1000000000)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
882 except:
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
883 # mathmodule.c is failing to weed out underflows from libm, or
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
884 # we've got an fp format with huge dynamic range
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
885 self.fail("underflowing exp() should not have raised "
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
886 "an exception")
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
887 if x != 0:
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
888 self.fail("underflowing exp() should have returned 0")
15170
09c7ac188ce2 Stop raising OverflowError on underflows reported by libm (errno==ERANGE and
Tim Peters <tim.peters@gmail.com>
parents: 13912
diff changeset
889
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
890 # If this fails, probably using a strict IEEE-754 conforming libm, and x
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
891 # is +Inf afterwards. But Python wants overflows detected by default.
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
892 try:
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
893 x = math.exp(1000000000)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
894 except OverflowError:
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
895 pass
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
896 else:
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
897 self.fail("overflowing exp() didn't trigger OverflowError")
15170
09c7ac188ce2 Stop raising OverflowError on underflows reported by libm (errno==ERANGE and
Tim Peters <tim.peters@gmail.com>
parents: 13912
diff changeset
898
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
899 # If this fails, it could be a puzzle. One odd possibility is that
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
900 # mathmodule.c's macros are getting confused while comparing
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
901 # Inf (HUGE_VAL) to a NaN, and artificially setting errno to ERANGE
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
902 # as a result (and so raising OverflowError instead).
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
903 try:
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
904 x = math.sqrt(-1.0)
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
905 except ValueError:
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
906 pass
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
907 else:
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
908 self.fail("sqrt(-1) didn't raise ValueError")
15170
09c7ac188ce2 Stop raising OverflowError on underflows reported by libm (errno==ERANGE and
Tim Peters <tim.peters@gmail.com>
parents: 13912
diff changeset
909
56089
f2555ad5fe09 Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
910 @requires_IEEE_754
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
911 def test_testfile(self):
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
912 for id, fn, ar, ai, er, ei, flags in parse_testfile(test_file):
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
913 # Skip if either the input or result is complex, or if
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
914 # flags is nonempty
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
915 if ai != 0. or ei != 0. or flags:
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
916 continue
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
917 if fn in ['rect', 'polar']:
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
918 # no real versions of rect, polar
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
919 continue
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
920 func = getattr(math, fn)
46498
31ff59d984bd Report additional diagnostic information in
Mark Dickinson <dickinsm@gmail.com>
parents: 46486
diff changeset
921 try:
31ff59d984bd Report additional diagnostic information in
Mark Dickinson <dickinsm@gmail.com>
parents: 46486
diff changeset
922 result = func(ar)
31ff59d984bd Report additional diagnostic information in
Mark Dickinson <dickinsm@gmail.com>
parents: 46486
diff changeset
923 except ValueError:
31ff59d984bd Report additional diagnostic information in
Mark Dickinson <dickinsm@gmail.com>
parents: 46486
diff changeset
924 message = ("Unexpected ValueError in " +
31ff59d984bd Report additional diagnostic information in
Mark Dickinson <dickinsm@gmail.com>
parents: 46486
diff changeset
925 "test %s:%s(%r)\n" % (id, fn, ar))
31ff59d984bd Report additional diagnostic information in
Mark Dickinson <dickinsm@gmail.com>
parents: 46486
diff changeset
926 self.fail(message)
47218
5a29552412fa Better error reporting in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 47217
diff changeset
927 except OverflowError:
5a29552412fa Better error reporting in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 47217
diff changeset
928 message = ("Unexpected OverflowError in " +
5a29552412fa Better error reporting in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 47217
diff changeset
929 "test %s:%s(%r)\n" % (id, fn, ar))
5a29552412fa Better error reporting in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents: 47217
diff changeset
930 self.fail(message)
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
931 self.ftest("%s:%s(%r)" % (id, fn, ar), result, er)
15247
dd0d199674f8 Test for math.* exceptional behavior only in verbose mode, so that the
Tim Peters <tim.peters@gmail.com>
parents: 15171
diff changeset
932
56268
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
933 @unittest.skipUnless(float.__getformat__("double").startswith("IEEE"),
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
934 "test requires IEEE 754 doubles")
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
935 def test_mtestfile(self):
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
936 ALLOWED_ERROR = 20 # permitted error, in ulps
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
937 fail_fmt = "{}:{}({!r}): expected {!r}, got {!r}"
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
938
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
939 failures = []
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
940 for id, fn, arg, expected, flags in parse_mtestfile(math_testcases):
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
941 func = getattr(math, fn)
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
942
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
943 if 'invalid' in flags or 'divide-by-zero' in flags:
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
944 expected = 'ValueError'
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
945 elif 'overflow' in flags:
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
946 expected = 'OverflowError'
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
947
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
948 try:
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
949 got = func(arg)
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
950 except ValueError:
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
951 got = 'ValueError'
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
952 except OverflowError:
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
953 got = 'OverflowError'
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
954
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
955 diff_ulps = None
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
956 if isinstance(got, float) and isinstance(expected, float):
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
957 if math.isnan(expected) and math.isnan(got):
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
958 continue
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
959 if not math.isnan(expected) and not math.isnan(got):
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
960 diff_ulps = to_ulps(expected) - to_ulps(got)
56307
5f245da72aeb Fix buggy accuracy test
Mark Dickinson <dickinsm@gmail.com>
parents: 56268
diff changeset
961 if abs(diff_ulps) <= ALLOWED_ERROR:
56268
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
962 continue
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
963
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
964 if isinstance(got, str) and isinstance(expected, str):
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
965 if got == expected:
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
966 continue
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
967
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
968 fail_msg = fail_fmt.format(id, fn, arg, expected, got)
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
969 if diff_ulps is not None:
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
970 fail_msg += ' ({} ulps)'.format(diff_ulps)
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
971 failures.append(fail_msg)
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
972
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
973 if failures:
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
974 self.fail('Failures in test_mtestfile:\n ' +
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
975 '\n '.join(failures))
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
976
b50dd17dfe26 Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents: 56089
diff changeset
977
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
978 def test_main():
46473
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
979 from doctest import DocFileSuite
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
980 suite = unittest.TestSuite()
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
981 suite.addTest(unittest.makeSuite(MathTests))
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
982 suite.addTest(DocFileSuite("ieee754.txt"))
5bc7b20dc04a I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents: 45079
diff changeset
983 run_unittest(suite)
40219
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
984
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
985 if __name__ == '__main__':
69728a7d2312 Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents: 31515
diff changeset
986 test_main()