public static int findLast(int[]x,int y){
for(int i = x.length-1;i>0;i--){//i>=0
if(x[i] == y){
return i;
}
}
return -1;
}
a)Identify the fault
For循环中的i>0应该为i>=0
b)If possible,identify a test case that does not execute the fault
空数组,此时抛出空指针异常
c)If possible,identify a test case that execute the fault,but does not result in an error state
X=[2,3,2];y=2
d)If possible,identify a test case that result in an error,but not a failure.
X=[2,3,4];y=2
public static int lastZero(int[]x){
for(int i = 0;i<x.length;i++){
if(x[i] == 0){
return i;
}
}
return -1;
}
a)Identify the fault
For循环中应该为int i = x.length-1;i>-0;i--
b)If possible,identify a test case that does not execute the fault
空数组,此时抛出空指针异常
c)If possible,identify a test case that execute the fault,but does not result in an error state
X=[2,3,0]
d)If possible,identify a test case that result in an error,but not a failure.
X=[0,3,0]
原文:http://www.cnblogs.com/guoxinqi/p/5248847.html