Activity: RIPR (countPositive)
(no submission)
Purpose:
- Understand the differences between fault, error, and failure
- Understand RIPR model and use it to design tests
- Get ready to work on homework assignment, prepare for quizzes and the final exam
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
- What is the fault? Explain what is wrong with the given code.
- If possible, find a test input that does not reach (i.e., not execute) the fault.
If not, briefly explain why not.
- If possible, find a test input that reaches the fault, but does not result in an error.
If not, briefly explain why not.
- If possible, find a test input that results in an error, but not a failure.
If not, briefly explain why not.
- Find a test input that results in a failure.
If not, briefly explain why not.
- Identify the first error state for the given test
(how about your test cases from questions 4 and 5?)