CS FundamentalsModerateTCS NQT · Infosys

What is the minimum number of tests that gives 100% statement coverage of this fragment?

What is the minimum number of tests that gives 100% statement coverage of this fragment?
if a > 0:
    if b > 0:
        X()
    else:
        Y()
else:
    Z()
  1. A. 1
  2. B. 3
  3. C. 2
  4. D. 4

Correct answer: B. 3

X, Y and Z lie on mutually exclusive paths, so every one needs its own test: 3. The same 3 tests also give branch coverage, matching V(G) = 2 + 1 = 3.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic