Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4420cf4

Browse files
authored
gh-124040: Adjust few tests in testHypot/testDist to get exactly computed results (GH-124042)
1 parent 7628f67 commit 4420cf4

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Lib/test/test_math.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -812,11 +812,13 @@ def testHypot(self):
812812
# Test allowable types (those with __float__)
813813
self.assertEqual(hypot(12.0, 5.0), 13.0)
814814
self.assertEqual(hypot(12, 5), 13)
815-
self.assertEqual(hypot(1, -1), math.sqrt(2))
816-
self.assertEqual(hypot(1, FloatLike(-1.)), math.sqrt(2))
815+
self.assertEqual(hypot(0.75, -1), 1.25)
816+
self.assertEqual(hypot(-1, 0.75), 1.25)
817+
self.assertEqual(hypot(0.75, FloatLike(-1.)), 1.25)
818+
self.assertEqual(hypot(FloatLike(-1.), 0.75), 1.25)
817819
self.assertEqual(hypot(Decimal(12), Decimal(5)), 13)
818820
self.assertEqual(hypot(Fraction(12, 32), Fraction(5, 32)), Fraction(13, 32))
819-
self.assertEqual(hypot(bool(1), bool(0), bool(1), bool(1)), math.sqrt(3))
821+
self.assertEqual(hypot(True, False, True, True, True), 2.0)
820822

821823
# Test corner cases
822824
self.assertEqual(hypot(0.0, 0.0), 0.0) # Max input is zero
@@ -972,9 +974,9 @@ def testDist(self):
972974
self.assertEqual(dist((D(14), D(1)), (D(2), D(-4))), D(13))
973975
self.assertEqual(dist((F(14, 32), F(1, 32)), (F(2, 32), F(-4, 32))),
974976
F(13, 32))
975-
self.assertEqual(dist((True, True, False, True, False),
976-
(True, False, True, True, False)),
977-
sqrt(2.0))
977+
self.assertEqual(dist((True, True, False, False, True, True),
978+
(True, False, True, False, False, False)),
979+
2.0)
978980

979981
# Test corner cases
980982
self.assertEqual(dist((13.25, 12.5, -3.25),

0 commit comments

Comments
 (0)