import static org.junit.Assert.*; import java.util.Arrays; import org.junit.Before; import org.junit.Test; public class SorterTest { @Before public void setUp() throws Exception { } @Test public void testQuicksort() { testSorter(new Quicksort(), "Quicksort"); } @Test public void testInsertionSort() { testSorter(new InsertionSort(), "Insertion sort"); } // more test cases for other sorting classes that have to be tested private void testSorter(IntSorter sorter, String name) { // test case, 10 elements with random values in the range 1..20 testSortData(sorter, name, new Data(10, 20, Data.Order.RANDOM).get() ); // More arrays, more test cases, odd and even lists // empty lists, single element lists, and other *good* // static tests } private void testSortData(IntSorter sorter, String name, int[] v){ int[] v_expected = Arrays.copyOf(v, v.length); Arrays.sort(v_expected); sorter.sort(v); assertArrayEquals(name, v_expected, v); } }