Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Lib/test/test_cmath.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,22 @@ 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:
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:
if z != w:
self.assertIsNotClose(z, w)
else:
self.assertIsClose(z, z)
Comment on lines +593 to +608
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, the test_cmath.py file has global variables for complex nans and infinities. You can reuse them here:

Suggested change
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:
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:
if z != w:
self.assertIsNotClose(z, w)
else:
self.assertIsClose(z, z)
for z in complex_nans:
for w in complex_infinities + complex_nans:
self.assertIsNotClose(z, w)
for z in complex_infinities:
for w in complex_infinities:
if z != w:
self.assertIsNotClose(z, w)
else:
self.assertIsClose(z, z)



if __name__ == "__main__":
Expand Down
Loading