CS FundamentalsVery hardProduct-company placement · ISTQB-style

The suite { classify([]), classify([1, -2]) } runs against the function below. Treating each if, the for loop (enter / skip-or-exit) and the conditional expression as two-outcome decisions, what decision coverage does it reach, and how many more tests are needed for 100%?

The suite { classify([]), classify([1, -2]) } runs against the function below. Treating each if, the for loop (enter / skip-or-exit) and the conditional expression as two-outcome decisions, what decision coverage does it reach, and how many more tests are needed for 100%?
def classify(a):
    if not a:
        return 'empty'
    neg = 0
    for x in a:
        if x < 0:
            neg += 1
            if neg > 2:
                return 'many'
    return 'some' if neg else 'none'
  1. A. 60%; 2 more tests
  2. B. 80%; 1 more test
  3. C. 80%; 2 more tests
  4. D. 70%; 2 more tests

Correct answer: C. 80%; 2 more tests

Of 10 outcomes the two tests cover 8: both of 'not a', loop enter and exit, x < 0 both ways, neg > 2 false and the 'some' side. Missing are neg > 2 true (needs three negatives, which returns early) and the 'none' side (no negatives). No one input does both, so 2 more tests.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic