Tutorial-7: DD Path Testing: Case of a Triangle
Objective of the Tutorial: To draw a Flow Graph, a DD Graph, calculation of Cyclomatic Complexity V(G) and find out all independent paths from the DD paths graph, for the case of a triangle wherein the program reads the three sides of a triangle (say a, b, c). The output may be Scalene triangle or a Isosceles triangle or an equilateral triangle or might not be a triangle at all.
When we have a flow graph, we can easily draw another graph that is known as decision-to-decision or (DD) path graph, wherein we lay our main focus on the decision nodes only. The nodes of the flow graph are combined into a single node it they are in sequence.
Process of constructing the DD Graph leading to computation of Cyclomatic Complexity goes like this:
Step 1: Start writing the following C – program
# include
# include
(1) int main ( )
(2) {
(3) int a, b, c, boolean = 0;
(4) printf (“nt Enter side-a :”);
(5) scanf (“%d”, & a);
(6) printf(“nt Enter side-b :”);
(7) scanf (“%d”, & b);
(8) printf (“nt Enter side-c:”);
(9) scanf (�’%d”, & c);
(10) if ((a > 0) && (a < – 100) && (b > 0) && (b < . 100) && (c > 0) && (c < =100)) {
(11) if ((a + b) > c) && ((c + a) > b) && ((b + c) > a)) {
(12) boolean = 1;
(13) }
(14) }
(15) else {
(16) boolean = -1;
(17) }
(18) if (boolean = = 1) {
(19) if ((a = =b) && (b = =c)) {
(20) printf (“Triangle is equilateral”);
(21) }
(22) else if ((a = =b) I I (b = = c) I I (c = = a)) {
(23) print (“Triangle is isosceles”);
(24) }
(25) else {
(26) printf(“Triangle is scalene�);
(27) }
(28) }
(29) else if (boolean = = 0) {
(30) printf (“Not a triangle”);
(31) }
(32) else
(33) printf (“n invalid input range”);
(34) }
(35) getch ( );
(36) return -1;
(37) }
Step 2: Draw the following Flow Graph
Step 3: Draw the following DD Path Graph
Since, nodes 1-9 are sequential nodes in the above flow graph, hence they are merged together as a single node � �a�.
Likewise we can go on deciding the merging of nodes & arrive at the following DD Path Graph
We get following decision table.
Step 4: Calculation of Cyclomatic Complexity V(G) by three methods
Method 1: V(G) = e � n + 2 ( Where �e� are edges & �n� are nodes)
V(G) = 23� 18+ 2 = 5 + 2 = 7
Method 2: V(G) = P + 1 (Where P � No. of predicate nodes with out degree = 2)
V(G) = 6 + 1 = 7 (Nodes b, c, g, h, j & n are predicate nodes with 2 outgoing edges)
Method 3: V(G) = Number of enclosed regions + 1 = 6+1=7
( Here R1, R2, R3, R4, R5 & R6 are the enclosed regions and 1 corresponds to one outer region)
V(G) = 7 and is same by all the three methods.
Step 5: Identification of the basis-set with Seven Paths
Conclusions from the above tutorial:
Conclusion 1: Each of these paths consists of at least one new edge. Hence this basis set of paths is NOT unique.
Conclusion 2: Test cases should be designed for the independent path execution as identified above.
Conclusion 3: We must execute these paths at least once in order to test the program thoroughly.
Many more Articles & Tutorials on White Box Testing
An expert on R&D, Online Training and Publishing. He is M.Tech. (Honours) and is a part of the STG team since inception.
Why from 10 to 18?
Path from 18 direct to 35?