To determine the number of tests required for statement coverage and branch coverage, we need to consider the different paths or branches in the code.
Let's analyze the given code:
IF A > B THEN
C = A – B
ELSE
C = A + B
ENDIF
Read D
IF C = D Then
Print “Error”
ENDIF
For statement coverage, we need to ensure that each statement in the code is executed at least once. In this case, we have the following statements:
- IF A > B THEN
- C = A – B
- ELSE
- C = A + B
- Read D
- IF C = D Then
- Print “Error”
To cover all the statements, we need to execute the code at least twice: once when A > B and once when A <= B. Therefore, we need 2 tests for statement coverage.
Now let's consider branch coverage. Branch coverage requires that each possible branch or decision point in the code is taken at least once. In this case, we have the following branches:
- A > B (True branch) or A <= B (False branch)
- C = D (True branch) or C != D (False branch)
To cover all the branches, we need to take both branches for the A > B decision (True and False branches) and both branches for the C = D decision (True and False branches). Therefore, we need 2 tests for branch coverage.
Therefore, the correct answer is B) 2 tests for statement coverage, 2 for branch coverage.