Knowledge Point Content review:
It mainly introduces the difference between the three concepts.
First of all, the fundamental question.
Fault, what's the matter falut, the problem in the code, that is, and the operating environment AH what does not matter, your code is problematic, in other words, your implementation is problematic, but this problem is not necessarily triggered or will not cause error, But whether or not it leads to error is fault.
Next is the error, in the process of code execution, run the above faults, there will be errors, (of course, there may be no error), but this state is called error, may lead to failure
Then say failure, this is the end of the wrong behavior, then is failures.
It's generally a feeling like fault->error->failure.
The root of everything is that the faults,faults in the code will produce error that could eventually lead to failures ...
Now, let's talk about this week's homework.
Public intFindLast (int[] x,inty) {//effects:if X==null Throw//NullPointerException//else return the index of the last element//In x that equals Y. //If No such element exists, return-1 for(inti=x.length-1; i >0; i--) { if(X[i] = =y) {returni; } } return-1; } //test:x=[2, 3, 5]; y = 2//expected = 0
1.fault:for cycle control Conditions i > 0 here should be i>=0, otherwise will not access x[0];
2. A sample that does not perform fault
x = {} y = 3;
This situation will directly access invalid memory and cause the program to hang
3. Fault is executed but no error is returned
x={1,2,3} y = 2
The expectation is 1, and the answer is 1.
4. Causes errors but does not fail
X={1,2,3},y =0
The expected answer is-1, the actual answer is-1;
Public Static intLastzero (int[] x) {//effects:if X==null Throw//NullPointerException//else return the index of the last 0 in X. //Return-1 If 0 does not occur in X for(inti =0; i < x.length; i++) { if(X[i] = =0) { returni; } } return-1; }//test:x=[0, 1, 0]//expected = 2
The 1.fault code is the position of the last 0 in the array, but the first 0 of the query is implemented
2. Do not execute fault, because there is fault from the loop (the direction is reversed) so there is no use case that does not execute fault
3. Execute fault but not error is the case that the array has only one element, no matter the pros and cons of the traversal will not be different (all are only traversed subscript 0 does not exist positive and negative)
such as x={4};
4. Execution fault cause error but no failure, when there is only one or no 0 in X
x = {1,0,2,3}
The answer is 1, and the answer is 1.
Software Test second Job