test/java/util/Arrays/Sorting.java

Print this page

        

@@ -544,17 +544,23 @@
         }
     }
 
     private static void prepareSubArray(int[] a, int fromIndex, int toIndex, int m) {
         for (int i = 0; i < fromIndex; i++) {
-            a[i] = 0xBABA;
+            a[i] = 0xDEDA;
         }
-        for (int i = fromIndex; i < toIndex; i++) {
-            a[i] = -i + m;
+        int middle = (fromIndex + toIndex) >>> 1;
+        int k = 0;
+
+        for (int i = fromIndex; i < middle; i++) {
+            a[i] = k++;
         }
+        for (int i = middle; i < toIndex; i++) {
+            a[i] = k--;
+        }
         for (int i = toIndex; i < a.length; i++) {
-            a[i] = 0xDEDA;
+            a[i] = 0xBABA;
         }
     }
 
     private static void scramble(int[] a) {
         for (int i = 0; i < a.length * 7; i++) {

@@ -1516,13 +1522,13 @@
         }
     }
 
     private static void checkSubArray(Integer[] a, int fromIndex, int toIndex, int m) {
         for (int i = 0; i < fromIndex; i++) {
-            if (a[i].intValue() != 0xBABA) {
+            if (a[i].intValue() != 0xDEDA) {
                 failed("Range sort changes left element on position " + i +
-                    ": " + a[i] + ", must be " + 0xBABA);
+                    ": " + a[i] + ", must be " + 0xDEDA);
             }
         }
 
         for (int i = fromIndex; i < toIndex - 1; i++) {
             if (a[i].intValue() > a[i + 1].intValue()) {

@@ -1529,22 +1535,22 @@
                 failedSort(i, "" + a[i], "" + a[i + 1]);
             }
         }
 
         for (int i = toIndex; i < a.length; i++) {
-            if (a[i].intValue() != 0xDEDA) {
+            if (a[i].intValue() != 0xBABA) {
                 failed("Range sort changes right element on position " + i +
-                    ": " + a[i] + ", must be " + 0xDEDA);
+                    ": " + 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] != 0xBABA) {
+            if (a[i] != 0xDEDA) {
                 failed("Range sort changes left element on position " + i +
-                    ": " + a[i] + ", must be " + 0xBABA);
+                    ": " + a[i] + ", must be " + 0xDEDA);
             }
         }
 
         for (int i = fromIndex; i < toIndex - 1; i++) {
             if (a[i] > a[i + 1]) {

@@ -1551,22 +1557,22 @@
                 failedSort(i, "" + a[i], "" + a[i + 1]);
             }
         }
 
         for (int i = toIndex; i < a.length; i++) {
-            if (a[i] != 0xDEDA) {
+            if (a[i] != 0xBABA) {
                 failed("Range sort changes right element on position " + i +
-                    ": " + a[i] + ", must be " + 0xDEDA);
+                    ": " + 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) 0xBABA) {
+            if (a[i] != (byte) 0xDEDA) {
                 failed("Range sort changes left element on position " + i +
-                    ": " + a[i] + ", must be " + 0xBABA);
+                    ": " + a[i] + ", must be " + 0xDEDA);
             }
         }
 
         for (int i = fromIndex; i < toIndex - 1; i++) {
             if (a[i] > a[i + 1]) {

@@ -1573,22 +1579,22 @@
                 failedSort(i, "" + a[i], "" + a[i + 1]);
             }
         }
 
         for (int i = toIndex; i < a.length; i++) {
-            if (a[i] != (byte) 0xDEDA) {
+            if (a[i] != (byte) 0xBABA) {
                 failed("Range sort changes right element on position " + i +
-                    ": " + a[i] + ", must be " + 0xDEDA);
+                    ": " + 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) 0xBABA) {
+            if (a[i] != (long) 0xDEDA) {
                 failed("Range sort changes left element on position " + i +
-                    ": " + a[i] + ", must be " + 0xBABA);
+                    ": " + a[i] + ", must be " + 0xDEDA);
             }
         }
 
         for (int i = fromIndex; i < toIndex - 1; i++) {
             if (a[i] > a[i + 1]) {

@@ -1595,22 +1601,22 @@
                 failedSort(i, "" + a[i], "" + a[i + 1]);
             }
         }
 
         for (int i = toIndex; i < a.length; i++) {
-            if (a[i] != (long) 0xDEDA) {
+            if (a[i] != (long) 0xBABA) {
                 failed("Range sort changes right element on position " + i +
-                    ": " + a[i] + ", must be " + 0xDEDA);
+                    ": " + 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) 0xBABA) {
+            if (a[i] != (char) 0xDEDA) {
                 failed("Range sort changes left element on position " + i +
-                    ": " + a[i] + ", must be " + 0xBABA);
+                    ": " + a[i] + ", must be " + 0xDEDA);
             }
         }
 
         for (int i = fromIndex; i < toIndex - 1; i++) {
             if (a[i] > a[i + 1]) {

@@ -1617,22 +1623,22 @@
                 failedSort(i, "" + a[i], "" + a[i + 1]);
             }
         }
 
         for (int i = toIndex; i < a.length; i++) {
-            if (a[i] != (char) 0xDEDA) {
+            if (a[i] != (char) 0xBABA) {
                 failed("Range sort changes right element on position " + i +
-                    ": " + a[i] + ", must be " + 0xDEDA);
+                    ": " + 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) 0xBABA) {
+            if (a[i] != (short) 0xDEDA) {
                 failed("Range sort changes left element on position " + i +
-                    ": " + a[i] + ", must be " + 0xBABA);
+                    ": " + a[i] + ", must be " + 0xDEDA);
             }
         }
 
         for (int i = fromIndex; i < toIndex - 1; i++) {
             if (a[i] > a[i + 1]) {

@@ -1639,22 +1645,22 @@
                 failedSort(i, "" + a[i], "" + a[i + 1]);
             }
         }
 
         for (int i = toIndex; i < a.length; i++) {
-            if (a[i] != (short) 0xDEDA) {
+            if (a[i] != (short) 0xBABA) {
                 failed("Range sort changes right element on position " + i +
-                    ": " + a[i] + ", must be " + 0xDEDA);
+                    ": " + 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) 0xBABA) {
+            if (a[i] != (float) 0xDEDA) {
                 failed("Range sort changes left element on position " + i +
-                    ": " + a[i] + ", must be " + 0xBABA);
+                    ": " + a[i] + ", must be " + 0xDEDA);
             }
         }
 
         for (int i = fromIndex; i < toIndex - 1; i++) {
             if (a[i] > a[i + 1]) {

@@ -1661,22 +1667,22 @@
                 failedSort(i, "" + a[i], "" + a[i + 1]);
             }
         }
 
         for (int i = toIndex; i < a.length; i++) {
-            if (a[i] != (float) 0xDEDA) {
+            if (a[i] != (float) 0xBABA) {
                 failed("Range sort changes right element on position " + i +
-                    ": " + a[i] + ", must be " + 0xDEDA);
+                    ": " + 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) 0xBABA) {
+            if (a[i] != (double) 0xDEDA) {
                 failed("Range sort changes left element on position " + i +
-                    ": " + a[i] + ", must be " + 0xBABA);
+                    ": " + a[i] + ", must be " + 0xDEDA);
             }
         }
 
         for (int i = fromIndex; i < toIndex - 1; i++) {
             if (a[i] > a[i + 1]) {

@@ -1683,13 +1689,13 @@
                 failedSort(i, "" + a[i], "" + a[i + 1]);
             }
         }
 
         for (int i = toIndex; i < a.length; i++) {
-            if (a[i] != (double) 0xDEDA) {
+            if (a[i] != (double) 0xBABA) {
                 failed("Range sort changes right element on position " + i +
-                    ": " + a[i] + ", must be " + 0xDEDA);
+                    ": " + a[i] + ", must be " + 0xBABA);
             }
         }
     }
 
     private static void checkRange(Object object, int m) {