
#Define isosceles code#
The only thing you need to change in your calling code is to call this with is_triangle(*sides), i.e. This uses the fact that after the sorted, a is always the smallest side, as mentioned in the comments. The sides of a triangle are customarily called a, b, c. Instead, just explicitly take three arguments. This opens you up to obscure bugs, such as these ones, which are not covered in your tests: > is_triangle() I find it therefore weird to take a single sides argument, which could be of any size. Self.assertIs(isosceles(), True)ĭef test_equilateral_triangles_are_also_isosceles(self):Ĭlass TestScaleneTriangle(unittest.TestCase):Ī triangle has, by definition, three sides. Self.assertIs(isosceles(), False)Ĭlass TestIsoscelesTriangle(unittest.TestCase): Self.assertIs(equilateral(), False)ĭef test_third_triangle_inequality_violation(self): Self.assertIs(equilateral(), True)ĭef test_all_zero_sides_is_not_a_triangle(self): import unittestįrom triangle import equilateral, isosceles, scaleneĬlass TestEquilateralTriangle(unittest.TestCase):

If equilateral(sides) or isosceles(sides):Īlso, I'm adding a simple unit test module.

The sides of a triangle come in a list e.g.

I've come up with a working solution, but I feel this could be greatly improved and/or simplified. I've been fiddling around with some easy code challenges and there's one about determining if a triangle is equilateral, isosceles, or scalene.
