1
5.5kviews
Draw the Control Flow Graph and show the coverage criteria for given code

This question appears in Mumbai University > Software Testing & Quality Assurance Subject

Marks: 10 M

Year: June 2012

1 Answer
0
50views

public static double Return Average ( int value [ ], int AS, int MIN, int MAX)

{

int i, ti, tv, sum;

doubleav;

i=0 ;ti= 0; tv=0 ; sum = 0;

while ( ti< AS && value[i] != -999)
{

ti++ ;

if( value [i] >= MIN && value [i] < = MAX)

{

tv++ ;

sum = sum + value [i] ;

}

i++; }

if(tv<0)

av = (double) sum/tv;

else

av = (double) -999;

return (av) ;

}

Control Flow Graph for Return Average Method :

enter image description here

Figure : A CFG Representation of ReturnAverage( ). Numbers 1 – 13 are the nodes.

Coverage criteria for Return Average Code :

  • Branch Coverage Criteria : Complete branch coverage means selecting a path such that every branch is included in at least one path.

Paths for branch coverage for ReturnAverage program are :

  1. BCPath1 : 1-2-3(F)-10(F)-11-13

  2. BCPath2 : 1-2-3(T)-4(F)-10(F)-11-13

  3. BCPath3 : 1-2-3(T)-4(T)-5-6(F)-7-8-9-3(F)-10(T)-12-13

  4. BCPath4 : 1-2-3(T)-4(T)-5-6(F)-9-3(F)-10(F)-11-13

  5. BCPath5 : 1-2-3(T)-4(T)-5-6(T)-7(F)-9-3(F)-10(F)-11-13

Statement Coverage Criteria :Statement Coverage criteria refers to executing individual program statements and observing the outcome. 100% statement coverage has been achieved if all the statements have been executed at least once.

Paths for statement coverage for ReturnAverage program are :

  1. SCPath1 : 1-2-3(F)-10(F)-11-13

  2. SCPath2 : 1-2-3(T)-4(T)-5-6(T)-7(T)-8-9-3(F)-10(T)-12-13

  • Path Selection Criteria :

    • Select all the paths.

    • Select paths to achieve complete statement coverage.

    • Select paths to achieve complete branch coverage.

    • Select paths to achieve predicate coverage.

Path Selection Criteria for ReturnAverage program are :

  1. Path 1 : 1-2-3(F)-10(T)-12-13
  2. Path 2 : 1-2-3(F)-10(F)-11-13
  3. Path 3 : 1-2-3(T)-4(T)-5-6(T)-7(T)-8-9-3(F)-10(T)-12-13
  4. Path 4 : 1-2-3(T)-4(T)-5-6(T)-7(T)-8-9-3(T)-4(T)-5-6(T)-7(T)-8-9-3(F)-10(T)-12-13
Please log in to add an answer.