example of gragh and statement coverage and branch paths from textbook included)
Consider the following code
1 int binsearch (int X , int V [] , int n )
2 {
3 int low , high , mid , i ;
4 low = 0;
5 high = n - 1;
6
7 for ( i = 0; i < high ; i ++)
8 {
9 if( V[ i ] > V [ i +1])
10 return -2;
11 }
12
13 while ( low <= high )
14 {
15 mid = ( low + high )/2;
16 if ( X < V [ mid ])
17 high = mid - 1;
18 else
19 if ( X > V [ mid ])
20 low = mid + 1;
21 else
22 return mid ;
23 }
24 return -1;
25 }
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(). (please draw it)
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
