Software Metrics Review-1: M.Vamsi Chowdhary 17MIS1133
Software Metrics Review-1: M.Vamsi Chowdhary 17MIS1133
Software Metrics Review-1: M.Vamsi Chowdhary 17MIS1133
REVIEW-1
M.VAMSI CHOWDHARY
17MIS1133
ABSTRACT:
Cyclomatic complexity is a software testing used to indicate the complexity of a
program. Lower the Program's cyclomatic complexity, lower the risk to modify
and easier to understand. It is a quantitative measure of the number of linearly
independent paths through a program's source code.
It was developed by Thomas J McCabe ,Sr in 1976.
Cyclomatic complexity is computed using the control the graph of the program:
the nodes of the graph correspond to indivisible groups of commands of a
program, and a directed edge connects two nodes if the second command might
be executed immediately after the first command.
Cyclomatic complexity may also be applied to individual functions, modules,
methods or classes within a program.
One testing strategy, called basis path testing by McCabe who first proposed it, is
to test each linearly independent path through the program; in this case, the
number of test cases will equal the cyclomatic complexity of the program.
Mathematically, the cyclomatic complexity of a structured program is defined with
reference to the control flow graph of the program, a directed graph containing
the basic blocks of the program, with an edge between two basic blocks if control
may pass from the first to the second.
The complexity M is then defined as
M = E − N + 2P,
where
E = the number of edges of the graph.
N = the number of nodes of the graph.
P = the number of connected components.
This may be seen as calculating the number of linearly independent cycles that
exist in the graph, i.e. those cycles that do not contain other cycles within
themselves.
Note that because each exit point loops back to the entry point, there is at least
one such cycle for each exit point.
McCabe showed that the cyclomatic complexity of any structured program with
only one entry point and one exit point is equal to the number of decision points
contained in that program plus one.
π−s+2
where
π is the number of decision points in the program
s is the number of exit points.
One would also expect that a module with higher complexity would tend to have
lower cohesion (less than functional cohesion) than a module with lower
complexity.
The possible correlation between higher complexity measure with a lower level of
cohesion is predicated on a module with more decision points generally
implementing more than a single well defined function.
A 2005 study showed stronger correlations between complexity metrics and an
expert assessment of cohesion in the classes studied than the correlation
between the expert's assessment and metrics designed to calculate cohesion.
M is a lower bound for the number of paths through the control flow
graph (CFG). Assuming each test case takes one path, the number of cases
needed to achieve path coverage is equal to the number of paths that can actually
be taken.
Cyclomatic complexity may also be used for the evaluation of the semantic
complexity of artificial intelligence programs.