### Question:
Algorithms { public static <T> void mergeSort(List<T> data, Comparator<T> c, TaskMonitor monitor) { List<T> aux = new ArrayList<T>(data); mergeSort(aux, data, 0, data.size(), c, monitor); }  @SuppressWarnings({ "unchecked", "rawtypes" }) static int binarySearchWithDuplicates(List data, Object searchItem, Comparator comparator); static void bubbleSort(List<T> data, int low, int high, Comparator<T> comparator); static void mergeSort(List<T> data, Comparator<T> c, TaskMonitor monitor);  }### Answer:
@Test public void testmergeSort() { List<Long> data = getList(new long[] { 5, 8, 10, 2, 10, 3, 3, 7, 10, 23, 0, 15, 22 }); Algorithms.mergeSort(data, comparator, TaskMonitorAdapter.DUMMY_MONITOR); long[] expected = new long[] { 0, 2, 3, 3, 5, 7, 8, 10, 10, 10, 15, 22, 23 }; for (int i = 0; i < expected.length; i++) { assertEquals(new Long(expected[i]), data.get(i)); } }
@Test public void testmergeSort2() { List<Long> data = getList(new long[] { 0, 1, 2, 3, 4, 0, 0, 0 }); Algorithms.mergeSort(data, comparator, TaskMonitorAdapter.DUMMY_MONITOR); long[] expected = new long[] { 0, 0, 0, 0, 1, 2, 3, 4 }; for (int i = 0; i < expected.length; i++) { assertEquals(new Long(expected[i]), data.get(i)); } }
@Test public void testmergeSort3() { List<Long> data = getList(new long[] { 0, 1, 2, 3, 4, 4, 4, 4 }); Algorithms.mergeSort(data, comparator, TaskMonitorAdapter.DUMMY_MONITOR); long[] expected = new long[] { 0, 1, 2, 3, 4, 4, 4, 4 }; for (int i = 0; i < expected.length; i++) { assertEquals(new Long(expected[i]), data.get(i)); } }
@Test public void testmergeSort4() { List<Long> data = getList(new long[] { 1, 1, 1, 1, 1, 1, 1, 1 }); Algorithms.mergeSort(data, comparator, TaskMonitorAdapter.DUMMY_MONITOR); long[] expected = new long[] { 1, 1, 1, 1, 1, 1, 1, 1 }; for (int i = 0; i < expected.length; i++) { assertEquals(new Long(expected[i]), data.get(i)); } }
@Test public void testmergeSort5() { long[] l = new long[100000]; Random r = new Random(); for (int i = 0; i < l.length; i++) { l[i] = r.nextLong(); } List<Long> data = getList(l); Algorithms.mergeSort(data, comparator, TaskMonitorAdapter.DUMMY_MONITOR); for (int i = 0; i < l.length - 1; i++) { assertTrue("i = " + i, data.get(i) <= data.get(i + 1)); } }