Sort { @SuppressWarnings("WeakerAccess") public static void sort(int[] order, double[] values) { sort(order, values, 0, values.length); }  @SuppressWarnings("WeakerAccess") static void sort(int[] order, double[] values); @SuppressWarnings("WeakerAccess") static void sort(int[] order, double[] values, int n); @SuppressWarnings("WeakerAccess") static void sort(int[] order, double[] values, int start, int n); @SuppressWarnings("WeakerAccess") static void sort(double[] key, double[] ... values); @SuppressWarnings("WeakerAccess") static void sort(double[] key, int start, int n, double[]... values); @SuppressWarnings("UnusedDeclaration") static void checkPartition(int[] order, double[] values, double pivotValue, int start, int low, int high, int end); @SuppressWarnings("WeakerAccess") static void reverse(int[] order); @SuppressWarnings("WeakerAccess") static void reverse(int[] order, int offset, int length); @SuppressWarnings({"WeakerAccess", "SameParameterValue"}) static void reverse(double[] order, int offset, int length);  }
@Test public void testEmpty() { Sort.sort(new int[]{}, new double[]{}); }
@Test public void testOne() { int[] order = new int[1]; Sort.sort(order, new double[]{1}); assertEquals(0, order[0]); }
@Test public void testIdentical() { int[] order = new int[6]; double[] values = new double[6]; Sort.sort(order, values); checkOrder(order, values); }
@Test public void testRepeated() { int n = 50; int[] order = new int[n]; double[] values = new double[n]; for (int i = 0; i < n; i++) { values[i] = Math.rint(10 * ((double) i / n)) / 10.0; } Sort.sort(order, values); checkOrder(order, values); }
@Test public void testShort() { int[] order = new int[6]; double[] values = new double[6]; for (int i = 0; i < 6; i++) { values[i] = 1; } Sort.sort(order, values); checkOrder(order, values); values[0] = 0.8; values[1] = 0.3; Sort.sort(order, values); checkOrder(order, values); values[5] = 1.5; values[4] = 1.2; Sort.sort(order, values); checkOrder(order, values); }
@Test public void testLonger() { int[] order = new int[20]; double[] values = new double[20]; for (int i = 0; i < 20; i++) { values[i] = (i * 13) % 20; } Sort.sort(order, values); checkOrder(order, values); }
@Test public void testMultiPivots() { int[] order = new int[30]; double[] values = new double[30]; for (int i = 0; i < 9; i++) { values[i] = i + 20 * (i % 2); } for (int i = 9; i < 20; i++) { values[i] = 10; } for (int i = 20; i < 30; i++) { values[i] = i - 20 * (i % 2); } values[29] = 29; values[24] = 25; values[26] = 25; Sort.sort(order, values); checkOrder(order, values); }
@Test public void testMultiPivotsInPlace() { double[] keys = new double[30]; for (int i = 0; i < 9; i++) { keys[i] = i + 20 * (i % 2); } for (int i = 9; i < 20; i++) { keys[i] = 10; } for (int i = 20; i < 30; i++) { keys[i] = i - 20 * (i % 2); } keys[29] = 29; keys[24] = 25; keys[26] = 25; double[] v = valuesFromKeys(keys, 0); Sort.sort(keys, v); checkOrder(keys, 0, keys.length, v); }
@Test public void testRandomized() { Random rand = new Random(); for (int k = 0; k < 100; k++) { int[] order = new int[30]; double[] values = new double[30]; for (int i = 0; i < 30; i++) { values[i] = rand.nextDouble(); } Sort.sort(order, values); checkOrder(order, values); } }
@Test public void testRandomizedShortSort() { Random rand = new Random(); for (int k = 0; k < 100; k++) { double[] keys = new double[30]; for (int i = 0; i < 10; i++) { keys[i] = i; } for (int i = 10; i < 20; i++) { keys[i] = rand.nextDouble(); } for (int i = 20; i < 30; i++) { keys[i] = i; } double[] v0 = valuesFromKeys(keys, 0); double[] v1 = valuesFromKeys(keys, 1); Sort.sort(keys, 10, 10, v0, v1); checkOrder(keys, 10, 10, v0, v1); checkValues(keys, 0, keys.length, v0, v1); for (int i = 0; i < 10; i++) { assertEquals(i, keys[i], 0); } for (int i = 20; i < 30; i++) { assertEquals(i, keys[i], 0); } } }