CS FundamentalsHardProduct-company MCQ pattern

For the code `if (x > 0) { y = 1; }` followed by `print(y)`, a single test with x = 5 is run. What coverage does it achieve?

  1. A. 100% statement and 100% branch coverage
  2. B. 50% statement coverage and 50% branch coverage
  3. C. 100% statement coverage but only 50% branch coverage
  4. D. 50% statement coverage and 100% branch coverage

Correct answer: C. 100% statement coverage but only 50% branch coverage

x = 5 executes every statement, but only the true outcome of the if is taken; the false outcome (x ≤ 0) is never exercised, so 1 of 2 branches = 50%. Branch coverage is the stronger criterion.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic