< prev index next >
test/jdk/java/util/Arrays/Sorting.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
+ * 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,41 +22,47 @@
*/
/*
* @test
* @bug 6880672 6896573 6899694 6976036 7013585 7018258
- * @summary Exercise Arrays.sort
* @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.io.PrintStream;
+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 };
+ 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,11 +83,11 @@
testEmptyAndNullByteArray();
testEmptyAndNullFloatArray();
testEmptyAndNullDoubleArray();
for (int length : lengths) {
- testMergeSort(length);
+ testMergingSort(length);
testAndCheckRange(length);
testAndCheckSubArray(length);
}
for (long seed : randoms) {
for (int length : lengths) {
@@ -281,10 +287,19 @@
", 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,10 +342,16 @@
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,25 +410,25 @@
}
}
out.println();
}
- private static void testMergeSort(int length) {
+ private static void testMergingSort(int length) {
if (length < 1000) {
return;
}
- ourDescription = "Check merge sorting";
+ ourDescription = "Check merging sort";
int[] golden = new int[length];
- int period = 67; // java.util.DualPivotQuicksort.MAX_RUN_COUNT
+ final int period = 50;
for (int m = period - 2; m <= period + 2; m++) {
- for (MergeBuilder builder : MergeBuilder.values()) {
+ for (MergingBuilder builder : MergingBuilder.values()) {
builder.build(golden, m);
int[] test = golden.clone();
for (TypeConverter converter : TypeConverter.values()) {
- out.println("Test 'merge sort': " + converter + " " +
+ out.println("Test 'merging sort': " + converter + " " +
builder + "length = " + length + ", m = " + m);
Object convertedGolden = converter.convert(golden);
sort(convertedGolden);
checkSorted(convertedGolden);
}
@@ -467,22 +488,19 @@
}
private static void testAndCheckFloat(int length, MyRandom random) {
ourDescription = "Check float sorting";
float[] golden = new float[length];
- final int MAX = 10;
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;
- }
- if (a + g + z + n + p < length) {
+ 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,11 +560,11 @@
}
}
private static void prepareSubArray(int[] a, int fromIndex, int toIndex, int m) {
for (int i = 0; i < fromIndex; i++) {
- a[i] = 0xDEDA;
+ a[i] = A380;
}
int middle = (fromIndex + toIndex) >>> 1;
int k = 0;
for (int i = fromIndex; i < middle; i++) {
@@ -554,11 +572,11 @@
}
for (int i = middle; i < toIndex; i++) {
a[i] = k--;
}
for (int i = toIndex; i < a.length; i++) {
- a[i] = 0xBABA;
+ a[i] = B747;
}
}
private static void scramble(int[] a, Random random) {
for (int i = 0; i < a.length * 7; i++) {
@@ -665,19 +683,20 @@
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]);
+ b[i] = Integer.valueOf(a[i]);
}
return b;
}
};
abstract Object convert(int[] a);
- @Override public String toString() {
+ @Override
+ public String toString() {
String name = name();
for (int i = name.length(); i < 9; i++) {
name += " ";
}
@@ -826,21 +845,22 @@
}
};
abstract void build(int[] a, int m);
- @Override public String toString() {
+ @Override
+ public String toString() {
String name = name();
for (int i = name.length(); i < 12; i++) {
name += " ";
}
return name;
}
}
- private static enum MergeBuilder {
+ private static enum MergingBuilder {
ASCENDING {
void build(int[] a, int m) {
int period = a.length / m;
int v = 1, i = 0;
@@ -870,24 +890,74 @@
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() {
+ @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,11 +1060,12 @@
}
};
abstract void build(int[] a, int m, Random random);
- @Override public String toString() {
+ @Override
+ public String toString() {
String name = name();
for (int i = name.length(); i < 12; i++) {
name += " ";
}
@@ -1037,11 +1108,11 @@
} 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 " +
+ failed("Unknown type of array: " + test + " of class " +
test.getClass().getName());
}
}
private static void compare(int[] a, int[] b) {
@@ -1124,11 +1195,11 @@
} 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 " +
+ failed("Unknown type of array: " + object + " of class " +
object.getClass().getName());
}
}
private static void checkSorted(int[] a) {
@@ -1220,11 +1291,11 @@
} 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 " +
+ failed("Unknown type of array: " + object + " of class " +
object.getClass().getName());
return -1;
}
}
@@ -1316,11 +1387,11 @@
} 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 " +
+ failed("Unknown type of array: " + object + " of class " +
object.getClass().getName());
return -1;
}
}
@@ -1412,11 +1483,11 @@
} 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 " +
+ failed("Unknown type of array: " + object + " of class " +
object.getClass().getName());
}
}
private static void sortByInsertionSort(int[] a) {
@@ -1515,11 +1586,11 @@
} 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 " +
+ failed("Unknown type of array: " + object + " of class " +
object.getClass().getName());
}
}
private static void sortSubArray(Object object, int fromIndex, int toIndex) {
@@ -1538,11 +1609,11 @@
} 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 " +
+ failed("Unknown type of array: " + object + " of class " +
object.getClass().getName());
}
}
private static void checkSubArray(Object object, int fromIndex, int toIndex, int m) {
@@ -1561,187 +1632,187 @@
} 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 " +
+ 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() != 0xDEDA) {
+ if (a[i].intValue() != A380) {
failed("Range sort changes left element on position " + i +
- ": " + a[i] + ", must be " + 0xDEDA);
+ ": " + 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() != 0xBABA) {
+ if (a[i].intValue() != B747) {
failed("Range sort changes right element on position " + i +
- ": " + a[i] + ", must be " + 0xBABA);
+ ": " + 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] != 0xDEDA) {
+ if (a[i] != A380) {
failed("Range sort changes left element on position " + i +
- ": " + a[i] + ", must be " + 0xDEDA);
+ ": " + 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] != 0xBABA) {
+ if (a[i] != B747) {
failed("Range sort changes right element on position " + i +
- ": " + a[i] + ", must be " + 0xBABA);
+ ": " + 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) 0xDEDA) {
+ if (a[i] != (byte) A380) {
failed("Range sort changes left element on position " + i +
- ": " + a[i] + ", must be " + 0xDEDA);
+ ": " + 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) 0xBABA) {
+ if (a[i] != (byte) B747) {
failed("Range sort changes right element on position " + i +
- ": " + a[i] + ", must be " + 0xBABA);
+ ": " + 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) 0xDEDA) {
+ if (a[i] != (long) A380) {
failed("Range sort changes left element on position " + i +
- ": " + a[i] + ", must be " + 0xDEDA);
+ ": " + 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) 0xBABA) {
+ if (a[i] != (long) B747) {
failed("Range sort changes right element on position " + i +
- ": " + a[i] + ", must be " + 0xBABA);
+ ": " + 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) 0xDEDA) {
+ if (a[i] != (char) A380) {
failed("Range sort changes left element on position " + i +
- ": " + a[i] + ", must be " + 0xDEDA);
+ ": " + 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) 0xBABA) {
+ if (a[i] != (char) B747) {
failed("Range sort changes right element on position " + i +
- ": " + a[i] + ", must be " + 0xBABA);
+ ": " + 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) 0xDEDA) {
+ if (a[i] != (short) A380) {
failed("Range sort changes left element on position " + i +
- ": " + a[i] + ", must be " + 0xDEDA);
+ ": " + 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) 0xBABA) {
+ if (a[i] != (short) B747) {
failed("Range sort changes right element on position " + i +
- ": " + a[i] + ", must be " + 0xBABA);
+ ": " + 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) 0xDEDA) {
+ if (a[i] != (float) A380) {
failed("Range sort changes left element on position " + i +
- ": " + a[i] + ", must be " + 0xDEDA);
+ ": " + 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) 0xBABA) {
+ if (a[i] != (float) B747) {
failed("Range sort changes right element on position " + i +
- ": " + a[i] + ", must be " + 0xBABA);
+ ": " + 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) 0xDEDA) {
+ if (a[i] != (double) A380) {
failed("Range sort changes left element on position " + i +
- ": " + a[i] + ", must be " + 0xDEDA);
+ ": " + 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) 0xBABA) {
+ if (a[i] != (double) B747) {
failed("Range sort changes right element on position " + i +
- ": " + a[i] + ", must be " + 0xBABA);
+ ": " + a[i] + ", must be " + B747);
}
}
}
private static void checkRange(Object object, int m) {
@@ -1760,35 +1831,35 @@
} 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 " +
+ 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("Sort does not throw IllegalArgumentException " +
+ 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("Sort does not throw ArrayIndexOutOfBoundsException " +
+ failed("Arrays.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 " +
+ failed("Arrays.sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
@@ -1798,26 +1869,26 @@
private static void checkRange(int[] a, int m) {
try {
Arrays.sort(a, m + 1, m);
- failed("Sort does not throw IllegalArgumentException " +
+ 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("Sort does not throw ArrayIndexOutOfBoundsException " +
+ failed("Arrays.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 " +
+ failed("Arrays.sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
@@ -1827,26 +1898,26 @@
private static void checkRange(long[] a, int m) {
try {
Arrays.sort(a, m + 1, m);
- failed("Sort does not throw IllegalArgumentException " +
+ 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("Sort does not throw ArrayIndexOutOfBoundsException " +
+ failed("Arrays.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 " +
+ failed("Arrays.sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
@@ -1856,26 +1927,26 @@
private static void checkRange(byte[] a, int m) {
try {
Arrays.sort(a, m + 1, m);
- failed("Sort does not throw IllegalArgumentException " +
+ 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("Sort does not throw ArrayIndexOutOfBoundsException " +
+ failed("Arrays.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 " +
+ failed("Arrays.sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
@@ -1885,26 +1956,26 @@
private static void checkRange(short[] a, int m) {
try {
Arrays.sort(a, m + 1, m);
- failed("Sort does not throw IllegalArgumentException " +
+ 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("Sort does not throw ArrayIndexOutOfBoundsException " +
+ failed("Arrays.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 " +
+ failed("Arrays.sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
@@ -1914,26 +1985,26 @@
private static void checkRange(char[] a, int m) {
try {
Arrays.sort(a, m + 1, m);
- failed("Sort does not throw IllegalArgumentException " +
+ 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("Sort does not throw ArrayIndexOutOfBoundsException " +
+ failed("Arrays.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 " +
+ failed("Arrays.sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
@@ -1943,26 +2014,26 @@
private static void checkRange(float[] a, int m) {
try {
Arrays.sort(a, m + 1, m);
- failed("Sort does not throw IllegalArgumentException " +
+ 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("Sort does not throw ArrayIndexOutOfBoundsException " +
+ failed("Arrays.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 " +
+ failed("Arrays.sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
@@ -1972,26 +2043,26 @@
private static void checkRange(double[] a, int m) {
try {
Arrays.sort(a, m + 1, m);
- failed("Sort does not throw IllegalArgumentException " +
+ 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("Sort does not throw ArrayIndexOutOfBoundsException " +
+ failed("Arrays.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 " +
+ failed("Arrays.sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
< prev index next >