int binsearch (int X , int V [] , int n )  {      int low , high , mid , i ;      low = 0;      high = n - 1;            for ( i = 0; i < high ; i ++)      {          if( V[ i ] > V [ i +1])          return -2;      }                    while ( low <= high )          {              mid = ( low + high )/2;              if ( X < V [ mid ])              high = mid - 1;              else              if ( X > V [ mid ])              low = mid + 1;              else              return mid ;          }              return -1;  }   This code takes as input a sorted array V of size n, and an integer X, if X exists in the array it will return the index of X, else it will return -1. 1. Draw a CFG for binsearch(). 2. From the CFG, identify a set of entry–exit paths to satisfy the complete statement coverage criterion. 3. Identify additional paths, if necessary, to satisfy the complete branch coverage criterion. 4. For each path identified above, derive their path predicate expressions.

icon
Related questions
Question
int binsearch (int X , int V [] , int n )
 {
     int low , high , mid , i ;
     low = 0;
     high = n - 1;
     
     for ( i = 0; i < high ; i ++)
     {
         if( V[ i ] > V [ i +1])
         return -2;
     }
         
         while ( low <= high )
         {
             mid = ( low + high )/2;
             if ( X < V [ mid ])
             high = mid - 1;
             else
             if ( X > V [ mid ])
             low = mid + 1;
             else
             return mid ;
         }
             return -1;
 }
 

This code takes as input a sorted array V of size n, and an integer X, if X exists in the array it will return the index of X, else it will return -1.

1. Draw a CFG for binsearch().

2. From the CFG, identify a set of entry–exit paths to satisfy the complete statement coverage criterion.

3. Identify additional paths, if necessary, to satisfy the complete branch coverage criterion.

4. For each path identified above, derive their path predicate expressions.

5. Solve the path predicate expressions to generate test input and compute the corresponding expected outcomes.

6. Are all the selected paths feasible? If not, select and show that a path is infeasible, if it exists.

7. Can you introduce two faults in the routine so that these go undetected by your test cases designed for complete branch coverage?

8. Suggest a general way to detect the kinds of faults introduced in the previous step.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Concept of memory addresses in pointers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, data-structures-and-algorithms and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS