123k views
3 votes
The Classic Triangle Testing Problem, (Myer's Triangle): A program reads three integer values. The three values are interpreted as representing the lengths of the sides of a triangle. The program prints a message that states whether the triangle is scalene, isosceles, or equilateral. Develop a set of test cases (at least 6 ) that you feel will adequately test this program. (This is a classic testing problem and you could find numerous explanations about it on the internet. I would recommend that you try to submit your own answer, based on your understanding of the topic)

Let’s define what the three different types of triangle requirements for the side’s lengths are:______.

1 Answer

0 votes

Answer:

Here is the Python program:

def MyersTriangle(a, b, c): #method to test triangles

if not(isinstance(a, int) and isinstance(b, int) and isinstance(c, int)): #checks if values are of type int

return 'Enter integer values'

elif a==0 or b==0 or c==0: #checks if any value is equal to 0

return 'Enter integer values greater than 0'

elif a<0 or b<0 or c <0: #checks if any value is less than 0

return 'All values must be positive'

elif not (a+b>=c and b+c>=a and c+a>=b): #checks if triangle is valid

return 'Not a valid triangle'

elif a == b == c: #checks if triangle is equilateral

return 'triangle is equilateral'

elif a == b or b == c: #checks if triangle is isoceles

return 'triangle is isoceles'

elif a != b and a != c and b != c: #checks if triangle is scalene

return 'triangle is scalene'

#test cases

print(MyersTriangle(2.4,7.5,8.7))

print(MyersTriangle(0,0,0))

print(MyersTriangle(-1,5,4))

print(MyersTriangle(10,10,25))

print(MyersTriangle(5,5,5))

print(MyersTriangle(3,3,4))

print(MyersTriangle(3,4,5))

Step-by-step explanation:

The program uses if elif conditions to check:

if the values are integers: this is checked by using isinstance method that checks if values belongs to a particular int. If this returns true then values are integers otherwise not

if values are not 0: this is checked by using logical operator or between each variable which checks if any of the values is 0

if values are not negative: This is checked by using relational operator < which means the values are less than 0

if values make a valid triangle: this is checked by the rule that the sum of two sided of the triangle is greater than or equal to the third side.

and then checks if the triangle is scalene, isosceles, or equilateral: This is checked by the following rules:

For scalene all three sides are unequal in length

For isosceles any of the two sides are equal in length

For equilateral all sides should be equal in length.

The screenshot of the program along with the output is attached.

The Classic Triangle Testing Problem, (Myer's Triangle): A program reads three integer-example-1
User Franbenz
by
6.5k points