码迷,mamicode.com
首页 > 其他好文 > 详细

Fault,Error与Failure的联系与区别

时间:2018-03-16 00:13:15      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:有一个   error   产生   空指针   逻辑   fail   ide   possible   函数   

 

 

Fault

可能导致程序失败的因素,可理解成具体的代码。

Error

在程序运行过程中与设计时的预先设想不一致的情况,如变量值错误,错误的运行路径等。

Failure

当一程序不能完成所要求的功能时,即失败。 

 

函数findLast

  1. Identify the fault.

在边界判断时出错 在i=0 时退出循环,没有检验第一个int值。

for循环中的条件判断应为:(int i=x.length-1; i > =0; i--)

2. If possible, identify a test case that does not execute the fault. (Reachability)

test: x=[]

直接抛出空指针异常而不执行以后的代码,所以没有执行fault

  1. If possible, identify a test case that executes the fault, but does not result in an error state.

test: x=[1, 2, 3]; y = 2

Expected= 1

执行了含有fault的代码在产生error返回了正确结果

4. If possible identify a test case that results in an error, but not a failure.

test: x=[2, 4, 5]; y = 1

Expected = -1

没有遍历到x[0],直接返回了-1,因此执行了error但是没有产生 failure

 

函数lastZero

1、 Identify the fault.

应该从后往前遍历,for循环中的条件判断应为:(int i=x.length-1; i > =0; i--);

2、 If possible, identify a test case that does not execute the fault. (Reachability)

test: x=[]

3、 If possible, identify a test case that executes the fault, but does not result in an error state.

test: x=[3, 2, 1];

Expected = -1

遍历了没有发现0 没有进入到error的情况。

4、 If possible identify a test case that results in an error, but not a failure.

test: x=[1, 2, 0]

Expected = 2

发生了error没有发生failure

返回了第一个0的位置 但只有一个0,结果正确,代码逻辑错误。 

 

Fault,Error与Failure的联系与区别

标签:有一个   error   产生   空指针   逻辑   fail   ide   possible   函数   

原文地址:https://www.cnblogs.com/scsji/p/8576854.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!