CS FundamentalsHardProduct-company placement · Infosys SP
Counting each simple condition separately (each 'and'/'or' adds one) and each loop header as one decision, what is the cyclomatic complexity of this function?
Counting each simple condition separately (each 'and'/'or' adds one) and each loop header as one decision, what is the cyclomatic complexity of this function?
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. 5
- B. 3
- C. 6
- D. 1
Correct answer: C. 6
Decisions: for (1), x < 0 (1), x > n and x % 2 == 0 (2), x == n (1) = 5, so V(G) = 6. Counting the compound condition as one gives 5, counting only the three if/elif tests gives 3, and 1 treats the function as a single path.
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
- For the function below, which single call executes every statement (100% statement coverage)? python def f(a, n): total = 0 for x in a: if…
- 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…
- 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 =…