0% found this document useful (0 votes)
42 views17 pages

SE Lec 10 - Control Flow Graph

Software engineering

Uploaded by

Tahir2 Siddiqui
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views17 pages

SE Lec 10 - Control Flow Graph

Software engineering

Uploaded by

Tahir2 Siddiqui
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

SOFTWARE

ENGINEERING

SOFTWARE TESTING - III (DYNAMIC)


WHITE BOX TESTING
Topics to Cover

 Control Flow Graph 


Cyclomatic Complexity
 Graph Matrices
Control Flow Graph
 A simple notation for the representation of control flow is called a flow graph (or program graph).

 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.

 Areas bounded by edges and nodes are called regions.

 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.

 Most decision points are binary and are implemented by if-then-else


statements.

 Multi-way decision points are implemented by case statements.

 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.

 A path may go through several junctions,


processes, or decisions, one or more times.

 Paths consist of segments.

 The length of a path is the number of


links in a path.
Flow Graphs of various blocks [1]

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.

 Three ways to compute cyclomatic complexity:

 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) = Predicate Nodes + 1


=5+1 =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

You might also like