a) Compute the Cyclomatic complexity of the method. Full path coverage testing r
ID: 3853772 • Letter: A
Question
a) Compute the Cyclomatic complexity of the method. Full path coverage testing requires that every possible path through the code be tested at least once. For the code fragment below, how many test cases would be needed for full path coverage? Why might full path coverage be impossible to achieve for some programs?
public String printTriangleType (int x, y, z)
{
/* requires: The parameters are in ascending order (i.e. x <= y <= z)
effects: If x, y and z are the lengths of the sides of a triangle,
this function classifies the triangle using one of the three strings,
"scalene", "isosceles" or "equilateral". If x, y, and z do not form a
triangle, the empty string is returned. */
String r;
r="scalene";
if (x == y || y == z) { r="equilateral"; return r; }
if (x == z) { r="isosceles"; return r; }
if (x <= 0 || (x+y) <= z) { r=""; return r; }
return (r);
b) Statement coverage testing requires that all statements in the program executed at least once. Provide a test set which has a complete statement coverage. What kinds of error might this testing miss?
Explanation / Answer
As it is triangle, cyclomatic complexity is strongly connected graph. therefore, it is equal to total number of linear independent path in the graph [Jorgensen, 2002]. Therefore, the formula is
V(G)=e-n+p were e is the number of edges, n is the no. of nodes and p is the connected area.
therefore, the total test cases = 3 to the power of 3 = 27 test cases.
in any case of these kind of programs, with each statements due to multiple if else statements full path coverage is impossible to form
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.