(1) FindLast
public int FindLast (int[] x, int. y) {//effects:if x==null thrownullpointerexception//else return the index of the last element//In X that equals y.//if no such element exists, return-1for (int i=x.length-1; i > 0; i--) {If (x[i] = = y) {return i;}} return-1;} Test:x=[2, 3, 5]; y = 2//expected = 0
(a) Identify the fault:
for (int i=x.length-1; i > 0; i--), "i>0" should is "i>=0", otherwise, the 0 index can not is included
(b) If possible, identify a test case this does not execute the fault. (reachability)
Test:x=null;y=1;
Expected=null;
fact = null;
(c) If possible, identify a test case this executes the fault, but does not the result of an error state.
test:x=[3,2,5];y=2
expected=1;
fact = 1;
(d) If possible identify a test case this results in an error, and not a failure.
test:x=[3,2,5]; Y=6
expected =-1;
fact =-1;
(2) Lastzero
public static int Lastzero (int[] x) {//effects:if x==null thrownullpointerexception//else return the index of the last 0 in X.//Return-1 If 0 does not occur in xfor (int i = 0; i < x.length; i++) {if (x[i] = = 0) {Return i;}} return-1 ; }//test:x=[0, 1, 0]//expected = 2
(a) Identify the fault:
for (int i = 0; i < x.length; i++), order should is from high to low, should is "for (int i=x.length-1; i > 0; i--) "
(b) If possible, identify a test case this does not execute the fault. (reachability)
No possible
(c) If possible, identify a test case this executes the fault, but does not the result of an error state.
TEST:X=[1]
Expected=-1;
fact =-1;
(d) If Possible identify a test case this results in an error, and not a failure.
test:x=[1,0,1]
expected = 1;
fact = 1;
Tips
Software fault:a static defect in the software ( the design error in the software is that the code itself is wrong)
Software failure:external, incorrect behavior with respect to the requirements or other description of the expected Beha Vior (failure, not as expected, shown)
Software Error:an incorrect internal state which is the manifestation of some fault (during operation)
Fault, error---failure, defects in the software generate error at run time, and when error accumulates to a certain extent, it will fail, these are bugs
Software Test Job Two