edited by
5,064 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

3.8k
views
2 answers
0 votes
Arjun asked Jan 2, 2019
3,762 views
​​​​​​A survey has been conducted on methods of commuter travel. Each respondent was asked to check Bus, Train and Automobile as a major method of travelling ...
1.7k
views
1 answers
0 votes
Arjun asked Jan 2, 2019
1,713 views
The relation $\leq$ and $>$ on a boolean algebra are defined as:$x \leq y$ if and only if $x \vee y =y$$x <y$ means $x \leq y$ but $x \neq y$$x \geq y$ means $y \leq x$ a...
985
views
0 answers
1 votes
Arjun asked Jan 2, 2019
985 views
Use Dual Simplex Method to solve the following problem:$\begin{array} \text{Maximize} & z=-2x_1-3x_2 \\ \text{subject to:} & \\ & x_1+x_2 \geq 2 \\ & 2x_1 +x_2 \leq10 \\ ...
4.5k
views
2 answers
0 votes
Arjun asked Jan 2, 2019
4,486 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$