QUESTION 24 Consider the following faulty program, It includes a test case that
ID: 3718792 • Letter: Q
Question
QUESTION 24 Consider the following faulty program, It includes a test case that results in failure. Answer the following questions about the program. public int countNegative x) Effects: If throw NulPointerException else retum the number of negative elements in x int cot-0 for (int-0: 1 x-length: 1 ) f (s0) return count: / Test Case Input x--4, 2.0,-2] // Expected Output 2 (i) Identify the fault Specify the line of code where the faulty exists. (ii) If possible, identify a test case that does not execute the fault If possible, identify a test case that executes the fault, but does not result in an eror state (v) Fix the fault. Provide the fixed line of code. (Verify that the given Test Case now produces the expected output) TTT ? Paragraph ? ArialExplanation / Answer
i)
the fault here is in the if condition that is
if(x<=0)
here... 0 is also included but 0 is not a negative number
ii)
test case that doesn't contain zero: [-1,-2,2,3]
iii)
test case that doesn't contain zero and negative numbers:[1,2,3,4]
iv)
fix:
if(x<0) //excluding zero..
everything else is fine
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.