Software Metrics Review-1: M.Vamsi Chowdhary 17MIS1133

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

SOFTWARE METRICS

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.

An alternative formulation is to use a graph in which each exit point is connected


back to the entry point. In this case, the graph is strongly connected, and the
cyclomatic complexity of the program is equal to the cyclomatic complexity of its
graph (also known as the first Bette number), which is defined as
M = E − N + P.

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.

For a single program (or subroutine or method), P is always equal to 1. So a


simpler formula for a single subroutine is
M = E − N + 2.

Cyclomatic complexity may, however, be applied to several such programs or


subprograms at the same time (e.g., to all of the methods in a class), and in
these cases P will be equal to the number of programs in question, as each
subprogram will appear as a disconnected subset of the graph.

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.

Cyclomatic complexity may be extended to a program with multiple exit points; in


this case it is equal to

π−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.

Another application of cyclomatic complexity is in determining the number of test


cases that are necessary to achieve thorough test coverage of a particular
module.

It is useful because of two properties of the cyclomatic complexity, M, for a


specific module:

M is an upper bound for the number of test cases that are


necessary to achieve a complete branch coverage.

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.

Cyclomatic complexity has proven useful in geographical and landscape-


ecological analysis, after it was shown that it can be implemented on graphs that
are ultrametric distances.

cyclomatic complexity testing tools:

1) The JaCoCo Jenkins pipeline plugin


2) SonarQube

You might also like