TR = { line1, line2, line3, line4, line5 }
You may make a copy of a worksheet and complete this activity, or simply type your answers in any text editor.
You may work alone or with another student in this course.
public static int numZero(int[] x)
{
// Effects: if x == null throw NullPointerException
// else return the number of occurrences of 0 in x
int count = 0; // line 1
for (int i=0; i<x.length; i++) // line 2
{
if (x[i] == 0) // line 3
count++; // line 4
}
return count; // line 5
}
TR = { line1, line2, line3, line4, line5 }
TR = { NPE-B1, B1, !B1, B2, !B2 }
where NPE-B1 represents the true value of (x == null) in if x == null
B1 represents the true value of i<x.length
!B1 represents the false value of i<x.length
B2 represents the true value of (x[i] == 0) in if (x[i] == 0)
!B2 represents the false value of (x[i] == 0) in if (x[i] == 0)
where test case t1 has test input x=[5], t2 has test input x=[1,2,3], and t3 has test input x=[].
Compute the coverage level of test set T on line coverage criterion (question 1).
4/5 = 80% (missing line4)
where test case t1 has test input x=[5], t2 has test input x=[1,2,3], and t3 has test input x=[].
Compute the coverage level of test set T on branch coverage criterion (question 2).
3/5 = 60% (missing NPE-B1, B2)
For this SUT, branch coverage subsume line coverage
where test case t1 has test input x=[5], t2 has test input x=[1,2,3], and t3 has test input x=[].
Compute the coverage level of test set T on your coverage criterion.
Note: let C1 be a line coverage criterion and C2 be your coverage criterion. Further suppose that test set T1 satisfies C1 on the numZero() method and test set T2 satisfies C2 on the numZero() method. If C2 subsumes C1, T2 also satisfies C1, but T1 does not necessarily satisfy C2.
[Thought question] Suppose there is a fault in the numZero() method and suppose that Humpty's coverage criterion subsumes a line coverage criterion.
Let T1 be a set of tests that satisfies a line coverage criterion and T2 be a set of tests that satisfies Humpty's coverage criterion.
If T1 reveals the fault, can we conclude that T2 also reveals the fault? Justify.
No. (This is a hard question.) People often think that test sets for strong criteria are at least as good at finding faults as test sets for weaker criteria. But subsumption is about criteria, not about test sets. In particular, there is no requirement that test set T1 be a subset of test set T2. So, it could happen that T1 contains that one test that reveals the fault, and T2 doesn’t.
CC-BY-NC-SA 4.0 license.