CyclomaticComplexity - Maple Help

SoftwareMetrics

 CyclomaticComplexity
 compute McCabe's cyclomatic complexity metric

 Calling Sequence CyclomaticComplexity(prc, sm)

Parameters

 prc - Maple procedure, module, or list of procedures or modules sm - (optional) BooleanOpt(summarize); specifies whether to return the output in a tabular format or as a positive integer

Description

 • The CyclomaticComplexity routine computes Thomas McCabe's cyclomatic complexity metric for each procedure or module contained in the parameter prc. The metric represents the sum of the logic in the program which is based strictly on the number of decision elements.
 • The summarize option (sm) controls how the result is returned.
 If the summarize option is omitted (or is given as summarize=false), the result returned is an Array, which tabulates the cyclomatic complexity for each procedure and module contained in prc. Additionally, if prc contains at least two procedures (or a module with more than one export), the routine computes the total cyclomatic complexity for of all the procedures and modules combined. This total is included in the last row of the output Array.
 To force the display of large Arrays, you can increase the rtablesize setting using the interface function.
 If given as summarize=true, the result returned is a positive integer representing the total cyclomatic complexity of all of the procedures and modules contained in prc.
 The condition summarize=true can be abbreviated as summarize.

Examples

 > $\mathrm{with}\left(\mathrm{SoftwareMetrics}\right):$

Example procedure taken from the Maple Programming Guide

 > sieve := proc(n::integer)     local i, k, flags, count, twice_i;     count := 0;     for i from 2 to n do flags[i] := true end do;     for i from 2 to n do         if flags[i] then             twice_i := 2*i;             for k from twice_i by i to n do flags[k] := false end do;             count := count+1;         end if;     end do;     count; end proc:
 > $\mathrm{CyclomaticComplexity}\left('\mathrm{sieve}'\right)$
 $\left[\begin{array}{cc}{}& {\mathrm{Cyclomatic Complexity}}\\ {\mathrm{sieve}}& {5}\end{array}\right]$ (1)
 > $\mathrm{CyclomaticComplexity}\left('\mathrm{sieve}','\mathrm{summarize}'\right)$
 ${5}$ (2)

Examples using Maple library code

 > $\mathrm{CyclomaticComplexity}\left(\left['\mathrm{dsolve}','\mathrm{dsolve/numeric}'\right]\right)$
 $\left[\begin{array}{cc}{}& {\mathrm{Cyclomatic Complexity}}\\ {\mathrm{dsolve}}& {71}\\ {\mathrm{dsolve/numeric}}& {383}\\ {\mathrm{TOTAL}}& {454}\end{array}\right]$ (3)
 > $\mathrm{CyclomaticComplexity}\left('\mathrm{CurveFitting}'\right)$
 > $\mathrm{CyclomaticComplexity}\left('\mathrm{CurveFitting}','\mathrm{summarize}'\right)$
 ${376}$ (4)