Consider the method mcq():
int mcq(boolean a, boolean b, boolean c, boolean d)
{
int ans = 1;
if (a) { ans = 2; }
else if (b) { ans = 3; }
else if (c) { if (d) { ans = 4; } }
return ans;
}
Let M1 = number of tests to exhaustively test mcq(), M2 = minimum number of tests to achieve full statement coverage, and M3 = minimum number of tests to achieve full branch coverage. Then the value of (M1, M2, M3) is:
{
int ans = 1;
if (a) { ans = 2; }
else if (b) { ans = 3; }
else if (c) { if (d) { ans = 4; } }
return ans;
}
Pick an option to check yourself, or open the answer below.
Show answer & explanation
Correct answer: A. (16, 3, 5)
Explanation
M1: four boolean inputs give 24 = 16 exhaustive combinations. M2 (statement coverage): three tests suffice — a=T executes ans=2, (a=F, b=T) executes ans=3, and (a=F, b=F, c=T, d=T) executes ans=4; the statements ans=1 and return run in every test, so M2 = 3. M3 (branch coverage): every decision must take both outcomes, so we also need a case where c is false and a case where d is false. The five tests are a=T; (a=F,b=T); (a=F,b=F,c=F); (a=F,b=F,c=T,d=T); (a=F,b=F,c=T,d=F), giving M3 = 5. Hence (M1, M2, M3) = (16, 3, 5).More System Software and Operating System questions
- What is the normal order of activities in which traditional software testing is organised? 1. Integration Testing 2. System Testing 3. Unit…
- Which of the following testing techniques ensures that the software product runs correctly after the changes during maintenance?
- Which of the following statement(s) is/are TRUE with regard to software testing? I. Regression testing technique ensures that the software…
- For a program of k variables, boundary value analysis yields ______ test cases.
- The cyclomatic complexity of a flow graph V(G), in terms of predicate nodes, is: [where P is the number of predicate nodes in the flow grap…
- In software testing, how are error, fault and failure related to each other?