CS FundamentalsVery hardProduct company interview · GATE level
The tests (x = 3, y = 4) and (x = -2, y = 7) are run on this function. What statement, branch (decision) and condition coverage do they achieve? (Condition coverage counts the true and false outcomes of each of the three simple conditions; and short-circuits.)
The tests (x = 3, y = 4) and (x = -2, y = 7) are run on this function. What statement, branch (decision) and condition coverage do they achieve? (Condition coverage counts the true and false outcomes of each of the three simple conditions; and short-circuits.)
def f(x, y):
r = 0
if x > 0:
r = 1
if y > 0 and x < 5:
r = r + 2
else:
r = r - 1
return r- A. Statement 80%, branch 75%, condition 100%
- B. Statement 100%, branch 75%, condition 67%
- C. Statement 80%, branch 100%, condition 67%
- D. Statement 80%, branch 75%, condition 67%
Correct answer: D. Statement 80%, branch 75%, condition 67%
Count the five simple statements r = 0, r = 1, r = r + 2, r = r - 1 and return r. Both tests make the second decision true, so r = r - 1 never runs: 4/5 = 80%. Branches: the first if goes both ways (3 > 0, -2 > 0 false), the second only to its true side: 3 of 4 outcomes, 75%. Conditions: x > 0 is seen true and false, but y > 0 and x < 5 are only ever true: 4 of 6 outcomes, 67%. A test such as (x = 6, y = 1) would add the missing false outcomes.
Practise more Software Engineering, Git and Cloud Basics questionsSoftware Engineering, Git and Cloud Basics: notes and key points
More Software Engineering, Git and Cloud Basics questions
- Basic COCOMO for a semi-detached project uses Effort = 3.0 x KLOC^1.12 person-months and Development time = 2.5 x Effort^0.35 months. For…
- Intermediate COCOMO for an organic project uses Effort = 3.2 x KLOC^1.05 x EAF, where EAF is the product of the cost-driver multipliers. A…
- Function point counts with weights in brackets: external inputs - 6 simple (3), 4 average (4), 2 complex (6); external outputs - 5 average…
- A system is estimated at 300 function points, and the chosen language averages 53 lines of code per function point. Using basic COCOMO for…
- A program has 12 distinct operators, 20 distinct operands, 90 total operator occurrences and 70 total operand occurrences. Using…
- Activities (duration in days; predecessors): A (4; -), B (6; -), C (3; A), D (5; A), E (4; B, C), F (7; B), G (3; D, E), H (2; F, G), I…