Wednesday, January 12, 2011

Cyclomatic Complexity

Cyclomatic complexity is a software metric that provides a quantitative measure of the logical complexity of a program. When used in the context of the basis path-testing method, the value computed for cyclomatic complexity defines the number of independent paths in the basis set of a program, and provides us with an upper bound for the number of tests that must be conducted to ensure that all statements have been executed at least once.
An independent path is any path through the program that introduces at least one new set of processing statements or a new condition.

Cyclomatic complexity has a foundation in graph theory and is computed in one of three ways:
  1. The number of regions corresponds to the cyclomatic complexity.

  2. Cyclomatic complexity, V (G), for a flowgraph G, is defined as
    V(G)=E-N+2,
    where
    E=Number of flowgraph edges
    N=Number of flowgraph nodes.
  3.  Cyclomatic complexity, V (G) for a flowgraph G, is also defined as

    V(G)=P+1,
    where
    P = Number of predicate nodes contained in flow graphs G. 
    The value V (G) provides us with an upper bound for the number of independent paths that comprise the basis set, and by implication, an upper bound on the number of tests that must be designed and executed to guarantee coverage of all program statements.

No comments:

Post a Comment