FindLast

De Software testing
Ir para: navegação, pesquisa
/**
 * 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.
 */
public int findLast(int[] x, int y)
{
	for (int i=x.length-1; i > 0; i--) {
		if (x[i] == y) { 
			return i;
		}
	}
	return -1; 
}
  1. Identify the fault for the test case {Input: x = [2, 3, 5], y = 2; Expected output = 0}.
  2. If possible, identify a test case that does not execute the fault.
  3. If possible, identify a test case that executes the fault, but does not result in an error state.
  4. If possible identify a test case that results in an error, but not a failure. Hint: Don’t forget about the program counter.
  5. For the given test case, identify the first error state. Be sure to describe the complete state.
  6. Fix the fault and verify that the given test now produces the expected output.