To solve this question, the user needs to know the concepts of statement coverage and branch coverage in software testing.
Statement coverage means that each statement in the code is executed at least once during testing. Branch coverage means that each possible branch or decision point in the code is executed at least once during testing.
In the given code, there are two decision points:
- IF P+Q > 100
- If P > 50
Now, let's go through each option and explain why it is right or wrong:
A. 1 test for statement coverage, 3 for branch coverage: This option is incorrect because it requires 3 tests for branch coverage. However, there are only two decision points in the code, so it is not possible to have three branches. Therefore, option A is incorrect.
B. 1 test for statement coverage, 2 for branch coverage: This option is correct. To achieve statement coverage, only one test case is required where P = 50 and Q = 51. This will execute all statements in the code. To achieve branch coverage, two test cases are required: one where P = 50 and Q = 51 (to cover the first decision point) and another where P = 51 and Q = 50 (to cover the second decision point). Therefore, option B is the correct answer.
C. 1 test for statement coverage, 1 for branch coverage: This option is incorrect because there are two decision points in the code that require two test cases for branch coverage. Therefore, option C is incorrect.
D. 2 tests for statement coverage, 3 for branch coverage: This option is incorrect because there are only two decision points in the code that require two test cases for branch coverage. Therefore, option D is incorrect.
E. 2 tests for statement coverage, 2 for branch coverage: This option is incorrect because only one test case is required for statement coverage. Therefore, option E is incorrect.
The Answer is: B. 1 test for statement coverage, 2 for branch coverage.