Given the following code:
def slope(x1, y1, x2, y2):
"""
>>> slope(5, 3, 4, 2)
1.0
>>> slope(1, 2, 3, 2)
0.0
>>> slope(1, 2, 3, 3)
0.5
>>> slope(2, 4, 1, 2)
2.0
"""
xa = float (x1)
xb = float (x2)
ya = float (y1)
yb = float (y2)
return (ya-yb)/(xa-xb)
if name_ == '__main__':
import doctest
doctest.testmod()
The second doctest fails:
Failed example:
slope(1, 2, 3, 2)
Expected:
0.0
Got:
-0.0
However, we all know that -0.0 == 0.0. Is doctest doing a string comparison to check results here? Why does the second test fail?