StupidSort { public static int[] stupidSort(int[] array, Comparator<Integer> comparator) { for (int i = 0; i < array.length; i++) { for (int j = i + 1; j < array.length; j++) { if (comparator.compare(array[i], array[j]) > 0) { swap(array, i, j); } } } return array; }  static void swap(int[] array, int foo, int bar); static int[] stupidSort(int[] array, Comparator<Integer> comparator);  }
@Test public void ascendingOrderSort() { int[] array = { 5, 4, 3, 2, 1 }; int[] sorted = StupidSort.stupidSort(array, ascOrderComparator); assertArrayEquals("Failure => Array returned is not sorted.", sorted, new int[] { 1, 2, 3, 4, 5 }); }
@Test public void descendingOrderSort() { int[] array = { 1, 2, 3, 4, 5 }; int[] sorted = StupidSort.stupidSort(array, descOrderComparator); assertArrayEquals("Failure => Array returned is not sorted.", sorted, new int[] { 5, 4, 3, 2, 1 }); }
@Test public void randomOrderSort() { int[] array = { 5, 1, 3, 2, 4 }; int[] sorted = StupidSort.stupidSort(array, ascOrderComparator); assertArrayEquals("Failure => Array returned is not sorted.", sorted, new int[] { 1, 2, 3, 4, 5 }); }