< prev index next >
test/jdk/java/util/Arrays/ParallelSorting.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2011, 2013, 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) 2011, 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.
*** 21,69 ****
* questions.
*/
/* Adapted from test/java/util/Arrays/Sorting.java
*
* Where that test checks Arrays.sort against manual quicksort routines,
! * this test checks parallelSort against either Arrays.sort or manual
! * quicksort routines.
*/
/*
* @test
* @bug 8003981
* @run main ParallelSorting -shortrun
! * @summary Exercise Arrays.parallelSort (adapted from test Sorting)
*
* @author Vladimir Yaroslavskiy
* @author Jon Bentley
* @author Josh Bloch
*/
import java.util.Arrays;
import java.util.Random;
- import java.io.PrintStream;
import java.util.Comparator;
public class ParallelSorting {
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 = {
! 1000, 10000, 100000, 1000000 };
// Array lengths used in a short run
private static final int[] SHORT_RUN_LENGTHS = {
! 5000, 9000, 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 };
public static void main(String[] args) {
boolean shortRun = args.length > 0 && args[0].equals("-shortrun");
long start = System.currentTimeMillis();
if (shortRun) {
--- 21,76 ----
* questions.
*/
/* Adapted from test/java/util/Arrays/Sorting.java
*
+ * To generate the source of this class, take the source of Sorting.java
+ * and replace "Arrays.sort' by "Arrays.parallelSort'.
+ *
* Where that test checks Arrays.sort against manual quicksort routines,
! * this test checks parallelSort against manual quicksort routines.
*/
/*
* @test
* @bug 8003981
* @run main ParallelSorting -shortrun
! * @summary Exercise Arrays.parallelSort
*
* @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 ParallelSorting {
+
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) {
*** 84,94 ****
testEmptyAndNullByteArray();
testEmptyAndNullFloatArray();
testEmptyAndNullDoubleArray();
for (int length : lengths) {
! testMergeSort(length);
testAndCheckRange(length);
testAndCheckSubArray(length);
}
for (long seed : randoms) {
for (int length : lengths) {
--- 91,101 ----
testEmptyAndNullByteArray();
testEmptyAndNullFloatArray();
testEmptyAndNullDoubleArray();
for (int length : lengths) {
! testMergingSort(length);
testAndCheckRange(length);
testAndCheckSubArray(length);
}
for (long seed : randoms) {
for (int length : lengths) {
*** 102,113 ****
}
}
private static void testEmptyAndNullIntArray() {
ourDescription = "Check empty and null array";
! Arrays.parallelSort(new int[]{});
! Arrays.parallelSort(new int[]{}, 0, 0);
try {
Arrays.parallelSort((int[]) null);
} catch (NullPointerException expected) {
try {
--- 109,120 ----
}
}
private static void testEmptyAndNullIntArray() {
ourDescription = "Check empty and null array";
! Arrays.parallelSort(new int[] {});
! Arrays.parallelSort(new int[] {}, 0, 0);
try {
Arrays.parallelSort((int[]) null);
} catch (NullPointerException expected) {
try {
*** 121,132 ****
failed("Arrays.parallelSort(int[]) shouldn't catch null array");
}
private static void testEmptyAndNullLongArray() {
ourDescription = "Check empty and null array";
! Arrays.parallelSort(new long[]{});
! Arrays.parallelSort(new long[]{}, 0, 0);
try {
Arrays.parallelSort((long[]) null);
} catch (NullPointerException expected) {
try {
--- 128,139 ----
failed("Arrays.parallelSort(int[]) shouldn't catch null array");
}
private static void testEmptyAndNullLongArray() {
ourDescription = "Check empty and null array";
! Arrays.parallelSort(new long[] {});
! Arrays.parallelSort(new long[] {}, 0, 0);
try {
Arrays.parallelSort((long[]) null);
} catch (NullPointerException expected) {
try {
*** 140,151 ****
failed("Arrays.parallelSort(long[]) shouldn't catch null array");
}
private static void testEmptyAndNullShortArray() {
ourDescription = "Check empty and null array";
! Arrays.parallelSort(new short[]{});
! Arrays.parallelSort(new short[]{}, 0, 0);
try {
Arrays.parallelSort((short[]) null);
} catch (NullPointerException expected) {
try {
--- 147,158 ----
failed("Arrays.parallelSort(long[]) shouldn't catch null array");
}
private static void testEmptyAndNullShortArray() {
ourDescription = "Check empty and null array";
! Arrays.parallelSort(new short[] {});
! Arrays.parallelSort(new short[] {}, 0, 0);
try {
Arrays.parallelSort((short[]) null);
} catch (NullPointerException expected) {
try {
*** 159,170 ****
failed("Arrays.parallelSort(short[]) shouldn't catch null array");
}
private static void testEmptyAndNullCharArray() {
ourDescription = "Check empty and null array";
! Arrays.parallelSort(new char[]{});
! Arrays.parallelSort(new char[]{}, 0, 0);
try {
Arrays.parallelSort((char[]) null);
} catch (NullPointerException expected) {
try {
--- 166,177 ----
failed("Arrays.parallelSort(short[]) shouldn't catch null array");
}
private static void testEmptyAndNullCharArray() {
ourDescription = "Check empty and null array";
! Arrays.parallelSort(new char[] {});
! Arrays.parallelSort(new char[] {}, 0, 0);
try {
Arrays.parallelSort((char[]) null);
} catch (NullPointerException expected) {
try {
*** 178,189 ****
failed("Arrays.parallelSort(char[]) shouldn't catch null array");
}
private static void testEmptyAndNullByteArray() {
ourDescription = "Check empty and null array";
! Arrays.parallelSort(new byte[]{});
! Arrays.parallelSort(new byte[]{}, 0, 0);
try {
Arrays.parallelSort((byte[]) null);
} catch (NullPointerException expected) {
try {
--- 185,196 ----
failed("Arrays.parallelSort(char[]) shouldn't catch null array");
}
private static void testEmptyAndNullByteArray() {
ourDescription = "Check empty and null array";
! Arrays.parallelSort(new byte[] {});
! Arrays.parallelSort(new byte[] {}, 0, 0);
try {
Arrays.parallelSort((byte[]) null);
} catch (NullPointerException expected) {
try {
*** 197,208 ****
failed("Arrays.parallelSort(byte[]) shouldn't catch null array");
}
private static void testEmptyAndNullFloatArray() {
ourDescription = "Check empty and null array";
! Arrays.parallelSort(new float[]{});
! Arrays.parallelSort(new float[]{}, 0, 0);
try {
Arrays.parallelSort((float[]) null);
} catch (NullPointerException expected) {
try {
--- 204,215 ----
failed("Arrays.parallelSort(byte[]) shouldn't catch null array");
}
private static void testEmptyAndNullFloatArray() {
ourDescription = "Check empty and null array";
! Arrays.parallelSort(new float[] {});
! Arrays.parallelSort(new float[] {}, 0, 0);
try {
Arrays.parallelSort((float[]) null);
} catch (NullPointerException expected) {
try {
*** 216,227 ****
failed("Arrays.parallelSort(float[]) shouldn't catch null array");
}
private static void testEmptyAndNullDoubleArray() {
ourDescription = "Check empty and null array";
! Arrays.parallelSort(new double[]{});
! Arrays.parallelSort(new double[]{}, 0, 0);
try {
Arrays.parallelSort((double[]) null);
} catch (NullPointerException expected) {
try {
--- 223,234 ----
failed("Arrays.parallelSort(float[]) shouldn't catch null array");
}
private static void testEmptyAndNullDoubleArray() {
ourDescription = "Check empty and null array";
! Arrays.parallelSort(new double[] {});
! Arrays.parallelSort(new double[] {}, 0, 0);
try {
Arrays.parallelSort((double[]) null);
} catch (NullPointerException expected) {
try {
*** 293,307 ****
a = build(length, random);
out.println("Test 'stable' comparator: " + "random = " + random.getSeed() +
", length = " + length);
! Arrays.parallelSort(a, pairCmp);
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()) {
--- 300,313 ----
a = build(length, random);
out.println("Test 'stable' comparator: " + "random = " + random.getSeed() +
", length = " + length);
! Arrays.parallelSort(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()) {
*** 344,354 ****
a[i++] = new Pair(key, 4);
}
return a;
}
! private static Comparator<Pair> pairCmp = new Comparator<Pair>() {
public int compare(Pair p1, Pair p2) {
return p1.compareTo(p2);
}
};
--- 350,360 ----
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);
}
};
*** 412,436 ****
}
}
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);
}
--- 418,442 ----
}
}
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);
}
*** 490,511 ****
}
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 = " +
--- 496,514 ----
}
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 = " +
*** 565,575 ****
}
}
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++) {
--- 568,578 ----
}
}
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++) {
*** 577,587 ****
}
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++) {
--- 580,590 ----
}
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++) {
*** 688,706 ****
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 += " ";
}
--- 691,710 ----
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 += " ";
}
*** 849,869 ****
}
};
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;
--- 853,874 ----
}
};
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;
*** 893,916 ****
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();
--- 898,971 ----
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();
*** 1013,1023 ****
}
};
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 += " ";
}
--- 1068,1079 ----
}
};
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,1070 ****
} 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) {
--- 1116,1126 ----
} 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) {
*** 1147,1157 ****
} 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) {
--- 1203,1213 ----
} 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) {
*** 1243,1253 ****
} 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;
}
}
--- 1299,1309 ----
} 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;
}
}
*** 1339,1349 ****
} 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;
}
}
--- 1395,1405 ----
} 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;
}
}
*** 1435,1445 ****
} 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) {
--- 1491,1501 ----
} 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) {
*** 1538,1548 ****
} else if (object instanceof double[]) {
Arrays.parallelSort((double[]) object);
} else if (object instanceof Integer[]) {
Arrays.parallelSort((Integer[]) object);
} else {
! failed("Unknow type of array: " + object + " of class " +
object.getClass().getName());
}
}
private static void sortSubArray(Object object, int fromIndex, int toIndex) {
--- 1594,1604 ----
} else if (object instanceof double[]) {
Arrays.parallelSort((double[]) object);
} else if (object instanceof Integer[]) {
Arrays.parallelSort((Integer[]) object);
} else {
! failed("Unknown type of array: " + object + " of class " +
object.getClass().getName());
}
}
private static void sortSubArray(Object object, int fromIndex, int toIndex) {
*** 1561,1571 ****
} else if (object instanceof double[]) {
Arrays.parallelSort((double[]) object, fromIndex, toIndex);
} else if (object instanceof Integer[]) {
Arrays.parallelSort((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) {
--- 1617,1627 ----
} else if (object instanceof double[]) {
Arrays.parallelSort((double[]) object, fromIndex, toIndex);
} else if (object instanceof Integer[]) {
Arrays.parallelSort((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) {
*** 1584,1770 ****
} 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) {
--- 1640,1826 ----
} 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) {
*** 1783,1817 ****
} 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.parallelSort(a, m + 1, m);
! failed("ParallelSort does not throw IllegalArgumentException " +
" as expected: fromIndex = " + (m + 1) +
" toIndex = " + m);
}
catch (IllegalArgumentException iae) {
try {
Arrays.parallelSort(a, -m, a.length);
! failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
" as expected: fromIndex = " + (-m));
}
catch (ArrayIndexOutOfBoundsException aoe) {
try {
Arrays.parallelSort(a, 0, a.length + m);
! failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
--- 1839,1873 ----
} 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.parallelSort(a, m + 1, m);
! failed("Arrays.parallelSort does not throw IllegalArgumentException " +
" as expected: fromIndex = " + (m + 1) +
" toIndex = " + m);
}
catch (IllegalArgumentException iae) {
try {
Arrays.parallelSort(a, -m, a.length);
! failed("Arrays.parallelSort does not throw ArrayIndexOutOfBoundsException " +
" as expected: fromIndex = " + (-m));
}
catch (ArrayIndexOutOfBoundsException aoe) {
try {
Arrays.parallelSort(a, 0, a.length + m);
! failed("Arrays.parallelSort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
*** 1821,1846 ****
private static void checkRange(int[] a, int m) {
try {
Arrays.parallelSort(a, m + 1, m);
! failed("ParallelSort does not throw IllegalArgumentException " +
" as expected: fromIndex = " + (m + 1) +
" toIndex = " + m);
}
catch (IllegalArgumentException iae) {
try {
Arrays.parallelSort(a, -m, a.length);
! failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
" as expected: fromIndex = " + (-m));
}
catch (ArrayIndexOutOfBoundsException aoe) {
try {
Arrays.parallelSort(a, 0, a.length + m);
! failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
--- 1877,1902 ----
private static void checkRange(int[] a, int m) {
try {
Arrays.parallelSort(a, m + 1, m);
! failed("Arrays.parallelSort does not throw IllegalArgumentException " +
" as expected: fromIndex = " + (m + 1) +
" toIndex = " + m);
}
catch (IllegalArgumentException iae) {
try {
Arrays.parallelSort(a, -m, a.length);
! failed("Arrays.parallelSort does not throw ArrayIndexOutOfBoundsException " +
" as expected: fromIndex = " + (-m));
}
catch (ArrayIndexOutOfBoundsException aoe) {
try {
Arrays.parallelSort(a, 0, a.length + m);
! failed("Arrays.parallelSort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
*** 1850,1875 ****
private static void checkRange(long[] a, int m) {
try {
Arrays.parallelSort(a, m + 1, m);
! failed("ParallelSort does not throw IllegalArgumentException " +
" as expected: fromIndex = " + (m + 1) +
" toIndex = " + m);
}
catch (IllegalArgumentException iae) {
try {
Arrays.parallelSort(a, -m, a.length);
! failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
" as expected: fromIndex = " + (-m));
}
catch (ArrayIndexOutOfBoundsException aoe) {
try {
Arrays.parallelSort(a, 0, a.length + m);
! failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
--- 1906,1931 ----
private static void checkRange(long[] a, int m) {
try {
Arrays.parallelSort(a, m + 1, m);
! failed("Arrays.parallelSort does not throw IllegalArgumentException " +
" as expected: fromIndex = " + (m + 1) +
" toIndex = " + m);
}
catch (IllegalArgumentException iae) {
try {
Arrays.parallelSort(a, -m, a.length);
! failed("Arrays.parallelSort does not throw ArrayIndexOutOfBoundsException " +
" as expected: fromIndex = " + (-m));
}
catch (ArrayIndexOutOfBoundsException aoe) {
try {
Arrays.parallelSort(a, 0, a.length + m);
! failed("Arrays.parallelSort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
*** 1879,1904 ****
private static void checkRange(byte[] a, int m) {
try {
Arrays.parallelSort(a, m + 1, m);
! failed("ParallelSort does not throw IllegalArgumentException " +
" as expected: fromIndex = " + (m + 1) +
" toIndex = " + m);
}
catch (IllegalArgumentException iae) {
try {
Arrays.parallelSort(a, -m, a.length);
! failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
" as expected: fromIndex = " + (-m));
}
catch (ArrayIndexOutOfBoundsException aoe) {
try {
Arrays.parallelSort(a, 0, a.length + m);
! failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
--- 1935,1960 ----
private static void checkRange(byte[] a, int m) {
try {
Arrays.parallelSort(a, m + 1, m);
! failed("Arrays.parallelSort does not throw IllegalArgumentException " +
" as expected: fromIndex = " + (m + 1) +
" toIndex = " + m);
}
catch (IllegalArgumentException iae) {
try {
Arrays.parallelSort(a, -m, a.length);
! failed("Arrays.parallelSort does not throw ArrayIndexOutOfBoundsException " +
" as expected: fromIndex = " + (-m));
}
catch (ArrayIndexOutOfBoundsException aoe) {
try {
Arrays.parallelSort(a, 0, a.length + m);
! failed("Arrays.parallelSort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
*** 1908,1933 ****
private static void checkRange(short[] a, int m) {
try {
Arrays.parallelSort(a, m + 1, m);
! failed("ParallelSort does not throw IllegalArgumentException " +
" as expected: fromIndex = " + (m + 1) +
" toIndex = " + m);
}
catch (IllegalArgumentException iae) {
try {
Arrays.parallelSort(a, -m, a.length);
! failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
" as expected: fromIndex = " + (-m));
}
catch (ArrayIndexOutOfBoundsException aoe) {
try {
Arrays.parallelSort(a, 0, a.length + m);
! failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
--- 1964,1989 ----
private static void checkRange(short[] a, int m) {
try {
Arrays.parallelSort(a, m + 1, m);
! failed("Arrays.parallelSort does not throw IllegalArgumentException " +
" as expected: fromIndex = " + (m + 1) +
" toIndex = " + m);
}
catch (IllegalArgumentException iae) {
try {
Arrays.parallelSort(a, -m, a.length);
! failed("Arrays.parallelSort does not throw ArrayIndexOutOfBoundsException " +
" as expected: fromIndex = " + (-m));
}
catch (ArrayIndexOutOfBoundsException aoe) {
try {
Arrays.parallelSort(a, 0, a.length + m);
! failed("Arrays.parallelSort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
*** 1937,1962 ****
private static void checkRange(char[] a, int m) {
try {
Arrays.parallelSort(a, m + 1, m);
! failed("ParallelSort does not throw IllegalArgumentException " +
" as expected: fromIndex = " + (m + 1) +
" toIndex = " + m);
}
catch (IllegalArgumentException iae) {
try {
Arrays.parallelSort(a, -m, a.length);
! failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
" as expected: fromIndex = " + (-m));
}
catch (ArrayIndexOutOfBoundsException aoe) {
try {
Arrays.parallelSort(a, 0, a.length + m);
! failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
--- 1993,2018 ----
private static void checkRange(char[] a, int m) {
try {
Arrays.parallelSort(a, m + 1, m);
! failed("Arrays.parallelSort does not throw IllegalArgumentException " +
" as expected: fromIndex = " + (m + 1) +
" toIndex = " + m);
}
catch (IllegalArgumentException iae) {
try {
Arrays.parallelSort(a, -m, a.length);
! failed("Arrays.parallelSort does not throw ArrayIndexOutOfBoundsException " +
" as expected: fromIndex = " + (-m));
}
catch (ArrayIndexOutOfBoundsException aoe) {
try {
Arrays.parallelSort(a, 0, a.length + m);
! failed("Arrays.parallelSort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
*** 1966,1991 ****
private static void checkRange(float[] a, int m) {
try {
Arrays.parallelSort(a, m + 1, m);
! failed("ParallelSort does not throw IllegalArgumentException " +
" as expected: fromIndex = " + (m + 1) +
" toIndex = " + m);
}
catch (IllegalArgumentException iae) {
try {
Arrays.parallelSort(a, -m, a.length);
! failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
" as expected: fromIndex = " + (-m));
}
catch (ArrayIndexOutOfBoundsException aoe) {
try {
Arrays.parallelSort(a, 0, a.length + m);
! failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
--- 2022,2047 ----
private static void checkRange(float[] a, int m) {
try {
Arrays.parallelSort(a, m + 1, m);
! failed("Arrays.parallelSort does not throw IllegalArgumentException " +
" as expected: fromIndex = " + (m + 1) +
" toIndex = " + m);
}
catch (IllegalArgumentException iae) {
try {
Arrays.parallelSort(a, -m, a.length);
! failed("Arrays.parallelSort does not throw ArrayIndexOutOfBoundsException " +
" as expected: fromIndex = " + (-m));
}
catch (ArrayIndexOutOfBoundsException aoe) {
try {
Arrays.parallelSort(a, 0, a.length + m);
! failed("Arrays.parallelSort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
*** 1995,2020 ****
private static void checkRange(double[] a, int m) {
try {
Arrays.parallelSort(a, m + 1, m);
! failed("ParallelSort does not throw IllegalArgumentException " +
" as expected: fromIndex = " + (m + 1) +
" toIndex = " + m);
}
catch (IllegalArgumentException iae) {
try {
Arrays.parallelSort(a, -m, a.length);
! failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
" as expected: fromIndex = " + (-m));
}
catch (ArrayIndexOutOfBoundsException aoe) {
try {
Arrays.parallelSort(a, 0, a.length + m);
! failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
--- 2051,2076 ----
private static void checkRange(double[] a, int m) {
try {
Arrays.parallelSort(a, m + 1, m);
! failed("Arrays.parallelSort does not throw IllegalArgumentException " +
" as expected: fromIndex = " + (m + 1) +
" toIndex = " + m);
}
catch (IllegalArgumentException iae) {
try {
Arrays.parallelSort(a, -m, a.length);
! failed("Arrays.parallelSort does not throw ArrayIndexOutOfBoundsException " +
" as expected: fromIndex = " + (-m));
}
catch (ArrayIndexOutOfBoundsException aoe) {
try {
Arrays.parallelSort(a, 0, a.length + m);
! failed("Arrays.parallelSort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
< prev index next >