I have to calculate Cyclomatic Complexity for a Cobol program that contains only an EVALUATE like this one:
EVALUATE x
WHEN x<0 ...
WHEN x=0 ...
WHEN x between 1 and 10 ...
WHEN OTHER ...`
END EVALUATE.`
I have also to calculate Cyclomatic Complexity for a Cobol program that contains only an IF statement like this one:`
IF x<0 ...
ELSE IF x=0 ...
ELSE ...
What is the algorithm to calculate CC? Thanks for your time.
You can find the algorithm for Cyclomatic Complexity at Wikipedia.
You'll have to draw flowcharts and count edges and paths ... with that and some thought you should be able to do this exercise.
There are two useful hints that may help you.
1) In a structured program (no gotos), CC turns out be equal to number of conditions, plus 1. Your example programs look structured to me.
2) If you think about it carefully, your EVALUTE statement and your collection of IF statements seem like equivalent code. So you should expect the computed CC values to be the same.