Hw2
findLast Solution:
(a)fault:for循环中应该包含i=0的情况;
(b)当输入数据为空时将会产生空指针错误,程序不会执行for循环,所以不会executes the fault:
test: x=null;y = 3;
Expected = NullPointerException;
Actual = NullPointerException;
(c)对于任意测试用例中期待的值等于输入数据第二个或更靠后位置的元素时,不会产生error;当x为空时,也不会产生error:
test:x = [2,3,5]; y = 3;
Expected = 1;
Actual = 1;
(d)对于所期待的值不存在在输入数据中时,会产生error,但不会产生failure:
test:x = [2,3,4]; y = 5;
Expected = -1;
Actual = -1.
LastZero Solution:
(a)fault:for循环中的搜索应该从后向前搜索;
(b)任意的输入包括null都会经过程序的fault;
(c)当循环不能展开或者当for循环只能执行一次时,将不产生error:
test: x = [3];
Expected = -1;
Actual = -1;
(d)任意输入如果for循环展开的次数大于1,则会产生error,因为这时元素查找都不是递减的顺序:
test : x = [2,0,5];
Expected = 1;
Actual = 1