Guido van Rossum | fcce630 | 1996-08-08 18:26:25 +0000 | [diff] [blame] | 1 | # Python test set -- math module |
| 2 | # XXXX Should not do tests around zero only |
| 3 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 4 | from test.test_support import run_unittest, verbose |
| 5 | import unittest |
| 6 | import math |
Christian Heimes | 6f34109 | 2008-04-18 23:13:07 +0000 | [diff] [blame] | 7 | import os |
| 8 | import sys |
Guido van Rossum | fcce630 | 1996-08-08 18:26:25 +0000 | [diff] [blame] | 9 | |
Christian Heimes | 6f34109 | 2008-04-18 23:13:07 +0000 | [diff] [blame] | 10 | eps = 1E-05 |
| 11 | NAN = float('nan') |
| 12 | INF = float('inf') |
| 13 | NINF = float('-inf') |
| 14 | |
| 15 | # locate file with test values |
| 16 | if __name__ == '__main__': |
| 17 | file = sys.argv[0] |
| 18 | else: |
| 19 | file = __file__ |
| 20 | test_dir = os.path.dirname(file) or os.curdir |
| 21 | test_file = os.path.join(test_dir, 'cmath_testcases.txt') |
| 22 | |
| 23 | def parse_testfile(fname): |
| 24 | """Parse a file with test values |
| 25 | |
| 26 | Empty lines or lines starting with -- are ignored |
| 27 | yields id, fn, arg_real, arg_imag, exp_real, exp_imag |
| 28 | """ |
| 29 | with open(fname) as fp: |
| 30 | for line in fp: |
| 31 | # skip comment lines and blank lines |
| 32 | if line.startswith('--') or not line.strip(): |
| 33 | continue |
| 34 | |
| 35 | lhs, rhs = line.split('->') |
| 36 | id, fn, arg_real, arg_imag = lhs.split() |
| 37 | rhs_pieces = rhs.split() |
| 38 | exp_real, exp_imag = rhs_pieces[0], rhs_pieces[1] |
| 39 | flags = rhs_pieces[2:] |
| 40 | |
| 41 | yield (id, fn, |
| 42 | float(arg_real), float(arg_imag), |
| 43 | float(exp_real), float(exp_imag), |
| 44 | flags |
| 45 | ) |
Guido van Rossum | fcce630 | 1996-08-08 18:26:25 +0000 | [diff] [blame] | 46 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 47 | class MathTests(unittest.TestCase): |
Guido van Rossum | fcce630 | 1996-08-08 18:26:25 +0000 | [diff] [blame] | 48 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 49 | def ftest(self, name, value, expected): |
| 50 | if abs(value-expected) > eps: |
Nick Coghlan | ec2ce9b | 2007-07-27 10:36:30 +0000 | [diff] [blame] | 51 | # Use %r instead of %f so the error message |
| 52 | # displays full precision. Otherwise discrepancies |
| 53 | # in the last few bits will lead to very confusing |
| 54 | # error messages |
| 55 | self.fail('%s returned %r, expected %r' % |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 56 | (name, value, expected)) |
Guido van Rossum | fcce630 | 1996-08-08 18:26:25 +0000 | [diff] [blame] | 57 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 58 | def testConstants(self): |
| 59 | self.ftest('pi', math.pi, 3.1415926) |
| 60 | self.ftest('e', math.e, 2.7182818) |
Guido van Rossum | fcce630 | 1996-08-08 18:26:25 +0000 | [diff] [blame] | 61 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 62 | def testAcos(self): |
Walter Dörwald | 92911bf | 2006-10-29 22:06:28 +0000 | [diff] [blame] | 63 | self.assertRaises(TypeError, math.acos) |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 64 | self.ftest('acos(-1)', math.acos(-1), math.pi) |
| 65 | self.ftest('acos(0)', math.acos(0), math.pi/2) |
| 66 | self.ftest('acos(1)', math.acos(1), 0) |
Christian Heimes | 6f34109 | 2008-04-18 23:13:07 +0000 | [diff] [blame] | 67 | self.assertRaises(ValueError, math.acos, INF) |
| 68 | self.assertRaises(ValueError, math.acos, NINF) |
| 69 | self.assert_(math.isnan(math.acos(NAN))) |
| 70 | |
| 71 | def testAcosh(self): |
| 72 | self.assertRaises(TypeError, math.acosh) |
| 73 | self.ftest('acosh(1)', math.acosh(1), 0) |
| 74 | self.ftest('acosh(2)', math.acosh(2), 1.3169578969248168) |
| 75 | self.assertRaises(ValueError, math.acosh, 0) |
| 76 | self.assertRaises(ValueError, math.acosh, -1) |
| 77 | self.assertEquals(math.acosh(INF), INF) |
| 78 | self.assertRaises(ValueError, math.acosh, NINF) |
| 79 | self.assert_(math.isnan(math.acosh(NAN))) |
Guido van Rossum | fcce630 | 1996-08-08 18:26:25 +0000 | [diff] [blame] | 80 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 81 | def testAsin(self): |
Walter Dörwald | 92911bf | 2006-10-29 22:06:28 +0000 | [diff] [blame] | 82 | self.assertRaises(TypeError, math.asin) |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 83 | self.ftest('asin(-1)', math.asin(-1), -math.pi/2) |
| 84 | self.ftest('asin(0)', math.asin(0), 0) |
| 85 | self.ftest('asin(1)', math.asin(1), math.pi/2) |
Christian Heimes | 6f34109 | 2008-04-18 23:13:07 +0000 | [diff] [blame] | 86 | self.assertRaises(ValueError, math.asin, INF) |
| 87 | self.assertRaises(ValueError, math.asin, NINF) |
| 88 | self.assert_(math.isnan(math.asin(NAN))) |
| 89 | |
| 90 | def testAsinh(self): |
| 91 | self.assertRaises(TypeError, math.asinh) |
| 92 | self.ftest('asinh(0)', math.asinh(0), 0) |
| 93 | self.ftest('asinh(1)', math.asinh(1), 0.88137358701954305) |
| 94 | self.ftest('asinh(-1)', math.asinh(-1), -0.88137358701954305) |
| 95 | self.assertEquals(math.asinh(INF), INF) |
| 96 | self.assertEquals(math.asinh(NINF), NINF) |
| 97 | self.assert_(math.isnan(math.asinh(NAN))) |
Guido van Rossum | fcce630 | 1996-08-08 18:26:25 +0000 | [diff] [blame] | 98 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 99 | def testAtan(self): |
Walter Dörwald | 92911bf | 2006-10-29 22:06:28 +0000 | [diff] [blame] | 100 | self.assertRaises(TypeError, math.atan) |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 101 | self.ftest('atan(-1)', math.atan(-1), -math.pi/4) |
| 102 | self.ftest('atan(0)', math.atan(0), 0) |
| 103 | self.ftest('atan(1)', math.atan(1), math.pi/4) |
Christian Heimes | 6f34109 | 2008-04-18 23:13:07 +0000 | [diff] [blame] | 104 | self.ftest('atan(inf)', math.atan(INF), math.pi/2) |
Mark Dickinson | e941d97 | 2008-04-19 18:51:48 +0000 | [diff] [blame] | 105 | self.ftest('atan(-inf)', math.atan(NINF), -math.pi/2) |
Christian Heimes | 6f34109 | 2008-04-18 23:13:07 +0000 | [diff] [blame] | 106 | self.assert_(math.isnan(math.atan(NAN))) |
| 107 | |
| 108 | def testAtanh(self): |
| 109 | self.assertRaises(TypeError, math.atan) |
| 110 | self.ftest('atanh(0)', math.atanh(0), 0) |
| 111 | self.ftest('atanh(0.5)', math.atanh(0.5), 0.54930614433405489) |
| 112 | self.ftest('atanh(-0.5)', math.atanh(-0.5), -0.54930614433405489) |
| 113 | self.assertRaises(ValueError, math.atanh, 1) |
| 114 | self.assertRaises(ValueError, math.atanh, -1) |
| 115 | self.assertRaises(ValueError, math.atanh, INF) |
| 116 | self.assertRaises(ValueError, math.atanh, NINF) |
| 117 | self.assert_(math.isnan(math.atanh(NAN))) |
Guido van Rossum | fcce630 | 1996-08-08 18:26:25 +0000 | [diff] [blame] | 118 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 119 | def testAtan2(self): |
Walter Dörwald | 92911bf | 2006-10-29 22:06:28 +0000 | [diff] [blame] | 120 | self.assertRaises(TypeError, math.atan2) |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 121 | self.ftest('atan2(-1, 0)', math.atan2(-1, 0), -math.pi/2) |
| 122 | self.ftest('atan2(-1, 1)', math.atan2(-1, 1), -math.pi/4) |
| 123 | self.ftest('atan2(0, 1)', math.atan2(0, 1), 0) |
| 124 | self.ftest('atan2(1, 1)', math.atan2(1, 1), math.pi/4) |
| 125 | self.ftest('atan2(1, 0)', math.atan2(1, 0), math.pi/2) |
Guido van Rossum | fcce630 | 1996-08-08 18:26:25 +0000 | [diff] [blame] | 126 | |
Mark Dickinson | d6d5148 | 2008-04-20 20:38:48 +0000 | [diff] [blame] | 127 | # math.atan2(0, x) |
| 128 | self.ftest('atan2(0., -inf)', math.atan2(0., NINF), math.pi) |
| 129 | self.ftest('atan2(0., -2.3)', math.atan2(0., -2.3), math.pi) |
| 130 | self.ftest('atan2(0., -0.)', math.atan2(0., -0.), math.pi) |
| 131 | self.assertEqual(math.atan2(0., 0.), 0.) |
| 132 | self.assertEqual(math.atan2(0., 2.3), 0.) |
| 133 | self.assertEqual(math.atan2(0., INF), 0.) |
| 134 | self.assert_(math.isnan(math.atan2(0., NAN))) |
| 135 | # math.atan2(-0, x) |
| 136 | self.ftest('atan2(-0., -inf)', math.atan2(-0., NINF), -math.pi) |
| 137 | self.ftest('atan2(-0., -2.3)', math.atan2(-0., -2.3), -math.pi) |
| 138 | self.ftest('atan2(-0., -0.)', math.atan2(-0., -0.), -math.pi) |
| 139 | self.assertEqual(math.atan2(-0., 0.), -0.) |
| 140 | self.assertEqual(math.atan2(-0., 2.3), -0.) |
| 141 | self.assertEqual(math.atan2(-0., INF), -0.) |
| 142 | self.assert_(math.isnan(math.atan2(-0., NAN))) |
| 143 | # math.atan2(INF, x) |
| 144 | self.ftest('atan2(inf, -inf)', math.atan2(INF, NINF), math.pi*3/4) |
| 145 | self.ftest('atan2(inf, -2.3)', math.atan2(INF, -2.3), math.pi/2) |
| 146 | self.ftest('atan2(inf, -0.)', math.atan2(INF, -0.0), math.pi/2) |
| 147 | self.ftest('atan2(inf, 0.)', math.atan2(INF, 0.0), math.pi/2) |
| 148 | self.ftest('atan2(inf, 2.3)', math.atan2(INF, 2.3), math.pi/2) |
| 149 | self.ftest('atan2(inf, inf)', math.atan2(INF, INF), math.pi/4) |
| 150 | self.assert_(math.isnan(math.atan2(INF, NAN))) |
| 151 | # math.atan2(NINF, x) |
| 152 | self.ftest('atan2(-inf, -inf)', math.atan2(NINF, NINF), -math.pi*3/4) |
| 153 | self.ftest('atan2(-inf, -2.3)', math.atan2(NINF, -2.3), -math.pi/2) |
| 154 | self.ftest('atan2(-inf, -0.)', math.atan2(NINF, -0.0), -math.pi/2) |
| 155 | self.ftest('atan2(-inf, 0.)', math.atan2(NINF, 0.0), -math.pi/2) |
| 156 | self.ftest('atan2(-inf, 2.3)', math.atan2(NINF, 2.3), -math.pi/2) |
| 157 | self.ftest('atan2(-inf, inf)', math.atan2(NINF, INF), -math.pi/4) |
| 158 | self.assert_(math.isnan(math.atan2(NINF, NAN))) |
| 159 | # math.atan2(+finite, x) |
| 160 | self.ftest('atan2(2.3, -inf)', math.atan2(2.3, NINF), math.pi) |
| 161 | self.ftest('atan2(2.3, -0.)', math.atan2(2.3, -0.), math.pi/2) |
| 162 | self.ftest('atan2(2.3, 0.)', math.atan2(2.3, 0.), math.pi/2) |
| 163 | self.assertEqual(math.atan2(2.3, INF), 0.) |
| 164 | self.assert_(math.isnan(math.atan2(2.3, NAN))) |
| 165 | # math.atan2(-finite, x) |
| 166 | self.ftest('atan2(-2.3, -inf)', math.atan2(-2.3, NINF), -math.pi) |
| 167 | self.ftest('atan2(-2.3, -0.)', math.atan2(-2.3, -0.), -math.pi/2) |
| 168 | self.ftest('atan2(-2.3, 0.)', math.atan2(-2.3, 0.), -math.pi/2) |
| 169 | self.assertEqual(math.atan2(-2.3, INF), -0.) |
| 170 | self.assert_(math.isnan(math.atan2(-2.3, NAN))) |
| 171 | # math.atan2(NAN, x) |
| 172 | self.assert_(math.isnan(math.atan2(NAN, NINF))) |
| 173 | self.assert_(math.isnan(math.atan2(NAN, -2.3))) |
| 174 | self.assert_(math.isnan(math.atan2(NAN, -0.))) |
| 175 | self.assert_(math.isnan(math.atan2(NAN, 0.))) |
| 176 | self.assert_(math.isnan(math.atan2(NAN, 2.3))) |
| 177 | self.assert_(math.isnan(math.atan2(NAN, INF))) |
| 178 | self.assert_(math.isnan(math.atan2(NAN, NAN))) |
| 179 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 180 | def testCeil(self): |
Walter Dörwald | 92911bf | 2006-10-29 22:06:28 +0000 | [diff] [blame] | 181 | self.assertRaises(TypeError, math.ceil) |
Jeffrey Yasskin | 737c73f | 2008-01-04 08:01:23 +0000 | [diff] [blame] | 182 | # These types will be int in py3k. |
| 183 | self.assertEquals(float, type(math.ceil(1))) |
| 184 | self.assertEquals(float, type(math.ceil(1L))) |
| 185 | self.assertEquals(float, type(math.ceil(1.0))) |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 186 | self.ftest('ceil(0.5)', math.ceil(0.5), 1) |
| 187 | self.ftest('ceil(1.0)', math.ceil(1.0), 1) |
| 188 | self.ftest('ceil(1.5)', math.ceil(1.5), 2) |
| 189 | self.ftest('ceil(-0.5)', math.ceil(-0.5), 0) |
| 190 | self.ftest('ceil(-1.0)', math.ceil(-1.0), -1) |
| 191 | self.ftest('ceil(-1.5)', math.ceil(-1.5), -1) |
Christian Heimes | 6f34109 | 2008-04-18 23:13:07 +0000 | [diff] [blame] | 192 | self.assertEquals(math.ceil(INF), INF) |
| 193 | self.assertEquals(math.ceil(NINF), NINF) |
| 194 | self.assert_(math.isnan(math.ceil(NAN))) |
Guido van Rossum | fcce630 | 1996-08-08 18:26:25 +0000 | [diff] [blame] | 195 | |
Jeffrey Yasskin | 2f3c16b | 2008-01-03 02:21:52 +0000 | [diff] [blame] | 196 | class TestCeil(object): |
Jeffrey Yasskin | 9871d8f | 2008-01-05 08:47:13 +0000 | [diff] [blame] | 197 | def __float__(self): |
| 198 | return 41.3 |
Jeffrey Yasskin | 2f3c16b | 2008-01-03 02:21:52 +0000 | [diff] [blame] | 199 | class TestNoCeil(object): |
| 200 | pass |
| 201 | self.ftest('ceil(TestCeil())', math.ceil(TestCeil()), 42) |
| 202 | self.assertRaises(TypeError, math.ceil, TestNoCeil()) |
| 203 | |
| 204 | t = TestNoCeil() |
| 205 | t.__ceil__ = lambda *args: args |
| 206 | self.assertRaises(TypeError, math.ceil, t) |
| 207 | self.assertRaises(TypeError, math.ceil, t, 0) |
| 208 | |
Christian Heimes | 6f34109 | 2008-04-18 23:13:07 +0000 | [diff] [blame] | 209 | if float.__getformat__("double").startswith("IEEE"): |
| 210 | def testCopysign(self): |
| 211 | self.assertRaises(TypeError, math.copysign) |
| 212 | # copysign should let us distinguish signs of zeros |
| 213 | self.assertEquals(copysign(1., 0.), 1.) |
| 214 | self.assertEquals(copysign(1., -0.), -1.) |
| 215 | self.assertEquals(copysign(INF, 0.), INF) |
| 216 | self.assertEquals(copysign(INF, -0.), NINF) |
| 217 | self.assertEquals(copysign(NINF, 0.), INF) |
| 218 | self.assertEquals(copysign(NINF, -0.), NINF) |
| 219 | # and of infinities |
| 220 | self.assertEquals(copysign(1., INF), 1.) |
| 221 | self.assertEquals(copysign(1., NINF), -1.) |
| 222 | self.assertEquals(copysign(INF, INF), INF) |
| 223 | self.assertEquals(copysign(INF, NINF), NINF) |
| 224 | self.assertEquals(copysign(NINF, INF), INF) |
| 225 | self.assertEquals(copysign(NINF, NINF), NINF) |
| 226 | self.assert_(math.isnan(copysign(NAN, 1.))) |
| 227 | self.assert_(math.isnan(copysign(NAN, INF))) |
| 228 | self.assert_(math.isnan(copysign(NAN, NINF))) |
| 229 | self.assert_(math.isnan(copysign(NAN, NAN))) |
| 230 | # copysign(INF, NAN) may be INF or it may be NINF, since |
| 231 | # we don't know whether the sign bit of NAN is set on any |
| 232 | # given platform. |
| 233 | self.assert_(math.isinf(copysign(INF, NAN))) |
| 234 | # similarly, copysign(2., NAN) could be 2. or -2. |
| 235 | self.assertEquals(abs(copysign(2., NAN)), 2.) |
| 236 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 237 | def testCos(self): |
Walter Dörwald | 92911bf | 2006-10-29 22:06:28 +0000 | [diff] [blame] | 238 | self.assertRaises(TypeError, math.cos) |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 239 | self.ftest('cos(-pi/2)', math.cos(-math.pi/2), 0) |
| 240 | self.ftest('cos(0)', math.cos(0), 1) |
| 241 | self.ftest('cos(pi/2)', math.cos(math.pi/2), 0) |
| 242 | self.ftest('cos(pi)', math.cos(math.pi), -1) |
Christian Heimes | 6f34109 | 2008-04-18 23:13:07 +0000 | [diff] [blame] | 243 | try: |
| 244 | self.assert_(math.isnan(math.cos(INF))) |
| 245 | self.assert_(math.isnan(math.cos(NINF))) |
| 246 | except ValueError: |
| 247 | self.assertRaises(ValueError, math.cos, INF) |
| 248 | self.assertRaises(ValueError, math.cos, NINF) |
| 249 | self.assert_(math.isnan(math.cos(NAN))) |
Guido van Rossum | fcce630 | 1996-08-08 18:26:25 +0000 | [diff] [blame] | 250 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 251 | def testCosh(self): |
Walter Dörwald | 92911bf | 2006-10-29 22:06:28 +0000 | [diff] [blame] | 252 | self.assertRaises(TypeError, math.cosh) |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 253 | self.ftest('cosh(0)', math.cosh(0), 1) |
| 254 | self.ftest('cosh(2)-2*cosh(1)**2', math.cosh(2)-2*math.cosh(1)**2, -1) # Thanks to Lambert |
Christian Heimes | 6f34109 | 2008-04-18 23:13:07 +0000 | [diff] [blame] | 255 | self.assertEquals(math.cosh(INF), INF) |
| 256 | self.assertEquals(math.cosh(NINF), INF) |
| 257 | self.assert_(math.isnan(math.cosh(NAN))) |
Raymond Hettinger | 64108af | 2002-05-13 03:55:01 +0000 | [diff] [blame] | 258 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 259 | def testDegrees(self): |
Walter Dörwald | 92911bf | 2006-10-29 22:06:28 +0000 | [diff] [blame] | 260 | self.assertRaises(TypeError, math.degrees) |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 261 | self.ftest('degrees(pi)', math.degrees(math.pi), 180.0) |
| 262 | self.ftest('degrees(pi/2)', math.degrees(math.pi/2), 90.0) |
| 263 | self.ftest('degrees(-pi/4)', math.degrees(-math.pi/4), -45.0) |
Guido van Rossum | fcce630 | 1996-08-08 18:26:25 +0000 | [diff] [blame] | 264 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 265 | def testExp(self): |
Walter Dörwald | 92911bf | 2006-10-29 22:06:28 +0000 | [diff] [blame] | 266 | self.assertRaises(TypeError, math.exp) |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 267 | self.ftest('exp(-1)', math.exp(-1), 1/math.e) |
| 268 | self.ftest('exp(0)', math.exp(0), 1) |
| 269 | self.ftest('exp(1)', math.exp(1), math.e) |
Christian Heimes | 6f34109 | 2008-04-18 23:13:07 +0000 | [diff] [blame] | 270 | self.assertEquals(math.exp(INF), INF) |
| 271 | self.assertEquals(math.exp(NINF), 0.) |
| 272 | self.assert_(math.isnan(math.exp(NAN))) |
Guido van Rossum | fcce630 | 1996-08-08 18:26:25 +0000 | [diff] [blame] | 273 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 274 | def testFabs(self): |
Walter Dörwald | 92911bf | 2006-10-29 22:06:28 +0000 | [diff] [blame] | 275 | self.assertRaises(TypeError, math.fabs) |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 276 | self.ftest('fabs(-1)', math.fabs(-1), 1) |
| 277 | self.ftest('fabs(0)', math.fabs(0), 0) |
| 278 | self.ftest('fabs(1)', math.fabs(1), 1) |
Guido van Rossum | fcce630 | 1996-08-08 18:26:25 +0000 | [diff] [blame] | 279 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 280 | def testFloor(self): |
Walter Dörwald | 92911bf | 2006-10-29 22:06:28 +0000 | [diff] [blame] | 281 | self.assertRaises(TypeError, math.floor) |
Jeffrey Yasskin | 737c73f | 2008-01-04 08:01:23 +0000 | [diff] [blame] | 282 | # These types will be int in py3k. |
| 283 | self.assertEquals(float, type(math.floor(1))) |
| 284 | self.assertEquals(float, type(math.floor(1L))) |
| 285 | self.assertEquals(float, type(math.floor(1.0))) |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 286 | self.ftest('floor(0.5)', math.floor(0.5), 0) |
| 287 | self.ftest('floor(1.0)', math.floor(1.0), 1) |
| 288 | self.ftest('floor(1.5)', math.floor(1.5), 1) |
| 289 | self.ftest('floor(-0.5)', math.floor(-0.5), -1) |
| 290 | self.ftest('floor(-1.0)', math.floor(-1.0), -1) |
| 291 | self.ftest('floor(-1.5)', math.floor(-1.5), -2) |
Nick Coghlan | 00f2029 | 2007-07-26 14:03:00 +0000 | [diff] [blame] | 292 | # pow() relies on floor() to check for integers |
| 293 | # This fails on some platforms - so check it here |
| 294 | self.ftest('floor(1.23e167)', math.floor(1.23e167), 1.23e167) |
| 295 | self.ftest('floor(-1.23e167)', math.floor(-1.23e167), -1.23e167) |
Christian Heimes | 6f34109 | 2008-04-18 23:13:07 +0000 | [diff] [blame] | 296 | self.assertEquals(math.ceil(INF), INF) |
| 297 | self.assertEquals(math.ceil(NINF), NINF) |
| 298 | self.assert_(math.isnan(math.floor(NAN))) |
Guido van Rossum | fcce630 | 1996-08-08 18:26:25 +0000 | [diff] [blame] | 299 | |
Jeffrey Yasskin | 2f3c16b | 2008-01-03 02:21:52 +0000 | [diff] [blame] | 300 | class TestFloor(object): |
Jeffrey Yasskin | 9871d8f | 2008-01-05 08:47:13 +0000 | [diff] [blame] | 301 | def __float__(self): |
| 302 | return 42.3 |
Jeffrey Yasskin | 2f3c16b | 2008-01-03 02:21:52 +0000 | [diff] [blame] | 303 | class TestNoFloor(object): |
| 304 | pass |
| 305 | self.ftest('floor(TestFloor())', math.floor(TestFloor()), 42) |
| 306 | self.assertRaises(TypeError, math.floor, TestNoFloor()) |
| 307 | |
| 308 | t = TestNoFloor() |
| 309 | t.__floor__ = lambda *args: args |
| 310 | self.assertRaises(TypeError, math.floor, t) |
| 311 | self.assertRaises(TypeError, math.floor, t, 0) |
| 312 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 313 | def testFmod(self): |
Walter Dörwald | 92911bf | 2006-10-29 22:06:28 +0000 | [diff] [blame] | 314 | self.assertRaises(TypeError, math.fmod) |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 315 | self.ftest('fmod(10,1)', math.fmod(10,1), 0) |
| 316 | self.ftest('fmod(10,0.5)', math.fmod(10,0.5), 0) |
| 317 | self.ftest('fmod(10,1.5)', math.fmod(10,1.5), 1) |
| 318 | self.ftest('fmod(-10,1)', math.fmod(-10,1), 0) |
| 319 | self.ftest('fmod(-10,0.5)', math.fmod(-10,0.5), 0) |
| 320 | self.ftest('fmod(-10,1.5)', math.fmod(-10,1.5), -1) |
Christian Heimes | 6f34109 | 2008-04-18 23:13:07 +0000 | [diff] [blame] | 321 | self.assert_(math.isnan(math.fmod(NAN, 1.))) |
| 322 | self.assert_(math.isnan(math.fmod(1., NAN))) |
| 323 | self.assert_(math.isnan(math.fmod(NAN, NAN))) |
| 324 | self.assertRaises(ValueError, math.fmod, 1., 0.) |
| 325 | self.assertRaises(ValueError, math.fmod, INF, 1.) |
| 326 | self.assertRaises(ValueError, math.fmod, NINF, 1.) |
| 327 | self.assertRaises(ValueError, math.fmod, INF, 0.) |
| 328 | self.assertEquals(math.fmod(3.0, INF), 3.0) |
| 329 | self.assertEquals(math.fmod(-3.0, INF), -3.0) |
| 330 | self.assertEquals(math.fmod(3.0, NINF), 3.0) |
| 331 | self.assertEquals(math.fmod(-3.0, NINF), -3.0) |
| 332 | self.assertEquals(math.fmod(0.0, 3.0), 0.0) |
| 333 | self.assertEquals(math.fmod(0.0, NINF), 0.0) |
Guido van Rossum | fcce630 | 1996-08-08 18:26:25 +0000 | [diff] [blame] | 334 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 335 | def testFrexp(self): |
Walter Dörwald | 92911bf | 2006-10-29 22:06:28 +0000 | [diff] [blame] | 336 | self.assertRaises(TypeError, math.frexp) |
| 337 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 338 | def testfrexp(name, (mant, exp), (emant, eexp)): |
| 339 | if abs(mant-emant) > eps or exp != eexp: |
| 340 | self.fail('%s returned %r, expected %r'%\ |
| 341 | (name, (mant, exp), (emant,eexp))) |
Guido van Rossum | fcce630 | 1996-08-08 18:26:25 +0000 | [diff] [blame] | 342 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 343 | testfrexp('frexp(-1)', math.frexp(-1), (-0.5, 1)) |
| 344 | testfrexp('frexp(0)', math.frexp(0), (0, 0)) |
| 345 | testfrexp('frexp(1)', math.frexp(1), (0.5, 1)) |
| 346 | testfrexp('frexp(2)', math.frexp(2), (0.5, 2)) |
Guido van Rossum | fcce630 | 1996-08-08 18:26:25 +0000 | [diff] [blame] | 347 | |
Christian Heimes | 6f34109 | 2008-04-18 23:13:07 +0000 | [diff] [blame] | 348 | self.assertEquals(math.frexp(INF)[0], INF) |
| 349 | self.assertEquals(math.frexp(NINF)[0], NINF) |
| 350 | self.assert_(math.isnan(math.frexp(NAN)[0])) |
| 351 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 352 | def testHypot(self): |
Walter Dörwald | 92911bf | 2006-10-29 22:06:28 +0000 | [diff] [blame] | 353 | self.assertRaises(TypeError, math.hypot) |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 354 | self.ftest('hypot(0,0)', math.hypot(0,0), 0) |
| 355 | self.ftest('hypot(3,4)', math.hypot(3,4), 5) |
Christian Heimes | 6f34109 | 2008-04-18 23:13:07 +0000 | [diff] [blame] | 356 | self.assertEqual(math.hypot(NAN, INF), INF) |
| 357 | self.assertEqual(math.hypot(INF, NAN), INF) |
| 358 | self.assertEqual(math.hypot(NAN, NINF), INF) |
| 359 | self.assertEqual(math.hypot(NINF, NAN), INF) |
| 360 | self.assert_(math.isnan(math.hypot(1.0, NAN))) |
| 361 | self.assert_(math.isnan(math.hypot(NAN, -2.0))) |
Guido van Rossum | fcce630 | 1996-08-08 18:26:25 +0000 | [diff] [blame] | 362 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 363 | def testLdexp(self): |
Walter Dörwald | 92911bf | 2006-10-29 22:06:28 +0000 | [diff] [blame] | 364 | self.assertRaises(TypeError, math.ldexp) |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 365 | self.ftest('ldexp(0,1)', math.ldexp(0,1), 0) |
| 366 | self.ftest('ldexp(1,1)', math.ldexp(1,1), 2) |
| 367 | self.ftest('ldexp(1,-1)', math.ldexp(1,-1), 0.5) |
| 368 | self.ftest('ldexp(-1,1)', math.ldexp(-1,1), -2) |
Christian Heimes | 6f34109 | 2008-04-18 23:13:07 +0000 | [diff] [blame] | 369 | self.assertRaises(OverflowError, math.ldexp, 1., 1000000) |
| 370 | self.assertRaises(OverflowError, math.ldexp, -1., 1000000) |
| 371 | self.assertEquals(math.ldexp(1., -1000000), 0.) |
| 372 | self.assertEquals(math.ldexp(-1., -1000000), -0.) |
| 373 | self.assertEquals(math.ldexp(INF, 30), INF) |
| 374 | self.assertEquals(math.ldexp(NINF, -213), NINF) |
| 375 | self.assert_(math.isnan(math.ldexp(NAN, 0))) |
Guido van Rossum | fcce630 | 1996-08-08 18:26:25 +0000 | [diff] [blame] | 376 | |
Mark Dickinson | f8476c1 | 2008-05-09 17:54:23 +0000 | [diff] [blame] | 377 | # large second argument |
| 378 | for n in [10**5, 10L**5, 10**10, 10L**10, 10**20, 10**40]: |
| 379 | self.assertEquals(math.ldexp(INF, -n), INF) |
| 380 | self.assertEquals(math.ldexp(NINF, -n), NINF) |
| 381 | self.assertEquals(math.ldexp(1., -n), 0.) |
| 382 | self.assertEquals(math.ldexp(-1., -n), -0.) |
| 383 | self.assertEquals(math.ldexp(0., -n), 0.) |
| 384 | self.assertEquals(math.ldexp(-0., -n), -0.) |
| 385 | self.assert_(math.isnan(math.ldexp(NAN, -n))) |
| 386 | |
| 387 | self.assertRaises(OverflowError, math.ldexp, 1., n) |
| 388 | self.assertRaises(OverflowError, math.ldexp, -1., n) |
| 389 | self.assertEquals(math.ldexp(0., n), 0.) |
| 390 | self.assertEquals(math.ldexp(-0., n), -0.) |
| 391 | self.assertEquals(math.ldexp(INF, n), INF) |
| 392 | self.assertEquals(math.ldexp(NINF, n), NINF) |
| 393 | self.assert_(math.isnan(math.ldexp(NAN, n))) |
| 394 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 395 | def testLog(self): |
Walter Dörwald | 92911bf | 2006-10-29 22:06:28 +0000 | [diff] [blame] | 396 | self.assertRaises(TypeError, math.log) |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 397 | self.ftest('log(1/e)', math.log(1/math.e), -1) |
| 398 | self.ftest('log(1)', math.log(1), 0) |
| 399 | self.ftest('log(e)', math.log(math.e), 1) |
| 400 | self.ftest('log(32,2)', math.log(32,2), 5) |
| 401 | self.ftest('log(10**40, 10)', math.log(10**40, 10), 40) |
| 402 | self.ftest('log(10**40, 10**20)', math.log(10**40, 10**20), 2) |
Christian Heimes | 6f34109 | 2008-04-18 23:13:07 +0000 | [diff] [blame] | 403 | self.assertEquals(math.log(INF), INF) |
| 404 | self.assertRaises(ValueError, math.log, NINF) |
| 405 | self.assert_(math.isnan(math.log(NAN))) |
| 406 | |
| 407 | def testLog1p(self): |
| 408 | self.assertRaises(TypeError, math.log1p) |
| 409 | self.ftest('log1p(1/e -1)', math.log1p(1/math.e-1), -1) |
| 410 | self.ftest('log1p(0)', math.log1p(0), 0) |
| 411 | self.ftest('log1p(e-1)', math.log1p(math.e-1), 1) |
| 412 | self.ftest('log1p(1)', math.log1p(1), math.log(2)) |
| 413 | self.assertEquals(math.log1p(INF), INF) |
| 414 | self.assertRaises(ValueError, math.log1p, NINF) |
| 415 | self.assert_(math.isnan(math.log1p(NAN))) |
| 416 | n= 2**90 |
| 417 | self.assertAlmostEquals(math.log1p(n), 62.383246250395075) |
| 418 | self.assertAlmostEquals(math.log1p(n), math.log1p(float(n))) |
Guido van Rossum | fcce630 | 1996-08-08 18:26:25 +0000 | [diff] [blame] | 419 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 420 | def testLog10(self): |
Walter Dörwald | 92911bf | 2006-10-29 22:06:28 +0000 | [diff] [blame] | 421 | self.assertRaises(TypeError, math.log10) |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 422 | self.ftest('log10(0.1)', math.log10(0.1), -1) |
| 423 | self.ftest('log10(1)', math.log10(1), 0) |
| 424 | self.ftest('log10(10)', math.log10(10), 1) |
Christian Heimes | 6f34109 | 2008-04-18 23:13:07 +0000 | [diff] [blame] | 425 | self.assertEquals(math.log(INF), INF) |
| 426 | self.assertRaises(ValueError, math.log10, NINF) |
| 427 | self.assert_(math.isnan(math.log10(NAN))) |
Guido van Rossum | fcce630 | 1996-08-08 18:26:25 +0000 | [diff] [blame] | 428 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 429 | def testModf(self): |
Walter Dörwald | 92911bf | 2006-10-29 22:06:28 +0000 | [diff] [blame] | 430 | self.assertRaises(TypeError, math.modf) |
| 431 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 432 | def testmodf(name, (v1, v2), (e1, e2)): |
| 433 | if abs(v1-e1) > eps or abs(v2-e2): |
| 434 | self.fail('%s returned %r, expected %r'%\ |
| 435 | (name, (v1,v2), (e1,e2))) |
Guido van Rossum | fcce630 | 1996-08-08 18:26:25 +0000 | [diff] [blame] | 436 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 437 | testmodf('modf(1.5)', math.modf(1.5), (0.5, 1.0)) |
| 438 | testmodf('modf(-1.5)', math.modf(-1.5), (-0.5, -1.0)) |
Tim Peters | abd8a33 | 2006-11-03 02:32:46 +0000 | [diff] [blame] | 439 | |
Christian Heimes | 6f34109 | 2008-04-18 23:13:07 +0000 | [diff] [blame] | 440 | self.assertEquals(math.modf(INF), (0.0, INF)) |
| 441 | self.assertEquals(math.modf(NINF), (-0.0, NINF)) |
| 442 | |
| 443 | modf_nan = math.modf(NAN) |
| 444 | self.assert_(math.isnan(modf_nan[0])) |
| 445 | self.assert_(math.isnan(modf_nan[1])) |
| 446 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 447 | def testPow(self): |
Walter Dörwald | 92911bf | 2006-10-29 22:06:28 +0000 | [diff] [blame] | 448 | self.assertRaises(TypeError, math.pow) |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 449 | self.ftest('pow(0,1)', math.pow(0,1), 0) |
| 450 | self.ftest('pow(1,0)', math.pow(1,0), 1) |
| 451 | self.ftest('pow(2,1)', math.pow(2,1), 2) |
| 452 | self.ftest('pow(2,-1)', math.pow(2,-1), 0.5) |
Christian Heimes | 6f34109 | 2008-04-18 23:13:07 +0000 | [diff] [blame] | 453 | self.assertEqual(math.pow(INF, 1), INF) |
| 454 | self.assertEqual(math.pow(NINF, 1), NINF) |
| 455 | self.assertEqual((math.pow(1, INF)), 1.) |
| 456 | self.assertEqual((math.pow(1, NINF)), 1.) |
| 457 | self.assert_(math.isnan(math.pow(NAN, 1))) |
| 458 | self.assert_(math.isnan(math.pow(2, NAN))) |
| 459 | self.assert_(math.isnan(math.pow(0, NAN))) |
| 460 | self.assertEqual(math.pow(1, NAN), 1) |
Mark Dickinson | e941d97 | 2008-04-19 18:51:48 +0000 | [diff] [blame] | 461 | |
| 462 | # pow(0., x) |
| 463 | self.assertEqual(math.pow(0., INF), 0.) |
| 464 | self.assertEqual(math.pow(0., 3.), 0.) |
| 465 | self.assertEqual(math.pow(0., 2.3), 0.) |
| 466 | self.assertEqual(math.pow(0., 2.), 0.) |
| 467 | self.assertEqual(math.pow(0., 0.), 1.) |
| 468 | self.assertEqual(math.pow(0., -0.), 1.) |
| 469 | self.assertRaises(ValueError, math.pow, 0., -2.) |
| 470 | self.assertRaises(ValueError, math.pow, 0., -2.3) |
| 471 | self.assertRaises(ValueError, math.pow, 0., -3.) |
| 472 | self.assertRaises(ValueError, math.pow, 0., NINF) |
| 473 | self.assert_(math.isnan(math.pow(0., NAN))) |
| 474 | |
| 475 | # pow(INF, x) |
| 476 | self.assertEqual(math.pow(INF, INF), INF) |
| 477 | self.assertEqual(math.pow(INF, 3.), INF) |
| 478 | self.assertEqual(math.pow(INF, 2.3), INF) |
| 479 | self.assertEqual(math.pow(INF, 2.), INF) |
| 480 | self.assertEqual(math.pow(INF, 0.), 1.) |
| 481 | self.assertEqual(math.pow(INF, -0.), 1.) |
| 482 | self.assertEqual(math.pow(INF, -2.), 0.) |
| 483 | self.assertEqual(math.pow(INF, -2.3), 0.) |
| 484 | self.assertEqual(math.pow(INF, -3.), 0.) |
| 485 | self.assertEqual(math.pow(INF, NINF), 0.) |
| 486 | self.assert_(math.isnan(math.pow(INF, NAN))) |
| 487 | |
| 488 | # pow(-0., x) |
| 489 | self.assertEqual(math.pow(-0., INF), 0.) |
| 490 | self.assertEqual(math.pow(-0., 3.), -0.) |
| 491 | self.assertEqual(math.pow(-0., 2.3), 0.) |
| 492 | self.assertEqual(math.pow(-0., 2.), 0.) |
| 493 | self.assertEqual(math.pow(-0., 0.), 1.) |
| 494 | self.assertEqual(math.pow(-0., -0.), 1.) |
| 495 | self.assertRaises(ValueError, math.pow, -0., -2.) |
| 496 | self.assertRaises(ValueError, math.pow, -0., -2.3) |
| 497 | self.assertRaises(ValueError, math.pow, -0., -3.) |
| 498 | self.assertRaises(ValueError, math.pow, -0., NINF) |
| 499 | self.assert_(math.isnan(math.pow(-0., NAN))) |
| 500 | |
| 501 | # pow(NINF, x) |
| 502 | self.assertEqual(math.pow(NINF, INF), INF) |
| 503 | self.assertEqual(math.pow(NINF, 3.), NINF) |
| 504 | self.assertEqual(math.pow(NINF, 2.3), INF) |
| 505 | self.assertEqual(math.pow(NINF, 2.), INF) |
| 506 | self.assertEqual(math.pow(NINF, 0.), 1.) |
| 507 | self.assertEqual(math.pow(NINF, -0.), 1.) |
| 508 | self.assertEqual(math.pow(NINF, -2.), 0.) |
| 509 | self.assertEqual(math.pow(NINF, -2.3), 0.) |
| 510 | self.assertEqual(math.pow(NINF, -3.), -0.) |
| 511 | self.assertEqual(math.pow(NINF, NINF), 0.) |
| 512 | self.assert_(math.isnan(math.pow(NINF, NAN))) |
| 513 | |
| 514 | # pow(-1, x) |
| 515 | self.assertEqual(math.pow(-1., INF), 1.) |
| 516 | self.assertEqual(math.pow(-1., 3.), -1.) |
| 517 | self.assertRaises(ValueError, math.pow, -1., 2.3) |
| 518 | self.assertEqual(math.pow(-1., 2.), 1.) |
| 519 | self.assertEqual(math.pow(-1., 0.), 1.) |
| 520 | self.assertEqual(math.pow(-1., -0.), 1.) |
| 521 | self.assertEqual(math.pow(-1., -2.), 1.) |
| 522 | self.assertRaises(ValueError, math.pow, -1., -2.3) |
| 523 | self.assertEqual(math.pow(-1., -3.), -1.) |
| 524 | self.assertEqual(math.pow(-1., NINF), 1.) |
| 525 | self.assert_(math.isnan(math.pow(-1., NAN))) |
| 526 | |
| 527 | # pow(1, x) |
| 528 | self.assertEqual(math.pow(1., INF), 1.) |
| 529 | self.assertEqual(math.pow(1., 3.), 1.) |
| 530 | self.assertEqual(math.pow(1., 2.3), 1.) |
| 531 | self.assertEqual(math.pow(1., 2.), 1.) |
| 532 | self.assertEqual(math.pow(1., 0.), 1.) |
| 533 | self.assertEqual(math.pow(1., -0.), 1.) |
| 534 | self.assertEqual(math.pow(1., -2.), 1.) |
| 535 | self.assertEqual(math.pow(1., -2.3), 1.) |
| 536 | self.assertEqual(math.pow(1., -3.), 1.) |
| 537 | self.assertEqual(math.pow(1., NINF), 1.) |
| 538 | self.assertEqual(math.pow(1., NAN), 1.) |
| 539 | |
| 540 | # pow(x, 0) should be 1 for any x |
| 541 | self.assertEqual(math.pow(2.3, 0.), 1.) |
| 542 | self.assertEqual(math.pow(-2.3, 0.), 1.) |
| 543 | self.assertEqual(math.pow(NAN, 0.), 1.) |
| 544 | self.assertEqual(math.pow(2.3, -0.), 1.) |
| 545 | self.assertEqual(math.pow(-2.3, -0.), 1.) |
| 546 | self.assertEqual(math.pow(NAN, -0.), 1.) |
| 547 | |
| 548 | # pow(x, y) is invalid if x is negative and y is not integral |
| 549 | self.assertRaises(ValueError, math.pow, -1., 2.3) |
| 550 | self.assertRaises(ValueError, math.pow, -15., -3.1) |
| 551 | |
| 552 | # pow(x, NINF) |
| 553 | self.assertEqual(math.pow(1.9, NINF), 0.) |
| 554 | self.assertEqual(math.pow(1.1, NINF), 0.) |
| 555 | self.assertEqual(math.pow(0.9, NINF), INF) |
| 556 | self.assertEqual(math.pow(0.1, NINF), INF) |
| 557 | self.assertEqual(math.pow(-0.1, NINF), INF) |
| 558 | self.assertEqual(math.pow(-0.9, NINF), INF) |
| 559 | self.assertEqual(math.pow(-1.1, NINF), 0.) |
| 560 | self.assertEqual(math.pow(-1.9, NINF), 0.) |
| 561 | |
| 562 | # pow(x, INF) |
| 563 | self.assertEqual(math.pow(1.9, INF), INF) |
| 564 | self.assertEqual(math.pow(1.1, INF), INF) |
| 565 | self.assertEqual(math.pow(0.9, INF), 0.) |
| 566 | self.assertEqual(math.pow(0.1, INF), 0.) |
| 567 | self.assertEqual(math.pow(-0.1, INF), 0.) |
| 568 | self.assertEqual(math.pow(-0.9, INF), 0.) |
| 569 | self.assertEqual(math.pow(-1.1, INF), INF) |
| 570 | self.assertEqual(math.pow(-1.9, INF), INF) |
| 571 | |
Mark Dickinson | cec3f13 | 2008-04-20 04:13:13 +0000 | [diff] [blame] | 572 | # pow(x, y) should work for x negative, y an integer |
| 573 | self.ftest('(-2.)**3.', math.pow(-2.0, 3.0), -8.0) |
| 574 | self.ftest('(-2.)**2.', math.pow(-2.0, 2.0), 4.0) |
| 575 | self.ftest('(-2.)**1.', math.pow(-2.0, 1.0), -2.0) |
| 576 | self.ftest('(-2.)**0.', math.pow(-2.0, 0.0), 1.0) |
| 577 | self.ftest('(-2.)**-0.', math.pow(-2.0, -0.0), 1.0) |
| 578 | self.ftest('(-2.)**-1.', math.pow(-2.0, -1.0), -0.5) |
| 579 | self.ftest('(-2.)**-2.', math.pow(-2.0, -2.0), 0.25) |
| 580 | self.ftest('(-2.)**-3.', math.pow(-2.0, -3.0), -0.125) |
| 581 | self.assertRaises(ValueError, math.pow, -2.0, -0.5) |
| 582 | self.assertRaises(ValueError, math.pow, -2.0, 0.5) |
| 583 | |
Mark Dickinson | e941d97 | 2008-04-19 18:51:48 +0000 | [diff] [blame] | 584 | # the following tests have been commented out since they don't |
| 585 | # really belong here: the implementation of ** for floats is |
| 586 | # independent of the implemention of math.pow |
| 587 | #self.assertEqual(1**NAN, 1) |
| 588 | #self.assertEqual(1**INF, 1) |
| 589 | #self.assertEqual(1**NINF, 1) |
| 590 | #self.assertEqual(1**0, 1) |
| 591 | #self.assertEqual(1.**NAN, 1) |
| 592 | #self.assertEqual(1.**INF, 1) |
| 593 | #self.assertEqual(1.**NINF, 1) |
| 594 | #self.assertEqual(1.**0, 1) |
Guido van Rossum | fcce630 | 1996-08-08 18:26:25 +0000 | [diff] [blame] | 595 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 596 | def testRadians(self): |
Walter Dörwald | 92911bf | 2006-10-29 22:06:28 +0000 | [diff] [blame] | 597 | self.assertRaises(TypeError, math.radians) |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 598 | self.ftest('radians(180)', math.radians(180), math.pi) |
| 599 | self.ftest('radians(90)', math.radians(90), math.pi/2) |
| 600 | self.ftest('radians(-45)', math.radians(-45), -math.pi/4) |
Raymond Hettinger | 64108af | 2002-05-13 03:55:01 +0000 | [diff] [blame] | 601 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 602 | def testSin(self): |
Walter Dörwald | 92911bf | 2006-10-29 22:06:28 +0000 | [diff] [blame] | 603 | self.assertRaises(TypeError, math.sin) |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 604 | self.ftest('sin(0)', math.sin(0), 0) |
| 605 | self.ftest('sin(pi/2)', math.sin(math.pi/2), 1) |
| 606 | self.ftest('sin(-pi/2)', math.sin(-math.pi/2), -1) |
Christian Heimes | 6f34109 | 2008-04-18 23:13:07 +0000 | [diff] [blame] | 607 | try: |
| 608 | self.assert_(math.isnan(math.sin(INF))) |
| 609 | self.assert_(math.isnan(math.sin(NINF))) |
| 610 | except ValueError: |
| 611 | self.assertRaises(ValueError, math.sin, INF) |
| 612 | self.assertRaises(ValueError, math.sin, NINF) |
| 613 | self.assert_(math.isnan(math.sin(NAN))) |
Guido van Rossum | fcce630 | 1996-08-08 18:26:25 +0000 | [diff] [blame] | 614 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 615 | def testSinh(self): |
Walter Dörwald | 92911bf | 2006-10-29 22:06:28 +0000 | [diff] [blame] | 616 | self.assertRaises(TypeError, math.sinh) |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 617 | self.ftest('sinh(0)', math.sinh(0), 0) |
| 618 | self.ftest('sinh(1)**2-cosh(1)**2', math.sinh(1)**2-math.cosh(1)**2, -1) |
| 619 | self.ftest('sinh(1)+sinh(-1)', math.sinh(1)+math.sinh(-1), 0) |
Christian Heimes | 6f34109 | 2008-04-18 23:13:07 +0000 | [diff] [blame] | 620 | self.assertEquals(math.sinh(INF), INF) |
Mark Dickinson | e941d97 | 2008-04-19 18:51:48 +0000 | [diff] [blame] | 621 | self.assertEquals(math.sinh(NINF), NINF) |
Christian Heimes | 6f34109 | 2008-04-18 23:13:07 +0000 | [diff] [blame] | 622 | self.assert_(math.isnan(math.sinh(NAN))) |
Guido van Rossum | fcce630 | 1996-08-08 18:26:25 +0000 | [diff] [blame] | 623 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 624 | def testSqrt(self): |
Walter Dörwald | 92911bf | 2006-10-29 22:06:28 +0000 | [diff] [blame] | 625 | self.assertRaises(TypeError, math.sqrt) |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 626 | self.ftest('sqrt(0)', math.sqrt(0), 0) |
| 627 | self.ftest('sqrt(1)', math.sqrt(1), 1) |
| 628 | self.ftest('sqrt(4)', math.sqrt(4), 2) |
Christian Heimes | 6f34109 | 2008-04-18 23:13:07 +0000 | [diff] [blame] | 629 | self.assertEquals(math.sqrt(INF), INF) |
| 630 | self.assertRaises(ValueError, math.sqrt, NINF) |
| 631 | self.assert_(math.isnan(math.sqrt(NAN))) |
Guido van Rossum | fcce630 | 1996-08-08 18:26:25 +0000 | [diff] [blame] | 632 | |
Mark Dickinson | c11c339 | 2008-05-23 02:36:48 +0000 | [diff] [blame] | 633 | def testSum(self): |
| 634 | # Python version of math.sum algorithm, for comparison |
| 635 | def msum(iterable): |
| 636 | """Full precision sum of values in iterable. Returns the value of |
| 637 | the sum, rounded to the nearest representable floating-point number |
| 638 | using the round-half-to-even rule. |
| 639 | |
| 640 | """ |
| 641 | # Stage 1: accumulate partials |
| 642 | partials = [] |
| 643 | for x in iterable: |
| 644 | i = 0 |
| 645 | for y in partials: |
| 646 | if abs(x) < abs(y): |
| 647 | x, y = y, x |
| 648 | hi = x + y |
| 649 | lo = y - (hi - x) |
| 650 | if lo: |
| 651 | partials[i] = lo |
| 652 | i += 1 |
| 653 | x = hi |
| 654 | partials[i:] = [x] if x else [] |
| 655 | |
| 656 | # Stage 2: sum partials |
| 657 | if not partials: |
| 658 | return 0.0 |
| 659 | |
| 660 | # sum from the top, stopping as soon as the sum is inexact. |
| 661 | total = partials.pop() |
| 662 | while partials: |
| 663 | x = partials.pop() |
| 664 | old_total, total = total, total + x |
| 665 | error = x - (total - old_total) |
| 666 | if error != 0.0: |
| 667 | # adjust for correct rounding if necessary |
| 668 | if partials and (partials[-1] > 0.0) == (error > 0.0) and \ |
| 669 | total + 2*error - total == 2*error: |
| 670 | total += 2*error |
| 671 | break |
| 672 | return total |
| 673 | |
| 674 | from sys import float_info |
| 675 | maxfloat = float_info.max |
| 676 | twopow = 2.**(float_info.max_exp - 1) |
| 677 | |
| 678 | test_values = [ |
| 679 | ([], 0.0), |
| 680 | ([0.0], 0.0), |
| 681 | ([1e100, 1.0, -1e100, 1e-100, 1e50, -1.0, -1e50], 1e-100), |
| 682 | ([1e308, 1e308, -1e308], OverflowError), |
| 683 | ([-1e308, 1e308, 1e308], 1e308), |
| 684 | ([1e308, -1e308, 1e308], 1e308), |
| 685 | ([2.0**1023, 2.0**1023, -2.0**1000], OverflowError), |
| 686 | ([twopow, twopow, twopow, twopow, -twopow, -twopow, -twopow], |
| 687 | OverflowError), |
| 688 | ([2.0**53, -0.5, -2.0**-54], 2.0**53-1.0), |
| 689 | ([2.0**53, 1.0, 2.0**-100], 2.0**53+2.0), |
| 690 | ([2.0**53+10.0, 1.0, 2.0**-100], 2.0**53+12.0), |
| 691 | |
| 692 | ([2.0**53-4.0, 0.5, 2.0**-54], 2.0**53-3.0), |
| 693 | ([2.0**1023-2.0**970, -1.0, 2.0**1023], OverflowError), |
| 694 | ([maxfloat, maxfloat*2.**-54], maxfloat), |
| 695 | ([maxfloat, maxfloat*2.**-53], OverflowError), |
| 696 | ([1./n for n in range(1, 1001)], 7.4854708605503451), |
| 697 | ([(-1.)**n/n for n in range(1, 1001)], -0.69264743055982025), |
| 698 | ([1.7**(i+1)-1.7**i for i in range(1000)] + [-1.7**1000], -1.0), |
| 699 | ([INF, -INF, NAN], ValueError), |
| 700 | ([NAN, INF, -INF], ValueError), |
| 701 | ([INF, NAN, INF], ValueError), |
| 702 | |
| 703 | ([INF, INF], OverflowError), |
| 704 | ([INF, -INF], ValueError), |
| 705 | ([-INF, 1e308, 1e308, -INF], OverflowError), |
| 706 | ([2.0**1023-2.0**970, 0.0, 2.0**1023], OverflowError), |
| 707 | ([2.0**1023-2.0**970, 1.0, 2.0**1023], OverflowError), |
| 708 | ([2.0**1023, 2.0**1023], OverflowError), |
| 709 | ([2.0**1023, 2.0**1023, -1.0], OverflowError), |
| 710 | ([twopow, twopow, twopow, twopow, -twopow, -twopow], |
| 711 | OverflowError), |
| 712 | ([twopow, twopow, twopow, twopow, -twopow, twopow], OverflowError), |
| 713 | ([-twopow, -twopow, -twopow, -twopow], OverflowError), |
| 714 | |
| 715 | ([2.**1023, 2.**1023, -2.**971], OverflowError), |
| 716 | ([2.**1023, 2.**1023, -2.**970], OverflowError), |
| 717 | ([-2.**970, 2.**1023, 2.**1023, -2.**-1074], OverflowError), |
| 718 | ([ 2.**1023, 2.**1023, -2.**970, 2.**-1074], OverflowError), |
| 719 | ([-2.**1023, 2.**971, -2.**1023], -maxfloat), |
| 720 | ([-2.**1023, -2.**1023, 2.**970], OverflowError), |
| 721 | ([-2.**1023, -2.**1023, 2.**970, 2.**-1074], OverflowError), |
| 722 | ([-2.**-1074, -2.**1023, -2.**1023, 2.**970], OverflowError), |
| 723 | ([2.**930, -2.**980, 2.**1023, 2.**1023, twopow, -twopow], |
| 724 | OverflowError), |
| 725 | ([2.**1023, 2.**1023, -1e307], OverflowError), |
| 726 | ([1e16, 1., 1e-16], 10000000000000002.0), |
| 727 | ([1e16-2., 1.-2.**53, -(1e16-2.), -(1.-2.**53)], 0.0), |
| 728 | ] |
| 729 | |
| 730 | for i, (vals, s) in enumerate(test_values): |
| 731 | if isinstance(s, type) and issubclass(s, Exception): |
| 732 | try: |
| 733 | m = math.sum(vals) |
| 734 | except s: |
| 735 | pass |
| 736 | else: |
| 737 | self.fail("test %d failed: got %r, expected %r " |
| 738 | "for math.sum(%.100r)" % |
| 739 | (i, m, s.__name__, vals)) |
| 740 | else: |
| 741 | try: |
| 742 | self.assertEqual(math.sum(vals), s) |
| 743 | except OverflowError: |
| 744 | self.fail("test %d failed: got OverflowError, expected %r " |
| 745 | "for math.sum(%.100r)" % (i, s, vals)) |
| 746 | except ValueError: |
| 747 | self.fail("test %d failed: got ValueError, expected %r " |
| 748 | "for math.sum(%.100r)" % (i, s, vals)) |
| 749 | |
| 750 | # compare with output of msum above, but only when |
| 751 | # result isn't an IEEE special or an exception |
| 752 | if not math.isinf(s) and not math.isnan(s): |
| 753 | self.assertEqual(msum(vals), s) |
| 754 | |
| 755 | from random import random, gauss, shuffle |
| 756 | for j in xrange(1000): |
| 757 | vals = [7, 1e100, -7, -1e100, -9e-20, 8e-20] * 10 |
| 758 | s = 0 |
| 759 | for i in xrange(200): |
| 760 | v = gauss(0, random()) ** 7 - s |
| 761 | s += v |
| 762 | vals.append(v) |
| 763 | shuffle(vals) |
| 764 | |
| 765 | s = msum(vals) |
| 766 | self.assertEqual(msum(vals), math.sum(vals)) |
| 767 | |
| 768 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 769 | def testTan(self): |
Walter Dörwald | 92911bf | 2006-10-29 22:06:28 +0000 | [diff] [blame] | 770 | self.assertRaises(TypeError, math.tan) |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 771 | self.ftest('tan(0)', math.tan(0), 0) |
| 772 | self.ftest('tan(pi/4)', math.tan(math.pi/4), 1) |
| 773 | self.ftest('tan(-pi/4)', math.tan(-math.pi/4), -1) |
Christian Heimes | 6f34109 | 2008-04-18 23:13:07 +0000 | [diff] [blame] | 774 | try: |
| 775 | self.assert_(math.isnan(math.tan(INF))) |
| 776 | self.assert_(math.isnan(math.tan(NINF))) |
| 777 | except: |
| 778 | self.assertRaises(ValueError, math.tan, INF) |
| 779 | self.assertRaises(ValueError, math.tan, NINF) |
| 780 | self.assert_(math.isnan(math.tan(NAN))) |
Guido van Rossum | fcce630 | 1996-08-08 18:26:25 +0000 | [diff] [blame] | 781 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 782 | def testTanh(self): |
Walter Dörwald | 92911bf | 2006-10-29 22:06:28 +0000 | [diff] [blame] | 783 | self.assertRaises(TypeError, math.tanh) |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 784 | self.ftest('tanh(0)', math.tanh(0), 0) |
| 785 | self.ftest('tanh(1)+tanh(-1)', math.tanh(1)+math.tanh(-1), 0) |
Christian Heimes | 6f34109 | 2008-04-18 23:13:07 +0000 | [diff] [blame] | 786 | self.ftest('tanh(inf)', math.tanh(INF), 1) |
| 787 | self.ftest('tanh(-inf)', math.tanh(NINF), -1) |
| 788 | self.assert_(math.isnan(math.tanh(NAN))) |
Mark Dickinson | d6d5148 | 2008-04-20 20:38:48 +0000 | [diff] [blame] | 789 | # check that tanh(-0.) == -0. on IEEE 754 systems |
| 790 | if float.__getformat__("double").startswith("IEEE"): |
| 791 | self.assertEqual(math.tanh(-0.), -0.) |
| 792 | self.assertEqual(math.copysign(1., math.tanh(-0.)), |
| 793 | math.copysign(1., -0.)) |
Tim Peters | 1d12061 | 2000-10-12 06:10:25 +0000 | [diff] [blame] | 794 | |
Jeffrey Yasskin | ca2b69f | 2008-02-01 06:22:46 +0000 | [diff] [blame] | 795 | def test_trunc(self): |
| 796 | self.assertEqual(math.trunc(1), 1) |
| 797 | self.assertEqual(math.trunc(-1), -1) |
| 798 | self.assertEqual(type(math.trunc(1)), int) |
| 799 | self.assertEqual(type(math.trunc(1.5)), int) |
| 800 | self.assertEqual(math.trunc(1.5), 1) |
| 801 | self.assertEqual(math.trunc(-1.5), -1) |
| 802 | self.assertEqual(math.trunc(1.999999), 1) |
| 803 | self.assertEqual(math.trunc(-1.999999), -1) |
| 804 | self.assertEqual(math.trunc(-0.999999), -0) |
| 805 | self.assertEqual(math.trunc(-100.999), -100) |
| 806 | |
| 807 | class TestTrunc(object): |
| 808 | def __trunc__(self): |
| 809 | return 23 |
| 810 | |
| 811 | class TestNoTrunc(object): |
| 812 | pass |
| 813 | |
| 814 | self.assertEqual(math.trunc(TestTrunc()), 23) |
| 815 | |
| 816 | self.assertRaises(TypeError, math.trunc) |
| 817 | self.assertRaises(TypeError, math.trunc, 1, 2) |
| 818 | # XXX: This is not ideal, but see the comment in math_trunc(). |
| 819 | self.assertRaises(AttributeError, math.trunc, TestNoTrunc()) |
| 820 | |
| 821 | t = TestNoTrunc() |
| 822 | t.__trunc__ = lambda *args: args |
| 823 | self.assertEquals((), math.trunc(t)) |
| 824 | self.assertRaises(TypeError, math.trunc, t, 0) |
| 825 | |
Christian Heimes | eebb79c | 2008-01-03 22:32:26 +0000 | [diff] [blame] | 826 | def testCopysign(self): |
| 827 | self.assertEqual(math.copysign(1, 42), 1.0) |
| 828 | self.assertEqual(math.copysign(0., 42), 0.0) |
| 829 | self.assertEqual(math.copysign(1., -42), -1.0) |
| 830 | self.assertEqual(math.copysign(3, 0.), 3.0) |
| 831 | self.assertEqual(math.copysign(4., -0.), -4.0) |
| 832 | |
Christian Heimes | e2ca424 | 2008-01-03 20:23:15 +0000 | [diff] [blame] | 833 | def testIsnan(self): |
| 834 | self.assert_(math.isnan(float("nan"))) |
| 835 | self.assert_(math.isnan(float("inf")* 0.)) |
| 836 | self.failIf(math.isnan(float("inf"))) |
| 837 | self.failIf(math.isnan(0.)) |
| 838 | self.failIf(math.isnan(1.)) |
| 839 | |
| 840 | def testIsinf(self): |
| 841 | self.assert_(math.isinf(float("inf"))) |
| 842 | self.assert_(math.isinf(float("-inf"))) |
| 843 | self.assert_(math.isinf(1E400)) |
| 844 | self.assert_(math.isinf(-1E400)) |
| 845 | self.failIf(math.isinf(float("nan"))) |
| 846 | self.failIf(math.isinf(0.)) |
| 847 | self.failIf(math.isinf(1.)) |
| 848 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 849 | # RED_FLAG 16-Oct-2000 Tim |
| 850 | # While 2.0 is more consistent about exceptions than previous releases, it |
| 851 | # still fails this part of the test on some platforms. For now, we only |
| 852 | # *run* test_exceptions() in verbose mode, so that this isn't normally |
| 853 | # tested. |
Tim Peters | 1d12061 | 2000-10-12 06:10:25 +0000 | [diff] [blame] | 854 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 855 | if verbose: |
| 856 | def test_exceptions(self): |
| 857 | try: |
| 858 | x = math.exp(-1000000000) |
| 859 | except: |
| 860 | # mathmodule.c is failing to weed out underflows from libm, or |
| 861 | # we've got an fp format with huge dynamic range |
| 862 | self.fail("underflowing exp() should not have raised " |
| 863 | "an exception") |
| 864 | if x != 0: |
| 865 | self.fail("underflowing exp() should have returned 0") |
Tim Peters | 1d12061 | 2000-10-12 06:10:25 +0000 | [diff] [blame] | 866 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 867 | # If this fails, probably using a strict IEEE-754 conforming libm, and x |
| 868 | # is +Inf afterwards. But Python wants overflows detected by default. |
| 869 | try: |
| 870 | x = math.exp(1000000000) |
| 871 | except OverflowError: |
| 872 | pass |
| 873 | else: |
| 874 | self.fail("overflowing exp() didn't trigger OverflowError") |
Tim Peters | 1d12061 | 2000-10-12 06:10:25 +0000 | [diff] [blame] | 875 | |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 876 | # If this fails, it could be a puzzle. One odd possibility is that |
| 877 | # mathmodule.c's macros are getting confused while comparing |
| 878 | # Inf (HUGE_VAL) to a NaN, and artificially setting errno to ERANGE |
| 879 | # as a result (and so raising OverflowError instead). |
| 880 | try: |
| 881 | x = math.sqrt(-1.0) |
| 882 | except ValueError: |
| 883 | pass |
| 884 | else: |
| 885 | self.fail("sqrt(-1) didn't raise ValueError") |
Tim Peters | 98c8184 | 2000-10-16 17:35:13 +0000 | [diff] [blame] | 886 | |
Christian Heimes | 6f34109 | 2008-04-18 23:13:07 +0000 | [diff] [blame] | 887 | def test_testfile(self): |
| 888 | if not float.__getformat__("double").startswith("IEEE"): |
| 889 | return |
| 890 | for id, fn, ar, ai, er, ei, flags in parse_testfile(test_file): |
| 891 | # Skip if either the input or result is complex, or if |
| 892 | # flags is nonempty |
| 893 | if ai != 0. or ei != 0. or flags: |
| 894 | continue |
| 895 | if fn in ['rect', 'polar']: |
| 896 | # no real versions of rect, polar |
| 897 | continue |
| 898 | func = getattr(math, fn) |
Mark Dickinson | 9f99d70 | 2008-04-20 01:22:30 +0000 | [diff] [blame] | 899 | try: |
| 900 | result = func(ar) |
| 901 | except ValueError: |
| 902 | message = ("Unexpected ValueError in " + |
| 903 | "test %s:%s(%r)\n" % (id, fn, ar)) |
| 904 | self.fail(message) |
Mark Dickinson | d055835 | 2008-05-23 03:30:01 +0000 | [diff] [blame^] | 905 | except OverflowError: |
| 906 | message = ("Unexpected OverflowError in " + |
| 907 | "test %s:%s(%r)\n" % (id, fn, ar)) |
| 908 | self.fail(message) |
Christian Heimes | 6f34109 | 2008-04-18 23:13:07 +0000 | [diff] [blame] | 909 | self.ftest("%s:%s(%r)" % (id, fn, ar), result, er) |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 910 | |
| 911 | def test_main(): |
Christian Heimes | 6f34109 | 2008-04-18 23:13:07 +0000 | [diff] [blame] | 912 | from doctest import DocFileSuite |
| 913 | suite = unittest.TestSuite() |
| 914 | suite.addTest(unittest.makeSuite(MathTests)) |
| 915 | suite.addTest(DocFileSuite("ieee754.txt")) |
| 916 | run_unittest(suite) |
Georg Brandl | 2f03760 | 2006-10-28 13:51:49 +0000 | [diff] [blame] | 917 | |
| 918 | if __name__ == '__main__': |
| 919 | test_main() |