标签:
1 public int findLast (int[] x, int y) { 2 //Effects: If x==null throw 3 NullPointerException 4 // else return the index of the last element 5 // in x that equals y. 6 // If no such element exists, return -1 7 for (int i=x.length-1; i > 0; i--) 8 { 9 if (x[i] == y) 10 { 11 return i; 12 } 13 } 14 return -1; 15 } 16 // test: x=[2, 3, 5]; y = 2 17 // Expected = 0
错误:
for (int i=x.length-1; i > 0; i--)
应改为
for (int i=x.length-1; i >= 0; i--) //原代码中不会遍历到数组中第0个数据
不会执行故障的用例: x = [2,3,5];y = 5;Excepted = 2;
执行故障但是不会导致错误状态的测试用例: ??
导致故障而不会失败的测试用例: x = [2,3,5];y = 0; Excepted = -1;
1 public static int lastZero (int[] x) { 2 //Effects: if x==null throw 3 NullPointerException 4 // else return the index of the LAST 0 in x. 5 // Return -1 if 0 does not occur in x 6 for (int i = 0; i < x.length; i++) 7 { 8 if (x[i] == 0) 9 { 10 return i; 11 } 12 } return -1; 13 } 14 // test: x=[0, 1, 0] 15 // Expected = 2
错误:
for (int i = 0; i < x.length; i++)
应改为
for (int i = x.length - 1; i >= 0 ; i--) //原代码搜索出数组中第一个0而非最后一个
不会执行故障的测试用例: ??
执行故障但是不会导致错误状态的测试用例: ??
导致故障而不会失败的测试用例: x = [1,0,1]; Expected = 1;
知识点:
Reachability:项目中错误的位置是可以找到的
infection:项目中该阶段必须是不正确的
Propagation:项目中有有影响的部分必须导致一些输出或结果的不正确
标签:
原文地址:http://www.cnblogs.com/yi-jie/p/5256448.html