ISEB-SWTINT1 · Question #39
Given the following fragment of code, how many tests are required for 100% decision coverage? discount = 0 order_quantity=0 real order_quantity if order_quantity >=20 then discount = 0.05 if…
The correct answer is A. 3. Option A (3 tests) is correct because the code contains 2 decisions (the outer if order_quantity >= 20 and the inner if order_quantity >= 100), and decision coverage requires each decision to evaluate to both TRUE and FALSE. The three test cases needed are: (1) order_quantity <…
Question
Options
- A
- B
- C
- D
How the community answered
(52 responses)- A71% (37)
- B4% (2)
- C8% (4)
- D17% (9)
Explanation
Option A (3 tests) is correct because the code contains 2 decisions (the outer if order_quantity >= 20 and the inner if order_quantity >= 100), and decision coverage requires each decision to evaluate to both TRUE and FALSE. The three test cases needed are: (1) order_quantity < 20 - outer decision FALSE, inner never reached; (2) 20 ≤ order_quantity < 100 - outer TRUE, inner FALSE; (3) order_quantity ≥ 100 - both TRUE.
Option D (2) is wrong because two tests cannot cover all four decision outcomes - you'd have to leave at least one branch unexercised. Options B (4) and C (5) are wrong because they overcount; once both decisions have been driven TRUE and FALSE, coverage is complete with no additional tests needed.
Memory tip: For nested if statements, count the decisions and remember that a FALSE on the outer if "skips" the inner one entirely - so you don't need a separate test for the inner FALSE independently of the outer TRUE. That nesting is what keeps it at 3, not 4.
Topics
Community Discussion
No community discussion yet for this question.