软件测试技术第二次作业

题目:

1.出现的fault

(1)在

for(int i = x.length - 1; i > 0;i--)

中,没有遍历 i = 0 时的值,应该为:

for(int i = x.length - 1; i >= 0 ;i--)

(2)题干要求得到x数组最后一个值等于0的位置,因此for循环应从后向前遍历,将:

for(int i = 0;i < x.length; i++)

改为:

for(int i = x.length - 1; i >=0; i--)

2.不执行fault的用例

(1)

x = null;

当x为null时,抛出异常,从而不执行for循环中的错误代码。

(2)

x = null;

同理,第二段代码也将x数组改为null。

3.执行fault但不导致error

(1)

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

Expected:2

Actual:2

for循环从后向前遍历,在i = 2时x[2] = 3从而return 2,没有导致最后一次遍历应是i = 0而不是i = 1的情况。

(2)

x = [0];

Expected:0

Actual:0

由于x数组只有一个元素,所有x.length-1为0,从前到后遍历和从后向前遍历没有区别。

 4.导致error但不导致failure

(1)

x = [1, 2, 3]; y = 4;

Expected:-1

Actual:-1

完整的执行for循环,导致error,但由于x数组中没有与y相等的元素,导致return -1,没有出现failure。

(2)

x = [1, 0, 1];

Expected:1

Actual:1

该程序本应从后向前遍历,但实现是从前向后,导致error,但由于x数组中只有一个0,所有没有导致failure。

posted @ 2017-03-01 14:50  一洛  阅读(194)  评论(0编辑  收藏  举报