Skip to content

Commit 3b851ac

Browse files
committed
+ test special components for complex_abs()
1 parent 31d9fc3 commit 3b851ac

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

Lib/test/test_complex.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from random import random
1313
from math import isnan, copysign
14+
import cmath
1415
import operator
1516

1617
INF = float("inf")
@@ -791,6 +792,19 @@ def test_abs(self):
791792
for num in nums:
792793
self.assertAlmostEqual((num.real**2 + num.imag**2) ** 0.5, abs(num))
793794

795+
for x in 0.0, -0.0, INF, -INF, NAN:
796+
for y in 0.0, -0.0, INF, -INF, NAN:
797+
with self.subTest(x=x, y=y):
798+
z = complex(x, y)
799+
r = abs(z)
800+
if cmath.isfinite(z):
801+
self.assertFloatsAreIdentical(r, 0.0)
802+
elif cmath.isinf(z):
803+
self.assertEqual(r, INF)
804+
else:
805+
self.assertTrue(cmath.isnan(z))
806+
self.assertTrue(isnan(r))
807+
794808
self.assertRaises(OverflowError, abs, complex(DBL_MAX, DBL_MAX))
795809

796810
def test_abs_errno_handling(self):

0 commit comments

Comments
 (0)