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 at most two other students 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
}
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).
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).
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.
[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.
CC-BY-NC-SA 4.0 license.