The program reads three integer values from an input dialog. The three values represent the lengths of the sides of a triangle. The program displays a message that states whether the triangle is scalene, isosceles, or equilateral.
Remember that a scalene triangle is one where no two sides are equal, an isosceles triangle has two equal sides, and an equilateraltriangle has three sides of equal length.
Moreover, the angles opposite theequal sides in an isosceles triangle also are equal (it also follows that the sides opposite equal angles in a triangle are equal), and all angles in an equilateral triangle are equal.
def triangle(a = None ,b = None ,c = None):
if a != None and b != None and c != None and (a+b) > c and (b+c) > a and (c+a) > b :
return True
return False
https://docs.python.org/3/library/unittest.html
-
Do you have a test case that represents a valid scalene triangle? (Note that test cases such as 1, 2, 3 and 2, 5, 10 do not warrant a yes answer because a triangle having these dimensions is not valid.)
-
Do you have a test case that represents a valid equilateral triangle?
-
Do you have a test case that represents a valid isosceles triangle? (Note that a test case representing 2, 2, 4 would not count because it is not a valid triangle.)
-
Do you have at least three test cases that represent valid isosceles triangles such that you have tried all three permutations of two equal sides (such as, 3, 3, 4; 3, 4, 3; and 4, 3, 3)?
-
Do you have a test case in which one side has a zero value?
-
Do you have a test case in which one side has a negative value?
-
Do you have a test case with three integers greater than zero such that the sum of two of the numbers is equal to the third? (That is, if the program said that 1, 2, 3 represents a scalene triangle, it would contain a bug.)
-
Do you have at least three test cases in category 7 such that you have tried all three permutations where the length of one side is equal to the sum of the lengths of the other two sides (e.g., 1, 2, 3; 1, 3, 2; and 3, 1, 2)?
-
Do you have a test case with three integers greater than zero such that the sum of two of the numbers is less than the third (such as 1, 2, 4 or 12, 15, 30)?
-
Do you have at least three test cases in category 9 such that you have tried all three permutations (e.g., 1, 2, 4; 1, 4, 2; and 4, 1, 2)?
-
Do you have a test case in which all sides are zero (0, 0, 0)?
-
Do you have at least one test case specifying noninteger values (such as 2.5, 3.5, 5.5)?
-
Do you have at least one test case specifying the wrong number of values (two rather than three integers, for example)?
-
For each test case did you specify the expected output from the program in addition to the input values?
import unittest
class TestTriangle(unittest.TestCase):
# 1. Do you have a test case that represents a valid scalene triangle?
# (Note that test cases such as 1, 2, 3 and 2, 5, 10 do not warrant a yes
# answer because a triangle having these dimensions is not valid.)
def test_1_scalene_trinngle(self):
self.assertFalse(triangle(1,2,3))
self.assertFalse(triangle(2,5,10))
self.assertTrue(triangle(5,2,4))
# 2. Do you have a test case that represents a valid equilateral triangle?
def test_2_equilateral_triangle(self):
self.assertTrue(triangle(2,2,1))
# 3. Do you have a test case that represents a valid isosceles triangle?
# (Note that a test case representing 2, 2, 4 would not count because it
# is not a valid triangle.)
def test_3_isosceles_triangle(self):
self.assertFalse(triangle(2,2,4))
self.assertTrue(triangle(2,2,1))
# 4. Do you have at least three test cases that represent valid isosceles
# triangles such that you have tried all three permutations of two equal
# sides (such as, 3, 3, 4; 3, 4, 3; and 4, 3, 3)?
def test_4_isosceles_triangle_permutations(self):
self.assertTrue(triangle(3,3,4))
self.assertTrue(triangle(3,4,3))
self.assertTrue(triangle(4,3,3))
# 5. Do you have a test case in which one side has a zero value?
def test_5_triangle_one_side_zero(self):
self.assertFalse(triangle(2,2,0))
self.assertFalse(triangle(5,2,0))
# 6. Do you have a test case in which one side has a negative value?
def test_6_triangle_one_side_negative(self):
self.assertFalse(triangle(2,2,-1))
self.assertFalse(triangle(5,2,-1))
# 7. Do you have a test case with three integers greater than zero such that
# the sum of two of the numbers is equal to the third? (That is, if the
# program said that 1, 2, 3 represents a scalene triangle, it would contain
# a bug.)
def test_7_triangle_two_side_sum_equal_to_third(self):
self.assertFalse(triangle(1,2,3))
# 8. Do you have at least three test cases in category 7 such that you have
# tried all three permutations where the length of one side is equal to
# the sum of the lengths of the other two sides (e.g., 1, 2, 3; 1, 3, 2; and
# 3, 1, 2)?
def test_8_triangle_two_side_sum_equal_to_third_permutations(self):
self.assertFalse(triangle(1,2,3))
self.assertFalse(triangle(1,3,2))
self.assertFalse(triangle(3,1,2))
# 9. Do you have a test case with three integers greater than zero such that
# the sum of two of the numbers is less than the third (such as 1, 2, 4 or
# 12, 15, 30)?
def test_9_triangle_two_side_sum_less_than_third(self):
self.assertFalse(triangle(1,2,4))
self.assertFalse(triangle(12,15,30))
# 10. Do you have at least three test cases in category 9 such that you have
# tried all three permutations (e.g., 1, 2, 4; 1, 4, 2; and 4, 1, 2)?
def test_10_triangle_two_side_sum_less_than_third_permutations(self):
self.assertFalse(triangle(1,2,4))
self.assertFalse(triangle(1,4,2))
self.assertFalse(triangle(4,1,2))
# 11. Do you have a test case in which all sides are zero (0, 0, 0)?
def test_11_triangle_all_zero(self):
self.assertFalse(triangle(0,0,0))
# 12. Do you have at least one test case specifying noninteger values
# (such as 2.5, 3.5, 5.5)?
def test_12_triangle_noninteger(self):
self.assertTrue(triangle(2.5,3.5,5.5))
# 13. Do you have at least one test case specifying the wrong number of
# values (two rather than three integers, for example)?
def test_13_wrong_input(self):
self.assertFalse(triangle(5,2))
if __name__ == '__main__':
unittest.main(argv=['first-arg-is-ignored'], exit=False)