CS FundamentalsVery hardProduct-company placement · GATE CS
The function below has cyclomatic complexity 3. What is the minimum number of test calls that achieves 100% branch coverage of it?
The function below has cyclomatic complexity 3. What is the minimum number of test calls that achieves 100% branch coverage of it?
def g(n):
steps = 0
while n != 1:
if n % 2 == 0:
n //= 2
else:
n = 3 * n + 1
steps += 1
return steps- A. 3
- B. 2
- C. 1
- D. 4
Correct answer: C. 1
g(3) runs 3 → 10 → 5 → 16 → 8 → 4 → 2 → 1, taking the odd branch, the even branch, the loop body and finally the loop exit, so one test covers all four outcomes. Cyclomatic complexity is an upper bound on the tests branch coverage needs, not the minimum.
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 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…
- A function is a straight sequence of three independent if-else statements, with no loops. What are (total entry-to-exit paths, cyclomatic…