1. Identify the fault
1) for (int i=x.length-1; i > 0; i--)
Change to:for (int i=x.length; i > 0; i--)
2) for (int i = 0; i < x.length; i++)
Change to:for (int i=x.length; i > 0; i--)
2. If possible, identify a test case that does not execute the fault. (Reachability)
1) The test case is not reachable
The element of the test case are unique, which can not test whether it is the “last” element in X that equal to y.
2) The test case is reachable
The actual result is 0, so we can see there was something wrong with the codes.
3. If possible, identify a test case that executes the fault, but does not result in an error state.
1) Test: x=[2,3,4];y=2
Expected = 0
2) Test: x=[2,0,4];
Expected = 1;
4. If possible identify a test case that results in an error, but not a failure.
1) Test: x=[2,3,4];y=1
Expected = -1
2) Test: x=[1,3,4];
Expected = -1