Program P1 1 integer A B 2 input A 3 while A 0 4 5 A 2
Program P1 :
1) integer A, B;
2) input (A);
3) while (A > 0)
4) {
5) A = 2 * A;
6) if (A < 20 or A > 30)
7) {
8) B = A * 2;
10) }
11) else
12) {
13) B = A + 2;
15) }
16) output (A, B);
17) input (A);
18) }
19) end;
T = {t1=<4>, t2=<25>, t3=<-1>}
or T = {t1=, t2=, t3=}
What is the statement domain for P1? Express as line numbers. Exclude syntactical markers, such as {, }, else, and end.
What is the statement coverage of T for P1? Express as a fraction.
If the statement coverage of T for P1 is less than 100%, what test cases do you need to add to get 100% statement coverage?
What is the decision domain for P1? Express as “line number) decision”.
What is the decision coverage of T for P1? Express as a fraction.
If the decision coverage of T for P1 is less than 100%, what test cases do you need to add to get 100% decision coverage?
What is the condition domain for P1? Express as “line number) condition”.
What is the condition coverage of T for P1? Express as a fraction.
If the condition coverage of T for P1 is less than 100%, what test cases do you need to add to get 100% condition coverage?
Solution
Answer:
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. Software coverage: Software 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].

