### Question:
Sorting { public static int medianOf3(final int[] a, final int x, final int y, final int z, final IntComparator c) { if (c.compare(a[x], a[y]) < 0) { if (c.compare(a[y], a[z]) < 0) { return y; } if (c.compare(a[x], a[z]) < 0) { return z; } return x; } if (c.compare(a[y], a[z]) > 0) { return y; } if (c.compare(a[x], a[z]) > 0) { return z; } return x; } private  Sorting(); static int selectPivotIndex(final int[] indices, 
        int left, 
        int right, 
        final IntComparator comp); static int partitionIndices(
            final int[] indices,
            final int k0,
            final int left0,
            final int right0,
            final IntComparator comp); static void quickSort(final IndexedSortable sortable); static void quickSort(final IndexedSortable sortable, final int offset, final int len); static void quickSort(final int[] arr, final IntComparator comp); static void quickSort(final int[] arr, final int offset, final int len, final IntComparator comp); static int medianOf3(final int[] a, final int x, final int y, final int z, final IntComparator c); static int medianOf3(IndexedSortable sortable, int x, int y, int z); static void parallelSort(double[] dValues, int[] iValues);  }### Answer:
@Test public void testMedianOf3() { final int loops = 100; Random random = new Random(); for (int i = 0; i < loops; i++) { int len = 10 + random.nextInt(50); int[] values = new int[len]; for (int j = 0; j < len; j++) { values[j] = random.nextInt(); } IntComparator comp = new SimpleIntComparator(); final int x = 0; final int m = len>>1; final int y = len-1; int med = Sorting.medianOf3(values, x, m, y, comp); int[] otherTwo; if (med == x) { otherTwo = new int[] { m, y }; } else if (med == m) { otherTwo = new int[] { x, y }; } else { otherTwo = new int[] { x, m }; } boolean foundLE = false; boolean foundGE = false; for (int j=0; j<otherTwo.length; j++) { if (!foundLE && values[otherTwo[j]] <= values[med]) { foundLE = true; } if (!foundGE && values[otherTwo[j]] >= values[med]) { foundGE = true; } } assertTrue(foundLE && foundGE); } }