设计直角三角形测试用例。
输入三个数,设计一个函数,如果是直角三角形则返回1,如果是三角形但不是直角三角形则返回0,如果不是三角形或数据错误则返回-1。
1.设计测试用例,包括目的,输入,预期结果。
2.用你熟悉的语言,来实现这段功能。
用例设计:
(1)3 4 5 (覆盖1、2、3、4、5、6、13、14、15) 输出:1
(2)0 1 2 (覆盖7、2、3) 输出:-1
(3)1 0 2 (覆盖8、2、3) 输出:-1
(4)1 2 0 (覆盖8、2、3) 输出:-1
(5)2 3 2 (1、2、3、4、5、6、16、17、18) 输出:0
代码实现(python):
def Istriangle(a,b,c):
result = -1
if (a>0) and (b>0) and (c>0):
if (a+b>c) and (a+c>b) and (b+c>a):
result = 0
if (a*a+b*b==c*c) or (a*a+c*c==b*b) or (b*b+c*c==a*a):
result = 1
return result
if __name__ == '__main__':
x,y,z=map(int,input('请输入三个整数:').split(' '))
print(Istriangle(x,y,z))