Visio 2016 Key
Visio 2016 Key
MIDTERM SECTION #2
6 (a)
6 (b)
10-11
6 (c)
For this CFG line number is 6 is break into 3 parts i.e, parameters of for loop.
For example: for ( 6a; 6b; 6c) 6a: int n=1; 6b: n < (99+1); 6c: n++;
And our exit node is 6b ie., when condition of the loop will not satisfy then flow gets exit from the
loop and there is no any path flow outside of the loop. So the final node will be 6b
The cyclomatic complexity of this function:-
Where,
P = represents a number of nodes that have exit points in the control flow graph.
M = E – N +2*P
M = 7- 6 + 2(1)
M=1+2 M=3
According to the Cyclomatic Complexity number i.e., 3, there are three possible paths are possible of
the code flow. And there are minimum 3 test cases needed (at least one for each path) in the given
method to test the all the paths. As according to the definition, Cyclomatic complexity of a section of
source code is the number of linearly independent paths through the source code. Mathematically
Cyclomatic Complexity of a structured program is defined with reference to control flow graph of the
program. Cyclomatic complexity is used to determine minimum number of test cases that are
necessary to achieve complete test coverage of a particular program.
56(a)6(b)8(10-11)6(c)6(b) //i.e., Flow goes from both for loop and if statement
56(a)6(b)86(c)6(b) // i.e., Flow goes from for loop but not from if statement.
56(a)6(b) // i.e., Flow doesn’t go from both for loop and if statement.