From a4b73ddc0d395ec2e4d2e15637be8e1b51f35f22 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Fri, 13 Sep 2024 13:10:39 +0300 Subject: [PATCH 1/4] gh-124040: simplify two hypot tests One-argument form is enough to test L2636 and compare computed values exactly. --- Lib/test/test_math.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py index eabab2805f8110..c93876e701d314 100644 --- a/Lib/test/test_math.py +++ b/Lib/test/test_math.py @@ -809,8 +809,8 @@ def testHypot(self): # Test allowable types (those with __float__) self.assertEqual(hypot(12.0, 5.0), 13.0) self.assertEqual(hypot(12, 5), 13) - self.assertEqual(hypot(1, -1), math.sqrt(2)) - self.assertEqual(hypot(1, FloatLike(-1.)), math.sqrt(2)) + self.assertEqual(hypot(-1), 1.0) + self.assertEqual(hypot(FloatLike(-1.)), 1.0) self.assertEqual(hypot(Decimal(12), Decimal(5)), 13) self.assertEqual(hypot(Fraction(12, 32), Fraction(5, 32)), Fraction(13, 32)) self.assertEqual(hypot(bool(1), bool(0), bool(1), bool(1)), math.sqrt(3)) From 9fba2cbe501d7d17b62afa569f14403a3f45ec8b Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Fri, 13 Sep 2024 17:20:42 +0300 Subject: [PATCH 2/4] Fix also dist test --- Lib/test/test_math.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py index c93876e701d314..dba017a9bbcdbc 100644 --- a/Lib/test/test_math.py +++ b/Lib/test/test_math.py @@ -969,9 +969,9 @@ def testDist(self): self.assertEqual(dist((D(14), D(1)), (D(2), D(-4))), D(13)) self.assertEqual(dist((F(14, 32), F(1, 32)), (F(2, 32), F(-4, 32))), F(13, 32)) - self.assertEqual(dist((True, True, False, True, False), - (True, False, True, True, False)), - sqrt(2.0)) + self.assertEqual(dist((True, True, False, False, True, True), + (True, False, True, False, False, False)), + 2.0) # Test corner cases self.assertEqual(dist((13.25, 12.5, -3.25), From e1284dab2a2b477e828262a61f1dfb6e5f208956 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Fri, 13 Sep 2024 18:27:48 +0300 Subject: [PATCH 3/4] address review: Use two-argument form with exact result to test hypot() --- Lib/test/test_math.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py index dba017a9bbcdbc..cc147353cdb645 100644 --- a/Lib/test/test_math.py +++ b/Lib/test/test_math.py @@ -809,8 +809,10 @@ def testHypot(self): # Test allowable types (those with __float__) self.assertEqual(hypot(12.0, 5.0), 13.0) self.assertEqual(hypot(12, 5), 13) - self.assertEqual(hypot(-1), 1.0) - self.assertEqual(hypot(FloatLike(-1.)), 1.0) + self.assertEqual(hypot(0.75, -1), 1.25) + self.assertEqual(hypot(-1, 0.75), 1.25) + self.assertEqual(hypot(0.75, FloatLike(-1.)), 1.25) + self.assertEqual(hypot(FloatLike(-1.), 0.75), 1.25) self.assertEqual(hypot(Decimal(12), Decimal(5)), 13) self.assertEqual(hypot(Fraction(12, 32), Fraction(5, 32)), Fraction(13, 32)) self.assertEqual(hypot(bool(1), bool(0), bool(1), bool(1)), math.sqrt(3)) From ed5ccc9e49d6a9bf6851c9e4f3fd9cf06ece1c4b Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Fri, 13 Sep 2024 18:30:10 +0300 Subject: [PATCH 4/4] address review: change hypot test for bool's to produce exact value --- Lib/test/test_math.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py index cc147353cdb645..6be2a77690c534 100644 --- a/Lib/test/test_math.py +++ b/Lib/test/test_math.py @@ -815,7 +815,7 @@ def testHypot(self): self.assertEqual(hypot(FloatLike(-1.), 0.75), 1.25) self.assertEqual(hypot(Decimal(12), Decimal(5)), 13) self.assertEqual(hypot(Fraction(12, 32), Fraction(5, 32)), Fraction(13, 32)) - self.assertEqual(hypot(bool(1), bool(0), bool(1), bool(1)), math.sqrt(3)) + self.assertEqual(hypot(True, False, True, True, True), 2.0) # Test corner cases self.assertEqual(hypot(0.0, 0.0), 0.0) # Max input is zero