Cyclomatic complexity

NikitaKesharwani 3,914 views 22 slides Apr 12, 2018
Slide 1
Slide 1 of 22
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22

About This Presentation

Detail about cyclomatic complexity, formula to measure cyclomatic complexity and how this metric useful in software testing and uses of cyclomatic complexity etc.


Slide Content

Cyclomatic
Complexity
Cyclomatic
Complexity
Presented By:
Nikita Kesharwani

Overview..
What is Software Design?
Software Metrics.
Complexity.
Cyclomatic Complexity.
Example.
Determine Cyclometic Complexity.
How this metrics is useful for software Testing?
Uses of Cyclometic Complexity.
Conclusion.

What is a Software Design?
SoftwareDesignisaprocessto
transformuserrequirementsinto
somesuitableformwhichhelpsthe
programmerinsoftwarecodingand
implementation.

Toimprovequalityofasoftware,weneed
tomeasurevariousaspects:-
Size,
Complexity,
Maintainabilityofsoftwareetc..
Is Software Metrics Required...
Choosingtherightmetricscanmakethe
differencebetweensuccessandfailureofa
project.

TheTermComplexityStandsforstateof
eventsorthings,whichhavemultiple
interconnectedlinksandhighlycomplicated
structures.
Complexity...

Cont...
Complexitycanbeinterpretedindifferentways:-
Problemcomplexity(alsocalledcomputationalcomplexity)
measuresthecomplexityoftheunderlyingproblem.
Algorithmiccomplexityreflectsthecomplexityofthe
algorithmimplementedtosolvetheproblem.
Structuralcomplexitymeasuresthestructureofthesoftware
usedtoimplementthealgorithm.
Cognitivecomplexitymeasurestheeffortrequiredto
understandthesoftware.

Cyclometic Complexity..
Aprogramconsistsofstatements.
Someofthemaredecisionmakingwhichchange
theflowofprogram.
DevelopedbyMcCabe,in1976.
Measures the number of linearly independent
paths through a program.
LowertheProgram'scyclomaticcomplexity,
lowertherisktomodifyandeasiertounderstand.

Cont..
Thecomplexitywouldbe1,since
therewouldbeonlyasinglepath
throughthecode.
Ifthecodehadonesingle-conditionIF
statement,therewouldbetwopaths
throughthecode,sothecomplexity
wouldbe2.

Determine Cyclometic Complexity..
Thereareseveralmethods:
1.Cyclomaticcomplexity=edges-nodes+2p
2.Cyclomaticcomplexity=NumberofPredicate
Nodes+1
3.Cyclomaticcomplexity=Numberofregionsin
thecontrolflowgraph

Example..
Cyclometic Complexity = Edges –Nodes + 2P
P= Number of unconnected parts of the graph.

Another Example..
[1—2—6]
[1—2—3—5—2—6]
[1—2—3—4—5—2—6]
Cyclomatic Complexity
= 7 -6 + 2*1 = 3
In this Example:-

Cont..
Cyclomatic Complexity
= 7 -8 + 2*2 = 3
In this Example:-

Cont..
Cyclomatic Complexity
= 2 + 1 = 3
In this Example:-
Cyclomatic complexity= Number of Predicate
Nodes + 1

Cont..
Cyclomatic Complexity
= 3
In this Example:-
Cyclomatic complexity = number of regions in
the control flow graph.

How this metric is useful
for software testing..
BasisPathtestingisoneofWhiteboxtechnique
anditguaranteestoexecuteatleastonestatement
duringtesting.
Itcheckseachlinearlyindependentpaththrough
theprogram.

Cont..
Whichmeansnumberoftestcases,willbe
equivalenttothecyclomaticcomplexityofthe
program.

Cont..
Asyoucandeducefromtheabovetable,eventhe
smallestapplicationwrittentakenasawholewill
behaveveryhighCyclomaticcomplexity,soit's
measuredatfunctionlevel.
Industrystandardisnottohaveanyfunctionin
yourapplicationhavingCyclomaticcomplexity
greaterthan10.

Cont..
Theadvantageofthisisafunctioncanhave
maximumtestcaseof10.
Andresearchhasproventhatmostcomputer
programmerscaneasilyreadandmodifyfunctions
thatarehavingCyclomaticcomplexitylessthanor
equalto10.
Ascognitiveloadonhumanmindisless.

Uses of Cyclomatic Complexity..
CyclomaticComplexitycanprovetobeveryhelpfulin:-
Helpsdevelopersandtesterstodetermine
independentpathexecutions.
Developerscanassurethatallthepathshave
beentestedatleastonce.
Helpsustofocusmoreontheuncoveredpaths.
Evaluatetheriskassociatedwiththeapplication
orprogram.

Conclusion..
It is mainly used to evaluate complexity of a
program.
If the decision points are more, then complexity
of the program is more.
If program has high complexity number, then
probability of error is high with increased time for
maintenance and trouble shoot.