In: Computer Science
Program P1
1) integer A, B;
2) input (A);
3) while (A > 0)
4) {
5) B = 1;
6) if (A < 10)
7) B = 0;
8) if (A < 20 or A > 25)
9) B = A * B;
10) else
11) B = A + B;
12) output (A, B);
13) input (A);
14) }
15) output (“Program ends.”);
16) end;
T = {t1=<1>, t2=<33>, t3=<‐1>} or T = {t1=, t2=, t3=}
1. What is the statement domain for P1? Express as line numbers. Exclude syntactical markers, such as {, }, else, and end.
2. What is the statement coverage of T for P1? Express as an unsimplified fraction.
Answer 1
Statement domain contains all the line sequences which will be executed based on input value of A.
In given program if A <= 0 then program will not enter into while loop and exit simply so statement domain for A<=0 will be (1,2,3)
In given program if A < 10 and A > 0 then program will enter into while loop and both If conditions will be true. statement domain will be (1,2,3,5,6,7,8,9,12,13)
In given program if A >10 and A<20 then program will enter into while loop and second If conditions will be true. statement domain will be (1,2,3,5,6,8,9,12,13)
In given program if A >=20 or A<=25 then program will enter into while loop and both If conditions will be false. statement domain will be (1,2,3,5,6,8,11,12,13)
Similarly statement domain for P1 will be
{ (1,2,3), (1,2,3,5,6,7,8,9,12,13), (1,2,3,5,6,8,9,12,13), (1,2,3,5,6,8,11,12,13) }
Answer 2
t1 = 1
Statement domain for t1=1 will be (1,2,3,5,6,7,8,9,12,13)
So, coverage will be = number of lines covered / total lines = 10/11 = 91%
t2 = 33
Statement domain for t2=33 will be (1,2,3,5,6,8,9,12,13)
So, coverage will be = number of lines covered / total lines = 9/11 = 81%
t3 = -1
Statement domain for t3=-1 will be (1,2,3)
So, coverage will be = number of lines covered / total lines = 3/11 = 27%