1
4.3kviews
Consider the following program segment.


# include <stdio.h>
main ()
{ float x, y, z;
clrscr(),
printf( "enter the three variables x, y, z");
scanf( "%f%f" , &x, &y, &z);
if(x>y)
{
printf( "x is greatest");
else
printf ("z is gretest");
}
else
{
if (y > z)
printf ( " y is greatest" ),
else
printf( "z is greatest");
}
getch();
}
1) Draw the decision-to-decision graph or DD graph the above program.
2) Calculate the cyclomatic complexity of the program using all the methods.
3) List all the independent paths.
4) Design test cases from independent paths.

1 Answer
1
253views
  1. Draw decision-to-decision graph or DD graph

    enter image description here

  2. Cyclomatic complexity.

    1] V(G) = e - n + 2(p) = 15 - 13 + 2 = 4

    2] V(G) = Number of predicate nodes + 1 $(P_1, P_2, P_3)$ = 3 + 1 = 4

    3] V(G) = Number of regions = $4 (R_1, R_2, R_3, R_4)$

  3. Independent Paths.

    a) 1,2,3,4 - 5 - 6,7 - 8 - 10,11 - 19 -20 A - B - C - D - F - L - M
    b) 1,2,3,4 - 5 - 6,7 - 9 -10,11 - 19 -20 A - B - C - E - F - L - M
    c) 1,2,3,4 - 5 - 12 - 13, 14 - 15 - 17, 18 - 19 - 20 A - B - G - H - I -K -L -M
    d) 1,2,3,4 - 5 - 12 - 13, 14 - 16 - 17,18 - 19 - 20 AB - G - H - J - K - L - M
  4. Test cases from independent paths.

    Test case ID Input number X Y Z Expected result Independent paths covered by test case
    1 1 2 3 z is greatest A - B - G - H - J - K - L - M
    2 2 4 1 y is greatest A-B-G-H-I-K-L-M
    3 25 17 2 x is greatest A-B-C-D-F-L-M
    4 23 5 130 x is greatest A-B-C-E-F-L-M
Please log in to add an answer.