From d24e6ea6ce5b8afd4a565e577bed84850de815f9 Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Fri, 5 Jun 2026 05:40:56 +0000 Subject: [PATCH 1/6] add tests to improve coverage for test_complex_special --- Lib/test/test_cmath.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Lib/test/test_cmath.py b/Lib/test/test_cmath.py index a986fd6b892bd27..28bbc2e2eaaa39a 100644 --- a/Lib/test/test_cmath.py +++ b/Lib/test/test_cmath.py @@ -590,6 +590,25 @@ def test_complex_special(self): self.assertIsNotClose(-INF, INF) self.assertIsNotClose(0, INF) self.assertIsNotClose(0, INF*1j) + self.assertIsNotClose(complex(INF, INF), complex(-INF, -INF)) + self.assertIsNotClose(complex(INF, INF), complex(INF, -INF)) + self.assertIsNotClose(complex(INF, INF), complex(-INF, INF)) + self.assertIsNotClose(complex(-INF, INF), complex(INF, -INF)) + self.assertIsNotClose(complex(NAN, NAN), complex(NAN, NAN)) + self.assertIsNotClose(complex(NAN, 0), complex(NAN, 0)) + self.assertIsNotClose(complex(0, NAN), complex(0, NAN)) + self.assertIsNotClose(complex(INF, NAN), complex(INF, NAN)) + self.assertIsNotClose(complex(NAN, INF), complex(NAN, INF)) + self.assertIsNotClose(complex(-INF, NAN), complex(-INF, NAN)) + self.assertIsNotClose(complex(NAN, -INF), complex(NAN, -INF)) + self.assertIsNotClose(complex(INF, INF), complex(1, 1)) + self.assertIsNotClose(complex(-INF, -INF), complex(1, 1)) + self.assertIsNotClose(complex(INF, 0), complex(0, 0)) + self.assertIsNotClose(complex(0, INF), complex(0, 0)) + self.assertIsClose(complex(INF, INF), complex(INF, INF)) + self.assertIsClose(complex(-INF, -INF), complex(-INF, -INF)) + self.assertIsClose(complex(INF, -INF), complex(INF, -INF)) + self.assertIsClose(complex(-INF, INF), complex(-INF, INF)) if __name__ == "__main__": From deb883ef5c5ef7856fcae221b6be2b6d9cea1f4d Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Fri, 5 Jun 2026 09:06:09 +0000 Subject: [PATCH 2/6] add tests to improve coverage for test_complex_special --- Lib/test/test_cmath.py | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/Lib/test/test_cmath.py b/Lib/test/test_cmath.py index 28bbc2e2eaaa39a..52b645e6b145332 100644 --- a/Lib/test/test_cmath.py +++ b/Lib/test/test_cmath.py @@ -2,6 +2,7 @@ from test.support.testcase import ComplexesAreIdenticalMixin from test.test_math import parse_testfile, test_file import test.test_math as test_math +import itertools import unittest import cmath, math from cmath import phase, polar, rect, pi @@ -590,25 +591,22 @@ def test_complex_special(self): self.assertIsNotClose(-INF, INF) self.assertIsNotClose(0, INF) self.assertIsNotClose(0, INF*1j) - self.assertIsNotClose(complex(INF, INF), complex(-INF, -INF)) - self.assertIsNotClose(complex(INF, INF), complex(INF, -INF)) - self.assertIsNotClose(complex(INF, INF), complex(-INF, INF)) - self.assertIsNotClose(complex(-INF, INF), complex(INF, -INF)) - self.assertIsNotClose(complex(NAN, NAN), complex(NAN, NAN)) - self.assertIsNotClose(complex(NAN, 0), complex(NAN, 0)) - self.assertIsNotClose(complex(0, NAN), complex(0, NAN)) - self.assertIsNotClose(complex(INF, NAN), complex(INF, NAN)) - self.assertIsNotClose(complex(NAN, INF), complex(NAN, INF)) - self.assertIsNotClose(complex(-INF, NAN), complex(-INF, NAN)) - self.assertIsNotClose(complex(NAN, -INF), complex(NAN, -INF)) - self.assertIsNotClose(complex(INF, INF), complex(1, 1)) - self.assertIsNotClose(complex(-INF, -INF), complex(1, 1)) - self.assertIsNotClose(complex(INF, 0), complex(0, 0)) - self.assertIsNotClose(complex(0, INF), complex(0, 0)) - self.assertIsClose(complex(INF, INF), complex(INF, INF)) - self.assertIsClose(complex(-INF, -INF), complex(-INF, -INF)) - self.assertIsClose(complex(INF, -INF), complex(INF, -INF)) - self.assertIsClose(complex(-INF, INF), complex(-INF, INF)) + special = [INF, -INF, NAN] + special_complex = [complex(x, y) for x in special for y in special] + + nan_complex = [c for c in special_complex + if math.isnan(c.real) or math.isnan(c.imag)] + for z in nan_complex: + for w in special_complex: + self.assertIsNotClose(z, w) + + inf_complex = [c for c in special_complex + if not math.isnan(c.real) and not math.isnan(c.imag)] + for z, w in itertools.combinations(inf_complex, 2): + self.assertIsNotClose(z, w) + + for z in inf_complex: + self.assertIsClose(z, z) if __name__ == "__main__": From c1d0a00bec0ec6e588888d085d2bd5d07851e65c Mon Sep 17 00:00:00 2001 From: Aniket <148300120+Aniketsy@users.noreply.github.com> Date: Fri, 5 Jun 2026 18:54:47 +0530 Subject: [PATCH 3/6] Update Lib/test/test_cmath.py Co-authored-by: Sergey B Kirpichev --- Lib/test/test_cmath.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_cmath.py b/Lib/test/test_cmath.py index 52b645e6b145332..bb199b156e537ac 100644 --- a/Lib/test/test_cmath.py +++ b/Lib/test/test_cmath.py @@ -602,11 +602,12 @@ def test_complex_special(self): inf_complex = [c for c in special_complex if not math.isnan(c.real) and not math.isnan(c.imag)] - for z, w in itertools.combinations(inf_complex, 2): - self.assertIsNotClose(z, w) - for z in inf_complex: - self.assertIsClose(z, z) + for w in inf_complex: + if z != w: + self.assertIsNotClose(z, w) + else: + self.assertIsClose(z, z) if __name__ == "__main__": From 53f008342c84d8009d4864af1eab4e7394649f43 Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Fri, 5 Jun 2026 13:36:20 +0000 Subject: [PATCH 4/6] use cmath instead of math and remove itertools import --- Lib/test/test_cmath.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_cmath.py b/Lib/test/test_cmath.py index bb199b156e537ac..e21051a17c2eebb 100644 --- a/Lib/test/test_cmath.py +++ b/Lib/test/test_cmath.py @@ -2,7 +2,6 @@ from test.support.testcase import ComplexesAreIdenticalMixin from test.test_math import parse_testfile, test_file import test.test_math as test_math -import itertools import unittest import cmath, math from cmath import phase, polar, rect, pi @@ -591,17 +590,17 @@ def test_complex_special(self): self.assertIsNotClose(-INF, INF) self.assertIsNotClose(0, INF) self.assertIsNotClose(0, INF*1j) - special = [INF, -INF, NAN] + special = [INF, -INF, NAN, 0.0, -0.0, 1.0] special_complex = [complex(x, y) for x in special for y in special] nan_complex = [c for c in special_complex - if math.isnan(c.real) or math.isnan(c.imag)] + if cmath.isnan(c.real) or cmath.isnan(c.imag)] for z in nan_complex: for w in special_complex: self.assertIsNotClose(z, w) inf_complex = [c for c in special_complex - if not math.isnan(c.real) and not math.isnan(c.imag)] + if not cmath.isnan(c.real) and not cmath.isnan(c.imag)] for z in inf_complex: for w in inf_complex: if z != w: From 12f3f9c0b52eb685d30962b4ca37e86bee412249 Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Fri, 5 Jun 2026 13:46:32 +0000 Subject: [PATCH 5/6] test improvemnet --- Lib/test/test_cmath.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_cmath.py b/Lib/test/test_cmath.py index e21051a17c2eebb..6715e8824f65a91 100644 --- a/Lib/test/test_cmath.py +++ b/Lib/test/test_cmath.py @@ -593,14 +593,13 @@ def test_complex_special(self): special = [INF, -INF, NAN, 0.0, -0.0, 1.0] special_complex = [complex(x, y) for x in special for y in special] - nan_complex = [c for c in special_complex - if cmath.isnan(c.real) or cmath.isnan(c.imag)] + nan_complex = [c for c in special_complex if cmath.isnan(c)] for z in nan_complex: for w in special_complex: self.assertIsNotClose(z, w) inf_complex = [c for c in special_complex - if not cmath.isnan(c.real) and not cmath.isnan(c.imag)] + if cmath.isinf(c) and not cmath.isnan(c)] for z in inf_complex: for w in inf_complex: if z != w: From 3e6730b5b91065c2e607d8e2644ac67ea3534347 Mon Sep 17 00:00:00 2001 From: Aniket <148300120+Aniketsy@users.noreply.github.com> Date: Sat, 6 Jun 2026 08:39:58 +0530 Subject: [PATCH 6/6] Update Lib/test/test_cmath.py Co-authored-by: Sergey B Kirpichev --- Lib/test/test_cmath.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/Lib/test/test_cmath.py b/Lib/test/test_cmath.py index 6715e8824f65a91..b736b2b75a3db47 100644 --- a/Lib/test/test_cmath.py +++ b/Lib/test/test_cmath.py @@ -590,18 +590,12 @@ def test_complex_special(self): self.assertIsNotClose(-INF, INF) self.assertIsNotClose(0, INF) self.assertIsNotClose(0, INF*1j) - special = [INF, -INF, NAN, 0.0, -0.0, 1.0] - special_complex = [complex(x, y) for x in special for y in special] - - nan_complex = [c for c in special_complex if cmath.isnan(c)] - for z in nan_complex: - for w in special_complex: + for z in complex_nans: + for w in complex_infinities + complex_nans: self.assertIsNotClose(z, w) - inf_complex = [c for c in special_complex - if cmath.isinf(c) and not cmath.isnan(c)] - for z in inf_complex: - for w in inf_complex: + for z in complex_infinities: + for w in complex_infinities: if z != w: self.assertIsNotClose(z, w) else: