-
-
Notifications
You must be signed in to change notification settings - Fork 31k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
turtle: tests for Vec2D.__abs__ are too strict #88897
Comments
From the tests for Vec2D.__abs__ in the turtle module we have: def test_distance(self):
vec = Vec2D(6, 8)
expected = 10
self.assertEqual(abs(vec), expected)
vec = Vec2D(0, 0)
expected = 0
self.assertEqual(abs(vec), expected)
vec = Vec2D(2.5, 6)
expected = 6.5
self.assertEqual(abs(vec), expected) GitHub link: cpython/Lib/test/test_turtle.py Lines 237 to 248 in 8158e05
The first test was reported as failing in issue bpo-44728, with error: ====================================================================== Traceback (most recent call last):
File "/build/python/src/Python-3.9.6/Lib/test/test_turtle.py", line 237, in test_distance
self.assertEqual(abs(vec), expected)
AssertionError: 9.999999999999998 != 10 The first and last test should use assertAlmostEqual with a suitable tolerance (the default tolerance is probably fine). |
Thanks! ✨ 🍰 ✨ |
The merged PR only added tolerance to the last test. On some architectures, the first test still fails. Karolina's new PR is waiting for CLA confirmation. |
Low priority, but it may also be worth updating the implementation of def __abs__(self):
return (self[0]**2 + self[1]**2)**0.5 But would be more robust if it used hypot: def __abs__(self):
return math.hypot(self[0], self[1]) |
Apologies; looks like I'm out of date on this. It's already using hypot, which makes it more than a little worrying that it doesn't get the right answer for |
Sorry again, all; I failed to read everything that was going on here. The test *wasn't* failing with the hypot-based version of Vec2D.__abs__ that's in the main branch; only with the "**0.5"-based version that was still in the older branches. Please ignore this and the previous two messages ... |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: