Igor Adamenko
Igor Adamenko

Reputation: 878

How is cyclomatic complexity counted?

I'm reading Kent Beck's “TDD by Example” and I can't understand why the cyclomatic complexity of his program is fractional.

Table from the book

In Wikipedia the complexity is defined as M = E − N + 2P where E, N and P are integers.

Upvotes: 1

Views: 180

Answers (1)

Dave Schweisguth
Dave Schweisguth

Reputation: 37647

I believe that's the average of each method's standalone cyclomatic complexity (M = E - N + 2). I'm not going to calculate it myself, but

  • most of the methods shown have no conditionals by that point in the exercise (Kent eliminates them when he can), so their cyclomatic complexity is 1
  • Bank.rate does have a single if (page 63)

so it seems reasonable that the average is just above 1.

Upvotes: 2

Related Questions