A2 Testing & Measure
A2 Testing & Measure
Studen
Part CLO Question Score Comment
t Score
1 4 5
Total
5
1
Part 1:
Consider the code of the method:
determineTriangleType(double a, double b, double c)
in Page 4. This method determines the type of a triangle based on the
lengths of its sides.
a. Draw a control flow graph for the program and clearly label each node
to show its correspondence to a statement.
b. Calculate the program’s cyclomatic complexity. What does this mean in
terms of the number of test cases to cover the code with respect to its
branches?
c. Develop a set of test cases to achieve full decision coverage.
d. Using JUnit, define and execute all test cases in part c.
For each test case, you must provide the input values and the expected
output in addition to the covered path. Fill the following table:
On Moodle, submit this Word file including your answers to parts a-d
above. In addition, upload the Java test file for part d.
The requirements are given as follows:
Functional Requirements
Input Requirements:
The program shall accept three positive numerical inputs representing the
lengths of the sides of a triangle (a, b, and c).
2
The inputs shall be double-precision floating-point numbers.
Validation Requirements:
The program shall validate that none of the input lengths (a, b, c) are less
than or equal to zero. If any input is invalid, the program shall return a
message indicating that the sides cannot be less than or equal to zero.
The program shall check that the sum of the lengths of any two sides is
greater than the length of the third side (triangle inequality theorem). If
this condition is not met, the program shall return a message indicating a
triangle inequality violation.
Triangle Classification Requirements:
The program shall determine and classify the triangle based on the lengths
of its sides into one of the following categories:
Equilateral triangle: All three sides are equal.
Isosceles triangle: Exactly two sides are equal.
Scalene triangle: All three sides are different.
Right triangle: A triangle that satisfies the Pythagorean theorem (only
applicable filtering to other classifications).
If the input does not meet the criteria for being a triangle, it shall classify
the input as "Not a triangle".
Output Requirements:
The program shall return a string output indicating the type of triangle, or
an appropriate error message based on the input validation.
3
private static boolean isRightTriangle(double a, double b, double c) {
// Check if the triangle is right-angled
return (Math.abs(a * a + b * b - c * c) < 1e-10 ||
Math.abs(a * a + c * c - b * b) < 1e-10 ||
Math.abs(b * b + c * c - a * a) < 1e-10);
}
4
a.) Control Flow Graph
D.)
**The file has been uploaded and this is a screenshot of the JUnit Running
the tests**
6
7