< prev index next >
test/jdk/java/util/Arrays/Sorting.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
--- 1,7 ----
/*
! * Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*** 22,62 ****
*/
/*
* @test
* @bug 6880672 6896573 6899694 6976036 7013585 7018258
- * @summary Exercise Arrays.sort
* @build Sorting
* @run main Sorting -shortrun
*
* @author Vladimir Yaroslavskiy
* @author Jon Bentley
* @author Josh Bloch
*/
import java.util.Arrays;
import java.util.Random;
! import java.io.PrintStream;
public class Sorting {
private static final PrintStream out = System.out;
private static final PrintStream err = System.err;
// Array lengths used in a long run (default)
private static final int[] LONG_RUN_LENGTHS = {
1, 2, 3, 5, 8, 13, 21, 34, 55, 100, 1000, 10000, 100000, 1000000 };
// Array lengths used in a short run
private static final int[] SHORT_RUN_LENGTHS = {
! 1, 2, 3, 21, 55, 1000, 10000 };
// Random initial values used in a long run (default)
private static final long[] LONG_RUN_RANDOMS = { 666, 0xC0FFEE, 999 };
// Random initial values used in a short run
private static final long[] SHORT_RUN_RANDOMS = { 666 };
public static void main(String[] args) {
boolean shortRun = args.length > 0 && args[0].equals("-shortrun");
long start = System.currentTimeMillis();
if (shortRun) {
--- 22,68 ----
*/
/*
* @test
* @bug 6880672 6896573 6899694 6976036 7013585 7018258
* @build Sorting
* @run main Sorting -shortrun
+ * @summary Exercise Arrays.sort
*
* @author Vladimir Yaroslavskiy
* @author Jon Bentley
* @author Josh Bloch
*/
+ import java.io.PrintStream;
import java.util.Arrays;
import java.util.Random;
! import java.util.Comparator;
public class Sorting {
+
private static final PrintStream out = System.out;
private static final PrintStream err = System.err;
// Array lengths used in a long run (default)
private static final int[] LONG_RUN_LENGTHS = {
1, 2, 3, 5, 8, 13, 21, 34, 55, 100, 1000, 10000, 100000, 1000000 };
// Array lengths used in a short run
private static final int[] SHORT_RUN_LENGTHS = {
! 1, 2, 3, 21, 55, 1000, 10000, 12000 };
// Random initial values used in a long run (default)
private static final long[] LONG_RUN_RANDOMS = { 666, 0xC0FFEE, 999 };
// Random initial values used in a short run
private static final long[] SHORT_RUN_RANDOMS = { 666 };
+ // Constant values used in subarray sorting
+ private static final int A380 = 0xA380;
+ private static final int B747 = 0xB747;
+
public static void main(String[] args) {
boolean shortRun = args.length > 0 && args[0].equals("-shortrun");
long start = System.currentTimeMillis();
if (shortRun) {
*** 77,87 ****
testEmptyAndNullByteArray();
testEmptyAndNullFloatArray();
testEmptyAndNullDoubleArray();
for (int length : lengths) {
! testMergeSort(length);
testAndCheckRange(length);
testAndCheckSubArray(length);
}
for (long seed : randoms) {
for (int length : lengths) {
--- 83,93 ----
testEmptyAndNullByteArray();
testEmptyAndNullFloatArray();
testEmptyAndNullDoubleArray();
for (int length : lengths) {
! testMergingSort(length);
testAndCheckRange(length);
testAndCheckSubArray(length);
}
for (long seed : randoms) {
for (int length : lengths) {
*** 281,290 ****
--- 287,305 ----
", length = " + length);
Arrays.sort(a);
checkSorted(a);
checkStable(a);
out.println();
+
+ a = build(length, random);
+
+ out.println("Test 'stable' comparator: " + "random = " + random.getSeed() +
+ ", length = " + length);
+ Arrays.sort(a, pairComparator);
+ checkSorted(a);
+ checkStable(a);
+ out.println();
}
private static void checkSorted(Pair[] a) {
for (int i = 0; i < a.length - 1; i++) {
if (a[i].getKey() > a[i + 1].getKey()) {
*** 327,336 ****
--- 342,357 ----
a[i++] = new Pair(key, 4);
}
return a;
}
+ private static Comparator<Pair> pairComparator = new Comparator<Pair>() {
+ public int compare(Pair p1, Pair p2) {
+ return p1.compareTo(p2);
+ }
+ };
+
private static final class Pair implements Comparable<Pair> {
Pair(int key, int value) {
myKey = key;
myValue = value;
}
*** 389,413 ****
}
}
out.println();
}
! private static void testMergeSort(int length) {
if (length < 1000) {
return;
}
! ourDescription = "Check merge sorting";
int[] golden = new int[length];
! int period = 67; // java.util.DualPivotQuicksort.MAX_RUN_COUNT
for (int m = period - 2; m <= period + 2; m++) {
! for (MergeBuilder builder : MergeBuilder.values()) {
builder.build(golden, m);
int[] test = golden.clone();
for (TypeConverter converter : TypeConverter.values()) {
! out.println("Test 'merge sort': " + converter + " " +
builder + "length = " + length + ", m = " + m);
Object convertedGolden = converter.convert(golden);
sort(convertedGolden);
checkSorted(convertedGolden);
}
--- 410,434 ----
}
}
out.println();
}
! private static void testMergingSort(int length) {
if (length < 1000) {
return;
}
! ourDescription = "Check merging sort";
int[] golden = new int[length];
! final int period = 50;
for (int m = period - 2; m <= period + 2; m++) {
! for (MergingBuilder builder : MergingBuilder.values()) {
builder.build(golden, m);
int[] test = golden.clone();
for (TypeConverter converter : TypeConverter.values()) {
! out.println("Test 'merging sort': " + converter + " " +
builder + "length = " + length + ", m = " + m);
Object convertedGolden = converter.convert(golden);
sort(convertedGolden);
checkSorted(convertedGolden);
}
*** 467,488 ****
}
private static void testAndCheckFloat(int length, MyRandom random) {
ourDescription = "Check float sorting";
float[] golden = new float[length];
- final int MAX = 10;
boolean newLine = false;
for (int a = 0; a <= MAX; a++) {
for (int g = 0; g <= MAX; g++) {
for (int z = 0; z <= MAX; z++) {
for (int n = 0; n <= MAX; n++) {
for (int p = 0; p <= MAX; p++) {
! if (a + g + z + n + p > length) {
! continue;
! }
! if (a + g + z + n + p < length) {
continue;
}
for (FloatBuilder builder : FloatBuilder.values()) {
out.println("Test 'float': random = " + random.getSeed() +
", length = " + length + ", a = " + a + ", g = " +
--- 488,506 ----
}
private static void testAndCheckFloat(int length, MyRandom random) {
ourDescription = "Check float sorting";
float[] golden = new float[length];
boolean newLine = false;
+ final int MAX = 12;
for (int a = 0; a <= MAX; a++) {
for (int g = 0; g <= MAX; g++) {
for (int z = 0; z <= MAX; z++) {
for (int n = 0; n <= MAX; n++) {
for (int p = 0; p <= MAX; p++) {
! if (a + g + z + n + p != length) {
continue;
}
for (FloatBuilder builder : FloatBuilder.values()) {
out.println("Test 'float': random = " + random.getSeed() +
", length = " + length + ", a = " + a + ", g = " +
*** 542,552 ****
}
}
private static void prepareSubArray(int[] a, int fromIndex, int toIndex, int m) {
for (int i = 0; i < fromIndex; i++) {
! a[i] = 0xDEDA;
}
int middle = (fromIndex + toIndex) >>> 1;
int k = 0;
for (int i = fromIndex; i < middle; i++) {
--- 560,570 ----
}
}
private static void prepareSubArray(int[] a, int fromIndex, int toIndex, int m) {
for (int i = 0; i < fromIndex; i++) {
! a[i] = A380;
}
int middle = (fromIndex + toIndex) >>> 1;
int k = 0;
for (int i = fromIndex; i < middle; i++) {
*** 554,564 ****
}
for (int i = middle; i < toIndex; i++) {
a[i] = k--;
}
for (int i = toIndex; i < a.length; i++) {
! a[i] = 0xBABA;
}
}
private static void scramble(int[] a, Random random) {
for (int i = 0; i < a.length * 7; i++) {
--- 572,582 ----
}
for (int i = middle; i < toIndex; i++) {
a[i] = k--;
}
for (int i = toIndex; i < a.length; i++) {
! a[i] = B747;
}
}
private static void scramble(int[] a, Random random) {
for (int i = 0; i < a.length * 7; i++) {
*** 665,683 ****
INTEGER {
Object convert(int[] a) {
Integer[] b = new Integer[a.length];
for (int i = 0; i < a.length; i++) {
! b[i] = new Integer(a[i]);
}
return b;
}
};
abstract Object convert(int[] a);
! @Override public String toString() {
String name = name();
for (int i = name.length(); i < 9; i++) {
name += " ";
}
--- 683,702 ----
INTEGER {
Object convert(int[] a) {
Integer[] b = new Integer[a.length];
for (int i = 0; i < a.length; i++) {
! b[i] = Integer.valueOf(a[i]);
}
return b;
}
};
abstract Object convert(int[] a);
! @Override
! public String toString() {
String name = name();
for (int i = name.length(); i < 9; i++) {
name += " ";
}
*** 826,846 ****
}
};
abstract void build(int[] a, int m);
! @Override public String toString() {
String name = name();
for (int i = name.length(); i < 12; i++) {
name += " ";
}
return name;
}
}
! private static enum MergeBuilder {
ASCENDING {
void build(int[] a, int m) {
int period = a.length / m;
int v = 1, i = 0;
--- 845,866 ----
}
};
abstract void build(int[] a, int m);
! @Override
! public String toString() {
String name = name();
for (int i = name.length(); i < 12; i++) {
name += " ";
}
return name;
}
}
! private static enum MergingBuilder {
ASCENDING {
void build(int[] a, int m) {
int period = a.length / m;
int v = 1, i = 0;
*** 870,893 ****
for (int j = i; j < a.length - 1; j++) {
a[j] = v--;
}
a[a.length - 1] = 0;
}
};
abstract void build(int[] a, int m);
! @Override public String toString() {
String name = name();
for (int i = name.length(); i < 12; i++) {
name += " ";
}
return name;
}
}
private static enum UnsortedBuilder {
RANDOM {
void build(int[] a, int m, Random random) {
for (int i = 0; i < a.length; i++) {
a[i] = random.nextInt();
--- 890,963 ----
for (int j = i; j < a.length - 1; j++) {
a[j] = v--;
}
a[a.length - 1] = 0;
}
+ },
+ POINT {
+ void build(int[] a, int m) {
+ for (int i = 0; i < a.length; i++) {
+ a[i] = 0;
+ }
+ a[a.length / 2] = m;
+ }
+ },
+ LINE {
+ void build(int[] a, int m) {
+ for (int i = 0; i < a.length; i++) {
+ a[i] = i;
+ }
+ reverse(a, 0, a.length - 1);
+ }
+ },
+ PEARL {
+ void build(int[] a, int m) {
+ for (int i = 0; i < a.length; i++) {
+ a[i] = i;
+ }
+ reverse(a, 0, 2);
+ }
+ },
+ RING {
+ void build(int[] a, int m) {
+ int k1 = a.length / 3;
+ int k2 = a.length / 3 * 2;
+ int level = a.length / 3;
+
+ for (int i = 0, k = level; i < k1; i++) {
+ a[i] = k--;
+ }
+ for (int i = k1; i < k2; i++) {
+ a[i] = 0;
+ }
+ for (int i = k2, k = level; i < a.length; i++) {
+ a[i] = k--;
+ }
+ }
};
abstract void build(int[] a, int m);
! @Override
! public String toString() {
String name = name();
for (int i = name.length(); i < 12; i++) {
name += " ";
}
return name;
}
}
+ private static void reverse(int[] a, int lo, int hi) {
+ for (--hi; lo < hi; ) {
+ int tmp = a[lo];
+ a[lo++] = a[hi];
+ a[hi--] = tmp;
+ }
+ }
+
private static enum UnsortedBuilder {
RANDOM {
void build(int[] a, int m, Random random) {
for (int i = 0; i < a.length; i++) {
a[i] = random.nextInt();
*** 990,1000 ****
}
};
abstract void build(int[] a, int m, Random random);
! @Override public String toString() {
String name = name();
for (int i = name.length(); i < 12; i++) {
name += " ";
}
--- 1060,1071 ----
}
};
abstract void build(int[] a, int m, Random random);
! @Override
! public String toString() {
String name = name();
for (int i = name.length(); i < 12; i++) {
name += " ";
}
*** 1037,1047 ****
} else if (test instanceof double[]) {
compare((double[]) test, (double[]) golden);
} else if (test instanceof Integer[]) {
compare((Integer[]) test, (Integer[]) golden);
} else {
! failed("Unknow type of array: " + test + " of class " +
test.getClass().getName());
}
}
private static void compare(int[] a, int[] b) {
--- 1108,1118 ----
} else if (test instanceof double[]) {
compare((double[]) test, (double[]) golden);
} else if (test instanceof Integer[]) {
compare((Integer[]) test, (Integer[]) golden);
} else {
! failed("Unknown type of array: " + test + " of class " +
test.getClass().getName());
}
}
private static void compare(int[] a, int[] b) {
*** 1124,1134 ****
} else if (object instanceof double[]) {
checkSorted((double[]) object);
} else if (object instanceof Integer[]) {
checkSorted((Integer[]) object);
} else {
! failed("Unknow type of array: " + object + " of class " +
object.getClass().getName());
}
}
private static void checkSorted(int[] a) {
--- 1195,1205 ----
} else if (object instanceof double[]) {
checkSorted((double[]) object);
} else if (object instanceof Integer[]) {
checkSorted((Integer[]) object);
} else {
! failed("Unknown type of array: " + object + " of class " +
object.getClass().getName());
}
}
private static void checkSorted(int[] a) {
*** 1220,1230 ****
} else if (object instanceof double[]) {
return checkSumXor((double[]) object);
} else if (object instanceof Integer[]) {
return checkSumXor((Integer[]) object);
} else {
! failed("Unknow type of array: " + object + " of class " +
object.getClass().getName());
return -1;
}
}
--- 1291,1301 ----
} else if (object instanceof double[]) {
return checkSumXor((double[]) object);
} else if (object instanceof Integer[]) {
return checkSumXor((Integer[]) object);
} else {
! failed("Unknown type of array: " + object + " of class " +
object.getClass().getName());
return -1;
}
}
*** 1316,1326 ****
} else if (object instanceof double[]) {
return checkSumPlus((double[]) object);
} else if (object instanceof Integer[]) {
return checkSumPlus((Integer[]) object);
} else {
! failed("Unknow type of array: " + object + " of class " +
object.getClass().getName());
return -1;
}
}
--- 1387,1397 ----
} else if (object instanceof double[]) {
return checkSumPlus((double[]) object);
} else if (object instanceof Integer[]) {
return checkSumPlus((Integer[]) object);
} else {
! failed("Unknown type of array: " + object + " of class " +
object.getClass().getName());
return -1;
}
}
*** 1412,1422 ****
} else if (object instanceof double[]) {
sortByInsertionSort((double[]) object);
} else if (object instanceof Integer[]) {
sortByInsertionSort((Integer[]) object);
} else {
! failed("Unknow type of array: " + object + " of class " +
object.getClass().getName());
}
}
private static void sortByInsertionSort(int[] a) {
--- 1483,1493 ----
} else if (object instanceof double[]) {
sortByInsertionSort((double[]) object);
} else if (object instanceof Integer[]) {
sortByInsertionSort((Integer[]) object);
} else {
! failed("Unknown type of array: " + object + " of class " +
object.getClass().getName());
}
}
private static void sortByInsertionSort(int[] a) {
*** 1515,1525 ****
} else if (object instanceof double[]) {
Arrays.sort((double[]) object);
} else if (object instanceof Integer[]) {
Arrays.sort((Integer[]) object);
} else {
! failed("Unknow type of array: " + object + " of class " +
object.getClass().getName());
}
}
private static void sortSubArray(Object object, int fromIndex, int toIndex) {
--- 1586,1596 ----
} else if (object instanceof double[]) {
Arrays.sort((double[]) object);
} else if (object instanceof Integer[]) {
Arrays.sort((Integer[]) object);
} else {
! failed("Unknown type of array: " + object + " of class " +
object.getClass().getName());
}
}
private static void sortSubArray(Object object, int fromIndex, int toIndex) {
*** 1538,1548 ****
} else if (object instanceof double[]) {
Arrays.sort((double[]) object, fromIndex, toIndex);
} else if (object instanceof Integer[]) {
Arrays.sort((Integer[]) object, fromIndex, toIndex);
} else {
! failed("Unknow type of array: " + object + " of class " +
object.getClass().getName());
}
}
private static void checkSubArray(Object object, int fromIndex, int toIndex, int m) {
--- 1609,1619 ----
} else if (object instanceof double[]) {
Arrays.sort((double[]) object, fromIndex, toIndex);
} else if (object instanceof Integer[]) {
Arrays.sort((Integer[]) object, fromIndex, toIndex);
} else {
! failed("Unknown type of array: " + object + " of class " +
object.getClass().getName());
}
}
private static void checkSubArray(Object object, int fromIndex, int toIndex, int m) {
*** 1561,1747 ****
} else if (object instanceof double[]) {
checkSubArray((double[]) object, fromIndex, toIndex, m);
} else if (object instanceof Integer[]) {
checkSubArray((Integer[]) object, fromIndex, toIndex, m);
} else {
! failed("Unknow type of array: " + object + " of class " +
object.getClass().getName());
}
}
private static void checkSubArray(Integer[] a, int fromIndex, int toIndex, int m) {
for (int i = 0; i < fromIndex; i++) {
! if (a[i].intValue() != 0xDEDA) {
failed("Range sort changes left element on position " + i +
! ": " + a[i] + ", must be " + 0xDEDA);
}
}
for (int i = fromIndex; i < toIndex - 1; i++) {
if (a[i].intValue() > a[i + 1].intValue()) {
failedSort(i, "" + a[i], "" + a[i + 1]);
}
}
for (int i = toIndex; i < a.length; i++) {
! if (a[i].intValue() != 0xBABA) {
failed("Range sort changes right element on position " + i +
! ": " + a[i] + ", must be " + 0xBABA);
}
}
}
private static void checkSubArray(int[] a, int fromIndex, int toIndex, int m) {
for (int i = 0; i < fromIndex; i++) {
! if (a[i] != 0xDEDA) {
failed("Range sort changes left element on position " + i +
! ": " + a[i] + ", must be " + 0xDEDA);
}
}
for (int i = fromIndex; i < toIndex - 1; i++) {
if (a[i] > a[i + 1]) {
failedSort(i, "" + a[i], "" + a[i + 1]);
}
}
for (int i = toIndex; i < a.length; i++) {
! if (a[i] != 0xBABA) {
failed("Range sort changes right element on position " + i +
! ": " + a[i] + ", must be " + 0xBABA);
}
}
}
private static void checkSubArray(byte[] a, int fromIndex, int toIndex, int m) {
for (int i = 0; i < fromIndex; i++) {
! if (a[i] != (byte) 0xDEDA) {
failed("Range sort changes left element on position " + i +
! ": " + a[i] + ", must be " + 0xDEDA);
}
}
for (int i = fromIndex; i < toIndex - 1; i++) {
if (a[i] > a[i + 1]) {
failedSort(i, "" + a[i], "" + a[i + 1]);
}
}
for (int i = toIndex; i < a.length; i++) {
! if (a[i] != (byte) 0xBABA) {
failed("Range sort changes right element on position " + i +
! ": " + a[i] + ", must be " + 0xBABA);
}
}
}
private static void checkSubArray(long[] a, int fromIndex, int toIndex, int m) {
for (int i = 0; i < fromIndex; i++) {
! if (a[i] != (long) 0xDEDA) {
failed("Range sort changes left element on position " + i +
! ": " + a[i] + ", must be " + 0xDEDA);
}
}
for (int i = fromIndex; i < toIndex - 1; i++) {
if (a[i] > a[i + 1]) {
failedSort(i, "" + a[i], "" + a[i + 1]);
}
}
for (int i = toIndex; i < a.length; i++) {
! if (a[i] != (long) 0xBABA) {
failed("Range sort changes right element on position " + i +
! ": " + a[i] + ", must be " + 0xBABA);
}
}
}
private static void checkSubArray(char[] a, int fromIndex, int toIndex, int m) {
for (int i = 0; i < fromIndex; i++) {
! if (a[i] != (char) 0xDEDA) {
failed("Range sort changes left element on position " + i +
! ": " + a[i] + ", must be " + 0xDEDA);
}
}
for (int i = fromIndex; i < toIndex - 1; i++) {
if (a[i] > a[i + 1]) {
failedSort(i, "" + a[i], "" + a[i + 1]);
}
}
for (int i = toIndex; i < a.length; i++) {
! if (a[i] != (char) 0xBABA) {
failed("Range sort changes right element on position " + i +
! ": " + a[i] + ", must be " + 0xBABA);
}
}
}
private static void checkSubArray(short[] a, int fromIndex, int toIndex, int m) {
for (int i = 0; i < fromIndex; i++) {
! if (a[i] != (short) 0xDEDA) {
failed("Range sort changes left element on position " + i +
! ": " + a[i] + ", must be " + 0xDEDA);
}
}
for (int i = fromIndex; i < toIndex - 1; i++) {
if (a[i] > a[i + 1]) {
failedSort(i, "" + a[i], "" + a[i + 1]);
}
}
for (int i = toIndex; i < a.length; i++) {
! if (a[i] != (short) 0xBABA) {
failed("Range sort changes right element on position " + i +
! ": " + a[i] + ", must be " + 0xBABA);
}
}
}
private static void checkSubArray(float[] a, int fromIndex, int toIndex, int m) {
for (int i = 0; i < fromIndex; i++) {
! if (a[i] != (float) 0xDEDA) {
failed("Range sort changes left element on position " + i +
! ": " + a[i] + ", must be " + 0xDEDA);
}
}
for (int i = fromIndex; i < toIndex - 1; i++) {
if (a[i] > a[i + 1]) {
failedSort(i, "" + a[i], "" + a[i + 1]);
}
}
for (int i = toIndex; i < a.length; i++) {
! if (a[i] != (float) 0xBABA) {
failed("Range sort changes right element on position " + i +
! ": " + a[i] + ", must be " + 0xBABA);
}
}
}
private static void checkSubArray(double[] a, int fromIndex, int toIndex, int m) {
for (int i = 0; i < fromIndex; i++) {
! if (a[i] != (double) 0xDEDA) {
failed("Range sort changes left element on position " + i +
! ": " + a[i] + ", must be " + 0xDEDA);
}
}
for (int i = fromIndex; i < toIndex - 1; i++) {
if (a[i] > a[i + 1]) {
failedSort(i, "" + a[i], "" + a[i + 1]);
}
}
for (int i = toIndex; i < a.length; i++) {
! if (a[i] != (double) 0xBABA) {
failed("Range sort changes right element on position " + i +
! ": " + a[i] + ", must be " + 0xBABA);
}
}
}
private static void checkRange(Object object, int m) {
--- 1632,1818 ----
} else if (object instanceof double[]) {
checkSubArray((double[]) object, fromIndex, toIndex, m);
} else if (object instanceof Integer[]) {
checkSubArray((Integer[]) object, fromIndex, toIndex, m);
} else {
! failed("Unknown type of array: " + object + " of class " +
object.getClass().getName());
}
}
private static void checkSubArray(Integer[] a, int fromIndex, int toIndex, int m) {
for (int i = 0; i < fromIndex; i++) {
! if (a[i].intValue() != A380) {
failed("Range sort changes left element on position " + i +
! ": " + a[i] + ", must be " + A380);
}
}
for (int i = fromIndex; i < toIndex - 1; i++) {
if (a[i].intValue() > a[i + 1].intValue()) {
failedSort(i, "" + a[i], "" + a[i + 1]);
}
}
for (int i = toIndex; i < a.length; i++) {
! if (a[i].intValue() != B747) {
failed("Range sort changes right element on position " + i +
! ": " + a[i] + ", must be " + B747);
}
}
}
private static void checkSubArray(int[] a, int fromIndex, int toIndex, int m) {
for (int i = 0; i < fromIndex; i++) {
! if (a[i] != A380) {
failed("Range sort changes left element on position " + i +
! ": " + a[i] + ", must be " + A380);
}
}
for (int i = fromIndex; i < toIndex - 1; i++) {
if (a[i] > a[i + 1]) {
failedSort(i, "" + a[i], "" + a[i + 1]);
}
}
for (int i = toIndex; i < a.length; i++) {
! if (a[i] != B747) {
failed("Range sort changes right element on position " + i +
! ": " + a[i] + ", must be " + B747);
}
}
}
private static void checkSubArray(byte[] a, int fromIndex, int toIndex, int m) {
for (int i = 0; i < fromIndex; i++) {
! if (a[i] != (byte) A380) {
failed("Range sort changes left element on position " + i +
! ": " + a[i] + ", must be " + A380);
}
}
for (int i = fromIndex; i < toIndex - 1; i++) {
if (a[i] > a[i + 1]) {
failedSort(i, "" + a[i], "" + a[i + 1]);
}
}
for (int i = toIndex; i < a.length; i++) {
! if (a[i] != (byte) B747) {
failed("Range sort changes right element on position " + i +
! ": " + a[i] + ", must be " + B747);
}
}
}
private static void checkSubArray(long[] a, int fromIndex, int toIndex, int m) {
for (int i = 0; i < fromIndex; i++) {
! if (a[i] != (long) A380) {
failed("Range sort changes left element on position " + i +
! ": " + a[i] + ", must be " + A380);
}
}
for (int i = fromIndex; i < toIndex - 1; i++) {
if (a[i] > a[i + 1]) {
failedSort(i, "" + a[i], "" + a[i + 1]);
}
}
for (int i = toIndex; i < a.length; i++) {
! if (a[i] != (long) B747) {
failed("Range sort changes right element on position " + i +
! ": " + a[i] + ", must be " + B747);
}
}
}
private static void checkSubArray(char[] a, int fromIndex, int toIndex, int m) {
for (int i = 0; i < fromIndex; i++) {
! if (a[i] != (char) A380) {
failed("Range sort changes left element on position " + i +
! ": " + a[i] + ", must be " + A380);
}
}
for (int i = fromIndex; i < toIndex - 1; i++) {
if (a[i] > a[i + 1]) {
failedSort(i, "" + a[i], "" + a[i + 1]);
}
}
for (int i = toIndex; i < a.length; i++) {
! if (a[i] != (char) B747) {
failed("Range sort changes right element on position " + i +
! ": " + a[i] + ", must be " + B747);
}
}
}
private static void checkSubArray(short[] a, int fromIndex, int toIndex, int m) {
for (int i = 0; i < fromIndex; i++) {
! if (a[i] != (short) A380) {
failed("Range sort changes left element on position " + i +
! ": " + a[i] + ", must be " + A380);
}
}
for (int i = fromIndex; i < toIndex - 1; i++) {
if (a[i] > a[i + 1]) {
failedSort(i, "" + a[i], "" + a[i + 1]);
}
}
for (int i = toIndex; i < a.length; i++) {
! if (a[i] != (short) B747) {
failed("Range sort changes right element on position " + i +
! ": " + a[i] + ", must be " + B747);
}
}
}
private static void checkSubArray(float[] a, int fromIndex, int toIndex, int m) {
for (int i = 0; i < fromIndex; i++) {
! if (a[i] != (float) A380) {
failed("Range sort changes left element on position " + i +
! ": " + a[i] + ", must be " + A380);
}
}
for (int i = fromIndex; i < toIndex - 1; i++) {
if (a[i] > a[i + 1]) {
failedSort(i, "" + a[i], "" + a[i + 1]);
}
}
for (int i = toIndex; i < a.length; i++) {
! if (a[i] != (float) B747) {
failed("Range sort changes right element on position " + i +
! ": " + a[i] + ", must be " + B747);
}
}
}
private static void checkSubArray(double[] a, int fromIndex, int toIndex, int m) {
for (int i = 0; i < fromIndex; i++) {
! if (a[i] != (double) A380) {
failed("Range sort changes left element on position " + i +
! ": " + a[i] + ", must be " + A380);
}
}
for (int i = fromIndex; i < toIndex - 1; i++) {
if (a[i] > a[i + 1]) {
failedSort(i, "" + a[i], "" + a[i + 1]);
}
}
for (int i = toIndex; i < a.length; i++) {
! if (a[i] != (double) B747) {
failed("Range sort changes right element on position " + i +
! ": " + a[i] + ", must be " + B747);
}
}
}
private static void checkRange(Object object, int m) {
*** 1760,1794 ****
} else if (object instanceof double[]) {
checkRange((double[]) object, m);
} else if (object instanceof Integer[]) {
checkRange((Integer[]) object, m);
} else {
! failed("Unknow type of array: " + object + " of class " +
object.getClass().getName());
}
}
private static void checkRange(Integer[] a, int m) {
try {
Arrays.sort(a, m + 1, m);
! failed("Sort does not throw IllegalArgumentException " +
" as expected: fromIndex = " + (m + 1) +
" toIndex = " + m);
}
catch (IllegalArgumentException iae) {
try {
Arrays.sort(a, -m, a.length);
! failed("Sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: fromIndex = " + (-m));
}
catch (ArrayIndexOutOfBoundsException aoe) {
try {
Arrays.sort(a, 0, a.length + m);
! failed("Sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
--- 1831,1865 ----
} else if (object instanceof double[]) {
checkRange((double[]) object, m);
} else if (object instanceof Integer[]) {
checkRange((Integer[]) object, m);
} else {
! failed("Unknown type of array: " + object + " of class " +
object.getClass().getName());
}
}
private static void checkRange(Integer[] a, int m) {
try {
Arrays.sort(a, m + 1, m);
! failed("Arrays.sort does not throw IllegalArgumentException " +
" as expected: fromIndex = " + (m + 1) +
" toIndex = " + m);
}
catch (IllegalArgumentException iae) {
try {
Arrays.sort(a, -m, a.length);
! failed("Arrays.sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: fromIndex = " + (-m));
}
catch (ArrayIndexOutOfBoundsException aoe) {
try {
Arrays.sort(a, 0, a.length + m);
! failed("Arrays.sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
*** 1798,1823 ****
private static void checkRange(int[] a, int m) {
try {
Arrays.sort(a, m + 1, m);
! failed("Sort does not throw IllegalArgumentException " +
" as expected: fromIndex = " + (m + 1) +
" toIndex = " + m);
}
catch (IllegalArgumentException iae) {
try {
Arrays.sort(a, -m, a.length);
! failed("Sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: fromIndex = " + (-m));
}
catch (ArrayIndexOutOfBoundsException aoe) {
try {
Arrays.sort(a, 0, a.length + m);
! failed("Sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
--- 1869,1894 ----
private static void checkRange(int[] a, int m) {
try {
Arrays.sort(a, m + 1, m);
! failed("Arrays.sort does not throw IllegalArgumentException " +
" as expected: fromIndex = " + (m + 1) +
" toIndex = " + m);
}
catch (IllegalArgumentException iae) {
try {
Arrays.sort(a, -m, a.length);
! failed("Arrays.sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: fromIndex = " + (-m));
}
catch (ArrayIndexOutOfBoundsException aoe) {
try {
Arrays.sort(a, 0, a.length + m);
! failed("Arrays.sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
*** 1827,1852 ****
private static void checkRange(long[] a, int m) {
try {
Arrays.sort(a, m + 1, m);
! failed("Sort does not throw IllegalArgumentException " +
" as expected: fromIndex = " + (m + 1) +
" toIndex = " + m);
}
catch (IllegalArgumentException iae) {
try {
Arrays.sort(a, -m, a.length);
! failed("Sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: fromIndex = " + (-m));
}
catch (ArrayIndexOutOfBoundsException aoe) {
try {
Arrays.sort(a, 0, a.length + m);
! failed("Sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
--- 1898,1923 ----
private static void checkRange(long[] a, int m) {
try {
Arrays.sort(a, m + 1, m);
! failed("Arrays.sort does not throw IllegalArgumentException " +
" as expected: fromIndex = " + (m + 1) +
" toIndex = " + m);
}
catch (IllegalArgumentException iae) {
try {
Arrays.sort(a, -m, a.length);
! failed("Arrays.sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: fromIndex = " + (-m));
}
catch (ArrayIndexOutOfBoundsException aoe) {
try {
Arrays.sort(a, 0, a.length + m);
! failed("Arrays.sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
*** 1856,1881 ****
private static void checkRange(byte[] a, int m) {
try {
Arrays.sort(a, m + 1, m);
! failed("Sort does not throw IllegalArgumentException " +
" as expected: fromIndex = " + (m + 1) +
" toIndex = " + m);
}
catch (IllegalArgumentException iae) {
try {
Arrays.sort(a, -m, a.length);
! failed("Sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: fromIndex = " + (-m));
}
catch (ArrayIndexOutOfBoundsException aoe) {
try {
Arrays.sort(a, 0, a.length + m);
! failed("Sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
--- 1927,1952 ----
private static void checkRange(byte[] a, int m) {
try {
Arrays.sort(a, m + 1, m);
! failed("Arrays.sort does not throw IllegalArgumentException " +
" as expected: fromIndex = " + (m + 1) +
" toIndex = " + m);
}
catch (IllegalArgumentException iae) {
try {
Arrays.sort(a, -m, a.length);
! failed("Arrays.sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: fromIndex = " + (-m));
}
catch (ArrayIndexOutOfBoundsException aoe) {
try {
Arrays.sort(a, 0, a.length + m);
! failed("Arrays.sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
*** 1885,1910 ****
private static void checkRange(short[] a, int m) {
try {
Arrays.sort(a, m + 1, m);
! failed("Sort does not throw IllegalArgumentException " +
" as expected: fromIndex = " + (m + 1) +
" toIndex = " + m);
}
catch (IllegalArgumentException iae) {
try {
Arrays.sort(a, -m, a.length);
! failed("Sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: fromIndex = " + (-m));
}
catch (ArrayIndexOutOfBoundsException aoe) {
try {
Arrays.sort(a, 0, a.length + m);
! failed("Sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
--- 1956,1981 ----
private static void checkRange(short[] a, int m) {
try {
Arrays.sort(a, m + 1, m);
! failed("Arrays.sort does not throw IllegalArgumentException " +
" as expected: fromIndex = " + (m + 1) +
" toIndex = " + m);
}
catch (IllegalArgumentException iae) {
try {
Arrays.sort(a, -m, a.length);
! failed("Arrays.sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: fromIndex = " + (-m));
}
catch (ArrayIndexOutOfBoundsException aoe) {
try {
Arrays.sort(a, 0, a.length + m);
! failed("Arrays.sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
*** 1914,1939 ****
private static void checkRange(char[] a, int m) {
try {
Arrays.sort(a, m + 1, m);
! failed("Sort does not throw IllegalArgumentException " +
" as expected: fromIndex = " + (m + 1) +
" toIndex = " + m);
}
catch (IllegalArgumentException iae) {
try {
Arrays.sort(a, -m, a.length);
! failed("Sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: fromIndex = " + (-m));
}
catch (ArrayIndexOutOfBoundsException aoe) {
try {
Arrays.sort(a, 0, a.length + m);
! failed("Sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
--- 1985,2010 ----
private static void checkRange(char[] a, int m) {
try {
Arrays.sort(a, m + 1, m);
! failed("Arrays.sort does not throw IllegalArgumentException " +
" as expected: fromIndex = " + (m + 1) +
" toIndex = " + m);
}
catch (IllegalArgumentException iae) {
try {
Arrays.sort(a, -m, a.length);
! failed("Arrays.sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: fromIndex = " + (-m));
}
catch (ArrayIndexOutOfBoundsException aoe) {
try {
Arrays.sort(a, 0, a.length + m);
! failed("Arrays.sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
*** 1943,1968 ****
private static void checkRange(float[] a, int m) {
try {
Arrays.sort(a, m + 1, m);
! failed("Sort does not throw IllegalArgumentException " +
" as expected: fromIndex = " + (m + 1) +
" toIndex = " + m);
}
catch (IllegalArgumentException iae) {
try {
Arrays.sort(a, -m, a.length);
! failed("Sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: fromIndex = " + (-m));
}
catch (ArrayIndexOutOfBoundsException aoe) {
try {
Arrays.sort(a, 0, a.length + m);
! failed("Sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
--- 2014,2039 ----
private static void checkRange(float[] a, int m) {
try {
Arrays.sort(a, m + 1, m);
! failed("Arrays.sort does not throw IllegalArgumentException " +
" as expected: fromIndex = " + (m + 1) +
" toIndex = " + m);
}
catch (IllegalArgumentException iae) {
try {
Arrays.sort(a, -m, a.length);
! failed("Arrays.sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: fromIndex = " + (-m));
}
catch (ArrayIndexOutOfBoundsException aoe) {
try {
Arrays.sort(a, 0, a.length + m);
! failed("Arrays.sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
*** 1972,1997 ****
private static void checkRange(double[] a, int m) {
try {
Arrays.sort(a, m + 1, m);
! failed("Sort does not throw IllegalArgumentException " +
" as expected: fromIndex = " + (m + 1) +
" toIndex = " + m);
}
catch (IllegalArgumentException iae) {
try {
Arrays.sort(a, -m, a.length);
! failed("Sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: fromIndex = " + (-m));
}
catch (ArrayIndexOutOfBoundsException aoe) {
try {
Arrays.sort(a, 0, a.length + m);
! failed("Sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
--- 2043,2068 ----
private static void checkRange(double[] a, int m) {
try {
Arrays.sort(a, m + 1, m);
! failed("Arrays.sort does not throw IllegalArgumentException " +
" as expected: fromIndex = " + (m + 1) +
" toIndex = " + m);
}
catch (IllegalArgumentException iae) {
try {
Arrays.sort(a, -m, a.length);
! failed("Arrays.sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: fromIndex = " + (-m));
}
catch (ArrayIndexOutOfBoundsException aoe) {
try {
Arrays.sort(a, 0, a.length + m);
! failed("Arrays.sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
< prev index next >