我试图计算斜坡的截距,但是我不能测试所有的测试单元。我得到的第一个测试单位工作,但最后一个我有一些麻烦。有人能帮我找到错误吗?
def test(actual, expected):
""" Compare the actual to the expected value,
and print a suitable message.
"""
import sys
linenum = sys._getframe(1).f_lineno # get the caller's line number.
if (expected == actual):
msg = "Test on line {0} passed.".format(linenum)
else:
msg = ("Test on line {0} failed. Expected '{1}', but got '{2}'."
. format(linenum, expected, actual))
print(msg)
def slope (x1, y1, x2, y2):
x2 = (x2 - x1)
y2 = (y2 - y1)
m = (y2/x2)
return m
def intercept(x1, y1, x2, y2):
m = slope(x1,y1,x2,y2)
b = y2 - (m*x2)
return b
def test_suite():
test(intercept(1, 6, 3, 12), 3.0)
test(intercept(6, 1, 1, 6), 7.0)
test(intercept(4, 6, 12, 8), 5.0)
test_suite()