CS FundamentalsVery hardProduct-company placement · TCS Digital
For the function below, which single call executes every statement (100% statement coverage)?
For the function below, which single call executes every statement (100% statement coverage)?
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. f([8, 5, -1], 5)
- B. f([-1, 8, 5], 5)
- C. f([-1, 7, 5], 5)
- D. f([5, -1, 8], 5)
Correct answer: B. f([-1, 8, 5], 5)
[-1, 8, 5] hits continue (-1), total += x (8 is > 5 and even) and then break (5). In [8, 5, -1] and [5, -1, 8] the loop breaks at 5 before reaching -1 or 8; 7 is odd, so total += x never runs.
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 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 =…
- With short-circuit evaluation, how many distinct evaluation patterns (which conditions are evaluated and their values) can the decision (A…