CS FundamentalsVery hardProduct-company placement
For the call f([3], 5) on the function below, what decision (branch) coverage is achieved, treating the for loop as a decision with two outcomes (enter body / exit) and the compound if as one decision?
For the call f([3], 5) on the function below, what decision (branch) coverage is achieved, treating the for loop as a decision with two outcomes (enter body / exit) and the compound if as one decision?
def f(a, n):
total = 0
for x in a:
if x < 0:
continue
if x > n and x % 2 == 0:
total += x
elif x == n:
break
return total- A. 62.5%
- B. 50%
- C. 37.5%
- D. 75%
Correct answer: A. 62.5%
There are 4 decisions, so 8 outcomes. The loop both enters and exits (2), while x < 0, the compound if and x == n are each only False (3): 5/8 = 62.5%. Forgetting that the loop's exit outcome is covered gives 50%.
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
- The function below has cyclomatic complexity 3. What is the minimum number of test calls that achieves 100% branch coverage of it? python…
- A planar control-flow graph of a single function has 11 nodes and 14 edges. By the region method, McCabe's V(G) equals the number of…
- How many of these statements about coverage criteria are correct? 1. 100% branch coverage guarantees 100% statement coverage. 2. 100%…
- In Java, the non-short-circuit operator | evaluates both sides. For if ((a > 0) | (b > 0)) { X(); } else { Y(); } the tests (a = 1, b =…
- With short-circuit evaluation, how many distinct evaluation patterns (which conditions are evaluated and their values) can the decision (A…
- A loop can execute between 0 and 10 times (n = 10). Following Beizer's guidelines for simple-loop testing, which set of iteration counts…