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'- A. 60%; 2 more tests
- B. 80%; 1 more test
- C. 80%; 2 more tests
- 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.
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
- A program classifies three side lengths as equilateral, isosceles, scalene or 'not a triangle' (when the two shorter sides sum to no more…
- A class has fields a, b, c, d and methods m1 (uses a, b), m2 (uses b), m3 (uses c), m4 (uses c, d) and m5 (uses no field but calls m1)…
- A package has 10 classes, 2 of them abstract. 3 outside classes depend on it (Ca = 3) and it depends on 9 outside classes (Ce = 9). Using…
- What happens when this builder code runs? python class QB: def init(self): self.parts = [] def where(self, c): self.parts.append(c)…
- What does this plugin-registry code print? python class Plugin: registry = [] def init(self, name): self.registry.append(name) class…
- What does this Template Method code print? python class Base: def run(self): return self.a() + self.b() def a(self): return 'A' def…