Multiple choice technology testing

Given the following code, which is true about the minimum number of test cases required for full statement and branch coverage: Read P Read Q IF P+Q > 100 THEN Print “Large” ENDIF If P > 50 THEN Print “P Large” ENDIF

  1. 1 test for statement coverage, 3 for branch coverage

  2. 1 test for statement coverage, 2 for branch coverage

  3. 1 test for statement coverage, 1 for branch coverage

  4. 2 tests for statement coverage, 2 for branch coverage

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Statement coverage requires every statement to be executed at least once. With test values P=60, Q=50, both IF conditions are true and all 4 statements execute, achieving statement coverage in 1 test. Branch coverage requires both true and false outcomes for each decision. There are 2 IF statements (branches): P+Q>100 and P>50. The second branch (P>50) is only reached when the first is true. With P=60, Q=50 both are true; with P=30, Q=40 both are false. Thus 2 tests achieve full branch coverage.