edited by
4,967 views
0 votes
0 votes

Consider the following method:

int f(int m, int n, boolean x, boolean y)
{
    int res=0;
    if (m<0) {res=n-m;}
    else if (x || y)
    {
        res=-1;
        if(n==m){res=1;}
    }
    else {res=n;}
    return res;
} /*end of f */

If $P$ is the minimum number of tests to achieve full statement coverage for $f()$, and $Q$ is the minimum number of tests to achieve full branch coverage for $f()$, then $(P,Q)$ = 

  1. $(3, 4)$
  2. $(4,3)$
  3. $(2,3)$
  4. $(3,2)$
edited by

2 Answers

0 votes
0 votes
Ans is (3,4)

 Full statement coverage means execution of all the executable statements in the source code at least once. So here,

first time keep m<0 to cover statements of if block

second time keep (x>0 or  y>0) and (n==m) to cover all statements of else if block

third time make above 2 conditiions false so that else block is executed.

Thus P= 3

In the branch coverage, every outcome from a code should be tested.

Here there are 4 outcomes possible, res = n-m, res= -1, res= 1, res = n. Observe else if block has 2 outcomes and therefore both should be covered which will require 2 test cases. if block and else block will require only 1 -1 testcases.

thus Q= 4
0 votes
0 votes
Ans A

Related questions

1 votes
1 votes
0 answers
3
0 votes
0 votes
2 answers
4
Arjun asked Jan 2, 2019
4,324 views
Consider the graph shown below:Use Kruskal’s algorithm to find the minimum spanning tree of the graph. The weight of this minimum spanning tree is$17$$14$$16$$13$