|
DD Path graph is given in Fig. 20 (b)
Indeenden
e
(i) ABFGNPQR
(ii) ABFGNOQR
(iii) ABCEGNPQR
(iv) ABCDEGNOQR
(v) ABFGHIMQR
(vi) ABFGHJKMQR
(vii)ABFGHJMQR
O
|
Ô
Ôex
McCabe¶s cyclomatic metric V(G) = ± + 2P.
For example, a flow graph shown in in Fig. 21 with entry node µ¶ and exit node µ¶.
O O
|
÷he value of cyclomatic complexity can be calculated as :
V(G) = 9 ± 6 + 2 = 5
Here = 9, = 6 and P =1
÷here will be five independent paths for the flow graph illustrated in Fig. 21.
|
|evee
e
ex
e
ede
1. V(G) 1
2. V (G) is the maximum number of independent paths in graph G.
3. Inserting & deleting functional statements to G does not affect V(G).
4. G has only one path if and only if V(G)=1.
5. Inserting a new row in G increases V(G) by unity.
6. V(G) depends only on the decision structure of G.
|
÷he role of P in the complexity calculation V(G)=e-n+2P is required to be understood
correctly. We define a flow graph with unique entry and exit nodes, all nodes
reachable from the entry, and exit reachable from all nodes. ÷his definition would
result in all flow graphs having only one connected component. One could, however,
imagine a main program M and two called subroutines A and B having a flow graph
shown in Fig. 22.
O
|
Met us denote the total graph above with 3 connected components as
Õ `!
= 13-13+2*3
=6
÷his method with P 1 can be used to calculate the complexity of a
collection of programs, particularly a hierarchical nest of subroutines.
|
Notice that J Õ Õ J Î . In general, the
complexity of a collection C of flow graphs with K connected components is
equal to the summation of their complexities. ÷o see this let Ci,1 I K
denote the k distinct connected component, and let ei and ni be the number of edges
and nodes in the ith-connected component. ÷hen
Õ ` Õ `G
Õ `
|
÷wo alternate methods are available for the complexity calculations.
1. Cyclomatic complexity V(G) of a flow graph G is equal to the number of
predicate (decision) nodes plus one.
V(G)= +1
Where is the number of predicate nodes contained in the flow graph
G.
2. Cyclomatic complexity is equal to the number of regions of the flow
graph.
|
ëxe
Consider a flow graph given in Fig. 23 and calculate the cyclomatic
complexity by all three methods.
O
|
|
n
Cyclomatic complexity can be calculated by any of the three methods.
1. V(G) =± + 2P
= 13 ± 10 + 2 = 5
2. V(G) =ʌ+1
=4+1=5
3. V(G) = number of regions
=5
÷herefore, complexity value of a flow graph in Fig. 23 is 5.
|
ëxe
Consider the previous date program with DD path graph given in Fig. 17.
Find cyclomatic complexity.
|
|
n
Number of edges () = 65
Number of nodes ( ) =49
(i) V(G) = ± + 2P = 65 ± 49 + 2 = 18
(ii) V(G) = ʌ + 1 = 17 + 1 = 18
(iii) V(G) = Number of regions = 18
÷he cyclomatic complexity is 18.
|
ëxe
Consider the quadratic equation problem given in example 8.13 with its DD
Path graph. Find the cyclomatic complexity:
|
|
n
Number of nodes ( ) = 19
Number of edges () = 24
(i) V(G) = ± + 2P = 24 ± 19 + 2 = 7
(ii) V(G) = ʌ + 1 = 6 + 1 = 7
(iii) V(G) = Number of regions = 7
Hence cyclomatic complexity is 7 meaning thereby, seven
independent paths in the DD Path graph.
|
ëxe
Consider the classification of triangle problem given in example 8.14. Find
the cyclomatic complexity.
|
|
n
Number of edges () = 23
Number of nodes ( ) =18
(i) V(G) = ± + 2P = 23 ± 18 + 2 = 7
(ii) V(G) = ʌ + 1 = 6 + 1 = 7
(iii) V(G) = Number of regions = 7
÷he cyclomatic complexity is 7. Hence, there are seven independent paths
as given in example 8.14.
|
a
e
A graph matrix is a square matrix with one row and one column for every node in the
graph. ÷he size of the matrix (i.e., the number of rows and columns) is equal to the
number of nodes in the flow graph. Some examples of graphs and associated
matrices are shown in fig. 24.
O Ond
e
|
O Ond
e
|
O Ond
e
|
O Ônne
n
xn nO
|
÷he square matrix represent that there are two path and from node 1 to
node 2.
|
ëxe
Consider the flow graph shown in the Fig. 26 and draw the graph & connection
matrices. Find out cyclomatic complexity and two / three link paths from a node to
any other node.
O O
|
|
n
÷he graph & connection matrices are given below :
÷o find two link paths, we have to generate a square of graph matrix [A] and for three
link paths, a cube of matrix [A] is required.
|
|
Oe
n
Data flow testing is another from of structural testing. It has nothing to do with data
flow diagrams.
i. Statements where variables receive values.
ii. Statements where these values are used or referenced.
As we know, variables are defined and referenced throughout the program. We
may have few define/ reference anomalies:
i. A variable is defined but not used/ referenced.
ii. A variable is used but never defined.
iii. A variable is defined twice before it is used.
|
e n
n
÷he definitions refer to a program P that has a program graph G(P) and a set of
program variables V. ÷he G(P) has a single entry node and a single exit node. ÷he
set of all paths in P is PA÷HS(P)
e n n de Node n ' G(P) is a defining node of the variable î ' V,
written as DEF (î, ), if the value of the variable î is defined at the statement
fragment corresponding to node .
e de Node n ' G(P) is a usage node of the variable î ' V, written as
USE (î, ), if the value of the variable î is used at statement fragment
corresponding to node . A usage node USE (î, n) is a predicate use (denote
as p) if statement n is a predicate statement otherwise USE (î, n) is a
computation use (denoted as ).
|
e n
n e A definition use path with respect to a variable v (denoted
du-path) is a path in PA÷HS(P) such that, for some î ' V, there are define and
usage nodes DEF(v, m) and USE(v, n) such that m and n are initial and final
nodes of the path.
v
e n
n e A definition clear path with respect to a variable v (denoted
dc-path) is a definition use path in PA÷HS(P) with initial and final nodes DEF (î,
m) and USE (î, n), such that no other node in the path is a defining node of î.
÷he du-paths and dc-paths describe the flow of data across source statements from
points at which the values are defined to points at which the values are used. ÷he
du-paths that are not definition clear are potential trouble spots.
|
Hence, our objective is to find all du-paths and then identity those du-paths which are
not dc-paths. ÷he steps are given in Fig. 27. We may like to generate specific test
cases for du-paths that are not dc-paths.
O |
ed
e
n
|
ëxe
Consider the program of the determination of the nature of roots of a quadratic
equation. Its input is a triple of positive integers (say a,b,c) and values for each of
these may be from interval [0,100]. ÷he program is given in Fig. 19. ÷he output may
have one of the option given below:
(i) Not a quadratic program
(ii) real roots
(iii) imaginary roots
(iv) equal roots
(v) invalid inputs
Find all du-paths and identify those du-paths that are definition clear.
|
Ôn
|
O Ôded
e
ne
|
|
n
|
e I ÷he program flow graph is given in Fig. 19 (a). ÷he variables used in the
program are a,b,c,d, validinput, D.
|
e II DD Path graph is given in Fig. 19(b). ÷he cyclomatic complexity of this graph
is 7 indicating there are seven independent paths.
|
e III Define/use nodes for all variables are given below:
è e
e ned
nde ed
nde
a 6 11,13,18,20,24,27,28
b 8 11,18,20,24,28
c 10 11,18
d 18 19,22,23,27
D 23, 27 24,28
Validinput 3, 12, 14 17,31
|
|
e Iè ÷he du-paths are identified and are named by their beginning and ending
nodes using Fig. 19 (a).
è e
e nn n endnde
e n
ne!
6, 11 Yes
a
6, 13 Yes
6, 18 Yes
6, 20 Yes
6, 24 Yes
6, 27 Yes
6, 28 Yes
8, 11 Yes
b 8, 18 Yes
8, 20 Yes
8, 24 Yes
8, 28 Yes
|
è e
e nn n endnde
e n
ne!
10, 11 Yes
c
10, 18 Yes
d 18, 19 Yes
18, 22 Yes
18, 23 Yes
18, 27 Yes
D 23, 24 Yes
23, 28 Path not possible
27, 24 Path not possible
27, 28 Yes
3, 17 no
validinput
3, 31 no
12, 17 no
12, 31 no
14, 17 yes
14, 31 yes
|
ëxe
Consider the program given in Fig. 20 for the classification of a triangle. Its
input is a triple of positive integers (say a,b,c) from the interval [1,100]. ÷he
output may be:
[Scalene, Isosceles, Equilateral, Not a triangle, Invalid inputs].
Find all du-paths and identify those du-paths that are definition clear.
|
|
n
|
e I ÷he program flow graph is given in Fig. 20 (a). ÷he variables used in
the program are a,b,c, valid input.
|
e II DD Path graph is given in Fig. 20(b). ÷he cyclomatic complexity of
this graph is 7 and thus, there are 7 independent paths.
|
e III Define/use nodes for all variables are given below:
è e
e ned
nde ed
nde
a 6 10, 11, 19, 22
b 7 10, 11, 19, 22
c 9 10, 11, 19, 22
valid input 3, 13, 16 18, 29
|
|
e Iè ÷he du-paths are identified and are named by their beginning and ending
nodes using Fig. 20 (a).
è e
e nn n endnde
e n
ne!
5, 10 Yes
a
5, 11 Yes
5, 19 Yes
5, 22 Yes
7, 10 Yes
b 7, 11 Yes
7, 19 Yes
7, 22 Yes
|
è e
e nn n endnde
e n
ne!
9, 10 Yes
c
9, 11 Yes
9, 19 Yes
9, 22 Yes
3, 18 no
valid input
3, 29 no
12, 18 no
12, 29 no
16, 18 Yes
16, 29 Yes
Hence total du-paths are 18 out of which four paths are not definition clear
|
ne
n
Mutation testing is a fault based technique that is similar to fault seeding, except that
mutations to program statements are made in order to determine properties about
test cases. it is basically a fault simulation technique.
Multiple copies of a program are made, and each copy is altered; this altered copy is
called a mutant. Mutants are executed with test data to determine whether the test
data are capable of detecting the change between the original program and the
mutated program.
A mutant that is detected by a test case is termed ³killed´ and the goal of mutation
procedure is to find a set of test cases that are able to kill groups of mutant
programs.