cyclomatic complexity, number of tests for full coverage?

Wikipedia says that following program has cyclomatic complexity of 3 Given that formula is V-E+2P, the answer is definitely 3 (9 - 8 + 2*1 = 3). Alternative definition says: Number of tests to cover all lines. But I see that only two tests are enough to cover 100% of lines. Test1 - always choosing left. (straight down) Test2 - always branching to the right once (or looping once) What am I missing? Why should there be 3 tests?

Jun 12, 2025 - 17:30
 0
cyclomatic complexity, number of tests for full coverage?

Wikipedia says that following program has cyclomatic complexity of 3

code with for+if

Given that formula is V-E+2P, the answer is definitely 3 (9 - 8 + 2*1 = 3).

Alternative definition says: Number of tests to cover all lines.

But I see that only two tests are enough to cover 100% of lines.

  1. Test1 - always choosing left. (straight down)
  2. Test2 - always branching to the right once (or looping once)

What am I missing? Why should there be 3 tests?