All mock tests are FREE till 31 December — register to save your progress

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:

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