Exercise: Statement coverage & Branch/Decision coverage:
1) a. Calculate statement coverage
Read A b. Calculate Branch/Decision coverage
Read B
IF A+B > 10 THEN
Print "A+B is Large"
ENDIF
If A > 5 THEN
Print "A Large"
ENDIF
2) a. How many tests are required to achieve 100% statement
READ X coverage?
READ Y b. How many tests are required to achieve 100% Branch
IF “X > Y” coverage?
PRINT X is greater that Y
ENDIF
3) a. How many tests are required to achieve 100% statement
IF A > B THEN coverage?
C=A–B b. How many tests are required to achieve 100%
ELSE Branch/Decision coverage?
C=A+B
ENDIF
Read D
IF C = D
Then Print “Error”
ENDIF
4) a. Calculate total number of statement coverage
Example (int x) b. Calculate total number of Branch/Decision coverage
{
if (x < 10)
print("x < 10")
else
print("x >= 10")
}
5) a. How many tests are required to achieve 100% statement
1 READ A coverage?
2 READ B b. How many tests are required to achieve 100%
3 C = A – 2 *B Branch/Decision coverage?
4 IFC <0THEN
5 PRINT “C negative”
6 ENDIF
1
6) a. Calculate statement coverage
Test (int a=3) b. Calculate Branch/Decision coverage
{ if (a>4)
a=a*3
print (a)
}
7) a. How many tests are required to achieve 100% statement
Read X coverage?
Read Y b. How many tests are required to achieve 100%
IF X+Y > 100 THEN Branch/Decision coverage?
Print "Large"
ENDIF
If X + Y<100 THEN
Print "Small"
ENDIF
8) a. How many tests are required to achieve 100% statement
Read A coverage?
Read B b. How many tests are required to achieve 100%
If A > B then Branch/Decision coverage?
x=0
End if
9) a. How many tests are required to achieve 100% statement
Read X, Y coverage?
if X > Y then b. How many tests are required to achieve 100%
print "X is Greater" Branch/Decision coverage?
else
print Y is Greater
End
10) a. How many tests are required to achieve 100% statement
Input a, b coverage?
Let c = a + b b. How many tests are required to achieve 100%
If c < 10, print c Branch/Decision coverage?
Else, print ‘Sorry’
11) a. Calculate total number of statement coverage
if(a=2) b. Calculate total number of Branch/Decision coverage
print "execute this line";
else
print "executing else statement";
end if;
2
12) a. How many tests are required to achieve 100% statement
Read a coverage?
Read b b. How many tests are required to achieve 100%
if a>b Branch/Decision coverage?
print "a is largest"
else
if a==b
print "Both a and b are equivalent"
else
print "b is largest number"
end if