SE Lec 10 - Control Flow Graph
SE Lec 10 - Control Flow Graph
ENGINEERING
In flow graph each circle (a flow graph node) represents one or more procedural statements.
A sequence of process boxes and a decision diamond can map into a single node.
The arrows on the flow graph called edges or links represents flow of control.
An edge must terminate at a node even if the node does not represent any procedural statements.
A compound condition occurs when one or more Boolean operators is present in a conditional statement
Each node that contains a condition is called a predicate node & is characterized by two or more edges
emanating from it.
Elements of Control Flow Graph
Process Block Decision
Point
Decision Point
Junction Point
Junction
Point
Process Block
A process block is a sequence of program statements that execute sequentially from
beginning to end.
Once the block is initiated, every statement within it will be executed sequentially.
Process blocks are represented in control flow graphs by a bubble with one or more
entries and one exit.
Decision Point
A decision point is a point in the module at which the control flow can change.
They are represented by a bubble with one entry and multiple exits.
Junction Point
A junction point is a point at which control flows join
together.
Path
A path through a program is a sequence
of statements that starts at an entry,
junction, or decision and ends at another
(possible the same), junction, decision, or
exit.
C
If C Then S1 else S2;
Sequential statement block
S1 S2
C Case C of
C
L1: S1; If C Then S1;
Sn L2: S2;
…
Kn: Sn; S1
end;
Flow Graphs of various blocks
C I=1
While C do S; For loop:
F for I = 1 to n do S;
T S
S
yes
I <=n
no
S1 Do loop:
do S1 until C;
F
C
T
Flow Graph
Cyclomatic Complexity [2]
Cyclomatic complexity is a software metric that provides a quantitative measure of
the global complexity of a program.
When this metric is used in the context of the basis path testing, the value
computed for cyclomatic complexity defines the number of independent paths
in the basis set of a program.
The number of regions of the flow graph correspond to the cyclomatic complexity.
Cyclomatic complexity, V(G), for a flow graph G is defined as
V(G) = E - N + 2, where E is the number of flow graph edges and N is the number of
flow graph nodes.
Cyclomatic complexity, V(G) = P + 1
where P is the number of predicate nodes contained in the flow graph G.
Example
Region, R= 6
Number of Nodes = 13
Number of edges = 17
Number of Predicate Nodes = 5
Cyclomatic Complexity, V( C) :
V( C ) = R = 6;
Or
V( C)= E-N+2
= 17-13+2
Assignment
i=1;
1
total.input = total.valid = 0; 2
Sum=0;
Do while value[i]<>-999 and total.input <= 100 3
4 increment total.input by 1;
IF value[i] >= minimum
5
6
THEN increment total.valid by 1;
sum = sum + value[I];
7 ENDIF
increment i by 1;
8 End
IF value[i] >0 9
10 THEN average = sum / total.valid;
ELSE average = -999;
11
ENDIF 12
END average
C(G), Quality and Testability
C(G) < 5
„simple and easy to understand‟
C(G) ≤ 10
„not too difficult‟
C(G) > 20
„complexity perceived as high‟
C(G) > 50
„for all practical purposes untestable‟
References
[1] Software Engineering by Roger Pressman
[2] http://www.freetutes.com/systemanalysis/sa9-white-box-testing.html
[3] http://docs.ncover.com/best-practices/code-quality-metrics/
[4] http://en.wikipedia.org/wiki/Unit_testing
[5] https://users.cs.jmu.edu/bernstdh/web/common/help/stubs-and-drivers.php
[6] http://www.cs.gmu.edu/~mcjunkin/cs112lectures/Stubs.htm
[7] http://agile.csc.ncsu.edu/SEMaterials/WhiteBox.pdf
[8] http://soft-testing.blogspot.com/2007/12/loop-testing.html
For any query Feel Free to ask