Skip to content

Commit deb883e

Browse files
committed
add tests to improve coverage for test_complex_special
1 parent d24e6ea commit deb883e

1 file changed

Lines changed: 17 additions & 19 deletions

File tree

Lib/test/test_cmath.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from test.support.testcase import ComplexesAreIdenticalMixin
33
from test.test_math import parse_testfile, test_file
44
import test.test_math as test_math
5+
import itertools
56
import unittest
67
import cmath, math
78
from cmath import phase, polar, rect, pi
@@ -590,25 +591,22 @@ def test_complex_special(self):
590591
self.assertIsNotClose(-INF, INF)
591592
self.assertIsNotClose(0, INF)
592593
self.assertIsNotClose(0, INF*1j)
593-
self.assertIsNotClose(complex(INF, INF), complex(-INF, -INF))
594-
self.assertIsNotClose(complex(INF, INF), complex(INF, -INF))
595-
self.assertIsNotClose(complex(INF, INF), complex(-INF, INF))
596-
self.assertIsNotClose(complex(-INF, INF), complex(INF, -INF))
597-
self.assertIsNotClose(complex(NAN, NAN), complex(NAN, NAN))
598-
self.assertIsNotClose(complex(NAN, 0), complex(NAN, 0))
599-
self.assertIsNotClose(complex(0, NAN), complex(0, NAN))
600-
self.assertIsNotClose(complex(INF, NAN), complex(INF, NAN))
601-
self.assertIsNotClose(complex(NAN, INF), complex(NAN, INF))
602-
self.assertIsNotClose(complex(-INF, NAN), complex(-INF, NAN))
603-
self.assertIsNotClose(complex(NAN, -INF), complex(NAN, -INF))
604-
self.assertIsNotClose(complex(INF, INF), complex(1, 1))
605-
self.assertIsNotClose(complex(-INF, -INF), complex(1, 1))
606-
self.assertIsNotClose(complex(INF, 0), complex(0, 0))
607-
self.assertIsNotClose(complex(0, INF), complex(0, 0))
608-
self.assertIsClose(complex(INF, INF), complex(INF, INF))
609-
self.assertIsClose(complex(-INF, -INF), complex(-INF, -INF))
610-
self.assertIsClose(complex(INF, -INF), complex(INF, -INF))
611-
self.assertIsClose(complex(-INF, INF), complex(-INF, INF))
594+
special = [INF, -INF, NAN]
595+
special_complex = [complex(x, y) for x in special for y in special]
596+
597+
nan_complex = [c for c in special_complex
598+
if math.isnan(c.real) or math.isnan(c.imag)]
599+
for z in nan_complex:
600+
for w in special_complex:
601+
self.assertIsNotClose(z, w)
602+
603+
inf_complex = [c for c in special_complex
604+
if not math.isnan(c.real) and not math.isnan(c.imag)]
605+
for z, w in itertools.combinations(inf_complex, 2):
606+
self.assertIsNotClose(z, w)
607+
608+
for z in inf_complex:
609+
self.assertIsClose(z, z)
612610

613611

614612
if __name__ == "__main__":

0 commit comments

Comments
 (0)