ShellSort { public static void ShellSort(int[] data, int[] gaps) { for (int gap : gaps) { for (int i = gap; i < data.length; i++) { int temp = data[i]; int j = i; for (; j >= gap && data[j - gap] > temp; j -= gap) { data[j] = data[j - gap]; } data[j] = temp; } } }  static void ShellSort(int[] data, int[] gaps);  }
@Test public void testShellSortBig() throws Exception { int n = 100000; int[] toSort = getArray(n); ShellSort.ShellSort(toSort, getGaps()); assertTrue(isSorted(toSort)); }
@Test public void testShellSortDuplicates() throws Exception { int[] toSort = new int[] {1,2,2,2,3,4,5,6,5,5,1,7,2,5}; ShellSort.ShellSort(toSort, getGaps()); assertTrue(isSorted(toSort)); }
@Test public void testShellSortNegative() throws Exception { int[] toSort = new int[] {1,2,-2,2,3,4,-5,6,5,5,-1,7,2,5}; ShellSort.ShellSort(toSort, getGaps()); assertTrue(isSorted(toSort)); }
@Test public void testShellSortZero() throws Exception { int[] toSort = new int[] {}; ShellSort.ShellSort(toSort, getGaps()); assertTrue(isSorted(toSort)); }
@Test public void testShellSortOneElam() throws Exception { int[] toSort = new int[] {3}; ShellSort.ShellSort(toSort, getGaps()); assertTrue(isSorted(toSort)); }