Answer questions (a) through (d) for the mutant in the two methods, findVal() an
ID: 3682264 • Letter: A
Question
Answer questions (a) through (d) for the mutant in the two methods, findVal()
and sum().
(a) If possible, find a test input that does not reach the mutant.
(b) If possible, find a test input that satisfies reachability but not infection for
the mutant.
(c) If possible, find a test input that satisfies infection, but not propagation
for the mutant.
(d) If possible, find a test input that kills mutant m.
//Effects: If numbers null throw NullPointerException
// else return LAST occurrence of val in numbers[]
// If val not in numbers[] return -1
1. public static int findVal(int numbers[], int val)
2. {
3. int findVal = -1;
4.
5. for (int i=0; i<numbers.length; i++)
5’.// for (int i=(0+1); i<numbers.length; i++)
6.
if (numbers [i] == val)
7.
findVal = i;
8. return (findVal);
9. }
//Effects: If x null throw NullPointerException
// else return the sum of the values in x
1. public static int sum(int[] x)
2. {
3. int s = 0;
4. for (int i=0; i < x.length; i++) }
5. {
6.
s = s + x[i];
6’. // s = s - x[i]; //AOR
7. }
8. return s;
9. }
Explanation / Answer
Assuming
(d) not only depends on the input but also on the test oracle -- achieving propagation does not imply killing the mutant.
The following inputs satisfy the requirements:
(a) There exists no such input; the loop initializer int i = 0 is executed for every input, even if numbers is null and consequently numbers.length raises a NullPointerException. Note that only a test that does not call the findVal method can't reach the mutant -- calling findVal implies satisfying reachability for this mutant.
(b) There exists no such input; the mutated expression is independent of the method parameters (i=0 != i=1 for any input) -- satisfying reachability implies satisfying infection for this mutant.
(c) numbers is an empty array; if numbers.length is 0, then the initial value of i (for any i>=0) doesn't matter, even though the state of i is infected. Passing in null for numbers is another example that satisfies infection but not propagation.
(d) numbers is a one-element array, whose element value equals val. There are many inputs that satisfy propagation, which means that the mutant can be killed -- whether the test actually kills the mutant depends on whether the test asserts on the outcome.