Question: Provide: A failure - inducing input for the buggy program, as a JUnit test and any associated code ( write it as a code block

Provide:
A failure-inducing input for the buggy program, as a JUnit test and any associated code (write it as a code block in Markdown)
An input that doesn't induce a failure, as a JUnit test and any associated code (write it as a code block in Markdown)
The symptom, as the output of running the tests (provide it as a screenshot of running JUnit with at least the two inputs above)
The bug, as the before-and-after code change required to fix it (as two code blocks in Markdown)
Briefly describe why the fix addresses the issue.
Buggy Program:
import java.util.ArrayList;
import java.util.List;
interface StringChecker { boolean checkString(String s); }
class ListExamples {
// Returns a new list that has all the elements of the input list for which
// the StringChecker returns true, and not the elements that return false, in
// the same order they appeared in the input list;
static List filter(List list, StringChecker sc){
List result = new ArrayList<>();
for(String s: list){
if(sc.checkString(s)){
result.add(0, s);
}
}
return result;
}
// Takes two sorted list of strings (so "a" appears before "b" and so on),
// and return a new list that has all the strings in both list in sorted order.
static List merge(List list1, List list2){
List result = new ArrayList<>();
int index1=0, index2=0;
while(index1< list1.size() && index2< list2.size()){
if(list1.get(index1).compareTo(list2.get(index2))<0){
result.add(list1.get(index1));
index1+=1;
}
else {
result.add(list2.get(index2));
index2+=1;
}
}
while(index1< list1.size()){
result.add(list1.get(index1));
index1+=1;
}
while(index2< list2.size()){
result.add(list2.get(index2));
index1+=1;
}
return result;
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!