All mock tests are FREE till 31 December — register to save your progress
Unit 6 · Software Engineering Paper 2 CS · December 2018

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 for full statement coverage of f() and Q is the minimum number for full branch coverage, then (P, Q) =

Pick an option to check yourself, or open the answer below.

Show answer & explanation

Correct answer: A. (3,4)

Explanation

Statements: one test with m < 0, one with x || y true and n == m (covers res = −1 and res = 1), one with everything false: P = 3. Branches also need the n == m false outcome, adding a fourth test: Q = 4.

More Software Engineering questions