Let's assume that we have a code like this:
switch(y)
{
case 1: case 2: case 3:
function();
break;
case 4: case 5: case 6:
function_2();
break;
}
Can we get the CC value as 6+1 here? Why a value of 1 is added? If the CC value is considered as 7, is that the number of independent paths?
What if a fall through scenario is considered above? As only possible two unique paths are there, 2 +1 =3
Which of the above are correct or are the both of them correct?
As we know, CC = P+1.
Here, P = number of predicate nodes (conditions) = 2
Number of conditions will be 2 because:
Case branch can cover several alternative values or ranges, such as Case 1, 2, 5 To 10. As they introduce no additional branches to decide on, they do not increase cyclomatic complexity either.
source: here
So, CC = 2+1 = 3
来源:https://stackoverflow.com/questions/39055516/clarifying-the-manual-count-of-cyclomatic-complexity