Hello, everyone!
I have made a function, which receives three integer inputs for the lengths of the sides of a triangle and returns one of four values to determine the triangle type and I need to make unittest, but nothing happends. Can someone correct my code or give advise?
tri.py
I have made a function, which receives three integer inputs for the lengths of the sides of a triangle and returns one of four values to determine the triangle type and I need to make unittest, but nothing happends. Can someone correct my code or give advise?
tri.py
a = int(input("a = ")) b = int(input("b = ")) c = int(input("c = ")) def triangle_type(a,b,c): print("Enter lenghts of triangle sides:") if a<0 or b<0 or c<0: return "4=error" else: if a+b>c and a+c>b and b+c>a: if a==b==c: return "3=equilateral" elif a==b or a==c or b==c: return "2=isosceles" else: return "1=scalene" else: return "4=error" print (triangle_type(a,b,c))test_tri.py
import unittest import tri class CalcTest(unittest.TestCase): #scalene def triangle_type_scalene(self): self.assertEqual(tri.triangle_type(2,3,4), "1=scalene") #isosceles def triangle_type_isosceles(self): self.assertEqual(tri.triangle_type(3,3,2), "2=isosceles") #equilateral def triangle_type_equilateral(self): self.assertEqual(tri.triangle_type(3,3,3), "3=equilateral") #error for negative sides def triangle_type_negative_sides(self): self.assertEqual(tri.triangle_type(-1,3,4), "4=error") self.assertEqual(tri.triangle_type(1,-2,3), "4=error") self.assertEqual(tri.triangle_type(1,2,-4), "4=error") #error for mismatching the condition for building triangle def triangle_type_wrong_condiion(self): self.assertEqual(tri.triangle_type(10,2,3), "4=error") self.assertEqual(tri.triangle_type(1,10,2), "4=error") self.assertEqual(tri.triangle_type(1,2,10), "4=error")