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
  1. A. 62.5%
  2. B. 50%
  3. C. 37.5%
  4. 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%.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic