Question: Below is a faulty program that includes a test case that results in failure. Answer the following questions about each program. /** Count negative elements
Below is a faulty program that includes a test case that results in failure. Answer the following questions about each program.
/** Count negative elements *
@param x array to search *
@return count of negative elements in x *
@throws NULLPointerException if x is null */
public int countNegative (int[] x) {
int count = 0;
for (int i=x.length-1; i>=0; i++) {
if (x[i] <=0)
count++;
}
return count;
}
// test: x = [-4, 2, 0, 2]; Expected = 1
a. Identify the fault and fix the fault.
b. If possible, identify a test case that does not execute the fault.
c. If possible, identify a test case that executes the fault, but does not result in an error state.
d. If possible identify a test case that results in an error, but not a failure.
e. For the given test case, identify the first error state. Be sure to describe the complete state.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
