Activity: RIPR (countPositive)

(no submission)

Purpose:
Instruction:

Consider the countPositive 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.

/**
 * Count positive elements
 *
 * @param x array to search
 * @return count of positive elements in x
 * @throws NullPointerException if x is null
 */
line  1  public int countPositive (int[] x)  
line  2  { 
line  3     int count = 0;  
line  4     for (int i=0; i < x.length; i++)
line  5     { 
line  6        if (x[i] >= 0)
line  7           count++; 
line  8     } 
line  9     return count;
line 10   }
// Given test case
//   test input: x = [-4, 2, 0, 2] 
//   expected = 2 
  1. What is the fault? Explain what is wrong with the given code.
  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. If not, briefly explain why not. Make sure that your test input is different from the given test case input.
  7. Identify the first error state for the given test (how about your test cases from questions 4 and 5? Any error states? Where?)

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