Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Engineering Concepts (http://www.go4expert.com/articles/engineering-concepts-tutorials/)
-   -   Cyclomatic Complexity Calculations ( CC ) (http://www.go4expert.com/articles/cyclomatic-complexity-calculations-cc-t26214/)

alssadi 6Jul2011 03:45

Cyclomatic Complexity Calculations ( CC )
 
Cyclomatic Complexity its a type of white box testing for Structural testing use under reference of code complexity.

Facts about why White Box Testing?

  • Most programe coding represents what the program actually dose and not what intended to do.
  • It minimizes delay between defect injection and defect detection.
  • Can catch "obvious" programming errors that do not necessarily map to common user scenarios ( e.g. divide by zero ).

How Cyclomatic Complexity can help ?



Cyclomatic Complexity provides answers to such a questions like :-
  • Which of the paths are independent ?
  • Can we be able to minimize the number of tests of an application?
  • Is there any boundary on the number of tests to be executed to ensure that all statements have been executed at least once ?
Cyclomatic Complexity can provide answers to some of these questions.

Steps in Determining Cyclomatic Complexity :-


  • Start with a conventional flow chart.
  • Identify the "decision points."
  • Convert "complex predicates" to "simple predicates" (see figure below).

    http://imgs.g4estatic.com/cyclomatic...8d73e2805b.png
  • If there are loops, convert the loop conditions to simple predicates.
  • Combine all the sequential statements into a single node in the flow graph.
  • When a set of sequential statements are followed by a simple predicate, combine all the sequential statements and the predicate check into one node and have two edges emanating out of this node. Nodes with two emanating edges are called predicate nodes.
  • Make sure that all edges terminate in some node, adding a node to represent all the statements at the end of the program.

http://imgs.g4estatic.com/cyclomatic...9296340374.png

Example of Cyclomatic Complexity demonstration?



In this post we will demonstrate how to calculate the Cyclomatic Complexity, in order to do the right calculations based on the following flow chart detailing the functions of Java application, which checks to see if a Person's username and password are correct before granting access to an online E-commerce site .

http://imgs.g4estatic.com/cyclomatic...60ddeb8439.png

First of all we will create a flow graph/diagram based on the flow chart above .

So lets have a look what have we done here :

http://imgs.g4estatic.com/cyclomatic...b37efde7eb.png

Cyclomatic Complexity = number of edges - number of nodes + 2

= ( 7 - 5 ) +2 = 4

The Cyclomatic Complexity of this software application is 4

I hope i have made a bit of a good explanation of the CC in software testing and quality assurance, any information regarding to this post , please feel free to ask, although i didnt cover everything but the most important things ;) .

With all kind regards
Hisham Alssadi


All times are GMT +5.5. The time now is 05:32.