Cyclomatic Complexity Calculations ( CC )

Discussion in 'Engineering Concepts' started by alssadi, Jul 5, 2011.

  1. alssadi

    alssadi Banned

    Joined:
    Dec 11, 2010
    Messages:
    41
    Likes Received:
    3
    Trophy Points:
    0
    Occupation:
    Creative director & web developer
    Location:
    Dubai
    Home Page:
    http://uaeinfographics.blogspot.com/
    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).

      [​IMG]
    • 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.

    [​IMG]

    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 .

    [​IMG]

    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 :

    [​IMG]

    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
     
    Last edited by a moderator: Jan 21, 2017

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice