mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
bpo-37691: Let math.dist() accept sequences and iterables for coordinates (GH-14975)
This commit is contained in:
parent
3221a63c69
commit
6b5f1b496f
5 changed files with 47 additions and 20 deletions
|
@ -833,6 +833,10 @@ class MathTests(unittest.TestCase):
|
|||
sqrt(sum((px - qx) ** 2.0 for px, qx in zip(p, q)))
|
||||
)
|
||||
|
||||
# Test non-tuple inputs
|
||||
self.assertEqual(dist([1.0, 2.0, 3.0], [4.0, 2.0, -1.0]), 5.0)
|
||||
self.assertEqual(dist(iter([1.0, 2.0, 3.0]), iter([4.0, 2.0, -1.0])), 5.0)
|
||||
|
||||
# Test allowable types (those with __float__)
|
||||
self.assertEqual(dist((14.0, 1.0), (2.0, -4.0)), 13.0)
|
||||
self.assertEqual(dist((14, 1), (2, -4)), 13)
|
||||
|
@ -873,8 +877,6 @@ class MathTests(unittest.TestCase):
|
|||
dist((1, 2, 3), (4, 5, 6), (7, 8, 9))
|
||||
with self.assertRaises(TypeError): # Scalars not allowed
|
||||
dist(1, 2)
|
||||
with self.assertRaises(TypeError): # Lists not allowed
|
||||
dist([1, 2, 3], [4, 5, 6])
|
||||
with self.assertRaises(TypeError): # Reject values without __float__
|
||||
dist((1.1, 'string', 2.2), (1, 2, 3))
|
||||
with self.assertRaises(ValueError): # Check dimension agree
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue