Question
Develop JUnit tests for five standard sorting algorithms: Bubble Sort, Insertion Sort, Selection Sort, Shell Sort, Merge Sort. Implement the above sorts. Test your code.
Develop JUnit tests for five standard sorting algorithms: Bubble Sort, Insertion Sort, Selection Sort, Shell Sort, Merge Sort.
Implement the above sorts. Test your code.
Measure your codes performance over increasingly large datasets.
Your sorting project will contain the following classes:
SortInterface interface (below)
import java.util.ArrayList;
public interface SortInterface {
public void bubblesort(ArrayList
highindex, boolean reversed);
public void insertionsort(ArrayList
highindex, boolean reversed);
public void selectionsort(ArrayList
highindex, boolean reversed);
public void shellsort(ArrayList
highindex, boolean reversed);
public void mergesort(ArrayList
highindex, boolean reversed);
}
Sort class, which implements the interface class
SortTest class, JUnit test cases for your Sort methods.
Profiler class, which contains your measurement code
It is critically important that:
Your JUnit class be named SortTest
You thoroughly test all of the public methods in the Sort class specified by the API in SortInterface.
It is recommended that you develop your test cases before implementing the Sort methods. Then develop your Sort methods incrementally; testing as you go.
Testing
Develop tests for your Sort methods. Create a JUnit class called SortTest. Populate SortTest with test methods that thoroughly test your sorts for all possible edge cases.
To test a sort:
Create two equivalent unsorted ArrayLists.
Sort one with Collections.sort (Links to an external site.)Links to an external site..
Sort the other with one of the Sort methods. If an error occurs here, the test fails.
Compare the two sorted lists. If they are not equivalent, the test fails.
Try to find the edge cases that will break your code.
At a minimum you should test:
Sorting an empty list, a list with 1 element, 2 elements, 3 elements, 100 elements.
Sort an already sorted list.
Sort a reverse sorted list.
Some other suggestions are:
Sort lists with the minimum number in the far left position, far right positions, middle.
Sort lists with the maximum number in the far left, right, or middle positions.
Sort in ascending and descending order.
Sort different ranges (lowindex, highindex)
Sort lists with even numbers of elements and odd numbers of elements.
It is recommended that you develop your test cases before implementing the Sort methods. Then develop your Sort methods incrementally; testing as you go.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started