Assume the flow graph of a function is below (sorry I have forgotten the code of the function):enter image description here
And when I try to calculate the cyclomatic complexity:
When I use the edge and node to calculate it, V(G)= 9 - 8 + 2 = 3
; when I use the branch node to calculate it, V(G) = 3 + 1 = 4
. However, when I try to find the independent paths, I think I can find 4 paths:
Path 1: 1 -> 2 -> 6 -> 7
Path 2: 1 -> 2 -> 6 -> 8
Path 3: 1 -> 2 -> 3 -> 5 -> 2 -> ...
Path 4: 1 -> 2 -> 3 -> 4 -> 5 -> 2 -> ...
And I wonder which one is correct and what is my mistake? Thanks a lot.
-
The simplified formulas don't work because you have multiple exit points (states 7 and 8). There are more complete formulas, or you can introduce an exit state E plus the edges 7→E, 8→E.amon– amon2020年01月04日 15:20:00 +00:00Commented Jan 4, 2020 at 15:20
-
@amon I think it should be 7->E, 8->EPaul Zhang– Paul Zhang2020年01月04日 16:13:46 +00:00Commented Jan 4, 2020 at 16:13