Fault是静态编码时的程序设计时的错误,例如for循环数组中计数器i从1开始循环,这个就是fault。
error是能够导致系统出现failure的内部状态。(这个建议结合下面的例子看)
failure是运行到fault并且发生了故障,导致与预期的结果不一致。
举个板栗:
QUESTION
There are 3 conditions in the PIE model. Please construct a simple program P (with a fault) and 4 test cases (t1, t2, t3, t4), s.t.(1) t1 did not execute the fault.
(2) t2 executes the fault, but no error.
(3) t3 (executes the fault and) produces an error, but no failure.
(4) t4 produces a failure.
ANSWER
int sort(int []x,int n)
{
for(int i=x.length-1;i>0;i++)
{
if (x[i]==n)
return i;
}
return 0;
}
TESTING
t1:x=[],n=1
t2:x=[1,2,3],n=3
t3:x=[1,2,3],n=5
t4:x=[1,2,3],n=1
t1空数组,函数都没执行,所以没有执行到fault;
t2从数组后面开始数,执行了Fault (i>0)但是没有引发error,因为刚开始遍历就找到了;
t3执行到了fault,引发了error但是没有触发failure,因为与预期结果一致。没有5这个数在数组中,所以返回0;
t4执行到了fault,引发了error,偏偏要找的数就是x[0],而fault(i>0),所以导致了failure。