4. For the following program P3 written in pseudo-code, given the test set T: T
ID: 3700097 • Letter: 4
Question
4. For the following program P3 written in pseudo-code, given the test set T: T == {t1 == <-5, 2>, t2 == <3, 1>, t3 == <9, 3>} a) What is the domain for statement coverage of P3? Note: do not include syntactical markers such as comments, {, }, else, begin, end.
b) What is the statement coverage for T?
c) What test cases (if any) should you add to T to provide 100% statement coverage?
d) What is the domain for decision coverage of P3?
e) What is the decision coverage for T?
f) What test cases (if any) should you add to T to provide 100% decision coverage?
g) What is the domain for condition coverage of P3?
h) What is the condition coverage for T?
i) What test cases (if any) should you add to T to provide 100% condition coverage?
Program P3
1) integer A, B, C;
2) input (A, B);
3) if (A<-8 or A>8 or B<0 or B>3)
4) {
5) output (“Boundary condition failure on inputs.”);
6) }
7) else // valid input
8) {
9) C = A * B;
10) if (A < 0)
11) {
12) C = C + A + B;
13) if (B > 1)
14) {
15) C = C + 3;
16) } // end if (B>1)
17) C == C * C;
18) } // end if (A<0)
19) else
20) {
21) C = C – A – B;
22) if (B == 1)
23) {
24) C = B * C;
25) } // end if (B=1)
26) else
27) {
28) C = B / C;
29) } // end else !(B=1)
30) C = C + 2;
31) } // end else !(A<0)
32) output (A, B, C);
33) } // end else valid input
34) return 0;
35) end;
Explanation / Answer
a)
Domain for statement coverage:
t1={2,3,9,21,22,24,30,32}
t2={2,3,5}
Therefore
domain = {2,3,5,9,21,22,24,30,32}
b)Statement coverage for T :
For set t1 statement coverage = 8/9 = 88.08%
For set t2 statement coverage = 3/9 = 33.33%
c)
Domain for decision coverage:
Coverage domain De= {3,10,13,22}
d)
Decision coverage for T:
t1 = {3,10,13}
t2={3}
Coverage domain De = {3,10,13,22}
Decisions covered Dc = {3,10,13}
Infeasible decision Di = {13}
Decision coverage = 3/(4-1) = 1
1. Statement domain for P1: Statement domain of P1 will constitute all those line sequences which can possibly be executed depending on the inputted value of A. It can be given as follows:
{ (1,2,3), (1,2,3,5,8,16,17), (1,2,3,5,6,13,16,17)}
2. Statement coverage: Statement coverage refers to a test scenario (case) in which every statement of the program is executed at least once. It can be calculated as:
Statement coverage = (No. of executed statements/No. of total statements)*100;
T specifies three scenarios for P1. That is:
a) t1=<4>: For this, second line sequence of statement domain will be executed. Hence, executed statements=7, total statements (excluding syntactical markers as assumed) = 9. Therefore:
Statement coverage = (7/9)*100 = 77.78%
b) t2=<25>: For this again, second line sequence of statement domain will be executed. Hence in this case also:
Statement coverage = 77.78%
c) t3=<-1>: For this, first line sequence of statement domain will be executed. Hence for this case:
Statement coverage = (3/9)*100 = 33.33%
It is clear that third line sequence will never be executed with the given test cases and statement coverage is not 100%.
For 100% statement coverage, it will be required to add new test cases to T and new test case should be such that else part of condition at line 6 (third line sequence of statement domain) is executed. Such a test case can be for any value of A in range [20,30].
3. Decision domain: Decision domain refers to all possible decision paths that can be executed in a program. For P1, it can be specified as:
{ (3), (3,6), (3,5,6,8), (3,5,6,13)}
4. Decision coverage: Decision coverage refers to the scenario in which each condition takes on all possible results of condition at least once. Same as explained above, with the given test cases under T, decision coverage will not be 100% and it will be required to add new test cases to T. Such a test case can be for any value of A in range [20,30].
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.