发现一个bug 编辑过程中如果将字体手动设置为黑色 那么使用黑色背景是不会自动变为灰色 如此
知识点回顾:
Fault、Error、Failure区别
Fault的定义:可能导致系统或功能失效的异常条件(Abnormal condition that can cause an element or an item tofail.),可译为“故障”。
Error的定义:计算、观察或测量值或条件,与真实、规定或理论上正确的值或条件之间的差异(Discrepancy between a computed, observed or measured value or condition and the true, specified, or theoretically correct value or condition.),可译为“错误”。Error是能够导致系统出现Failure的系统内部状态。
Failure的定义:当一个系统不能执行所要求的功能时,即为Failure,可译为“失效”。(Termination of the ability of an element or an item to perform a function as required.)
找出失败的三个条件RIP:
程序中包含错误的位置必须找到(可达性,reachability)
执行该位置后,程序的状态必须是不正确的(影响,infection)
受到影响的状态必须传播出来,引起该程序某个输出是不正确的(传播,propagation)
作业:
1 public int findLast (int[] x, int y) { //Effects: If x==null throw 2 NullPointerException 3 // else return the index of the last element // in x that equals y. 4 // If no such element exists, return -1 5 for (int i=x.length-1; i > 0; i--) 6 { 7 if (x[i] == y) { 8 return i; } 9 } 10 return -1; 11 } 12 // test: x=[2, 3, 5]; y = 2 // Expected = 0
错误是 第5行 循环条件应该为 i >= 0
可以看到12行测试用例中,当y出现在【0】位置 会导致故障而不会失效
y出现在其他位置 如 x=[2,3,5] y=5,不会执行故障
执行故障而不导致错误的测试用例不存在
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
错误:由于要找最后一个0 所以第六行应该从反序遍历
不会执行故障 不存在
执行故障但是不导致错误 不存在
执行故障但是不导致失效,当序列中只有一个或没有0时 如 x=[1,1,1] expected = -1 or x=[1,0,1] expected =1