• edited by
9,472 views
12 12 votes

The following program is to be tested for statement coverage:

begin
    if (a==b) {S1; exit;}
    else if (c==d) {S2;}
        else {S3; exit;}
    S4;
end

The test cases T1, T2, T3 and T4 given below are expressed in terms of the properties satisfied by the values of variables $a,\:b,\:c$ and $d$. The exact values are not given.

T1: a, b, c and d are all equal

T2: a, b, c and d are all distinct

T3: a = b and c != d

T4: a != b and c = d

Which of the test suites given below ensures coverage of statements S1, S2, S3 and S4?

  1. T1, T2, T3
  2. T2, T4
  3. T3, T4
  4. T1, T2, T4

6 Answers

Best answer
33 33 votes
T1 covers S1

T2 covers S3

T3 covers S1

T4 covers S2, S4

so inorder to cover all 4 either T1,T2, T4 or  T2, T3 , T4

option D
• selected by
3 3 votes
#include <stdio.h>
#include <stdlib.h>
void main(){
	int a=2;
	int b=3;
	int c=4;
	int d=4;

	if(a==b){
		printf("a is equal to b\n");exit;
	}
	else if(c==d){
		printf("b is equal to d\n");exit;
	}
	else 
		printf("b is not equal to d\n");exit;

	printf("s4 case\n");
}

This is code you can change values appropriately and get the answer.

T1 covers: s1,s4

T2 covers: s3,s4

T3 covers: s1,s4

T1 covers: s2,s4

Ans: D. T1, T2, T3

2 2 votes
T2 is essential because it is the only statement covering S4, eliminate option (c)

S2 can be covered by T4 only

now condition a==b leading to S1 can be satisfied by T1 only.

Answer : (d)
1 1 vote

To achieve statement coverage, we need to ensure that all statements (S1, S2, S3, and S4) are executed at least once by the test cases. Let's analyze each test case to check which statements are executed:

Program logic breakdown:

  1. If (a == b):

    • If true, S1 is executed, and the program exits.
    • If false, the second condition if (c == d) is checked.
  2. If (c == d) (executed when a != b):

    • If true, S2 is executed.
    • If false, S3 is executed, and the program exits.
  3. After S2 (if c == d is true), the program moves to S4.

Test case analysis:

  • T1: a == b, c == d (i.e., a, b, c, d are all equal)

    • The first condition a == b is true, so S1 is executed, and the program exits. (Only S1 is covered.)
  • T2: a != b, c != d (i.e., a, b, c, d are all distinct)

    • The first condition a == b is false, so it checks c == d.
    • The second condition c == d is also false, so S3 is executed, and the program exits. (Only S3 is covered.)
  • T3: a == b, c != d

    • The first condition a == b is true, so S1 is executed, and the program exits. (Only S1 is covered.)
  • T4: a != b, c == d

    • The first condition a == b is false, so it checks c == d.
    • The second condition c == d is true, so S2 is executed, followed by S4. (S2 and S4 are covered.)

Test Suite Analysis:

  • Option (a) T1, T2, T3:

    • T1: covers S1.
    • T2: covers S3.
    • T3: covers S1 again (redundant).
    • This suite does not cover S2 or S4.
  • Option (b) T2, T4:

    • T2: covers S3.
    • T4: covers S2 and S4.
    • This suite does not cover S1.
  • Option (c) T3, T4:

    • T3: covers S1.
    • T4: covers S2 and S4.
    • This suite does not cover S3.
  • Option (d) T1, T2, T4:

    • T1: covers S1.
    • T2: covers S3.
    • T4: covers S2 and S4.
    • This suite covers all statements: S1, S2, S3, and S4.

Correct Answer:

(d) T1, T2, T4 ensures coverage of all statements (S1, S2, S3, and S4).

0 0 votes
For condition if(a == b)

T1 is valid as it's just asking if a == b

For condition elseif(c==d)

T4 is valid as elseif only executes if previous if condition was false so a!=b and c==d

For condition else

T2 is valid as neither a==b not c==d
Answer:
Position:
Show:

Related questions

15 15 votes
4 answers 4 answers
19.0k
19.0k views
go_editor asked Sep 29, 2014
18,991 views
The cyclomatic complexity of each of the modules $\text{A}$ and $\text{B}$ shown below is $10.$ What is the cyclomatic complexity of the sequential integration shown on t...
9 9 votes
5 answers 5 answers
9.0k
9.0k views
go_editor asked Sep 28, 2014
8,950 views
In the context of modular software design, which one of the following combinations is desirable?High cohesion and high couplingHigh cohesion and low couplingLow cohesion ...
4 4 votes
1 answers 1 answer
3.9k
3.9k views
go_editor asked Feb 12, 2015
3,872 views
Which one of the following assertions concerning code inspection and code walkthrough is true?Code inspection is carried out once the code has been unit testedCode inspec...
3 3 votes
1 answers 1 answer
4.1k
4.1k views
go_editor asked Sep 29, 2014
4,071 views
What is the appropriate pairing of items in the two columns listing various activities encountered in a software life cycle?P. Requirements Capture 1. Module...