|
1 |
| -from test.support import run_unittest, requires_IEEE_754 |
| 1 | +from test.support import run_unittest, requires_IEEE_754, cpython_only |
2 | 2 | from test.test_math import parse_testfile, test_file
|
3 | 3 | import unittest
|
4 | 4 | import cmath, math
|
@@ -381,17 +381,48 @@ def polar_complex(z):
|
381 | 381 | self.rAssertAlmostEqual(expected.imag, actual.imag,
|
382 | 382 | msg=error_message)
|
383 | 383 |
|
384 |
| - def assertCISEqual(self, a, b): |
385 |
| - eps = 1E-7 |
386 |
| - if abs(a[0] - b[0]) > eps or abs(a[1] - b[1]) > eps: |
387 |
| - self.fail((a ,b)) |
| 384 | + def check_polar(self, func): |
| 385 | + def check(arg, expected): |
| 386 | + got = func(arg) |
| 387 | + for e, g in zip(expected, got): |
| 388 | + self.rAssertAlmostEqual(e, g) |
| 389 | + check(0, (0., 0.)) |
| 390 | + check(1, (1., 0.)) |
| 391 | + check(-1, (1., pi)) |
| 392 | + check(1j, (1., pi / 2)) |
| 393 | + check(-3j, (3., -pi / 2)) |
| 394 | + inf = float('inf') |
| 395 | + check(complex(inf, 0), (inf, 0.)) |
| 396 | + check(complex(-inf, 0), (inf, pi)) |
| 397 | + check(complex(3, inf), (inf, pi / 2)) |
| 398 | + check(complex(5, -inf), (inf, -pi / 2)) |
| 399 | + check(complex(inf, inf), (inf, pi / 4)) |
| 400 | + check(complex(inf, -inf), (inf, -pi / 4)) |
| 401 | + check(complex(-inf, inf), (inf, 3 * pi / 4)) |
| 402 | + check(complex(-inf, -inf), (inf, -3 * pi / 4)) |
| 403 | + nan = float('nan') |
| 404 | + check(complex(nan, 0), (nan, nan)) |
| 405 | + check(complex(0, nan), (nan, nan)) |
| 406 | + check(complex(nan, nan), (nan, nan)) |
| 407 | + check(complex(inf, nan), (inf, nan)) |
| 408 | + check(complex(-inf, nan), (inf, nan)) |
| 409 | + check(complex(nan, inf), (inf, nan)) |
| 410 | + check(complex(nan, -inf), (inf, nan)) |
388 | 411 |
|
389 | 412 | def test_polar(self):
|
390 |
| - self.assertCISEqual(polar(0), (0., 0.)) |
391 |
| - self.assertCISEqual(polar(1.), (1., 0.)) |
392 |
| - self.assertCISEqual(polar(-1.), (1., pi)) |
393 |
| - self.assertCISEqual(polar(1j), (1., pi/2)) |
394 |
| - self.assertCISEqual(polar(-1j), (1., -pi/2)) |
| 413 | + self.check_polar(polar) |
| 414 | + |
| 415 | + @cpython_only |
| 416 | + def test_polar_errno(self): |
| 417 | + # Issue #24489: check a previously set C errno doesn't disturb polar() |
| 418 | + from _testcapi import set_errno |
| 419 | + def polar_with_errno_set(z): |
| 420 | + set_errno(11) |
| 421 | + try: |
| 422 | + return polar(z) |
| 423 | + finally: |
| 424 | + set_errno(0) |
| 425 | + self.check_polar(polar_with_errno_set) |
395 | 426 |
|
396 | 427 | def test_phase(self):
|
397 | 428 | self.assertAlmostEqual(phase(0), 0.)
|
|
0 commit comments