1 Public intFindLast (int[] x,inty) {2 //effects:if X==null Throw3 NullPointerException4 //else return the index of the last element5 //In x that equals Y.6 //If No such element exists, return-17 for(inti=x.length-1; i >0; i--)8 {9 if(X[i] = =y)Ten { One returni; A } - } - return-1; the } - //test:x=[2, 3, 5]; y = 2 - //expected = 0
Error:
for (int i=x.length-1; i > 0; i--)
should read
for (int i=x.length-1; i >= 0; i--)//The No. 0 data in the array is not traversed in the original code
Use cases that do not fail: x = [2,3,5];y = 5; excepted = 2;
Test cases that fail but do not cause an error state:??
A test case that causes a failure without failure: x = [2,3,5];y = 0; excepted =-1;
1 Public Static intLastzero (int[] x) {2 //effects:if X==null Throw3 NullPointerException4 //else return the index of the last 0 in X.5 //Return-1 If 0 does not occur in X6 for(inti =0; i < x.length; i++)7 {8 if(X[i] = =0)9 {Ten returni; One } A}return-1; - } - //test:x=[0, 1, 0] the //expected = 2
Error:
for (int i = 0; i < x.length; i++)
should read
for (int i = x.length-1; I >= 0; i--)//The original code searches for the first 0 in the array rather than the last
Test cases that do not fail:??
Test cases that fail but do not cause an error state:??
Test cases that cause failure without failure: x = [1,0,1]; expected = 1;
Knowledge Points:
- Software failure (software Fault): Defects in the static code in the software
- Software error (software error): Incorrect internal state, which is the performance of the failure.
- Software failure (software Failure): A description of a requirement or expected behavior about Del, external, incorrect behavior
Reachability: The wrong location in the project can be found
Infection: The stage in the project must be incorrect
Propagation: An affected part of a project must cause some output or incorrect results
Software Test Technology Job 2