Activity: RIPR (findLast)

(no submission)

Purpose:
Instruction:

Consider the findLast method and answer the questions.

You may make a copy of a worksheet and complete this activity, or write your answer on paper(s) or your computer.

You may work alone or with another student in this course.

/**
 * Find last index of element
 *
 * @param x array to search
 * @param y value to look for
 * @return last index of y in x; -1 if absent
 * @throws NullPointerException if x is null
 */
line  1  public static int findLast(int[] x, int y)  
line  2  { 
line  3     if (x == null)  
line  4        throw new NullPointerException();
line  5     for (int i=x.length-1; i>0; i--) 
line  6     {
line  7        if (x[i] == y) 
line  8           return i; 
line  9     }
line 10     return -1; 
line 11   }
// test: x = [2, 3, 5]; y = 2; 
// expected = 0 
  1. What is the fault?
  2. Provide the reachability, infection, and propagation conditions for the fault.
  3. If possible, find a test input that does not reach (i.e., not execute) the fault.
  4. If possible, find a test input that reaches the fault, but does not result in an error.
  5. If possible, find a test input that results in an error, but not a failure.
  6. Find a test input that results in a failure.
  7. Identify the first error state for the given test (how about the test cases from questions 3 and 4?).
  8. Thought question: Why do we practice finding test inputs for questions 2-5?.

Copyright © 2026 Upsorn Praphamontripong
Released under the Creative Commons License CC-BY-NC-SA 4.0 license.
Last updated 2026-09-11 18:52