Home | History | Annotate | Download | only in util
      1 /*
      2  *  Licensed to the Apache Software Foundation (ASF) under one or more
      3  *  contributor license agreements.  See the NOTICE file distributed with
      4  *  this work for additional information regarding copyright ownership.
      5  *  The ASF licenses this file to You under the Apache License, Version 2.0
      6  *  (the "License"); you may not use this file except in compliance with
      7  *  the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  */
     17 package org.apache.harmony.tests.java.util;
     18 
     19 import libcore.java.util.SpliteratorTester;
     20 import tests.support.Support_UnmodifiableCollectionTest;
     21 import java.lang.reflect.Method;
     22 import java.util.ArrayList;
     23 import java.util.Arrays;
     24 import java.util.Collections;
     25 import java.util.Comparator;
     26 import java.util.Date;
     27 import java.util.LinkedList;
     28 import java.util.List;
     29 import java.util.Random;
     30 import java.util.Spliterator;
     31 import java.util.function.Consumer;
     32 import java.util.function.DoubleConsumer;
     33 import java.util.function.IntConsumer;
     34 import java.util.function.LongConsumer;
     35 import java.util.HashMap;
     36 import java.util.Map;
     37 import java.util.concurrent.ForkJoinPool;
     38 
     39 public class ArraysTest extends junit.framework.TestCase {
     40 
     41     public static class ReversedIntegerComparator implements Comparator {
     42         public int compare(Object o1, Object o2) {
     43             return -(((Integer) o1).compareTo((Integer) o2));
     44         }
     45 
     46         public boolean equals(Object o1, Object o2) {
     47             return ((Integer) o1).compareTo((Integer) o2) == 0;
     48         }
     49     }
     50 
     51     static class MockComparable implements Comparable {
     52         public int compareTo(Object o) {
     53             return 0;
     54         }
     55     }
     56 
     57     final static int arraySize = 100;
     58 
     59     Object[] objArray;
     60 
     61     boolean[] booleanArray;
     62 
     63     byte[] byteArray;
     64 
     65     char[] charArray;
     66 
     67     double[] doubleArray;
     68 
     69     float[] floatArray;
     70 
     71     int[] intArray;
     72 
     73     long[] longArray;
     74 
     75     Object[] objectArray;
     76 
     77     short[] shortArray;
     78 
     79     /**
     80      * java.util.Arrays#asList(java.lang.Object[])
     81      */
     82     public void test_asList$Ljava_lang_Object() {
     83         // Test for method java.util.List
     84         // java.util.Arrays.asList(java.lang.Object [])
     85         List convertedList = Arrays.asList(objectArray);
     86         for (int counter = 0; counter < arraySize; counter++) {
     87             assertTrue(
     88                     "Array and List converted from array do not contain identical elements",
     89                     convertedList.get(counter) == objectArray[counter]);
     90         }
     91         convertedList.set(50, new Integer(1000));
     92         assertTrue("set/get did not work on coverted list", convertedList.get(
     93                 50).equals(new Integer(1000)));
     94         convertedList.set(50, new Integer(50));
     95         new Support_UnmodifiableCollectionTest("", convertedList).runTest();
     96 
     97         Object[] myArray = (Object[]) (objectArray.clone());
     98         myArray[30] = null;
     99         myArray[60] = null;
    100         convertedList = Arrays.asList(myArray);
    101         for (int counter = 0; counter < arraySize; counter++) {
    102             assertTrue(
    103                     "Array and List converted from array do not contain identical elements",
    104                     convertedList.get(counter) == myArray[counter]);
    105         }
    106 
    107         try {
    108             Arrays.asList((Object[]) null);
    109             fail("asList with null arg didn't throw NPE");
    110         } catch (NullPointerException e) {
    111             // Expected
    112         }
    113     }
    114 
    115     /**
    116      * java.util.Arrays#binarySearch(byte[], byte)
    117      */
    118     public void test_binarySearch$BB() {
    119         // Test for method int java.util.Arrays.binarySearch(byte [], byte)
    120         for (byte counter = 0; counter < arraySize; counter++)
    121             assertTrue("Binary search on byte[] answered incorrect position",
    122                     Arrays.binarySearch(byteArray, counter) == counter);
    123         assertEquals("Binary search succeeded for value not present in array 1",
    124                 -1, Arrays.binarySearch(intArray, (byte) -1));
    125         assertTrue(
    126                 "Binary search succeeded for value not present in array 2",
    127                 Arrays.binarySearch(intArray, (byte) arraySize) == -(arraySize + 1));
    128         for (byte counter = 0; counter < arraySize; counter++)
    129             byteArray[counter] -= 50;
    130         for (byte counter = 0; counter < arraySize; counter++)
    131             assertTrue(
    132                     "Binary search on byte[] involving negative numbers answered incorrect position",
    133                     Arrays.binarySearch(byteArray, (byte) (counter - 50)) == counter);
    134     }
    135 
    136     /**
    137      * java.util.Arrays#binarySearch(char[], char)
    138      */
    139     public void test_binarySearch$CC() {
    140         // Test for method int java.util.Arrays.binarySearch(char [], char)
    141         for (char counter = 0; counter < arraySize; counter++)
    142             assertTrue(
    143                     "Binary search on char[] answered incorrect position",
    144                     Arrays.binarySearch(charArray, (char) (counter + 1)) == counter);
    145         assertEquals("Binary search succeeded for value not present in array 1",
    146                 -1, Arrays.binarySearch(charArray, '\u0000'));
    147         assertTrue(
    148                 "Binary search succeeded for value not present in array 2",
    149                 Arrays.binarySearch(charArray, (char) (arraySize + 1)) == -(arraySize + 1));
    150     }
    151 
    152     /**
    153      * java.util.Arrays#binarySearch(double[], double)
    154      */
    155     public void test_binarySearch$DD() {
    156         // Test for method int java.util.Arrays.binarySearch(double [], double)
    157         for (int counter = 0; counter < arraySize; counter++)
    158             assertTrue(
    159                     "Binary search on double[] answered incorrect position",
    160                     Arrays.binarySearch(doubleArray, (double) counter) == (double) counter);
    161         assertEquals("Binary search succeeded for value not present in array 1",
    162                 -1, Arrays.binarySearch(doubleArray, (double) -1));
    163         assertTrue(
    164                 "Binary search succeeded for value not present in array 2",
    165                 Arrays.binarySearch(doubleArray, (double) arraySize) == -(arraySize + 1));
    166         for (int counter = 0; counter < arraySize; counter++)
    167             doubleArray[counter] -= (double) 50;
    168         for (int counter = 0; counter < arraySize; counter++)
    169             assertTrue(
    170                     "Binary search on double[] involving negative numbers answered incorrect position",
    171                     Arrays.binarySearch(doubleArray, (double) (counter - 50)) == (double) counter);
    172 
    173         double[] specials = new double[] { Double.NEGATIVE_INFINITY,
    174                 -Double.MAX_VALUE, -2d, -Double.MIN_VALUE, -0d, 0d,
    175                 Double.MIN_VALUE, 2d, Double.MAX_VALUE,
    176                 Double.POSITIVE_INFINITY, Double.NaN };
    177         for (int i = 0; i < specials.length; i++) {
    178             int result = Arrays.binarySearch(specials, specials[i]);
    179             assertTrue(specials[i] + " invalid: " + result, result == i);
    180         }
    181         assertEquals("-1d", -4, Arrays.binarySearch(specials, -1d));
    182         assertEquals("1d", -8, Arrays.binarySearch(specials, 1d));
    183 
    184     }
    185 
    186     /**
    187      * java.util.Arrays#binarySearch(float[], float)
    188      */
    189     public void test_binarySearch$FF() {
    190         // Test for method int java.util.Arrays.binarySearch(float [], float)
    191         for (int counter = 0; counter < arraySize; counter++)
    192             assertTrue(
    193                     "Binary search on float[] answered incorrect position",
    194                     Arrays.binarySearch(floatArray, (float) counter) == (float) counter);
    195         assertEquals("Binary search succeeded for value not present in array 1",
    196                 -1, Arrays.binarySearch(floatArray, (float) -1));
    197         assertTrue(
    198                 "Binary search succeeded for value not present in array 2",
    199                 Arrays.binarySearch(floatArray, (float) arraySize) == -(arraySize + 1));
    200         for (int counter = 0; counter < arraySize; counter++)
    201             floatArray[counter] -= (float) 50;
    202         for (int counter = 0; counter < arraySize; counter++)
    203             assertTrue(
    204                     "Binary search on float[] involving negative numbers answered incorrect position",
    205                     Arrays.binarySearch(floatArray, (float) counter - 50) == (float) counter);
    206 
    207         float[] specials = new float[] { Float.NEGATIVE_INFINITY,
    208                 -Float.MAX_VALUE, -2f, -Float.MIN_VALUE, -0f, 0f,
    209                 Float.MIN_VALUE, 2f, Float.MAX_VALUE, Float.POSITIVE_INFINITY,
    210                 Float.NaN };
    211         for (int i = 0; i < specials.length; i++) {
    212             int result = Arrays.binarySearch(specials, specials[i]);
    213             assertTrue(specials[i] + " invalid: " + result, result == i);
    214         }
    215         assertEquals("-1f", -4, Arrays.binarySearch(specials, -1f));
    216         assertEquals("1f", -8, Arrays.binarySearch(specials, 1f));
    217     }
    218 
    219     /**
    220      * java.util.Arrays#binarySearch(int[], int)
    221      */
    222     public void test_binarySearch$II() {
    223         // Test for method int java.util.Arrays.binarySearch(int [], int)
    224         for (int counter = 0; counter < arraySize; counter++)
    225             assertTrue("Binary search on int[] answered incorrect position",
    226                     Arrays.binarySearch(intArray, counter) == counter);
    227         assertEquals("Binary search succeeded for value not present in array 1",
    228                 -1, Arrays.binarySearch(intArray, -1));
    229         assertTrue("Binary search succeeded for value not present in array 2",
    230                 Arrays.binarySearch(intArray, arraySize) == -(arraySize + 1));
    231         for (int counter = 0; counter < arraySize; counter++)
    232             intArray[counter] -= 50;
    233         for (int counter = 0; counter < arraySize; counter++)
    234             assertTrue(
    235                     "Binary search on int[] involving negative numbers answered incorrect position",
    236                     Arrays.binarySearch(intArray, counter - 50) == counter);
    237     }
    238 
    239     /**
    240      * java.util.Arrays#binarySearch(long[], long)
    241      */
    242     public void test_binarySearch$JJ() {
    243         // Test for method int java.util.Arrays.binarySearch(long [], long)
    244         for (long counter = 0; counter < arraySize; counter++)
    245             assertTrue("Binary search on long[] answered incorrect position",
    246                     Arrays.binarySearch(longArray, counter) == counter);
    247         assertEquals("Binary search succeeded for value not present in array 1",
    248                 -1, Arrays.binarySearch(longArray, (long) -1));
    249         assertTrue(
    250                 "Binary search succeeded for value not present in array 2",
    251                 Arrays.binarySearch(longArray, (long) arraySize) == -(arraySize + 1));
    252         for (long counter = 0; counter < arraySize; counter++)
    253             longArray[(int) counter] -= (long) 50;
    254         for (long counter = 0; counter < arraySize; counter++)
    255             assertTrue(
    256                     "Binary search on long[] involving negative numbers answered incorrect position",
    257                     Arrays.binarySearch(longArray, counter - (long) 50) == counter);
    258     }
    259 
    260     /**
    261      * java.util.Arrays#binarySearch(java.lang.Object[],
    262      *        java.lang.Object)
    263      */
    264     public void test_binarySearch$Ljava_lang_ObjectLjava_lang_Object() {
    265         // Test for method int java.util.Arrays.binarySearch(java.lang.Object
    266         // [], java.lang.Object)
    267         assertEquals(
    268                 "Binary search succeeded for non-comparable value in empty array",
    269                 -1, Arrays.binarySearch(new Object[] {}, new Object()));
    270         assertEquals(
    271                 "Binary search succeeded for comparable value in empty array",
    272                 -1, Arrays.binarySearch(new Object[] {}, new Integer(-1)));
    273         for (int counter = 0; counter < arraySize; counter++)
    274             assertTrue(
    275                     "Binary search on Object[] answered incorrect position",
    276                     Arrays.binarySearch(objectArray, objArray[counter]) == counter);
    277         assertEquals("Binary search succeeded for value not present in array 1",
    278                 -1, Arrays.binarySearch(objectArray, new Integer(-1)));
    279         assertTrue(
    280                 "Binary search succeeded for value not present in array 2",
    281                 Arrays.binarySearch(objectArray, new Integer(arraySize)) == -(arraySize + 1));
    282 
    283         Object object = new Object();
    284         Object[] objects = new MockComparable[] { new MockComparable() };
    285         assertEquals("Should always return 0", 0, Arrays.binarySearch(objects, object));
    286 
    287         Object[] string_objects = new String[] { "one" };
    288         try {
    289             Arrays.binarySearch(string_objects, object);
    290             fail("No expected ClassCastException");
    291         } catch (ClassCastException e) {
    292             // Expected
    293         }
    294     }
    295 
    296     /**
    297      * java.util.Arrays#binarySearch(java.lang.Object[],
    298      *        java.lang.Object, java.util.Comparator)
    299      */
    300     public void test_binarySearch$Ljava_lang_ObjectLjava_lang_ObjectLjava_util_Comparator() {
    301         // Test for method int java.util.Arrays.binarySearch(java.lang.Object
    302         // [], java.lang.Object, java.util.Comparator)
    303         Comparator comp = new ReversedIntegerComparator();
    304         for (int counter = 0; counter < arraySize; counter++)
    305             objectArray[counter] = objArray[arraySize - counter - 1];
    306         assertTrue(
    307                 "Binary search succeeded for value not present in array 1",
    308                 Arrays.binarySearch(objectArray, new Integer(-1), comp) == -(arraySize + 1));
    309         assertEquals("Binary search succeeded for value not present in array 2",
    310                 -1, Arrays.binarySearch(objectArray, new Integer(arraySize), comp));
    311         for (int counter = 0; counter < arraySize; counter++)
    312             assertTrue(
    313                     "Binary search on Object[] with custom comparator answered incorrect position",
    314                     Arrays.binarySearch(objectArray, objArray[counter], comp) == arraySize
    315                             - counter - 1);
    316     }
    317 
    318     /**
    319      * java.util.Arrays#binarySearch(short[], short)
    320      */
    321     public void test_binarySearch$SS() {
    322         // Test for method int java.util.Arrays.binarySearch(short [], short)
    323         for (short counter = 0; counter < arraySize; counter++)
    324             assertTrue("Binary search on short[] answered incorrect position",
    325                     Arrays.binarySearch(shortArray, counter) == counter);
    326         assertEquals("Binary search succeeded for value not present in array 1",
    327                 -1, Arrays.binarySearch(intArray, (short) -1));
    328         assertTrue(
    329                 "Binary search succeeded for value not present in array 2",
    330                 Arrays.binarySearch(intArray, (short) arraySize) == -(arraySize + 1));
    331         for (short counter = 0; counter < arraySize; counter++)
    332             shortArray[counter] -= 50;
    333         for (short counter = 0; counter < arraySize; counter++)
    334             assertTrue(
    335                     "Binary search on short[] involving negative numbers answered incorrect position",
    336                     Arrays.binarySearch(shortArray, (short) (counter - 50)) == counter);
    337     }
    338 
    339     public void test_Arrays_binaraySearch_byte() {
    340         assertEquals(-1, Arrays.binarySearch(new byte[] { '0' }, 0, 0,
    341                 (byte) '1'));
    342         assertEquals(-2, Arrays.binarySearch(new byte[] { '0' }, 1, 1,
    343                 (byte) '1'));
    344         assertEquals(-2, Arrays.binarySearch(new byte[] { '0', '1' }, 1, 1,
    345                 (byte) '2'));
    346         assertEquals(-3, Arrays.binarySearch(new byte[] { '0', '1' }, 2, 2,
    347                 (byte) '2'));
    348     }
    349 
    350     public void test_Arrays_binaraySearch_char() {
    351         assertEquals(-1, Arrays.binarySearch(new char[] { '0' }, 0, 0, '1'));
    352         assertEquals(-2, Arrays.binarySearch(new char[] { '0' }, 1, 1, '1'));
    353         assertEquals(-2, Arrays
    354                 .binarySearch(new char[] { '0', '1' }, 1, 1, '2'));
    355         assertEquals(-3, Arrays
    356                 .binarySearch(new char[] { '0', '1' }, 2, 2, '2'));
    357     }
    358 
    359     public void test_Arrays_binaraySearch_float() {
    360         assertEquals(-1, Arrays.binarySearch(new float[] { -1.0f }, 0, 0, 0.0f));
    361         assertEquals(-2, Arrays.binarySearch(new float[] { -1.0f }, 1, 1, 0.0f));
    362         assertEquals(-2, Arrays.binarySearch(new float[] { -1.0f, 0f }, 1, 1,
    363                 1f));
    364         assertEquals(-3, Arrays.binarySearch(new float[] { -1.0f, 0f }, 2, 2,
    365                 1f));
    366     }
    367 
    368     public void test_Arrays_binaraySearch_double() {
    369         assertEquals(-1, Arrays.binarySearch(new double[] { -1.0 }, 0, 0, 0.0));
    370         assertEquals(-2, Arrays.binarySearch(new double[] { -1.0 }, 1, 1, 0.0));
    371         assertEquals(-2, Arrays.binarySearch(new double[] { -1.0, 0 }, 1, 1, 1));
    372         assertEquals(-3, Arrays.binarySearch(new double[] { -1.0, 0 }, 2, 2, 1));
    373     }
    374 
    375     public void test_Arrays_binaraySearch_int() {
    376         assertEquals(-1, Arrays.binarySearch(new int[] { -1 }, 0, 0, 0));
    377         assertEquals(-2, Arrays.binarySearch(new int[] { -1 }, 1, 1, 0));
    378         assertEquals(-2, Arrays.binarySearch(new int[] { -1, 0 }, 1, 1, 1));
    379         assertEquals(-3, Arrays.binarySearch(new int[] { -1, 0 }, 2, 2, 1));
    380     }
    381 
    382     public void test_Arrays_binaraySearch_long() {
    383         assertEquals(-1, Arrays.binarySearch(new long[] { -1l }, 0, 0, 0l));
    384         assertEquals(-2, Arrays.binarySearch(new long[] { -1l }, 1, 1, 0l));
    385         assertEquals(-2, Arrays.binarySearch(new long[] { -1l, 0l }, 1, 1, 1l));
    386         assertEquals(-3, Arrays.binarySearch(new long[] { -1l, 0l }, 2, 2, 1l));
    387     }
    388 
    389     public void test_Arrays_binaraySearch_short() {
    390         assertEquals(-1, Arrays.binarySearch(new short[] { (short) -1 }, 0, 0,
    391                 (short) 0));
    392         assertEquals(-2, Arrays.binarySearch(new short[] { (short) -1 }, 1, 1,
    393                 (short) 0));
    394         assertEquals(-2, Arrays.binarySearch(new short[] { (short) -1,
    395                 (short) 0 }, 1, 1, (short) 1));
    396         assertEquals(-3, Arrays.binarySearch(new short[] { (short) -1,
    397                 (short) 0 }, 2, 2, (short) 1));
    398     }
    399 
    400     public void test_Arrays_binaraySearch_Object() {
    401         assertEquals(-1, Arrays.binarySearch(new Object[] { new Integer(-1) },
    402                 0, 0, new Integer(0)));
    403         assertEquals(-2, Arrays.binarySearch(new Object[] { new Integer(-1) },
    404                 1, 1, new Integer(0)));
    405         assertEquals(-2, Arrays.binarySearch(new Object[] { new Integer(-1),
    406                 new Integer(0) }, 1, 1, new Integer(1)));
    407         assertEquals(-3, Arrays.binarySearch(new Object[] { new Integer(-1),
    408                 new Integer(0) }, 2, 2, new Integer(1)));
    409     }
    410 
    411     public void test_Arrays_binaraySearch_T() {
    412         ReversedIntegerComparator reversedComparator = new ReversedIntegerComparator();
    413         assertEquals(-1, Arrays.binarySearch(new Integer[] { new Integer(-1) },
    414                 0, 0, new Integer(0), reversedComparator));
    415         assertEquals(-2, Arrays.binarySearch(new Integer[] { new Integer(-1) },
    416                 1, 1, new Integer(0), reversedComparator));
    417         assertEquals(-2, Arrays.binarySearch(new Integer[] { new Integer(-1),
    418                 new Integer(0) }, 1, 1, new Integer(1), reversedComparator));
    419         assertEquals(-3, Arrays.binarySearch(new Integer[] { new Integer(-1),
    420                 new Integer(0) }, 2, 2, new Integer(1), reversedComparator));
    421     }
    422 
    423     /**
    424      * java.util.Arrays#fill(byte[], byte)
    425      */
    426     public void test_fill$BB() {
    427         // Test for method void java.util.Arrays.fill(byte [], byte)
    428 
    429         byte d[] = new byte[1000];
    430         Arrays.fill(d, Byte.MAX_VALUE);
    431         for (int i = 0; i < d.length; i++)
    432             assertTrue("Failed to fill byte array correctly",
    433                     d[i] == Byte.MAX_VALUE);
    434     }
    435 
    436     /**
    437      * java.util.Arrays#fill(byte[], int, int, byte)
    438      */
    439     public void test_fill$BIIB() {
    440         // Test for method void java.util.Arrays.fill(byte [], int, int, byte)
    441         byte val = Byte.MAX_VALUE;
    442         byte d[] = new byte[1000];
    443         Arrays.fill(d, 400, d.length, val);
    444         for (int i = 0; i < 400; i++)
    445             assertTrue("Filled elements not in range", !(d[i] == val));
    446         for (int i = 400; i < d.length; i++)
    447             assertTrue("Failed to fill byte array correctly", d[i] == val);
    448 
    449         int result;
    450         try {
    451             Arrays.fill(new byte[2], 2, 1, (byte) 27);
    452             result = 0;
    453         } catch (ArrayIndexOutOfBoundsException e) {
    454             result = 1;
    455         } catch (IllegalArgumentException e) {
    456             result = 2;
    457         }
    458         assertEquals("Wrong exception1", 2, result);
    459         try {
    460             Arrays.fill(new byte[2], -1, 1, (byte) 27);
    461             result = 0;
    462         } catch (ArrayIndexOutOfBoundsException e) {
    463             result = 1;
    464         } catch (IllegalArgumentException e) {
    465             result = 2;
    466         }
    467         assertEquals("Wrong exception2", 1, result);
    468         try {
    469             Arrays.fill(new byte[2], 1, 4, (byte) 27);
    470             result = 0;
    471         } catch (ArrayIndexOutOfBoundsException e) {
    472             result = 1;
    473         } catch (IllegalArgumentException e) {
    474             result = 2;
    475         }
    476         assertEquals("Wrong exception", 1, result);
    477     }
    478 
    479     /**
    480      * java.util.Arrays#fill(short[], short)
    481      */
    482     public void test_fill$SS() {
    483         // Test for method void java.util.Arrays.fill(short [], short)
    484 
    485         short d[] = new short[1000];
    486         Arrays.fill(d, Short.MAX_VALUE);
    487         for (int i = 0; i < d.length; i++)
    488             assertTrue("Failed to fill short array correctly",
    489                     d[i] == Short.MAX_VALUE);
    490     }
    491 
    492     /**
    493      * java.util.Arrays#fill(short[], int, int, short)
    494      */
    495     public void test_fill$SIIS() {
    496         // Test for method void java.util.Arrays.fill(short [], int, int, short)
    497         short val = Short.MAX_VALUE;
    498         short d[] = new short[1000];
    499         Arrays.fill(d, 400, d.length, val);
    500         for (int i = 0; i < 400; i++)
    501             assertTrue("Filled elements not in range", !(d[i] == val));
    502         for (int i = 400; i < d.length; i++)
    503             assertTrue("Failed to fill short array correctly", d[i] == val);
    504 
    505         try {
    506             Arrays.fill(d, 10, 0, val);
    507             fail("IllegalArgumentException expected");
    508         } catch (IllegalArgumentException e) {
    509             //expected
    510         }
    511 
    512         try {
    513             Arrays.fill(d, -10, 0, val);
    514             fail("ArrayIndexOutOfBoundsException expected");
    515         } catch (ArrayIndexOutOfBoundsException e) {
    516             //expected
    517         }
    518 
    519         try {
    520             Arrays.fill(d, 10, d.length+1, val);
    521             fail("ArrayIndexOutOfBoundsException expected");
    522         } catch (ArrayIndexOutOfBoundsException e) {
    523             //expected
    524         }
    525     }
    526 
    527     /**
    528      * java.util.Arrays#fill(char[], char)
    529      */
    530     public void test_fill$CC() {
    531         // Test for method void java.util.Arrays.fill(char [], char)
    532 
    533         char d[] = new char[1000];
    534         Arrays.fill(d, 'V');
    535         for (int i = 0; i < d.length; i++)
    536             assertEquals("Failed to fill char array correctly", 'V', d[i]);
    537     }
    538 
    539     /**
    540      * java.util.Arrays#fill(char[], int, int, char)
    541      */
    542     public void test_fill$CIIC() {
    543         // Test for method void java.util.Arrays.fill(char [], int, int, char)
    544         char val = 'T';
    545         char d[] = new char[1000];
    546         Arrays.fill(d, 400, d.length, val);
    547         for (int i = 0; i < 400; i++)
    548             assertTrue("Filled elements not in range", !(d[i] == val));
    549         for (int i = 400; i < d.length; i++)
    550             assertTrue("Failed to fill char array correctly", d[i] == val);
    551 
    552         try {
    553             Arrays.fill(d, 10, 0, val);
    554             fail("IllegalArgumentException expected");
    555         } catch (IllegalArgumentException e) {
    556             //expected
    557         }
    558 
    559         try {
    560             Arrays.fill(d, -10, 0, val);
    561             fail("ArrayIndexOutOfBoundsException expected");
    562         } catch (ArrayIndexOutOfBoundsException e) {
    563             //expected
    564         }
    565 
    566         try {
    567             Arrays.fill(d, 10, d.length+1, val);
    568             fail("ArrayIndexOutOfBoundsException expected");
    569         } catch (ArrayIndexOutOfBoundsException e) {
    570             //expected
    571         }
    572     }
    573 
    574     /**
    575      * java.util.Arrays#fill(int[], int)
    576      */
    577     public void test_fill$II() {
    578         // Test for method void java.util.Arrays.fill(int [], int)
    579 
    580         int d[] = new int[1000];
    581         Arrays.fill(d, Integer.MAX_VALUE);
    582         for (int i = 0; i < d.length; i++)
    583             assertTrue("Failed to fill int array correctly",
    584                     d[i] == Integer.MAX_VALUE);
    585     }
    586 
    587     /**
    588      * java.util.Arrays#fill(int[], int, int, int)
    589      */
    590     public void test_fill$IIII() {
    591         // Test for method void java.util.Arrays.fill(int [], int, int, int)
    592         int val = Integer.MAX_VALUE;
    593         int d[] = new int[1000];
    594         Arrays.fill(d, 400, d.length, val);
    595         for (int i = 0; i < 400; i++)
    596             assertTrue("Filled elements not in range", !(d[i] == val));
    597         for (int i = 400; i < d.length; i++)
    598             assertTrue("Failed to fill int array correctly", d[i] == val);
    599 
    600         try {
    601             Arrays.fill(d, 10, 0, val);
    602             fail("IllegalArgumentException expected");
    603         } catch (IllegalArgumentException e) {
    604             //expected
    605         }
    606 
    607         try {
    608             Arrays.fill(d, -10, 0, val);
    609             fail("ArrayIndexOutOfBoundsException expected");
    610         } catch (ArrayIndexOutOfBoundsException e) {
    611             //expected
    612         }
    613 
    614         try {
    615             Arrays.fill(d, 10, d.length+1, val);
    616             fail("ArrayIndexOutOfBoundsException expected");
    617         } catch (ArrayIndexOutOfBoundsException e) {
    618             //expected
    619         }
    620     }
    621 
    622     /**
    623      * java.util.Arrays#fill(long[], long)
    624      */
    625     public void test_fill$JJ() {
    626         // Test for method void java.util.Arrays.fill(long [], long)
    627 
    628         long d[] = new long[1000];
    629         Arrays.fill(d, Long.MAX_VALUE);
    630         for (int i = 0; i < d.length; i++)
    631             assertTrue("Failed to fill long array correctly",
    632                     d[i] == Long.MAX_VALUE);
    633     }
    634 
    635     /**
    636      * java.util.Arrays#fill(long[], int, int, long)
    637      */
    638     public void test_fill$JIIJ() {
    639         // Test for method void java.util.Arrays.fill(long [], int, int, long)
    640         long d[] = new long[1000];
    641         Arrays.fill(d, 400, d.length, Long.MAX_VALUE);
    642         for (int i = 0; i < 400; i++)
    643             assertTrue("Filled elements not in range", !(d[i] == Long.MAX_VALUE));
    644         for (int i = 400; i < d.length; i++)
    645             assertTrue("Failed to fill long array correctly",
    646                     d[i] == Long.MAX_VALUE);
    647 
    648         try {
    649             Arrays.fill(d, 10, 0, Long.MIN_VALUE);
    650             fail("IllegalArgumentException expected");
    651         } catch (IllegalArgumentException e) {
    652             //expected
    653         }
    654 
    655         try {
    656             Arrays.fill(d, -10, 0, Long.MAX_VALUE);
    657             fail("ArrayIndexOutOfBoundsException expected");
    658         } catch (ArrayIndexOutOfBoundsException e) {
    659             //expected
    660         }
    661 
    662         try {
    663             Arrays.fill(d, 10, d.length+1, Long.MAX_VALUE);
    664             fail("ArrayIndexOutOfBoundsException expected");
    665         } catch (ArrayIndexOutOfBoundsException e) {
    666             //expected
    667         }
    668     }
    669 
    670     /**
    671      * java.util.Arrays#fill(float[], float)
    672      */
    673     public void test_fill$FF() {
    674         // Test for method void java.util.Arrays.fill(float [], float)
    675         float d[] = new float[1000];
    676         Arrays.fill(d, Float.MAX_VALUE);
    677         for (int i = 0; i < d.length; i++)
    678             assertTrue("Failed to fill float array correctly",
    679                     d[i] == Float.MAX_VALUE);
    680     }
    681 
    682     /**
    683      * java.util.Arrays#fill(float[], int, int, float)
    684      */
    685     public void test_fill$FIIF() {
    686         // Test for method void java.util.Arrays.fill(float [], int, int, float)
    687         float val = Float.MAX_VALUE;
    688         float d[] = new float[1000];
    689         Arrays.fill(d, 400, d.length, val);
    690         for (int i = 0; i < 400; i++)
    691             assertTrue("Filled elements not in range", !(d[i] == val));
    692         for (int i = 400; i < d.length; i++)
    693             assertTrue("Failed to fill float array correctly", d[i] == val);
    694 
    695         try {
    696             Arrays.fill(d, 10, 0, val);
    697             fail("IllegalArgumentException expected");
    698         } catch (IllegalArgumentException e) {
    699             //expected
    700         }
    701 
    702         try {
    703             Arrays.fill(d, -10, 0, val);
    704             fail("ArrayIndexOutOfBoundsException expected");
    705         } catch (ArrayIndexOutOfBoundsException e) {
    706             //expected
    707         }
    708 
    709         try {
    710             Arrays.fill(d, 10, d.length+1, val);
    711             fail("ArrayIndexOutOfBoundsException expected");
    712         } catch (ArrayIndexOutOfBoundsException e) {
    713             //expected
    714         }
    715     }
    716 
    717     /**
    718      * java.util.Arrays#fill(double[], double)
    719      */
    720     public void test_fill$DD() {
    721         // Test for method void java.util.Arrays.fill(double [], double)
    722 
    723         double d[] = new double[1000];
    724         Arrays.fill(d, Double.MAX_VALUE);
    725         for (int i = 0; i < d.length; i++)
    726             assertTrue("Failed to fill double array correctly",
    727                     d[i] == Double.MAX_VALUE);
    728     }
    729 
    730     /**
    731      * java.util.Arrays#fill(double[], int, int, double)
    732      */
    733     public void test_fill$DIID() {
    734         // Test for method void java.util.Arrays.fill(double [], int, int,
    735         // double)
    736         double val = Double.MAX_VALUE;
    737         double d[] = new double[1000];
    738         Arrays.fill(d, 400, d.length, val);
    739         for (int i = 0; i < 400; i++)
    740             assertTrue("Filled elements not in range", !(d[i] == val));
    741         for (int i = 400; i < d.length; i++)
    742             assertTrue("Failed to fill double array correctly", d[i] == val);
    743 
    744         try {
    745             Arrays.fill(d, 10, 0, val);
    746             fail("IllegalArgumentException expected");
    747         } catch (IllegalArgumentException e) {
    748             //expected
    749         }
    750 
    751         try {
    752             Arrays.fill(d, -10, 0, val);
    753             fail("ArrayIndexOutOfBoundsException expected");
    754         } catch (ArrayIndexOutOfBoundsException e) {
    755             //expected
    756         }
    757 
    758         try {
    759             Arrays.fill(d, 10, d.length+1, val);
    760             fail("ArrayIndexOutOfBoundsException expected");
    761         } catch (ArrayIndexOutOfBoundsException e) {
    762             //expected
    763         }
    764     }
    765 
    766     /**
    767      * java.util.Arrays#fill(boolean[], boolean)
    768      */
    769     public void test_fill$ZZ() {
    770         // Test for method void java.util.Arrays.fill(boolean [], boolean)
    771 
    772         boolean d[] = new boolean[1000];
    773         Arrays.fill(d, true);
    774         for (int i = 0; i < d.length; i++)
    775             assertTrue("Failed to fill boolean array correctly", d[i]);
    776     }
    777 
    778     /**
    779      * java.util.Arrays#fill(boolean[], int, int, boolean)
    780      */
    781     public void test_fill$ZIIZ() {
    782         // Test for method void java.util.Arrays.fill(boolean [], int, int,
    783         // boolean)
    784         boolean val = true;
    785         boolean d[] = new boolean[1000];
    786         Arrays.fill(d, 400, d.length, val);
    787         for (int i = 0; i < 400; i++)
    788             assertTrue("Filled elements not in range", !(d[i] == val));
    789         for (int i = 400; i < d.length; i++)
    790             assertTrue("Failed to fill boolean array correctly", d[i] == val);
    791 
    792         try {
    793             Arrays.fill(d, 10, 0, val);
    794             fail("IllegalArgumentException expected");
    795         } catch (IllegalArgumentException e) {
    796             //expected
    797         }
    798 
    799         try {
    800             Arrays.fill(d, -10, 0, val);
    801             fail("ArrayIndexOutOfBoundsException expected");
    802         } catch (ArrayIndexOutOfBoundsException e) {
    803             //expected
    804         }
    805 
    806         try {
    807             Arrays.fill(d, 10, d.length+1, val);
    808             fail("ArrayIndexOutOfBoundsException expected");
    809         } catch (ArrayIndexOutOfBoundsException e) {
    810             //expected
    811         }
    812     }
    813 
    814     /**
    815      * java.util.Arrays#fill(java.lang.Object[], java.lang.Object)
    816      */
    817     public void test_fill$Ljava_lang_ObjectLjava_lang_Object() {
    818         // Test for method void java.util.Arrays.fill(java.lang.Object [],
    819         // java.lang.Object)
    820         Object val = new Object();
    821         Object d[] = new Object[1000];
    822         Arrays.fill(d, 0, d.length, val);
    823         for (int i = 0; i < d.length; i++)
    824             assertTrue("Failed to fill Object array correctly", d[i] == val);
    825     }
    826 
    827     /**
    828      * java.util.Arrays#fill(java.lang.Object[], int, int,
    829      *        java.lang.Object)
    830      */
    831     public void test_fill$Ljava_lang_ObjectIILjava_lang_Object() {
    832         // Test for method void java.util.Arrays.fill(java.lang.Object [], int,
    833         // int, java.lang.Object)
    834         Object val = new Object();
    835         Object d[] = new Object[1000];
    836         Arrays.fill(d, 400, d.length, val);
    837         for (int i = 0; i < 400; i++)
    838             assertTrue("Filled elements not in range", !(d[i] == val));
    839         for (int i = 400; i < d.length; i++)
    840             assertTrue("Failed to fill Object array correctly", d[i] == val);
    841 
    842         Arrays.fill(d, 400, d.length, null);
    843         for (int i = 400; i < d.length; i++)
    844             assertNull("Failed to fill Object array correctly with nulls",
    845                     d[i]);
    846 
    847         try {
    848             Arrays.fill(d, 10, 0, val);
    849             fail("IllegalArgumentException expected");
    850         } catch (IllegalArgumentException e) {
    851             //expected
    852         }
    853 
    854         try {
    855             Arrays.fill(d, -10, 0, val);
    856             fail("ArrayIndexOutOfBoundsException expected");
    857         } catch (ArrayIndexOutOfBoundsException e) {
    858             //expected
    859         }
    860 
    861         try {
    862             Arrays.fill(d, 10, d.length+1, val);
    863             fail("ArrayIndexOutOfBoundsException expected");
    864         } catch (ArrayIndexOutOfBoundsException e) {
    865             //expected
    866         }
    867     }
    868 
    869     /**
    870      * java.util.Arrays#equals(byte[], byte[])
    871      */
    872     public void test_equals$B$B() {
    873         // Test for method boolean java.util.Arrays.equals(byte [], byte [])
    874         byte d[] = new byte[1000];
    875         byte x[] = new byte[1000];
    876         Arrays.fill(d, Byte.MAX_VALUE);
    877         Arrays.fill(x, Byte.MIN_VALUE);
    878         assertTrue("Inequal arrays returned true", !Arrays.equals(d, x));
    879         Arrays.fill(x, Byte.MAX_VALUE);
    880         assertTrue("equal arrays returned false", Arrays.equals(d, x));
    881     }
    882 
    883     /**
    884      * java.util.Arrays#equals(short[], short[])
    885      */
    886     public void test_equals$S$S() {
    887         // Test for method boolean java.util.Arrays.equals(short [], short [])
    888         short d[] = new short[1000];
    889         short x[] = new short[1000];
    890         Arrays.fill(d, Short.MAX_VALUE);
    891         Arrays.fill(x, Short.MIN_VALUE);
    892         assertTrue("Inequal arrays returned true", !Arrays.equals(d, x));
    893         Arrays.fill(x, Short.MAX_VALUE);
    894         assertTrue("equal arrays returned false", Arrays.equals(d, x));
    895     }
    896 
    897     /**
    898      * java.util.Arrays#equals(char[], char[])
    899      */
    900     public void test_equals$C$C() {
    901         // Test for method boolean java.util.Arrays.equals(char [], char [])
    902         char d[] = new char[1000];
    903         char x[] = new char[1000];
    904         char c = 'T';
    905         Arrays.fill(d, c);
    906         Arrays.fill(x, 'L');
    907         assertTrue("Inequal arrays returned true", !Arrays.equals(d, x));
    908         Arrays.fill(x, c);
    909         assertTrue("equal arrays returned false", Arrays.equals(d, x));
    910     }
    911 
    912     /**
    913      * java.util.Arrays#equals(int[], int[])
    914      */
    915     public void test_equals$I$I() {
    916         // Test for method boolean java.util.Arrays.equals(int [], int [])
    917         int d[] = new int[1000];
    918         int x[] = new int[1000];
    919         Arrays.fill(d, Integer.MAX_VALUE);
    920         Arrays.fill(x, Integer.MIN_VALUE);
    921         assertTrue("Inequal arrays returned true", !Arrays.equals(d, x));
    922         Arrays.fill(x, Integer.MAX_VALUE);
    923         assertTrue("equal arrays returned false", Arrays.equals(d, x));
    924 
    925         assertTrue("wrong result for null array1", !Arrays.equals(new int[2],
    926                 null));
    927         assertTrue("wrong result for null array2", !Arrays.equals(null,
    928                 new int[2]));
    929     }
    930 
    931     /**
    932      * java.util.Arrays#equals(long[], long[])
    933      */
    934     public void test_equals$J$J() {
    935         // Test for method boolean java.util.Arrays.equals(long [], long [])
    936         long d[] = new long[1000];
    937         long x[] = new long[1000];
    938         Arrays.fill(d, Long.MAX_VALUE);
    939         Arrays.fill(x, Long.MIN_VALUE);
    940         assertTrue("Inequal arrays returned true", !Arrays.equals(d, x));
    941         Arrays.fill(x, Long.MAX_VALUE);
    942         assertTrue("equal arrays returned false", Arrays.equals(d, x));
    943 
    944         assertTrue("should be false", !Arrays.equals(
    945                 new long[] { 0x100000000L }, new long[] { 0x200000000L }));
    946 
    947     }
    948 
    949     /**
    950      * java.util.Arrays#equals(float[], float[])
    951      */
    952     public void test_equals$F$F() {
    953         // Test for method boolean java.util.Arrays.equals(float [], float [])
    954         float d[] = new float[1000];
    955         float x[] = new float[1000];
    956         Arrays.fill(d, Float.MAX_VALUE);
    957         Arrays.fill(x, Float.MIN_VALUE);
    958         assertTrue("Inequal arrays returned true", !Arrays.equals(d, x));
    959         Arrays.fill(x, Float.MAX_VALUE);
    960         assertTrue("equal arrays returned false", Arrays.equals(d, x));
    961 
    962         assertTrue("NaN not equals", Arrays.equals(new float[] { Float.NaN },
    963                 new float[] { Float.NaN }));
    964         assertTrue("0f equals -0f", !Arrays.equals(new float[] { 0f },
    965                 new float[] { -0f }));
    966     }
    967 
    968     /**
    969      * java.util.Arrays#equals(double[], double[])
    970      */
    971     public void test_equals$D$D() {
    972         // Test for method boolean java.util.Arrays.equals(double [], double [])
    973         double d[] = new double[1000];
    974         double x[] = new double[1000];
    975         Arrays.fill(d, Double.MAX_VALUE);
    976         Arrays.fill(x, Double.MIN_VALUE);
    977         assertTrue("Inequal arrays returned true", !Arrays.equals(d, x));
    978         Arrays.fill(x, Double.MAX_VALUE);
    979         assertTrue("equal arrays returned false", Arrays.equals(d, x));
    980 
    981         assertTrue("should be false", !Arrays.equals(new double[] { 1.0 },
    982                 new double[] { 2.0 }));
    983 
    984         assertTrue("NaN not equals", Arrays.equals(new double[] { Double.NaN },
    985                 new double[] { Double.NaN }));
    986         assertTrue("0d equals -0d", !Arrays.equals(new double[] { 0d },
    987                 new double[] { -0d }));
    988     }
    989 
    990     /**
    991      * java.util.Arrays#equals(boolean[], boolean[])
    992      */
    993     public void test_equals$Z$Z() {
    994         // Test for method boolean java.util.Arrays.equals(boolean [], boolean
    995         // [])
    996         boolean d[] = new boolean[1000];
    997         boolean x[] = new boolean[1000];
    998         Arrays.fill(d, true);
    999         Arrays.fill(x, false);
   1000         assertTrue("Inequal arrays returned true", !Arrays.equals(d, x));
   1001         Arrays.fill(x, true);
   1002         assertTrue("equal arrays returned false", Arrays.equals(d, x));
   1003     }
   1004 
   1005     /**
   1006      * java.util.Arrays#equals(java.lang.Object[], java.lang.Object[])
   1007      */
   1008     public void test_equals$Ljava_lang_Object$Ljava_lang_Object() {
   1009         // Test for method boolean java.util.Arrays.equals(java.lang.Object [],
   1010         // java.lang.Object [])
   1011         Object d[] = new Object[1000];
   1012         Object x[] = new Object[1000];
   1013         Object o = new Object();
   1014         Arrays.fill(d, o);
   1015         Arrays.fill(x, new Object());
   1016         assertTrue("Inequal arrays returned true", !Arrays.equals(d, x));
   1017         Arrays.fill(x, o);
   1018         d[50] = null;
   1019         x[50] = null;
   1020         assertTrue("equal arrays returned false", Arrays.equals(d, x));
   1021     }
   1022 
   1023     /**
   1024      * java.util.Arrays#sort(byte[])
   1025      */
   1026     public void test_sort$B() {
   1027         // Test for method void java.util.Arrays.sort(byte [])
   1028         byte[] reversedArray = new byte[arraySize];
   1029         for (int counter = 0; counter < arraySize; counter++)
   1030             reversedArray[counter] = (byte) (arraySize - counter - 1);
   1031         Arrays.sort(reversedArray);
   1032         for (int counter = 0; counter < arraySize; counter++)
   1033             assertTrue("Resulting array not sorted",
   1034                     reversedArray[counter] == (byte) counter);
   1035     }
   1036 
   1037     /**
   1038      * java.util.Arrays#sort(byte[], int, int)
   1039      */
   1040     public void test_sort$BII() {
   1041         // Test for method void java.util.Arrays.sort(byte [], int, int)
   1042         int startIndex = arraySize / 4;
   1043         int endIndex = 3 * arraySize / 4;
   1044         byte[] reversedArray = new byte[arraySize];
   1045         byte[] originalReversedArray = new byte[arraySize];
   1046         for (int counter = 0; counter < arraySize; counter++) {
   1047             reversedArray[counter] = (byte) (arraySize - counter - 1);
   1048             originalReversedArray[counter] = reversedArray[counter];
   1049         }
   1050         Arrays.sort(reversedArray, startIndex, endIndex);
   1051         for (int counter = 0; counter < startIndex; counter++)
   1052             assertTrue("Array modified outside of bounds",
   1053                     reversedArray[counter] == originalReversedArray[counter]);
   1054         for (int counter = startIndex; counter < endIndex - 1; counter++)
   1055             assertTrue("Array not sorted within bounds",
   1056                     reversedArray[counter] <= reversedArray[counter + 1]);
   1057         for (int counter = endIndex; counter < arraySize; counter++)
   1058             assertTrue("Array modified outside of bounds",
   1059                     reversedArray[counter] == originalReversedArray[counter]);
   1060 
   1061         //exception testing
   1062         try {
   1063             Arrays.sort(reversedArray, startIndex + 1, startIndex);
   1064             fail("IllegalArgumentException expected");
   1065         } catch (IllegalArgumentException ignore) {
   1066         }
   1067 
   1068         try {
   1069             Arrays.sort(reversedArray, -1, startIndex);
   1070             fail("ArrayIndexOutOfBoundsException expected (1)");
   1071         } catch (ArrayIndexOutOfBoundsException ignore) {
   1072         }
   1073 
   1074         try {
   1075             Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
   1076             fail("ArrayIndexOutOfBoundsException expected (2)");
   1077         } catch (ArrayIndexOutOfBoundsException ignore) {
   1078         }
   1079     }
   1080 
   1081     /**
   1082      * java.util.Arrays#sort(char[])
   1083      */
   1084     public void test_sort$C() {
   1085         // Test for method void java.util.Arrays.sort(char [])
   1086         char[] reversedArray = new char[arraySize];
   1087         for (int counter = 0; counter < arraySize; counter++)
   1088             reversedArray[counter] = (char) (arraySize - counter - 1);
   1089         Arrays.sort(reversedArray);
   1090         for (int counter = 0; counter < arraySize; counter++)
   1091             assertTrue("Resulting array not sorted",
   1092                     reversedArray[counter] == (char) counter);
   1093 
   1094     }
   1095 
   1096     /**
   1097      * java.util.Arrays#sort(char[], int, int)
   1098      */
   1099     public void test_sort$CII() {
   1100         // Test for method void java.util.Arrays.sort(char [], int, int)
   1101         int startIndex = arraySize / 4;
   1102         int endIndex = 3 * arraySize / 4;
   1103         char[] reversedArray = new char[arraySize];
   1104         char[] originalReversedArray = new char[arraySize];
   1105         for (int counter = 0; counter < arraySize; counter++) {
   1106             reversedArray[counter] = (char) (arraySize - counter - 1);
   1107             originalReversedArray[counter] = reversedArray[counter];
   1108         }
   1109         Arrays.sort(reversedArray, startIndex, endIndex);
   1110         for (int counter = 0; counter < startIndex; counter++)
   1111             assertTrue("Array modified outside of bounds",
   1112                     reversedArray[counter] == originalReversedArray[counter]);
   1113         for (int counter = startIndex; counter < endIndex - 1; counter++)
   1114             assertTrue("Array not sorted within bounds",
   1115                     reversedArray[counter] <= reversedArray[counter + 1]);
   1116         for (int counter = endIndex; counter < arraySize; counter++)
   1117             assertTrue("Array modified outside of bounds",
   1118                     reversedArray[counter] == originalReversedArray[counter]);
   1119 
   1120         //exception testing
   1121         try {
   1122             Arrays.sort(reversedArray, startIndex + 1, startIndex);
   1123             fail("IllegalArgumentException expected");
   1124         } catch (IllegalArgumentException ignore) {
   1125         }
   1126 
   1127         try {
   1128             Arrays.sort(reversedArray, -1, startIndex);
   1129             fail("ArrayIndexOutOfBoundsException expected (1)");
   1130         } catch (ArrayIndexOutOfBoundsException ignore) {
   1131         }
   1132 
   1133         try {
   1134             Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
   1135             fail("ArrayIndexOutOfBoundsException expected (2)");
   1136         } catch (ArrayIndexOutOfBoundsException ignore) {
   1137         }
   1138     }
   1139 
   1140     /**
   1141      * java.util.Arrays#sort(double[])
   1142      */
   1143     public void test_sort$D() {
   1144         // Test for method void java.util.Arrays.sort(double [])
   1145         double[] reversedArray = new double[arraySize];
   1146         for (int counter = 0; counter < arraySize; counter++)
   1147             reversedArray[counter] = (double) (arraySize - counter - 1);
   1148         Arrays.sort(reversedArray);
   1149         for (int counter = 0; counter < arraySize; counter++)
   1150             assertTrue("Resulting array not sorted",
   1151                     reversedArray[counter] == (double) counter);
   1152 
   1153         double[] specials1 = new double[] { Double.NaN, Double.MAX_VALUE,
   1154                 Double.MIN_VALUE, 0d, -0d, Double.POSITIVE_INFINITY,
   1155                 Double.NEGATIVE_INFINITY };
   1156         double[] specials2 = new double[] { 0d, Double.POSITIVE_INFINITY, -0d,
   1157                 Double.NEGATIVE_INFINITY, Double.MIN_VALUE, Double.NaN,
   1158                 Double.MAX_VALUE };
   1159         double[] specials3 = new double[] { 0.0, Double.NaN, 1.0, 2.0, Double.NaN,
   1160                 Double.NaN, 1.0, 3.0, -0.0 };
   1161         double[] answer = new double[] { Double.NEGATIVE_INFINITY, -0d, 0d,
   1162                 Double.MIN_VALUE, Double.MAX_VALUE, Double.POSITIVE_INFINITY,
   1163                 Double.NaN };
   1164         double[] answer3 = new double[] { -0.0, 0.0, 1.0, 1.0, 2.0, 3.0, Double.NaN,
   1165                 Double.NaN, Double.NaN };
   1166 
   1167         Arrays.sort(specials1);
   1168         Object[] print1 = new Object[specials1.length];
   1169         for (int i = 0; i < specials1.length; i++)
   1170             print1[i] = new Double(specials1[i]);
   1171         assertTrue("specials sort incorrectly 1: " + Arrays.asList(print1),
   1172                 Arrays.equals(specials1, answer));
   1173 
   1174         Arrays.sort(specials2);
   1175         Object[] print2 = new Object[specials2.length];
   1176         for (int i = 0; i < specials2.length; i++)
   1177             print2[i] = new Double(specials2[i]);
   1178         assertTrue("specials sort incorrectly 2: " + Arrays.asList(print2),
   1179                 Arrays.equals(specials2, answer));
   1180 
   1181         Arrays.sort(specials3);
   1182         Object[] print3 = new Object[specials3.length];
   1183         for (int i = 0; i < specials3.length; i++)
   1184             print3[i] = new Double(specials3[i]);
   1185         assertTrue("specials sort incorrectly 3: " + Arrays.asList(print3),
   1186                 Arrays.equals(specials3, answer3));
   1187     }
   1188 
   1189     /**
   1190      * java.util.Arrays#sort(double[], int, int)
   1191      */
   1192     public void test_sort$DII() {
   1193         // Test for method void java.util.Arrays.sort(double [], int, int)
   1194         int startIndex = arraySize / 4;
   1195         int endIndex = 3 * arraySize / 4;
   1196         double[] reversedArray = new double[arraySize];
   1197         double[] originalReversedArray = new double[arraySize];
   1198         for (int counter = 0; counter < arraySize; counter++) {
   1199             reversedArray[counter] = (double) (arraySize - counter - 1);
   1200             originalReversedArray[counter] = reversedArray[counter];
   1201         }
   1202         Arrays.sort(reversedArray, startIndex, endIndex);
   1203         for (int counter = 0; counter < startIndex; counter++)
   1204             assertTrue("Array modified outside of bounds",
   1205                     reversedArray[counter] == originalReversedArray[counter]);
   1206         for (int counter = startIndex; counter < endIndex - 1; counter++)
   1207             assertTrue("Array not sorted within bounds",
   1208                     reversedArray[counter] <= reversedArray[counter + 1]);
   1209         for (int counter = endIndex; counter < arraySize; counter++)
   1210             assertTrue("Array modified outside of bounds",
   1211                     reversedArray[counter] == originalReversedArray[counter]);
   1212 
   1213         //exception testing
   1214         try {
   1215             Arrays.sort(reversedArray, startIndex + 1, startIndex);
   1216             fail("IllegalArgumentException expected");
   1217         } catch (IllegalArgumentException ignore) {
   1218         }
   1219 
   1220         try {
   1221             Arrays.sort(reversedArray, -1, startIndex);
   1222             fail("ArrayIndexOutOfBoundsException expected (1)");
   1223         } catch (ArrayIndexOutOfBoundsException ignore) {
   1224         }
   1225 
   1226         try {
   1227             Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
   1228             fail("ArrayIndexOutOfBoundsException expected (2)");
   1229         } catch (ArrayIndexOutOfBoundsException ignore) {
   1230         }
   1231     }
   1232 
   1233     /**
   1234      * java.util.Arrays#sort(float[])
   1235      */
   1236     public void test_sort$F() {
   1237         // Test for method void java.util.Arrays.sort(float [])
   1238         float[] reversedArray = new float[arraySize];
   1239         for (int counter = 0; counter < arraySize; counter++)
   1240             reversedArray[counter] = (float) (arraySize - counter - 1);
   1241         Arrays.sort(reversedArray);
   1242         for (int counter = 0; counter < arraySize; counter++)
   1243             assertTrue("Resulting array not sorted",
   1244                     reversedArray[counter] == (float) counter);
   1245 
   1246         float[] specials1 = new float[] { Float.NaN, Float.MAX_VALUE,
   1247                 Float.MIN_VALUE, 0f, -0f, Float.POSITIVE_INFINITY,
   1248                 Float.NEGATIVE_INFINITY };
   1249         float[] specials2 = new float[] { 0f, Float.POSITIVE_INFINITY, -0f,
   1250                 Float.NEGATIVE_INFINITY, Float.MIN_VALUE, Float.NaN,
   1251                 Float.MAX_VALUE };
   1252         float[] answer = new float[] { Float.NEGATIVE_INFINITY, -0f, 0f,
   1253                 Float.MIN_VALUE, Float.MAX_VALUE, Float.POSITIVE_INFINITY,
   1254                 Float.NaN };
   1255 
   1256         Arrays.sort(specials1);
   1257         Object[] print1 = new Object[specials1.length];
   1258         for (int i = 0; i < specials1.length; i++)
   1259             print1[i] = new Float(specials1[i]);
   1260         assertTrue("specials sort incorrectly 1: " + Arrays.asList(print1),
   1261                 Arrays.equals(specials1, answer));
   1262 
   1263         Arrays.sort(specials2);
   1264         Object[] print2 = new Object[specials2.length];
   1265         for (int i = 0; i < specials2.length; i++)
   1266             print2[i] = new Float(specials2[i]);
   1267         assertTrue("specials sort incorrectly 2: " + Arrays.asList(print2),
   1268                 Arrays.equals(specials2, answer));
   1269     }
   1270 
   1271     /**
   1272      * java.util.Arrays#sort(float[], int, int)
   1273      */
   1274     public void test_sort$FII() {
   1275         // Test for method void java.util.Arrays.sort(float [], int, int)
   1276         int startIndex = arraySize / 4;
   1277         int endIndex = 3 * arraySize / 4;
   1278         float[] reversedArray = new float[arraySize];
   1279         float[] originalReversedArray = new float[arraySize];
   1280         for (int counter = 0; counter < arraySize; counter++) {
   1281             reversedArray[counter] = (float) (arraySize - counter - 1);
   1282             originalReversedArray[counter] = reversedArray[counter];
   1283         }
   1284         Arrays.sort(reversedArray, startIndex, endIndex);
   1285         for (int counter = 0; counter < startIndex; counter++)
   1286             assertTrue("Array modified outside of bounds",
   1287                     reversedArray[counter] == originalReversedArray[counter]);
   1288         for (int counter = startIndex; counter < endIndex - 1; counter++)
   1289             assertTrue("Array not sorted within bounds",
   1290                     reversedArray[counter] <= reversedArray[counter + 1]);
   1291         for (int counter = endIndex; counter < arraySize; counter++)
   1292             assertTrue("Array modified outside of bounds",
   1293                     reversedArray[counter] == originalReversedArray[counter]);
   1294 
   1295         //exception testing
   1296         try {
   1297             Arrays.sort(reversedArray, startIndex + 1, startIndex);
   1298             fail("IllegalArgumentException expected");
   1299         } catch (IllegalArgumentException ignore) {
   1300         }
   1301 
   1302         try {
   1303             Arrays.sort(reversedArray, -1, startIndex);
   1304             fail("ArrayIndexOutOfBoundsException expected (1)");
   1305         } catch (ArrayIndexOutOfBoundsException ignore) {
   1306         }
   1307 
   1308         try {
   1309             Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
   1310             fail("ArrayIndexOutOfBoundsException expected (2)");
   1311         } catch (ArrayIndexOutOfBoundsException ignore) {
   1312         }
   1313     }
   1314 
   1315     /**
   1316      * java.util.Arrays#sort(int[])
   1317      */
   1318     public void test_sort$I() {
   1319         // Test for method void java.util.Arrays.sort(int [])
   1320         int[] reversedArray = new int[arraySize];
   1321         for (int counter = 0; counter < arraySize; counter++)
   1322             reversedArray[counter] = arraySize - counter - 1;
   1323         Arrays.sort(reversedArray);
   1324         for (int counter = 0; counter < arraySize; counter++)
   1325             assertTrue("Resulting array not sorted",
   1326                     reversedArray[counter] == counter);
   1327     }
   1328 
   1329     /**
   1330      * java.util.Arrays#sort(int[], int, int)
   1331      */
   1332     public void test_sort$III() {
   1333         // Test for method void java.util.Arrays.sort(int [], int, int)
   1334         int startIndex = arraySize / 4;
   1335         int endIndex = 3 * arraySize / 4;
   1336         int[] reversedArray = new int[arraySize];
   1337         int[] originalReversedArray = new int[arraySize];
   1338         for (int counter = 0; counter < arraySize; counter++) {
   1339             reversedArray[counter] = arraySize - counter - 1;
   1340             originalReversedArray[counter] = reversedArray[counter];
   1341         }
   1342         Arrays.sort(reversedArray, startIndex, endIndex);
   1343         for (int counter = 0; counter < startIndex; counter++)
   1344             assertTrue("Array modified outside of bounds",
   1345                     reversedArray[counter] == originalReversedArray[counter]);
   1346         for (int counter = startIndex; counter < endIndex - 1; counter++)
   1347             assertTrue("Array not sorted within bounds",
   1348                     reversedArray[counter] <= reversedArray[counter + 1]);
   1349         for (int counter = endIndex; counter < arraySize; counter++)
   1350             assertTrue("Array modified outside of bounds",
   1351                     reversedArray[counter] == originalReversedArray[counter]);
   1352 
   1353         //exception testing
   1354         try {
   1355             Arrays.sort(reversedArray, startIndex + 1, startIndex);
   1356             fail("IllegalArgumentException expected");
   1357         } catch (IllegalArgumentException ignore) {
   1358         }
   1359 
   1360         try {
   1361             Arrays.sort(reversedArray, -1, startIndex);
   1362             fail("ArrayIndexOutOfBoundsException expected (1)");
   1363         } catch (ArrayIndexOutOfBoundsException ignore) {
   1364         }
   1365 
   1366         try {
   1367             Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
   1368             fail("ArrayIndexOutOfBoundsException expected (2)");
   1369         } catch (ArrayIndexOutOfBoundsException ignore) {
   1370         }
   1371     }
   1372 
   1373     /**
   1374      * java.util.Arrays#sort(long[])
   1375      */
   1376     public void test_sort$J() {
   1377         // Test for method void java.util.Arrays.sort(long [])
   1378         long[] reversedArray = new long[arraySize];
   1379         for (int counter = 0; counter < arraySize; counter++)
   1380             reversedArray[counter] = (long) (arraySize - counter - 1);
   1381         Arrays.sort(reversedArray);
   1382         for (int counter = 0; counter < arraySize; counter++)
   1383             assertTrue("Resulting array not sorted",
   1384                     reversedArray[counter] == (long) counter);
   1385 
   1386     }
   1387 
   1388     /**
   1389      * java.util.Arrays#sort(long[], int, int)
   1390      */
   1391     public void test_sort$JII() {
   1392         // Test for method void java.util.Arrays.sort(long [], int, int)
   1393         int startIndex = arraySize / 4;
   1394         int endIndex = 3 * arraySize / 4;
   1395         long[] reversedArray = new long[arraySize];
   1396         long[] originalReversedArray = new long[arraySize];
   1397         for (int counter = 0; counter < arraySize; counter++) {
   1398             reversedArray[counter] = (long) (arraySize - counter - 1);
   1399             originalReversedArray[counter] = reversedArray[counter];
   1400         }
   1401         Arrays.sort(reversedArray, startIndex, endIndex);
   1402         for (int counter = 0; counter < startIndex; counter++)
   1403             assertTrue("Array modified outside of bounds",
   1404                     reversedArray[counter] == originalReversedArray[counter]);
   1405         for (int counter = startIndex; counter < endIndex - 1; counter++)
   1406             assertTrue("Array not sorted within bounds",
   1407                     reversedArray[counter] <= reversedArray[counter + 1]);
   1408         for (int counter = endIndex; counter < arraySize; counter++)
   1409             assertTrue("Array modified outside of bounds",
   1410                     reversedArray[counter] == originalReversedArray[counter]);
   1411 
   1412         //exception testing
   1413         try {
   1414             Arrays.sort(reversedArray, startIndex + 1, startIndex);
   1415             fail("IllegalArgumentException expected");
   1416         } catch (IllegalArgumentException ignore) {
   1417         }
   1418 
   1419         try {
   1420             Arrays.sort(reversedArray, -1, startIndex);
   1421             fail("ArrayIndexOutOfBoundsException expected (1)");
   1422         } catch (ArrayIndexOutOfBoundsException ignore) {
   1423         }
   1424 
   1425         try {
   1426             Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
   1427             fail("ArrayIndexOutOfBoundsException expected (2)");
   1428         } catch (ArrayIndexOutOfBoundsException ignore) {
   1429         }
   1430     }
   1431 
   1432     /**
   1433      * java.util.Arrays#sort(java.lang.Object[])
   1434      */
   1435     public void test_sort$Ljava_lang_Object() {
   1436         // Test for method void java.util.Arrays.sort(java.lang.Object [])
   1437         Object[] reversedArray = new Object[arraySize];
   1438         for (int counter = 0; counter < arraySize; counter++)
   1439             reversedArray[counter] = objectArray[arraySize - counter - 1];
   1440         Arrays.sort(reversedArray);
   1441         for (int counter = 0; counter < arraySize; counter++)
   1442             assertTrue("Resulting array not sorted",
   1443                     reversedArray[counter] == objectArray[counter]);
   1444 
   1445         Arrays.fill(reversedArray, 0, reversedArray.length/2, "String");
   1446         Arrays.fill(reversedArray, reversedArray.length/2, reversedArray.length, new Integer(1));
   1447 
   1448         try {
   1449             Arrays.sort(reversedArray);
   1450             fail("ClassCastException expected");
   1451         } catch (ClassCastException e) {
   1452             //expected
   1453         }
   1454     }
   1455 
   1456     /**
   1457      * java.util.Arrays#sort(java.lang.Object[], int, int)
   1458      */
   1459     public void test_sort$Ljava_lang_ObjectII() {
   1460         // Test for method void java.util.Arrays.sort(java.lang.Object [], int,
   1461         // int)
   1462         int startIndex = arraySize / 4;
   1463         int endIndex = 3 * arraySize / 4;
   1464         Object[] reversedArray = new Object[arraySize];
   1465         Object[] originalReversedArray = new Object[arraySize];
   1466         for (int counter = 0; counter < arraySize; counter++) {
   1467             reversedArray[counter] = objectArray[arraySize - counter - 1];
   1468             originalReversedArray[counter] = reversedArray[counter];
   1469         }
   1470         Arrays.sort(reversedArray, startIndex, endIndex);
   1471         for (int counter = 0; counter < startIndex; counter++)
   1472             assertTrue("Array modified outside of bounds",
   1473                     reversedArray[counter] == originalReversedArray[counter]);
   1474         for (int counter = startIndex; counter < endIndex - 1; counter++)
   1475             assertTrue("Array not sorted within bounds",
   1476                     ((Comparable) reversedArray[counter])
   1477                             .compareTo(reversedArray[counter + 1]) <= 0);
   1478         for (int counter = endIndex; counter < arraySize; counter++)
   1479             assertTrue("Array modified outside of bounds",
   1480                     reversedArray[counter] == originalReversedArray[counter]);
   1481 
   1482         //exception testing
   1483         try {
   1484             Arrays.sort(reversedArray, startIndex + 1, startIndex);
   1485             fail("IllegalArgumentException expected");
   1486         } catch (IllegalArgumentException ignore) {
   1487         }
   1488 
   1489         try {
   1490             Arrays.sort(reversedArray, -1, startIndex);
   1491             fail("ArrayIndexOutOfBoundsException expected (1)");
   1492         } catch (ArrayIndexOutOfBoundsException ignore) {
   1493         }
   1494 
   1495         try {
   1496             Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
   1497             fail("ArrayIndexOutOfBoundsException expected (2)");
   1498         } catch (ArrayIndexOutOfBoundsException ignore) {
   1499         }
   1500 
   1501         Arrays.fill(reversedArray, 0, reversedArray.length/2, "String");
   1502         Arrays.fill(reversedArray, reversedArray.length/2, reversedArray.length, new Integer(1));
   1503 
   1504         try {
   1505             Arrays.sort(reversedArray, reversedArray.length/4, 3*reversedArray.length/4);
   1506             fail("ClassCastException expected");
   1507         } catch (ClassCastException e) {
   1508             //expected
   1509         }
   1510 
   1511         Arrays.sort(reversedArray, 0, reversedArray.length/4);
   1512         Arrays.sort(reversedArray, 3*reversedArray.length/4, reversedArray.length);
   1513     }
   1514 
   1515     /**
   1516      * java.util.Arrays#sort(java.lang.Object[], int, int,
   1517      *        java.util.Comparator)
   1518      */
   1519     public void test_sort$Ljava_lang_ObjectIILjava_util_Comparator() {
   1520         // Test for method void java.util.Arrays.sort(java.lang.Object [], int,
   1521         // int, java.util.Comparator)
   1522         int startIndex = arraySize / 4;
   1523         int endIndex = 3 * arraySize / 4;
   1524         ReversedIntegerComparator comp = new ReversedIntegerComparator();
   1525         Object[] originalArray = new Object[arraySize];
   1526         for (int counter = 0; counter < arraySize; counter++)
   1527             originalArray[counter] = objectArray[counter];
   1528         Arrays.sort(objectArray, startIndex, endIndex, comp);
   1529         for (int counter = 0; counter < startIndex; counter++)
   1530             assertTrue("Array modified outside of bounds",
   1531                     objectArray[counter] == originalArray[counter]);
   1532         for (int counter = startIndex; counter < endIndex - 1; counter++)
   1533             assertTrue("Array not sorted within bounds", comp.compare(
   1534                     objectArray[counter], objectArray[counter + 1]) <= 0);
   1535         for (int counter = endIndex; counter < arraySize; counter++)
   1536             assertTrue("Array modified outside of bounds",
   1537                     objectArray[counter] == originalArray[counter]);
   1538 
   1539         Arrays.fill(originalArray, 0, originalArray.length/2, "String");
   1540         Arrays.fill(originalArray, originalArray.length/2, originalArray.length, new Integer(1));
   1541 
   1542         try {
   1543             Arrays.sort(originalArray, startIndex, endIndex, comp);
   1544             fail("ClassCastException expected");
   1545         } catch (ClassCastException e) {
   1546             //expected
   1547         }
   1548 
   1549         Arrays.sort(originalArray, endIndex, originalArray.length, comp);
   1550 
   1551         try {
   1552             Arrays.sort(originalArray, endIndex, originalArray.length + 1, comp);
   1553             fail("ArrayIndexOutOfBoundsException expected");
   1554         } catch(ArrayIndexOutOfBoundsException e) {
   1555             //expected
   1556         }
   1557 
   1558         try {
   1559             Arrays.sort(originalArray, -1, startIndex, comp);
   1560             fail("ArrayIndexOutOfBoundsException expected");
   1561         } catch(ArrayIndexOutOfBoundsException e) {
   1562             //expected
   1563         }
   1564 
   1565         try {
   1566             Arrays.sort(originalArray, originalArray.length, endIndex, comp);
   1567             fail("IllegalArgumentException expected");
   1568         } catch(IllegalArgumentException e) {
   1569             //expected
   1570         }
   1571     }
   1572 
   1573     /**
   1574      * java.util.Arrays#sort(java.lang.Object[], java.util.Comparator)
   1575      */
   1576     public void test_sort$Ljava_lang_ObjectLjava_util_Comparator() {
   1577         // Test for method void java.util.Arrays.sort(java.lang.Object [],
   1578         // java.util.Comparator)
   1579         ReversedIntegerComparator comp = new ReversedIntegerComparator();
   1580         Arrays.sort(objectArray, comp);
   1581         for (int counter = 0; counter < arraySize - 1; counter++)
   1582             assertTrue("Array not sorted correctly with custom comparator",
   1583                     comp
   1584                             .compare(objectArray[counter],
   1585                                     objectArray[counter + 1]) <= 0);
   1586 
   1587         Arrays.fill(objectArray, 0, objectArray.length/2, "String");
   1588         Arrays.fill(objectArray, objectArray.length/2, objectArray.length, new Integer(1));
   1589 
   1590         try {
   1591             Arrays.sort(objectArray, comp);
   1592             fail("ClassCastException expected");
   1593         } catch (ClassCastException e) {
   1594             //expected
   1595         }
   1596     }
   1597 
   1598     // Regression HARMONY-6076
   1599     public void test_sort$Ljava_lang_ObjectLjava_util_Comparator_stable() {
   1600         Element[] array = new Element[11];
   1601         array[0] = new Element(122);
   1602         array[1] = new Element(146);
   1603         array[2] = new Element(178);
   1604         array[3] = new Element(208);
   1605         array[4] = new Element(117);
   1606         array[5] = new Element(146);
   1607         array[6] = new Element(173);
   1608         array[7] = new Element(203);
   1609         array[8] = new Element(56);
   1610         array[9] = new Element(208);
   1611         array[10] = new Element(96);
   1612 
   1613         Comparator<Element> comparator = new Comparator<Element>() {
   1614             public int compare(Element object1, Element object2) {
   1615                 return object1.value - object2.value;
   1616             }
   1617         };
   1618 
   1619         Arrays.sort(array, comparator);
   1620 
   1621         for (int i = 1; i < array.length; i++) {
   1622             assertTrue(comparator.compare(array[i - 1], array[i]) <= 0);
   1623             if (comparator.compare(array[i - 1], array[i]) == 0) {
   1624                 assertTrue(array[i - 1].index < array[i].index);
   1625             }
   1626         }
   1627     }
   1628 
   1629     public static class Element {
   1630         public int value;
   1631 
   1632         public int index;
   1633 
   1634         private static int count = 0;
   1635 
   1636         public Element(int value) {
   1637             this.value = value;
   1638             index = count++;
   1639         }
   1640     }
   1641 
   1642     /**
   1643      * java.util.Arrays#sort(short[])
   1644      */
   1645     public void test_sort$S() {
   1646         // Test for method void java.util.Arrays.sort(short [])
   1647         short[] reversedArray = new short[arraySize];
   1648         for (int counter = 0; counter < arraySize; counter++)
   1649             reversedArray[counter] = (short) (arraySize - counter - 1);
   1650         Arrays.sort(reversedArray);
   1651         for (int counter = 0; counter < arraySize; counter++)
   1652             assertTrue("Resulting array not sorted",
   1653                     reversedArray[counter] == (short) counter);
   1654     }
   1655 
   1656     /**
   1657      * java.util.Arrays#sort(short[], int, int)
   1658      */
   1659     public void test_sort$SII() {
   1660         // Test for method void java.util.Arrays.sort(short [], int, int)
   1661         int startIndex = arraySize / 4;
   1662         int endIndex = 3 * arraySize / 4;
   1663         short[] reversedArray = new short[arraySize];
   1664         short[] originalReversedArray = new short[arraySize];
   1665         for (int counter = 0; counter < arraySize; counter++) {
   1666             reversedArray[counter] = (short) (arraySize - counter - 1);
   1667             originalReversedArray[counter] = reversedArray[counter];
   1668         }
   1669         Arrays.sort(reversedArray, startIndex, endIndex);
   1670         for (int counter = 0; counter < startIndex; counter++)
   1671             assertTrue("Array modified outside of bounds",
   1672                     reversedArray[counter] == originalReversedArray[counter]);
   1673         for (int counter = startIndex; counter < endIndex - 1; counter++)
   1674             assertTrue("Array not sorted within bounds",
   1675                     reversedArray[counter] <= reversedArray[counter + 1]);
   1676         for (int counter = endIndex; counter < arraySize; counter++)
   1677             assertTrue("Array modified outside of bounds",
   1678                     reversedArray[counter] == originalReversedArray[counter]);
   1679 
   1680         //exception testing
   1681         try {
   1682             Arrays.sort(reversedArray, startIndex + 1, startIndex);
   1683             fail("IllegalArgumentException expected");
   1684         } catch (IllegalArgumentException ignore) {
   1685         }
   1686 
   1687         try {
   1688             Arrays.sort(reversedArray, -1, startIndex);
   1689             fail("ArrayIndexOutOfBoundsException expected (1)");
   1690         } catch (ArrayIndexOutOfBoundsException ignore) {
   1691         }
   1692 
   1693         try {
   1694             Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
   1695             fail("ArrayIndexOutOfBoundsException expected (2)");
   1696         } catch (ArrayIndexOutOfBoundsException ignore) {
   1697         }
   1698     }
   1699 
   1700     /**
   1701      * java.util.Arrays#sort(byte[], int, int)
   1702      */
   1703     public void test_java_util_Arrays_sort_byte_array_NPE() {
   1704         byte[] byte_array_null = null;
   1705         try {
   1706             java.util.Arrays.sort(byte_array_null);
   1707             fail("Should throw java.lang.NullPointerException");
   1708         } catch (NullPointerException e) {
   1709             // Expected
   1710         }
   1711         try {
   1712             // Regression for HARMONY-378
   1713             java.util.Arrays.sort(byte_array_null, (int) -1, (int) 1);
   1714             fail("Should throw java.lang.NullPointerException");
   1715         } catch (NullPointerException e) {
   1716             // Expected
   1717         }
   1718     }
   1719 
   1720     /**
   1721      * java.util.Arrays#sort(char[], int, int)
   1722      */
   1723     public void test_java_util_Arrays_sort_char_array_NPE() {
   1724         char[] char_array_null = null;
   1725         try {
   1726             java.util.Arrays.sort(char_array_null);
   1727             fail("Should throw java.lang.NullPointerException");
   1728         } catch (NullPointerException e) {
   1729             // Expected
   1730         }
   1731         try {
   1732             // Regression for HARMONY-378
   1733             java.util.Arrays.sort(char_array_null, (int) -1, (int) 1);
   1734             fail("Should throw java.lang.NullPointerException");
   1735         } catch (NullPointerException e) {
   1736             // Expected
   1737         }
   1738     }
   1739 
   1740     /**
   1741      * java.util.Arrays#sort(double[], int, int)
   1742      */
   1743     public void test_java_util_Arrays_sort_double_array_NPE() {
   1744         double[] double_array_null = null;
   1745         try {
   1746             java.util.Arrays.sort(double_array_null);
   1747             fail("Should throw java.lang.NullPointerException");
   1748         } catch (NullPointerException e) {
   1749             // Expected
   1750         }
   1751         try {
   1752             // Regression for HARMONY-378
   1753             java.util.Arrays.sort(double_array_null, (int) -1, (int) 1);
   1754             fail("Should throw java.lang.NullPointerException");
   1755         } catch (NullPointerException e) {
   1756             // Expected
   1757         }
   1758     }
   1759 
   1760     /**
   1761      * java.util.Arrays#sort(float[], int, int)
   1762      */
   1763     public void test_java_util_Arrays_sort_float_array_NPE() {
   1764         float[] float_array_null = null;
   1765         try {
   1766             java.util.Arrays.sort(float_array_null);
   1767             fail("Should throw java.lang.NullPointerException");
   1768         } catch (NullPointerException e) {
   1769             // Expected
   1770         }
   1771         try {
   1772             // Regression for HARMONY-378
   1773             java.util.Arrays.sort(float_array_null, (int) -1, (int) 1);
   1774             fail("Should throw java.lang.NullPointerException");
   1775         } catch (NullPointerException e) {
   1776             // Expected
   1777         }
   1778     }
   1779 
   1780     /**
   1781      * java.util.Arrays#sort(int[], int, int)
   1782      */
   1783     public void test_java_util_Arrays_sort_int_array_NPE() {
   1784         int[] int_array_null = null;
   1785         try {
   1786             java.util.Arrays.sort(int_array_null);
   1787             fail("Should throw java.lang.NullPointerException");
   1788         } catch (NullPointerException e) {
   1789             // Expected
   1790         }
   1791         try {
   1792             // Regression for HARMONY-378
   1793             java.util.Arrays.sort(int_array_null, (int) -1, (int) 1);
   1794             fail("Should throw java.lang.NullPointerException");
   1795         } catch (NullPointerException e) {
   1796             // Expected
   1797         }
   1798     }
   1799 
   1800     /**
   1801      * java.util.Arrays#sort(Object[], int, int)
   1802      */
   1803     public void test_java_util_Arrays_sort_object_array_NPE() {
   1804         Object[] object_array_null = null;
   1805         try {
   1806             java.util.Arrays.sort(object_array_null);
   1807             fail("Should throw java.lang.NullPointerException");
   1808         } catch (NullPointerException e) {
   1809             // Expected
   1810         }
   1811         try {
   1812             // Regression for HARMONY-378
   1813             java.util.Arrays.sort(object_array_null, (int) -1, (int) 1);
   1814             fail("Should throw java.lang.NullPointerException");
   1815         } catch (NullPointerException e) {
   1816             // Expected
   1817         }
   1818         try {
   1819             // Regression for HARMONY-378
   1820             java.util.Arrays.sort(object_array_null, (int) -1, (int) 1, null);
   1821             fail("Should throw java.lang.NullPointerException");
   1822         } catch (NullPointerException e) {
   1823             // Expected
   1824         }
   1825     }
   1826 
   1827     /**
   1828      * java.util.Arrays#sort(long[], int, int)
   1829      */
   1830     public void test_java_util_Arrays_sort_long_array_NPE() {
   1831         long[] long_array_null = null;
   1832         try {
   1833             java.util.Arrays.sort(long_array_null);
   1834             fail("Should throw java.lang.NullPointerException");
   1835         } catch (NullPointerException e) {
   1836             // Expected
   1837         }
   1838         try {
   1839             // Regression for HARMONY-378
   1840             java.util.Arrays.sort(long_array_null, (int) -1, (int) 1);
   1841             fail("Should throw java.lang.NullPointerException");
   1842         } catch (NullPointerException e) {
   1843             // Expected
   1844         }
   1845     }
   1846 
   1847     /**
   1848      * java.util.Arrays#sort(short[], int, int)
   1849      */
   1850     public void test_java_util_Arrays_sort_short_array_NPE() {
   1851         short[] short_array_null = null;
   1852         try {
   1853             java.util.Arrays.sort(short_array_null);
   1854             fail("Should throw java.lang.NullPointerException");
   1855         } catch (NullPointerException e) {
   1856             // Expected
   1857         }
   1858         try {
   1859             // Regression for HARMONY-378
   1860             java.util.Arrays.sort(short_array_null, (int) -1, (int) 1);
   1861             fail("Should throw java.lang.NullPointerException");
   1862         } catch (NullPointerException e) {
   1863             // Expected
   1864         }
   1865     }
   1866 
   1867     // Lenghts of arrays to test in test_sort;
   1868     private static final int[] LENGTHS = { 0, 1, 2, 3, 5, 8, 13, 21, 34, 55, 100, 1000, 10000 };
   1869 
   1870     /**
   1871      * java.util.Arrays#sort()
   1872      */
   1873     public void test_sort() {
   1874         for (int len : LENGTHS) {
   1875             PrimitiveTypeArrayBuilder.reset();
   1876             int[] golden = new int[len];
   1877             for (int m = 1; m < 2 * len; m *= 2) {
   1878                 for (PrimitiveTypeArrayBuilder builder : PrimitiveTypeArrayBuilder.values()) {
   1879                     builder.build(golden, m);
   1880                     int[] test = golden.clone();
   1881 
   1882                     for (PrimitiveTypeConverter converter : PrimitiveTypeConverter.values()) {
   1883                         Object convertedGolden = converter.convert(golden);
   1884                         Object convertedTest = converter.convert(test);
   1885                         sort(convertedTest);
   1886                         checkSorted(convertedTest);
   1887                         assertEquals(checkSum(convertedGolden), checkSum(convertedTest));
   1888                     }
   1889                 }
   1890             }
   1891         }
   1892     }
   1893 
   1894     private void sort(Object array) {
   1895         if (array instanceof int[]) {
   1896             Arrays.sort((int[]) array);
   1897         }
   1898         else if (array instanceof long[]) {
   1899             Arrays.sort((long[]) array);
   1900         } else if (array instanceof short[]) {
   1901             Arrays.sort((short[]) array);
   1902         } else if (array instanceof byte[]) {
   1903             Arrays.sort((byte[]) array);
   1904         } else if (array instanceof char[]) {
   1905             Arrays.sort((char[]) array);
   1906         } else if (array instanceof float[]) {
   1907             Arrays.sort((float[]) array);
   1908         } else if (array instanceof double[]) {
   1909             Arrays.sort((double[]) array);
   1910         } else {
   1911             fail("Unknow type of array: " + array.getClass());
   1912         }
   1913     }
   1914 
   1915     private void checkSorted(Object array) {
   1916         if (array instanceof int[]) {
   1917             checkSorted((int[]) array);
   1918         } else if (array instanceof long[]) {
   1919             checkSorted((long[]) array);
   1920         } else if (array instanceof short[]) {
   1921             checkSorted((short[]) array);
   1922         } else if (array instanceof byte[]) {
   1923             checkSorted((byte[]) array);
   1924         } else if (array instanceof char[]) {
   1925             checkSorted((char[]) array);
   1926         } else if (array instanceof float[]) {
   1927             checkSorted((float[]) array);
   1928         } else if (array instanceof double[]) {
   1929             checkSorted((double[]) array);
   1930         } else {
   1931             fail("Unknow type of array: " + array.getClass());
   1932         }
   1933     }
   1934 
   1935     private void checkSorted(int[] a) {
   1936         for (int i = 0; i < a.length - 1; i++) {
   1937             if (a[i] > a[i + 1]) {
   1938                 orderFail(i, "" + a[i], "" + a[i + 1]);
   1939             }
   1940         }
   1941     }
   1942 
   1943     private void checkSorted(long[] a) {
   1944         for (int i = 0; i < a.length - 1; i++) {
   1945             if (a[i] > a[i + 1]) {
   1946                 orderFail(i, "" + a[i], "" + a[i + 1]);
   1947             }
   1948         }
   1949     }
   1950 
   1951     private void checkSorted(short[] a) {
   1952         for (int i = 0; i < a.length - 1; i++) {
   1953             if (a[i] > a[i + 1]) {
   1954                 orderFail(i, "" + a[i], "" + a[i + 1]);
   1955             }
   1956         }
   1957     }
   1958 
   1959     private void checkSorted(byte[] a) {
   1960         for (int i = 0; i < a.length - 1; i++) {
   1961             if (a[i] > a[i + 1]) {
   1962                 orderFail(i, "" + a[i], "" + a[i + 1]);
   1963             }
   1964         }
   1965     }
   1966 
   1967     private void checkSorted(char[] a) {
   1968         for (int i = 0; i < a.length - 1; i++) {
   1969             if (a[i] > a[i + 1]) {
   1970                 orderFail(i, "" + a[i], "" + a[i + 1]);
   1971             }
   1972         }
   1973     }
   1974 
   1975     private void checkSorted(float[] a) {
   1976         for (int i = 0; i < a.length - 1; i++) {
   1977             if (a[i] > a[i + 1]) {
   1978                 orderFail(i, "" + a[i], "" + a[i + 1]);
   1979             }
   1980         }
   1981     }
   1982 
   1983     private void checkSorted(double[] a) {
   1984         for (int i = 0; i < a.length - 1; i++) {
   1985             if (a[i] > a[i + 1]) {
   1986                 orderFail(i, "" + a[i], "" + a[i + 1]);
   1987             }
   1988         }
   1989     }
   1990 
   1991 
   1992     private void orderFail(int index, String value1, String value2) {
   1993         fail("Array is not sorted at " + index + "-th position: " + value1 + " and " + value2);
   1994     }
   1995 
   1996     private int checkSum(Object array) {
   1997         if (array instanceof int[]) {
   1998             return checkSum((int[]) array);
   1999         } else if (array instanceof long[]) {
   2000             return checkSum((long[]) array);
   2001         } else if (array instanceof short[]) {
   2002             return checkSum((short[]) array);
   2003         } else if (array instanceof byte[]) {
   2004             return checkSum((byte[]) array);
   2005         } else if (array instanceof char[]) {
   2006             return checkSum((char[]) array);
   2007         } else if (array instanceof float[]) {
   2008             return checkSum((float[]) array);
   2009         } else if (array instanceof double[]) {
   2010             return checkSum((double[]) array);
   2011         } else {
   2012             fail("Unknow type of array: " + array.getClass());
   2013         }
   2014         throw new AssertionError(); // Needed to shut up compiler
   2015     }
   2016 
   2017     private int checkSum(int[] a) {
   2018         int checkSum = 0;
   2019 
   2020         for (int e : a) {
   2021             checkSum ^= e; // xor
   2022         }
   2023         return checkSum;
   2024     }
   2025 
   2026     private int checkSum(long[] a) {
   2027         long checkSum = 0;
   2028 
   2029         for (long e : a) {
   2030             checkSum ^= e; // xor
   2031         }
   2032         return (int) checkSum;
   2033     }
   2034 
   2035     private int checkSum(short[] a) {
   2036         short checkSum = 0;
   2037 
   2038         for (short e : a) {
   2039             checkSum ^= e; // xor
   2040         }
   2041         return (int) checkSum;
   2042     }
   2043 
   2044     private int checkSum(byte[] a) {
   2045         byte checkSum = 0;
   2046 
   2047         for (byte e : a) {
   2048             checkSum ^= e; // xor
   2049         }
   2050         return (int) checkSum;
   2051     }
   2052 
   2053     private int checkSum(char[] a) {
   2054         char checkSum = 0;
   2055 
   2056         for (char e : a) {
   2057             checkSum ^= e; // xor
   2058         }
   2059         return (int) checkSum;
   2060     }
   2061 
   2062     private int checkSum(float[] a) {
   2063         int checkSum = 0;
   2064 
   2065         for (float e : a) {
   2066             checkSum ^= (int) e; // xor
   2067         }
   2068         return checkSum;
   2069     }
   2070 
   2071     private int checkSum(double[] a) {
   2072         int checkSum = 0;
   2073 
   2074         for (double e : a) {
   2075             checkSum ^= (int) e; // xor
   2076         }
   2077         return checkSum;
   2078     }
   2079 
   2080     private enum PrimitiveTypeArrayBuilder {
   2081 
   2082         RANDOM {
   2083             void build(int[] a, int m) {
   2084                 for (int i = 0; i < a.length; i++) {
   2085                     a[i] = ourRandom.nextInt();
   2086                 }
   2087             }
   2088         },
   2089 
   2090         ASCENDING {
   2091             void build(int[] a, int m) {
   2092                 for (int i = 0; i < a.length; i++) {
   2093                     a[i] = m + i;
   2094                 }
   2095             }
   2096         },
   2097 
   2098         DESCENDING {
   2099             void build(int[] a, int m) {
   2100                 for (int i = 0; i < a.length; i++) {
   2101                     a[i] = a.length - m - i;
   2102                 }
   2103             }
   2104         },
   2105 
   2106         ALL_EQUAL {
   2107             void build(int[] a, int m) {
   2108                 for (int i = 0; i < a.length; i++) {
   2109                     a[i] = m;
   2110                 }
   2111             }
   2112         },
   2113 
   2114         SAW {
   2115             void build(int[] a, int m) {
   2116                 int incCount = 1;
   2117                 int decCount = a.length;
   2118                 int i = 0;
   2119                 int period = m;
   2120                 m--;
   2121 
   2122                 while (true) {
   2123                     for (int k = 1; k <= period; k++) {
   2124                         if (i >= a.length) {
   2125                             return;
   2126                         }
   2127                         a[i++] = incCount++;
   2128                     }
   2129                     period += m;
   2130 
   2131                     for (int k = 1; k <= period; k++) {
   2132                         if (i >= a.length) {
   2133                             return;
   2134                         }
   2135                         a[i++] = decCount--;
   2136                     }
   2137                     period += m;
   2138                 }
   2139             }
   2140         },
   2141 
   2142         REPEATED {
   2143             void build(int[] a, int m) {
   2144                 for (int i = 0; i < a.length; i++) {
   2145                     a[i] = i % m;
   2146                 }
   2147             }
   2148         },
   2149 
   2150         DUPLICATED {
   2151             void build(int[] a, int m) {
   2152                 for (int i = 0; i < a.length; i++) {
   2153                     a[i] = ourRandom.nextInt(m);
   2154                 }
   2155             }
   2156         },
   2157 
   2158         ORGAN_PIPES {
   2159             void build(int[] a, int m) {
   2160                 int middle = a.length / (m + 1);
   2161 
   2162                 for (int i = 0; i < middle; i++) {
   2163                     a[i] = i;
   2164                 }
   2165                 for (int i = middle; i < a.length ; i++) {
   2166                     a[i] = a.length - i - 1;
   2167                 }
   2168             }
   2169         },
   2170 
   2171         STAGGER {
   2172             void build(int[] a, int m) {
   2173                 for (int i = 0; i < a.length; i++) {
   2174                     a[i] = (i * m + i) % a.length;
   2175                 }
   2176             }
   2177         },
   2178 
   2179         PLATEAU {
   2180             void build(int[] a, int m) {
   2181                 for (int i = 0; i < a.length; i++) {
   2182                     a[i] =  Math.min(i, m);
   2183                 }
   2184             }
   2185         },
   2186 
   2187         SHUFFLE {
   2188             void build(int[] a, int m) {
   2189                 for (int i = 0; i < a.length; i++) {
   2190                     a[i] = ourRandom.nextBoolean() ? (ourFirst += 2) : (ourSecond += 2);
   2191                 }
   2192             }
   2193         };
   2194 
   2195         abstract void build(int[] a, int m);
   2196 
   2197         static void reset() {
   2198             ourRandom = new Random(666);
   2199             ourFirst = 0;
   2200             ourSecond = 0;
   2201         }
   2202 
   2203         @Override
   2204         public String toString() {
   2205             String name = name();
   2206 
   2207             for (int i = name.length(); i < 12; i++) {
   2208                 name += " " ;
   2209             }
   2210             return name;
   2211         }
   2212 
   2213         private static int ourFirst;
   2214         private static int ourSecond;
   2215         private static Random ourRandom = new Random(666);
   2216     }
   2217 
   2218     private enum PrimitiveTypeConverter {
   2219 
   2220         INT {
   2221             Object convert(int[] a) {
   2222                 return a;
   2223             }
   2224         },
   2225 
   2226         LONG {
   2227             Object convert(int[] a) {
   2228                 long[] b = new long[a.length];
   2229 
   2230                 for (int i = 0; i < a.length; i++) {
   2231                     b[i] = (long) a[i];
   2232                 }
   2233                 return b;
   2234             }
   2235         },
   2236 
   2237         BYTE {
   2238             Object convert(int[] a) {
   2239                 byte[] b = new byte[a.length];
   2240 
   2241                 for (int i = 0; i < a.length; i++) {
   2242                     b[i] = (byte) a[i];
   2243                 }
   2244                 return b;
   2245             }
   2246         },
   2247 
   2248         SHORT {
   2249             Object convert(int[] a) {
   2250                 short[] b = new short[a.length];
   2251 
   2252                 for (int i = 0; i < a.length; i++) {
   2253                     b[i] = (short) a[i];
   2254                 }
   2255                 return b;
   2256             }
   2257         },
   2258 
   2259         CHAR {
   2260             Object convert(int[] a) {
   2261                 char[] b = new char[a.length];
   2262 
   2263                 for (int i = 0; i < a.length; i++) {
   2264                     b[i] = (char) a[i];
   2265                 }
   2266                 return b;
   2267             }
   2268         },
   2269 
   2270         FLOAT {
   2271             Object convert(int[] a) {
   2272                 float[] b = new float[a.length];
   2273 
   2274                 for (int i = 0; i < a.length; i++) {
   2275                     b[i] = (float) a[i];
   2276                 }
   2277                 return b;
   2278             }
   2279         },
   2280 
   2281         DOUBLE {
   2282             Object convert(int[] a) {
   2283                 double[] b = new double[a.length];
   2284 
   2285                 for (int i = 0; i < a.length; i++) {
   2286                     b[i] = (double) a[i];
   2287                 }
   2288                 return b;
   2289             }
   2290         };
   2291 
   2292         abstract Object convert(int[] a);
   2293 
   2294         public String toString() {
   2295             String name = name();
   2296 
   2297             for (int i = name.length(); i < 9; i++) {
   2298                 name += " " ;
   2299             }
   2300             return name;
   2301         }
   2302     }
   2303 
   2304 
   2305     /**
   2306      * java.util.Arrays#deepEquals(Object[], Object[])
   2307      */
   2308     public void test_deepEquals$Ljava_lang_ObjectLjava_lang_Object() {
   2309         int[] a1 = { 1, 2, 3 };
   2310         short[] a2 = { 0, 1 };
   2311         Object[] a3 = { new Integer(1), a2 };
   2312         int[] a4 = { 6, 5, 4 };
   2313 
   2314         int[] b1 = { 1, 2, 3 };
   2315         short[] b2 = { 0, 1 };
   2316         Object[] b3 = { new Integer(1), b2 };
   2317 
   2318         Object a[] = { a1, a2, a3 };
   2319         Object b[] = { b1, b2, b3 };
   2320 
   2321         assertFalse(Arrays.equals(a, b));
   2322         assertTrue(Arrays.deepEquals(a, b));
   2323 
   2324         a[2] = a4;
   2325 
   2326         assertFalse(Arrays.deepEquals(a, b));
   2327     }
   2328 
   2329     /**
   2330      * java.util.Arrays#deepHashCode(Object[])
   2331      */
   2332     public void test_deepHashCode$Ljava_lang_Object() {
   2333         int[] a1 = { 1, 2, 3 };
   2334         short[] a2 = { 0, 1 };
   2335         Object[] a3 = { new Integer(1), a2 };
   2336 
   2337         int[] b1 = { 1, 2, 3 };
   2338         short[] b2 = { 0, 1 };
   2339         Object[] b3 = { new Integer(1), b2 };
   2340 
   2341         Object a[] = { a1, a2, a3 };
   2342         Object b[] = { b1, b2, b3 };
   2343 
   2344         int deep_hash_a = Arrays.deepHashCode(a);
   2345         int deep_hash_b = Arrays.deepHashCode(b);
   2346 
   2347         assertEquals(deep_hash_a, deep_hash_b);
   2348     }
   2349 
   2350     /**
   2351      * java.util.Arrays#hashCode(boolean[] a)
   2352      */
   2353     public void test_hashCode$LZ() {
   2354         int listHashCode;
   2355         int arrayHashCode;
   2356 
   2357         boolean[] boolArr = { true, false, false, true, false };
   2358         List listOfBoolean = new LinkedList();
   2359         for (int i = 0; i < boolArr.length; i++) {
   2360             listOfBoolean.add(new Boolean(boolArr[i]));
   2361         }
   2362         listHashCode = listOfBoolean.hashCode();
   2363         arrayHashCode = Arrays.hashCode(boolArr);
   2364         assertEquals(listHashCode, arrayHashCode);
   2365     }
   2366 
   2367     /**
   2368      * java.util.Arrays#hashCode(int[] a)
   2369      */
   2370     public void test_hashCode$LI() {
   2371         int listHashCode;
   2372         int arrayHashCode;
   2373 
   2374         int[] intArr = { 10, 5, 134, 7, 19 };
   2375         List listOfInteger = new LinkedList();
   2376 
   2377         for (int i = 0; i < intArr.length; i++) {
   2378             listOfInteger.add(new Integer(intArr[i]));
   2379         }
   2380         listHashCode = listOfInteger.hashCode();
   2381         arrayHashCode = Arrays.hashCode(intArr);
   2382         assertEquals(listHashCode, arrayHashCode);
   2383 
   2384         int[] intArr2 = { 10, 5, 134, 7, 19 };
   2385         assertEquals(Arrays.hashCode(intArr2), Arrays.hashCode(intArr));
   2386     }
   2387 
   2388     /**
   2389      * java.util.Arrays#hashCode(char[] a)
   2390      */
   2391     public void test_hashCode$LC() {
   2392         int listHashCode;
   2393         int arrayHashCode;
   2394 
   2395         char[] charArr = { 'a', 'g', 'x', 'c', 'm' };
   2396         List listOfCharacter = new LinkedList();
   2397         for (int i = 0; i < charArr.length; i++) {
   2398             listOfCharacter.add(new Character(charArr[i]));
   2399         }
   2400         listHashCode = listOfCharacter.hashCode();
   2401         arrayHashCode = Arrays.hashCode(charArr);
   2402         assertEquals(listHashCode, arrayHashCode);
   2403     }
   2404 
   2405     /**
   2406      * java.util.Arrays#hashCode(byte[] a)
   2407      */
   2408     public void test_hashCode$LB() {
   2409         int listHashCode;
   2410         int arrayHashCode;
   2411 
   2412         byte[] byteArr = { 5, 9, 7, 6, 17 };
   2413         List listOfByte = new LinkedList();
   2414         for (int i = 0; i < byteArr.length; i++) {
   2415             listOfByte.add(new Byte(byteArr[i]));
   2416         }
   2417         listHashCode = listOfByte.hashCode();
   2418         arrayHashCode = Arrays.hashCode(byteArr);
   2419         assertEquals(listHashCode, arrayHashCode);
   2420     }
   2421 
   2422     /**
   2423      * java.util.Arrays#hashCode(long[] a)
   2424      */
   2425     public void test_hashCode$LJ() {
   2426         int listHashCode;
   2427         int arrayHashCode;
   2428 
   2429         long[] longArr = { 67890234512l, 97587236923425l, 257421912912l,
   2430                 6754268100l, 5 };
   2431         List listOfLong = new LinkedList();
   2432         for (int i = 0; i < longArr.length; i++) {
   2433             listOfLong.add(new Long(longArr[i]));
   2434         }
   2435         listHashCode = listOfLong.hashCode();
   2436         arrayHashCode = Arrays.hashCode(longArr);
   2437         assertEquals(listHashCode, arrayHashCode);
   2438     }
   2439 
   2440     /**
   2441      * java.util.Arrays#hashCode(float[] a)
   2442      */
   2443     public void test_hashCode$LF() {
   2444         int listHashCode;
   2445         int arrayHashCode;
   2446 
   2447         float[] floatArr = { 0.13497f, 0.268934f, 12e-5f, -3e+2f, 10e-4f };
   2448         List listOfFloat = new LinkedList();
   2449         for (int i = 0; i < floatArr.length; i++) {
   2450             listOfFloat.add(new Float(floatArr[i]));
   2451         }
   2452         listHashCode = listOfFloat.hashCode();
   2453         arrayHashCode = Arrays.hashCode(floatArr);
   2454         assertEquals(listHashCode, arrayHashCode);
   2455 
   2456         float[] floatArr2 = { 0.13497f, 0.268934f, 12e-5f, -3e+2f, 10e-4f };
   2457         assertEquals(Arrays.hashCode(floatArr2), Arrays.hashCode(floatArr));
   2458     }
   2459 
   2460     /**
   2461      * java.util.Arrays#hashCode(double[] a)
   2462      */
   2463     public void test_hashCode$LD() {
   2464         int listHashCode;
   2465         int arrayHashCode;
   2466 
   2467         double[] doubleArr = { 0.134945657, 0.0038754, 11e-150, -30e-300, 10e-4 };
   2468         List listOfDouble = new LinkedList();
   2469         for (int i = 0; i < doubleArr.length; i++) {
   2470             listOfDouble.add(new Double(doubleArr[i]));
   2471         }
   2472         listHashCode = listOfDouble.hashCode();
   2473         arrayHashCode = Arrays.hashCode(doubleArr);
   2474         assertEquals(listHashCode, arrayHashCode);
   2475     }
   2476 
   2477     /**
   2478      * java.util.Arrays#hashCode(short[] a)
   2479      */
   2480     public void test_hashCode$LS() {
   2481         int listHashCode;
   2482         int arrayHashCode;
   2483 
   2484         short[] shortArr = { 35, 13, 45, 2, 91 };
   2485         List listOfShort = new LinkedList();
   2486         for (int i = 0; i < shortArr.length; i++) {
   2487             listOfShort.add(new Short(shortArr[i]));
   2488         }
   2489         listHashCode = listOfShort.hashCode();
   2490         arrayHashCode = Arrays.hashCode(shortArr);
   2491         assertEquals(listHashCode, arrayHashCode);
   2492     }
   2493 
   2494     /**
   2495      * java.util.Arrays#hashCode(Object[] a)
   2496      */
   2497     public void test_hashCode$Ljava_lang_Object() {
   2498         int listHashCode;
   2499         int arrayHashCode;
   2500 
   2501         Object[] objectArr = { new Integer(1), new Float(10e-12f), null };
   2502         List listOfObject = new LinkedList();
   2503         for (int i = 0; i < objectArr.length; i++) {
   2504             listOfObject.add(objectArr[i]);
   2505         }
   2506         listHashCode = listOfObject.hashCode();
   2507         arrayHashCode = Arrays.hashCode(objectArr);
   2508         assertEquals(listHashCode, arrayHashCode);
   2509     }
   2510 
   2511     /**
   2512      * Sets up the fixture, for example, open a network connection. This method
   2513      * is called before a test is executed.
   2514      */
   2515     protected void setUp() {
   2516         objArray = new Object[arraySize];
   2517         for (int i = 0; i < objArray.length; i++)
   2518             objArray[i] = new Integer(i);
   2519 
   2520         booleanArray = new boolean[arraySize];
   2521         byteArray = new byte[arraySize];
   2522         charArray = new char[arraySize];
   2523         doubleArray = new double[arraySize];
   2524         floatArray = new float[arraySize];
   2525         intArray = new int[arraySize];
   2526         longArray = new long[arraySize];
   2527         objectArray = new Object[arraySize];
   2528         shortArray = new short[arraySize];
   2529 
   2530         for (int counter = 0; counter < arraySize; counter++) {
   2531             byteArray[counter] = (byte) counter;
   2532             charArray[counter] = (char) (counter + 1);
   2533             doubleArray[counter] = counter;
   2534             floatArray[counter] = counter;
   2535             intArray[counter] = counter;
   2536             longArray[counter] = counter;
   2537             objectArray[counter] = objArray[counter];
   2538             shortArray[counter] = (short) counter;
   2539         }
   2540         for (int counter = 0; counter < arraySize; counter += 2) {
   2541             booleanArray[counter] = false;
   2542             booleanArray[counter + 1] = true;
   2543         }
   2544     }
   2545 
   2546     /**
   2547      * java.util.Arrays#binarySearch(byte[], int, int, byte)
   2548      */
   2549     public void test_binarySearch$BIIB() {
   2550         for (byte counter = 0; counter < arraySize; counter++) {
   2551             assertTrue(
   2552                     "Binary search on byte[] answered incorrect position",
   2553                     Arrays.binarySearch(byteArray, counter, arraySize, counter) == counter);
   2554         }
   2555         assertEquals(
   2556                 "Binary search succeeded for value not present in array 1", -1,
   2557                 Arrays.binarySearch(byteArray, 0, arraySize, (byte) -1));
   2558         assertTrue(
   2559                 "Binary search succeeded for value not present in array 2",
   2560                 Arrays.binarySearch(byteArray, (byte) arraySize) == -(arraySize + 1));
   2561         for (byte counter = 0; counter < arraySize; counter++) {
   2562             byteArray[counter] -= 50;
   2563         }
   2564         for (byte counter = 0; counter < arraySize; counter++) {
   2565             assertTrue(
   2566                     "Binary search on byte[] involving negative numbers answered incorrect position",
   2567                     Arrays.binarySearch(byteArray, counter, arraySize,
   2568                             (byte) (counter - 50)) == counter);
   2569         }
   2570         try {
   2571             Arrays.binarySearch((byte[]) null, 2, 1, (byte) arraySize);
   2572             fail("should throw NullPointerException");
   2573         } catch (NullPointerException e) {
   2574             // expected
   2575         }
   2576         try {
   2577             Arrays.binarySearch((byte[]) null, -1, 0, (byte) arraySize);
   2578             fail("should throw NullPointerException");
   2579         } catch (NullPointerException e) {
   2580             // expected
   2581         }
   2582         try {
   2583             Arrays.binarySearch((byte[]) null, -1, -2, (byte) arraySize);
   2584             fail("should throw NullPointerException");
   2585         } catch (NullPointerException e) {
   2586             // expected
   2587         }
   2588         try {
   2589             Arrays.binarySearch(byteArray, 2, 1, (byte) arraySize);
   2590             fail("should throw IllegalArgumentException");
   2591         } catch (IllegalArgumentException e) {
   2592             // expected
   2593         }
   2594         assertEquals(-1, Arrays.binarySearch(byteArray, 0, 0, (byte) arraySize));
   2595         try {
   2596             Arrays.binarySearch(byteArray, -1, -2, (byte) arraySize);
   2597             fail("should throw IllegalArgumentException");
   2598         } catch (IllegalArgumentException e) {
   2599             // expected
   2600         }
   2601         try {
   2602             Arrays.binarySearch(byteArray, arraySize + 2, arraySize + 1,
   2603                     (byte) arraySize);
   2604             fail("should throw IllegalArgumentException");
   2605         } catch (IllegalArgumentException e) {
   2606             // expected
   2607         }
   2608         try {
   2609             Arrays.binarySearch(byteArray, -1, 0, (byte) arraySize);
   2610             fail("should throw ArrayIndexOutOfBoundsException");
   2611         } catch (ArrayIndexOutOfBoundsException e) {
   2612             // expected
   2613         }
   2614         try {
   2615             Arrays.binarySearch(byteArray, 0, arraySize + 1, (byte) arraySize);
   2616             fail("should throw ArrayIndexOutOfBoundsException");
   2617         } catch (ArrayIndexOutOfBoundsException e) {
   2618             // expected
   2619         }
   2620     }
   2621 
   2622     /**
   2623      * java.util.Arrays#binarySearch(char[], char)
   2624      */
   2625     public void test_binarySearch$CIIC() {
   2626         for (char counter = 0; counter < arraySize; counter++) {
   2627             assertTrue("Binary search on char[] answered incorrect position",
   2628                     Arrays.binarySearch(charArray, counter, arraySize,
   2629                             (char) (counter + 1)) == counter);
   2630         }
   2631         assertEquals(
   2632                 "Binary search succeeded for value not present in array 1", -1,
   2633                 Arrays.binarySearch(charArray, 0, arraySize, '\u0000'));
   2634         assertTrue("Binary search succeeded for value not present in array 2",
   2635                 Arrays.binarySearch(charArray, 0, arraySize,
   2636                         (char) (arraySize + 1)) == -(arraySize + 1));
   2637         try {
   2638             Arrays.binarySearch(charArray, 2, 1, (char) arraySize);
   2639             fail("should throw IllegalArgumentException");
   2640         } catch (IllegalArgumentException e) {
   2641             // expected
   2642         }
   2643         try {
   2644             Arrays.binarySearch((char[]) null, 2, 1, (char) arraySize);
   2645             fail("should throw NullPointerException");
   2646         } catch (NullPointerException e) {
   2647             // expected
   2648         }
   2649         try {
   2650             Arrays.binarySearch((char[]) null, -1, 0, (char) arraySize);
   2651             fail("should throw NullPointerException");
   2652         } catch (NullPointerException e) {
   2653             // expected
   2654         }
   2655         try {
   2656             Arrays.binarySearch((char[]) null, -1, -2, (char) arraySize);
   2657             fail("should throw NullPointerException");
   2658         } catch (NullPointerException e) {
   2659             // expected
   2660         }
   2661         assertEquals(-1, Arrays.binarySearch(charArray, 0, 0, (char) arraySize));
   2662         try {
   2663             Arrays.binarySearch(charArray, -1, -2, (char) arraySize);
   2664             fail("should throw IllegalArgumentException");
   2665         } catch (IllegalArgumentException e) {
   2666             // expected
   2667         }
   2668         try {
   2669             Arrays.binarySearch(charArray, arraySize + 2, arraySize + 1,
   2670                     (char) arraySize);
   2671             fail("should throw IllegalArgumentException");
   2672         } catch (IllegalArgumentException e) {
   2673             // expected
   2674         }
   2675         try {
   2676             Arrays.binarySearch(charArray, -1, 0, (char) arraySize);
   2677             fail("should throw ArrayIndexOutOfBoundsException");
   2678         } catch (ArrayIndexOutOfBoundsException e) {
   2679             // expected
   2680         }
   2681         try {
   2682             Arrays.binarySearch(charArray, 0, arraySize + 1, (char) arraySize);
   2683             fail("should throw ArrayIndexOutOfBoundsException");
   2684         } catch (ArrayIndexOutOfBoundsException e) {
   2685             // expected
   2686         }
   2687     }
   2688 
   2689     /**
   2690      * java.util.Arrays#binarySearch(double[], double)
   2691      */
   2692     public void test_binarySearch$DIID() {
   2693         for (int counter = 0; counter < arraySize; counter++) {
   2694             assertTrue("Binary search on double[] answered incorrect position",
   2695                     Arrays.binarySearch(doubleArray, counter, arraySize,
   2696                             (double) counter) == (double) counter);
   2697         }
   2698         assertEquals(
   2699                 "Binary search succeeded for value not present in array 1", -1,
   2700                 Arrays.binarySearch(doubleArray, 0, arraySize, (double) -1));
   2701         assertTrue("Binary search succeeded for value not present in array 2",
   2702                 Arrays.binarySearch(doubleArray, 0, arraySize,
   2703                         (double) arraySize) == -(arraySize + 1));
   2704         for (int counter = 0; counter < arraySize; counter++) {
   2705             doubleArray[counter] -= (double) 50;
   2706         }
   2707         for (int counter = 0; counter < arraySize; counter++) {
   2708             assertTrue(
   2709                     "Binary search on double[] involving negative numbers answered incorrect position",
   2710                     Arrays.binarySearch(doubleArray, counter, arraySize, (double) (counter - 50)) == (double) counter);
   2711         }
   2712         double[] specials = new double[] { Double.NEGATIVE_INFINITY,
   2713                 -Double.MAX_VALUE, -2d, -Double.MIN_VALUE, -0d, 0d,
   2714                 Double.MIN_VALUE, 2d, Double.MAX_VALUE,
   2715                 Double.POSITIVE_INFINITY, Double.NaN };
   2716         for (int i = 0; i < specials.length; i++) {
   2717             int result = Arrays.binarySearch(specials, i, specials.length, specials[i]);
   2718             assertTrue(specials[i] + " invalid: " + result, result == i);
   2719         }
   2720         assertEquals("-1d", -4, Arrays.binarySearch(specials, 0, specials.length, -1d));
   2721         assertEquals("1d", -8, Arrays.binarySearch(specials, 0, specials.length, 1d));
   2722         try {
   2723             Arrays.binarySearch((double[]) null, 2, 1, (double) arraySize);
   2724             fail("should throw NullPointerException");
   2725         } catch (NullPointerException e) {
   2726             // expected
   2727         }
   2728         try {
   2729             Arrays.binarySearch((double[]) null, -1, 0, (double) arraySize);
   2730             fail("should throw NullPointerException");
   2731         } catch (NullPointerException e) {
   2732             // expected
   2733         }
   2734         try {
   2735             Arrays.binarySearch((double[]) null, -1, -2, (double) arraySize);
   2736             fail("should throw NullPointerException");
   2737         } catch (NullPointerException e) {
   2738             // expected
   2739         }
   2740         try {
   2741             Arrays.binarySearch(doubleArray, 2, 1, (char) arraySize);
   2742             fail("should throw IllegalArgumentException");
   2743         } catch (IllegalArgumentException e) {
   2744             // expected
   2745         }
   2746         assertEquals(-1, Arrays.binarySearch(doubleArray, 0, 0, (char) arraySize));
   2747         try {
   2748             Arrays.binarySearch(doubleArray, -1, -2, (char) arraySize);
   2749             fail("should throw IllegalArgumentException");
   2750         } catch (IllegalArgumentException e) {
   2751             // expected
   2752         }
   2753         try {
   2754             Arrays.binarySearch(doubleArray, arraySize + 2, arraySize + 1,
   2755                     (char) arraySize);
   2756             fail("should throw IllegalArgumentException");
   2757         } catch (IllegalArgumentException e) {
   2758             // expected
   2759         }
   2760         try {
   2761             Arrays.binarySearch(doubleArray, -1, 0, (char) arraySize);
   2762             fail("should throw ArrayIndexOutOfBoundsException");
   2763         } catch (ArrayIndexOutOfBoundsException e) {
   2764             // expected
   2765         }
   2766         try {
   2767             Arrays.binarySearch(doubleArray, 0, arraySize + 1, (char) arraySize);
   2768             fail("should throw ArrayIndexOutOfBoundsException");
   2769         } catch (ArrayIndexOutOfBoundsException e) {
   2770             // expected
   2771         }
   2772     }
   2773 
   2774     /**
   2775      * java.util.Arrays#binarySearch(float[], float)
   2776      */
   2777     public void test_binarySearch$FIIF() {
   2778         for (int counter = 0; counter < arraySize; counter++) {
   2779             assertTrue("Binary search on float[] answered incorrect position",
   2780                     Arrays.binarySearch(floatArray, counter, arraySize,
   2781                             (float) counter) == (float) counter);
   2782         }
   2783         assertEquals(
   2784                 "Binary search succeeded for value not present in array 1", -1,
   2785                 Arrays.binarySearch(floatArray, 0, arraySize, (float) -1));
   2786         assertTrue("Binary search succeeded for value not present in array 2",
   2787                 Arrays
   2788                         .binarySearch(floatArray, 0, arraySize,
   2789                                 (float) arraySize) == -(arraySize + 1));
   2790         for (int counter = 0; counter < arraySize; counter++) {
   2791             floatArray[counter] -= (float) 50;
   2792         }
   2793         for (int counter = 0; counter < arraySize; counter++) {
   2794             assertTrue(
   2795                     "Binary search on float[] involving negative numbers answered incorrect position",
   2796                     Arrays.binarySearch(floatArray, 0, arraySize,
   2797                             (float) counter - 50) == (float) counter);
   2798         }
   2799         float[] specials = new float[] { Float.NEGATIVE_INFINITY,
   2800                 -Float.MAX_VALUE, -2f, -Float.MIN_VALUE, -0f, 0f,
   2801                 Float.MIN_VALUE, 2f, Float.MAX_VALUE, Float.POSITIVE_INFINITY,
   2802                 Float.NaN };
   2803         for (int i = 0; i < specials.length; i++) {
   2804             int result = Arrays.binarySearch(specials, i, specials.length, specials[i]);
   2805             assertTrue(specials[i] + " invalid: " + result, result == i);
   2806         }
   2807         assertEquals("-1f", -4, Arrays.binarySearch(specials, 0, specials.length, -1f));
   2808         assertEquals("1f", -8, Arrays.binarySearch(specials, 0, specials.length, 1f));
   2809         try {
   2810             Arrays.binarySearch((float[]) null, 2, 1, (float) arraySize);
   2811             fail("should throw NullPointerException");
   2812         } catch (NullPointerException e) {
   2813             // expected
   2814         }
   2815         try {
   2816             Arrays.binarySearch((float[]) null, -1, 0, (float) arraySize);
   2817             fail("should throw NullPointerException");
   2818         } catch (NullPointerException e) {
   2819             // expected
   2820         }
   2821         try {
   2822             Arrays.binarySearch((float[]) null, -1, -2, (float) arraySize);
   2823             fail("should throw NullPointerException");
   2824         } catch (NullPointerException e) {
   2825             // expected
   2826         }
   2827         try {
   2828             Arrays.binarySearch(floatArray, 2, 1, (char) arraySize);
   2829             fail("should throw IllegalArgumentException");
   2830         } catch (IllegalArgumentException e) {
   2831             // expected
   2832         }
   2833         assertEquals(-1, Arrays.binarySearch(floatArray, 0, 0,
   2834                 (char) arraySize));
   2835         try {
   2836             Arrays.binarySearch(floatArray, -1, -2, (char) arraySize);
   2837             fail("should throw IllegalArgumentException");
   2838         } catch (IllegalArgumentException e) {
   2839             // expected
   2840         }
   2841         try {
   2842             Arrays.binarySearch(floatArray, arraySize + 2, arraySize + 1,
   2843                     (char) arraySize);
   2844             fail("should throw IllegalArgumentException");
   2845         } catch (IllegalArgumentException e) {
   2846             // expected
   2847         }
   2848         try {
   2849             Arrays.binarySearch(floatArray, -1, 0, (char) arraySize);
   2850             fail("should throw ArrayIndexOutOfBoundsException");
   2851         } catch (ArrayIndexOutOfBoundsException e) {
   2852             // expected
   2853         }
   2854         try {
   2855             Arrays
   2856                     .binarySearch(floatArray, 0, arraySize + 1,
   2857                             (char) arraySize);
   2858             fail("should throw ArrayIndexOutOfBoundsException");
   2859         } catch (ArrayIndexOutOfBoundsException e) {
   2860             // expected
   2861         }
   2862     }
   2863 
   2864     /**
   2865      * java.util.Arrays#binarySearch(int[], int)
   2866      */
   2867     public void test_binarySearch$IIII() {
   2868         for (int counter = 0; counter < arraySize; counter++) {
   2869             assertTrue(
   2870                     "Binary search on int[] answered incorrect position",
   2871                     Arrays.binarySearch(intArray, counter, arraySize, counter) == counter);
   2872         }
   2873         assertEquals(
   2874                 "Binary search succeeded for value not present in array 1", -1,
   2875                 Arrays.binarySearch(intArray, 0, arraySize, -1));
   2876         assertTrue("Binary search succeeded for value not present in array 2",
   2877                 Arrays.binarySearch(intArray, 0, arraySize, arraySize) == -(arraySize + 1));
   2878         for (int counter = 0; counter < arraySize; counter++) {
   2879             intArray[counter] -= 50;
   2880         }
   2881         for (int counter = 0; counter < arraySize; counter++) {
   2882             assertTrue(
   2883                     "Binary search on int[] involving negative numbers answered incorrect position",
   2884                     Arrays.binarySearch(intArray, 0, arraySize, counter - 50) == counter);
   2885         }
   2886         try {
   2887             Arrays.binarySearch((int[]) null, 2, 1, (int) arraySize);
   2888             fail("should throw NullPointerException");
   2889         } catch (NullPointerException e) {
   2890             // expected
   2891         }
   2892         try {
   2893             Arrays.binarySearch((int[]) null, -1, 0, (int) arraySize);
   2894             fail("should throw NullPointerException");
   2895         } catch (NullPointerException e) {
   2896             // expected
   2897         }
   2898         try {
   2899             Arrays.binarySearch((int[]) null, -1, -2, (int) arraySize);
   2900             fail("should throw NullPointerException");
   2901         } catch (NullPointerException e) {
   2902             // expected
   2903         }
   2904         try {
   2905             Arrays.binarySearch(intArray, 2, 1, (char) arraySize);
   2906             fail("should throw IllegalArgumentException");
   2907         } catch (IllegalArgumentException e) {
   2908             // expected
   2909         }
   2910         assertEquals(-1, Arrays
   2911                 .binarySearch(intArray, 0, 0, (char) arraySize));
   2912         try {
   2913             Arrays.binarySearch(intArray, -1, -2, (char) arraySize);
   2914             fail("should throw IllegalArgumentException");
   2915         } catch (IllegalArgumentException e) {
   2916             // expected
   2917         }
   2918         try {
   2919             Arrays.binarySearch(intArray, arraySize + 2, arraySize + 1,
   2920                     (char) arraySize);
   2921             fail("should throw IllegalArgumentException");
   2922         } catch (IllegalArgumentException e) {
   2923             // expected
   2924         }
   2925         try {
   2926             Arrays.binarySearch(intArray, -1, 0, (char) arraySize);
   2927             fail("should throw ArrayIndexOutOfBoundsException");
   2928         } catch (ArrayIndexOutOfBoundsException e) {
   2929             // expected
   2930         }
   2931         try {
   2932             Arrays.binarySearch(intArray, 0, arraySize + 1, (char) arraySize);
   2933             fail("should throw ArrayIndexOutOfBoundsException");
   2934         } catch (ArrayIndexOutOfBoundsException e) {
   2935             // expected
   2936         }
   2937     }
   2938 
   2939     /**
   2940      * java.util.Arrays#binarySearch(long[], long)
   2941      */
   2942     public void test_binarySearch$JIIJ() {
   2943         for (long counter = 0; counter < arraySize; counter++) {
   2944             assertTrue("Binary search on long[] answered incorrect position",
   2945                     Arrays.binarySearch(longArray, 0, arraySize, counter) == counter);
   2946         }
   2947         assertEquals("Binary search succeeded for value not present in array 1",
   2948                 -1, Arrays.binarySearch(longArray, 0, arraySize, (long) -1));
   2949         assertTrue(
   2950                 "Binary search succeeded for value not present in array 2",
   2951                 Arrays.binarySearch(longArray, 0, arraySize, (long) arraySize) == -(arraySize + 1));
   2952         for (long counter = 0; counter < arraySize; counter++) {
   2953             longArray[(int) counter] -= (long) 50;
   2954         }
   2955         for (long counter = 0; counter < arraySize; counter++) {
   2956             assertTrue(
   2957                     "Binary search on long[] involving negative numbers answered incorrect position",
   2958                     Arrays.binarySearch(longArray, 0, arraySize, counter - (long) 50) == counter);
   2959         }
   2960         try {
   2961             Arrays.binarySearch((long[]) null, 2, 1, (long) arraySize);
   2962             fail("should throw NullPointerException");
   2963         } catch (NullPointerException e) {
   2964             // expected
   2965         }
   2966         try {
   2967             Arrays.binarySearch((long[]) null, -1, 0, (long) arraySize);
   2968             fail("should throw NullPointerException");
   2969         } catch (NullPointerException e) {
   2970             // expected
   2971         }
   2972         try {
   2973             Arrays.binarySearch((long[]) null, -1, -2, (long) arraySize);
   2974             fail("should throw NullPointerException");
   2975         } catch (NullPointerException e) {
   2976             // expected
   2977         }
   2978         try {
   2979             Arrays.binarySearch(longArray, 2, 1, (char) arraySize);
   2980             fail("should throw IllegalArgumentException");
   2981         } catch (IllegalArgumentException e) {
   2982             // expected
   2983         }
   2984         assertEquals(-1, Arrays
   2985                 .binarySearch(longArray, 0, 0, (char) arraySize));
   2986         try {
   2987             Arrays.binarySearch(longArray, -1, -2, (char) arraySize);
   2988             fail("should throw IllegalArgumentException");
   2989         } catch (IllegalArgumentException e) {
   2990             // expected
   2991         }
   2992         try {
   2993             Arrays.binarySearch(longArray, arraySize + 2, arraySize + 1,
   2994                     (char) arraySize);
   2995             fail("should throw IllegalArgumentException");
   2996         } catch (IllegalArgumentException e) {
   2997             // expected
   2998         }
   2999         try {
   3000             Arrays.binarySearch(longArray, -1, 0, (char) arraySize);
   3001             fail("should throw ArrayIndexOutOfBoundsException");
   3002         } catch (ArrayIndexOutOfBoundsException e) {
   3003             // expected
   3004         }
   3005         try {
   3006             Arrays.binarySearch(longArray, 0, arraySize + 1, (char) arraySize);
   3007             fail("should throw ArrayIndexOutOfBoundsException");
   3008         } catch (ArrayIndexOutOfBoundsException e) {
   3009             // expected
   3010         }
   3011     }
   3012 
   3013     /**
   3014      * java.util.Arrays#binarySearch(java.lang.Object[],
   3015      *java.lang.Object)
   3016      */
   3017     public void test_binarySearch$Ljava_lang_ObjectIILjava_lang_Object() {
   3018         assertEquals(
   3019                 "Binary search succeeded for non-comparable value in empty array",
   3020                 -1, Arrays.binarySearch(new Object[] { }, 0, 0, new Object()));
   3021         assertEquals(
   3022                 "Binary search succeeded for comparable value in empty array",
   3023                 -1, Arrays.binarySearch(new Object[] { }, 0, 0, new Integer(-1)));
   3024         for (int counter = 0; counter < arraySize; counter++) {
   3025             assertTrue(
   3026                     "Binary search on Object[] answered incorrect position",
   3027                     Arrays.binarySearch(objectArray, counter, arraySize, objArray[counter]) == counter);
   3028         }
   3029         assertEquals("Binary search succeeded for value not present in array 1",
   3030                 -1, Arrays.binarySearch(objectArray, 0, arraySize, new Integer(-1)));
   3031         assertTrue(
   3032                 "Binary search succeeded for value not present in array 2",
   3033                 Arrays.binarySearch(objectArray, 0, arraySize, new Integer(arraySize)) == -(arraySize + 1));
   3034         try {
   3035             Arrays.binarySearch((Object[]) null, 2, 1, (byte) arraySize);
   3036             fail("should throw NullPointerException");
   3037         } catch (NullPointerException e) {
   3038             // expected
   3039         }
   3040         try {
   3041             Arrays.binarySearch((Object[]) null, -1, 0, (byte) arraySize);
   3042             fail("should throw NullPointerException");
   3043         } catch (NullPointerException e) {
   3044             // expected
   3045         }
   3046         try {
   3047             Arrays.binarySearch((Object[]) null, -1, -2, (byte) arraySize);
   3048             fail("should throw NullPointerException");
   3049         } catch (NullPointerException e) {
   3050             // expected
   3051         }
   3052         try {
   3053             Arrays.binarySearch(objectArray, 2, 1, (char) arraySize);
   3054             fail("should throw IllegalArgumentException");
   3055         } catch (IllegalArgumentException e) {
   3056             // expected
   3057         }
   3058         assertEquals(-1, Arrays
   3059                 .binarySearch(objectArray, 0, 0, (char) arraySize));
   3060         try {
   3061             Arrays.binarySearch(objectArray, -1, -2, (char) arraySize);
   3062             fail("should throw IllegalArgumentException");
   3063         } catch (IllegalArgumentException e) {
   3064             // expected
   3065         }
   3066         try {
   3067             Arrays.binarySearch(objectArray, arraySize + 2, arraySize + 1,
   3068                     (char) arraySize);
   3069             fail("should throw IllegalArgumentException");
   3070         } catch (IllegalArgumentException e) {
   3071             // expected
   3072         }
   3073         try {
   3074             Arrays.binarySearch(objectArray, -1, 0, (char) arraySize);
   3075             fail("should throw ArrayIndexOutOfBoundsException");
   3076         } catch (ArrayIndexOutOfBoundsException e) {
   3077             // expected
   3078         }
   3079         try {
   3080             Arrays.binarySearch(objectArray, 0, arraySize + 1, (char) arraySize);
   3081             fail("should throw ArrayIndexOutOfBoundsException");
   3082         } catch (ArrayIndexOutOfBoundsException e) {
   3083             // expected
   3084         }
   3085     }
   3086 
   3087     /**
   3088      * java.util.Arrays#binarySearch(java.lang.Object[],
   3089      *java.lang.Object, java.util.Comparator)
   3090      */
   3091     public void test_binarySearch$Ljava_lang_ObjectIILjava_lang_ObjectLjava_util_Comparator() {
   3092         Comparator comp = new ReversedIntegerComparator();
   3093         for (int counter = 0; counter < arraySize; counter++) {
   3094             objectArray[counter] = objArray[arraySize - counter - 1];
   3095         }
   3096         assertTrue("Binary search succeeded for value not present in array 1",
   3097                 Arrays.binarySearch(objectArray, 0, arraySize, new Integer(-1),
   3098                         comp) == -(arraySize + 1));
   3099         assertEquals(
   3100                 "Binary search succeeded for value not present in array 2", -1,
   3101                 Arrays.binarySearch(objectArray, 0, arraySize, new Integer(
   3102                         arraySize), comp));
   3103         for (int counter = 0; counter < arraySize; counter++) {
   3104             assertTrue(
   3105                     "Binary search on Object[] with custom comparator answered incorrect position",
   3106                     Arrays.binarySearch(objectArray, objArray[counter], comp) == arraySize
   3107                             - counter - 1);
   3108         }
   3109         try {
   3110             Arrays.binarySearch((Object[]) null, 2, 1, (byte) arraySize);
   3111             fail("should throw NullPointerException");
   3112         } catch (NullPointerException e) {
   3113             // expected
   3114         }
   3115         try {
   3116             Arrays.binarySearch((Object[]) null, -1, 0, (byte) arraySize);
   3117             fail("should throw NullPointerException");
   3118         } catch (NullPointerException e) {
   3119             // expected
   3120         }
   3121         try {
   3122             Arrays.binarySearch((Object[]) null, -1, -2, (byte) arraySize);
   3123             fail("should throw NullPointerException");
   3124         } catch (NullPointerException e) {
   3125             // expected
   3126         }
   3127         try {
   3128             Arrays.binarySearch(objectArray, 2, 1, (char) arraySize, comp);
   3129             fail("should throw IllegalArgumentException");
   3130         } catch (IllegalArgumentException e) {
   3131             // expected
   3132         }
   3133         assertEquals(-1, Arrays.binarySearch(objectArray, 0, 0,
   3134                 (char) arraySize, comp));
   3135         try {
   3136             Arrays.binarySearch(objectArray, -1, -2, (char) arraySize, comp);
   3137             fail("should throw IllegalArgumentException");
   3138         } catch (IllegalArgumentException e) {
   3139             // expected
   3140         }
   3141         try {
   3142             Arrays.binarySearch(objectArray, arraySize + 2, arraySize + 1,
   3143                     (char) arraySize, comp);
   3144             fail("should throw IllegalArgumentException");
   3145         } catch (IllegalArgumentException e) {
   3146             // expected
   3147         }
   3148         try {
   3149             Arrays.binarySearch(objectArray, -1, 0, (char) arraySize, comp);
   3150             fail("should throw ArrayIndexOutOfBoundsException");
   3151         } catch (ArrayIndexOutOfBoundsException e) {
   3152             // expected
   3153         }
   3154         try {
   3155             Arrays.binarySearch(objectArray, 0, arraySize + 1,
   3156                     (char) arraySize, comp);
   3157             fail("should throw ArrayIndexOutOfBoundsException");
   3158         } catch (ArrayIndexOutOfBoundsException e) {
   3159             // expected
   3160         }
   3161         try {
   3162             Arrays.binarySearch(objectArray, 0, arraySize,
   3163                     new LinkedList(), comp);
   3164             fail("should throw ClassCastException");
   3165         } catch (ClassCastException e) {
   3166             // expected
   3167         }
   3168     }
   3169 
   3170     /**
   3171      * java.util.Arrays#binarySearch(short[], short)
   3172      */
   3173     public void test_binarySearch$SIIS() {
   3174         for (short counter = 0; counter < arraySize; counter++) {
   3175             assertTrue("Binary search on short[] answered incorrect position",
   3176                     Arrays.binarySearch(shortArray, counter, arraySize, counter) == counter);
   3177         }
   3178         assertEquals("Binary search succeeded for value not present in array 1",
   3179                 -1, Arrays.binarySearch(shortArray, 0, arraySize, (short) -1));
   3180         assertTrue(
   3181                 "Binary search succeeded for value not present in array 2",
   3182                 Arrays.binarySearch(shortArray, 0, arraySize, (short) arraySize) == -(arraySize + 1));
   3183         for (short counter = 0; counter < arraySize; counter++) {
   3184             shortArray[counter] -= 50;
   3185         }
   3186         for (short counter = 0; counter < arraySize; counter++) {
   3187             assertTrue(
   3188                     "Binary search on short[] involving negative numbers answered incorrect position",
   3189                     Arrays.binarySearch(shortArray, counter, arraySize, (short) (counter - 50)) == counter);
   3190         }
   3191         try {
   3192             Arrays.binarySearch((String[]) null, 2, 1, (byte) arraySize);
   3193             fail("should throw NullPointerException");
   3194         } catch (NullPointerException e) {
   3195             // expected
   3196         }
   3197         try {
   3198             Arrays.binarySearch((String[]) null, -1, 0, (byte) arraySize);
   3199             fail("should throw NullPointerException");
   3200         } catch (NullPointerException e) {
   3201             // expected
   3202         }
   3203         try {
   3204             Arrays.binarySearch((String[]) null, -1, -2, (byte) arraySize);
   3205             fail("should throw NullPointerException");
   3206         } catch (NullPointerException e) {
   3207             // expected
   3208         }
   3209         try {
   3210             Arrays.binarySearch(shortArray, 2, 1, (short) arraySize);
   3211             fail("should throw IllegalArgumentException");
   3212         } catch (IllegalArgumentException e) {
   3213             // expected
   3214         }
   3215         assertEquals(-1, Arrays
   3216                 .binarySearch(shortArray, 0, 0, (short) arraySize));
   3217         try {
   3218             Arrays.binarySearch(shortArray, -1, -2, (short) arraySize);
   3219             fail("should throw IllegalArgumentException");
   3220         } catch (IllegalArgumentException e) {
   3221             // expected
   3222         }
   3223         try {
   3224             Arrays.binarySearch(shortArray, arraySize + 2, arraySize + 1,
   3225                     (short) arraySize);
   3226             fail("should throw IllegalArgumentException");
   3227         } catch (IllegalArgumentException e) {
   3228             // expected
   3229         }
   3230         try {
   3231             Arrays.binarySearch(shortArray, -1, 0, (short) arraySize);
   3232             fail("should throw ArrayIndexOutOfBoundsException");
   3233         } catch (ArrayIndexOutOfBoundsException e) {
   3234             // expected
   3235         }
   3236         try {
   3237             Arrays.binarySearch(shortArray, 0, arraySize + 1, (short) arraySize);
   3238             fail("should throw ArrayIndexOutOfBoundsException");
   3239         } catch (ArrayIndexOutOfBoundsException e) {
   3240             // expected
   3241         }
   3242         String[] array = { "a", "b", "c" };
   3243         assertEquals(-2, Arrays.binarySearch(array, 1, 2, "a", null));
   3244     }
   3245 
   3246     /**
   3247      * {@link java.util.Arrays#copyOf(byte[], int)
   3248      */
   3249     public void test_copyOf_$BI() throws Exception {
   3250         byte[] result = Arrays.copyOf(byteArray, arraySize * 2);
   3251         int i = 0;
   3252         for (; i < arraySize; i++) {
   3253             assertEquals(i, result[i]);
   3254         }
   3255         for (; i < result.length; i++) {
   3256             assertEquals(0, result[i]);
   3257         }
   3258         result = Arrays.copyOf(byteArray, arraySize / 2);
   3259         i = 0;
   3260         for (; i < result.length; i++) {
   3261             assertEquals(i, result[i]);
   3262         }
   3263         try {
   3264             Arrays.copyOf((byte[]) null, arraySize);
   3265             fail("should throw NullPointerException");
   3266         } catch (NullPointerException e) {
   3267             // expected
   3268         }
   3269         try {
   3270             Arrays.copyOf(byteArray, -1);
   3271             fail("should throw NegativeArraySizeException");
   3272         } catch (NegativeArraySizeException e) {
   3273             // expected
   3274         }
   3275         try {
   3276             Arrays.copyOf((byte[]) null, -1);
   3277             fail("should throw NegativeArraySizeException");
   3278         } catch (NegativeArraySizeException e) {
   3279             // expected
   3280         }
   3281     }
   3282 
   3283     /**
   3284      * {@link java.util.Arrays#copyOf(short[], int)
   3285      */
   3286     public void test_copyOf_$SI() throws Exception {
   3287         short[] result = Arrays.copyOf(shortArray, arraySize * 2);
   3288         int i = 0;
   3289         for (; i < arraySize; i++) {
   3290             assertEquals(i, result[i]);
   3291         }
   3292         for (; i < result.length; i++) {
   3293             assertEquals(0, result[i]);
   3294         }
   3295         result = Arrays.copyOf(shortArray, arraySize / 2);
   3296         i = 0;
   3297         for (; i < result.length; i++) {
   3298             assertEquals(i, result[i]);
   3299         }
   3300         try {
   3301             Arrays.copyOf((short[]) null, arraySize);
   3302             fail("should throw NullPointerException");
   3303         } catch (NullPointerException e) {
   3304             // expected
   3305         }
   3306         try {
   3307             Arrays.copyOf(shortArray, -1);
   3308             fail("should throw NegativeArraySizeException");
   3309         } catch (NegativeArraySizeException e) {
   3310             // expected
   3311         }
   3312         try {
   3313             Arrays.copyOf((short[]) null, -1);
   3314             fail("should throw NegativeArraySizeException");
   3315         } catch (NegativeArraySizeException e) {
   3316             // expected
   3317         }
   3318     }
   3319 
   3320     /**
   3321      * {@link java.util.Arrays#copyOf(int[], int)
   3322      */
   3323     public void test_copyOf_$II() throws Exception {
   3324         int[] result = Arrays.copyOf(intArray, arraySize * 2);
   3325         int i = 0;
   3326         for (; i < arraySize; i++) {
   3327             assertEquals(i, result[i]);
   3328         }
   3329         for (; i < result.length; i++) {
   3330             assertEquals(0, result[i]);
   3331         }
   3332         result = Arrays.copyOf(intArray, arraySize / 2);
   3333         i = 0;
   3334         for (; i < result.length; i++) {
   3335             assertEquals(i, result[i]);
   3336         }
   3337         try {
   3338             Arrays.copyOf((int[]) null, arraySize);
   3339             fail("should throw NullPointerException");
   3340         } catch (NullPointerException e) {
   3341             // expected
   3342         }
   3343         try {
   3344             Arrays.copyOf(intArray, -1);
   3345             fail("should throw NegativeArraySizeException");
   3346         } catch (NegativeArraySizeException e) {
   3347             // expected
   3348         }
   3349         try {
   3350             Arrays.copyOf((int[]) null, -1);
   3351             fail("should throw NegativeArraySizeException");
   3352         } catch (NegativeArraySizeException e) {
   3353             // expected
   3354         }
   3355     }
   3356 
   3357     /**
   3358      * {@link java.util.Arrays#copyOf(boolean[], int)
   3359      */
   3360     public void test_copyOf_$ZI() throws Exception {
   3361         boolean[] result = Arrays.copyOf(booleanArray, arraySize * 2);
   3362         int i = 0;
   3363         for (; i < arraySize; i++) {
   3364             assertEquals(booleanArray[i], result[i]);
   3365         }
   3366         for (; i < result.length; i++) {
   3367             assertEquals(false, result[i]);
   3368         }
   3369         result = Arrays.copyOf(booleanArray, arraySize / 2);
   3370         i = 0;
   3371         for (; i < result.length; i++) {
   3372             assertEquals(booleanArray[i], result[i]);
   3373         }
   3374         try {
   3375             Arrays.copyOf((boolean[]) null, arraySize);
   3376             fail("should throw NullPointerException");
   3377         } catch (NullPointerException e) {
   3378             // expected
   3379         }
   3380         try {
   3381             Arrays.copyOf(booleanArray, -1);
   3382             fail("should throw NegativeArraySizeException");
   3383         } catch (NegativeArraySizeException e) {
   3384             // expected
   3385         }
   3386         try {
   3387             Arrays.copyOf((boolean[]) null, -1);
   3388             fail("should throw NegativeArraySizeException");
   3389         } catch (NegativeArraySizeException e) {
   3390             // expected
   3391         }
   3392     }
   3393 
   3394     /**
   3395      * {@link java.util.Arrays#copyOf(char[], int)
   3396      */
   3397     public void test_copyOf_$CI() throws Exception {
   3398         char[] result = Arrays.copyOf(charArray, arraySize * 2);
   3399         int i = 0;
   3400         for (; i < arraySize; i++) {
   3401             assertEquals(i + 1, result[i]);
   3402         }
   3403         for (; i < result.length; i++) {
   3404             assertEquals(0, result[i]);
   3405         }
   3406         result = Arrays.copyOf(charArray, arraySize / 2);
   3407         i = 0;
   3408         for (; i < result.length; i++) {
   3409             assertEquals(i + 1, result[i]);
   3410         }
   3411         try {
   3412             Arrays.copyOf((char[]) null, arraySize);
   3413             fail("should throw NullPointerException");
   3414         } catch (NullPointerException e) {
   3415             // expected
   3416         }
   3417         try {
   3418             Arrays.copyOf(charArray, -1);
   3419             fail("should throw NegativeArraySizeException");
   3420         } catch (NegativeArraySizeException e) {
   3421             // expected
   3422         }
   3423         try {
   3424             Arrays.copyOf((char[]) null, -1);
   3425             fail("should throw NegativeArraySizeException");
   3426         } catch (NegativeArraySizeException e) {
   3427             // expected
   3428         }
   3429     }
   3430 
   3431     /**
   3432      * {@link java.util.Arrays#copyOf(float[], int)
   3433      */
   3434     public void test_copyOf_$FI() throws Exception {
   3435         float[] result = Arrays.copyOf(floatArray, arraySize * 2);
   3436         int i = 0;
   3437         for (; i < arraySize; i++) {
   3438             assertEquals(floatArray[i], result[i]);
   3439         }
   3440         for (; i < result.length; i++) {
   3441             assertEquals(0.0f, result[i]);
   3442         }
   3443         result = Arrays.copyOf(floatArray, arraySize / 2);
   3444         i = 0;
   3445         for (; i < result.length; i++) {
   3446             assertEquals(floatArray[i], result[i]);
   3447         }
   3448         try {
   3449             Arrays.copyOf((float[]) null, arraySize);
   3450             fail("should throw NullPointerException");
   3451         } catch (NullPointerException e) {
   3452             // expected
   3453         }
   3454         try {
   3455             Arrays.copyOf(floatArray, -1);
   3456             fail("should throw NegativeArraySizeException");
   3457         } catch (NegativeArraySizeException e) {
   3458             // expected
   3459         }
   3460         try {
   3461             Arrays.copyOf((float[]) null, -1);
   3462             fail("should throw NegativeArraySizeException");
   3463         } catch (NegativeArraySizeException e) {
   3464             // expected
   3465         }
   3466     }
   3467 
   3468     /**
   3469      * {@link java.util.Arrays#copyOf(double[], int)
   3470      */
   3471     public void test_copyOf_$DI() throws Exception {
   3472         double[] result = Arrays.copyOf(doubleArray, arraySize * 2);
   3473         int i = 0;
   3474         for (; i < arraySize; i++) {
   3475             assertEquals(doubleArray[i], result[i]);
   3476         }
   3477         for (; i < result.length; i++) {
   3478             assertEquals(0.0, result[i]);
   3479         }
   3480         result = Arrays.copyOf(doubleArray, arraySize / 2);
   3481         i = 0;
   3482         for (; i < result.length; i++) {
   3483             assertEquals(doubleArray[i], result[i]);
   3484         }
   3485         try {
   3486             Arrays.copyOf((double[]) null, arraySize);
   3487             fail("should throw NullPointerException");
   3488         } catch (NullPointerException e) {
   3489             // expected
   3490         }
   3491         try {
   3492             Arrays.copyOf(doubleArray, -1);
   3493             fail("should throw NegativeArraySizeException");
   3494         } catch (NegativeArraySizeException e) {
   3495             // expected
   3496         }
   3497         try {
   3498             Arrays.copyOf((double[]) null, -1);
   3499             fail("should throw NegativeArraySizeException");
   3500         } catch (NegativeArraySizeException e) {
   3501             // expected
   3502         }
   3503     }
   3504 
   3505     /**
   3506      * {@link java.util.Arrays#copyOf(long[], int)
   3507      */
   3508     public void test_copyOf_$JI() throws Exception {
   3509         long[] result = Arrays.copyOf(longArray, arraySize * 2);
   3510         int i = 0;
   3511         for (; i < arraySize; i++) {
   3512             assertEquals(longArray[i], result[i]);
   3513         }
   3514         for (; i < result.length; i++) {
   3515             assertEquals(0, result[i]);
   3516         }
   3517         result = Arrays.copyOf(longArray, arraySize / 2);
   3518         i = 0;
   3519         for (; i < result.length; i++) {
   3520             assertEquals(longArray[i], result[i]);
   3521         }
   3522         try {
   3523             Arrays.copyOf((long[]) null, arraySize);
   3524             fail("should throw NullPointerException");
   3525         } catch (NullPointerException e) {
   3526             // expected
   3527         }
   3528         try {
   3529             Arrays.copyOf(longArray, -1);
   3530             fail("should throw NegativeArraySizeException");
   3531         } catch (NegativeArraySizeException e) {
   3532             // expected
   3533         }
   3534         try {
   3535             Arrays.copyOf((long[]) null, -1);
   3536             fail("should throw NegativeArraySizeException");
   3537         } catch (NegativeArraySizeException e) {
   3538             // expected
   3539         }
   3540     }
   3541 
   3542     /**
   3543      * {@link java.util.Arrays#copyOf(T[], int)
   3544      */
   3545     public void test_copyOf_$TI() throws Exception {
   3546         Object[] result = Arrays.copyOf(objArray, arraySize * 2);
   3547         int i = 0;
   3548         for (; i < arraySize; i++) {
   3549             assertEquals(objArray[i], result[i]);
   3550         }
   3551         for (; i < result.length; i++) {
   3552             assertNull(result[i]);
   3553         }
   3554         result = Arrays.copyOf(objArray, arraySize / 2);
   3555         i = 0;
   3556         for (; i < result.length; i++) {
   3557             assertEquals(objArray[i], result[i]);
   3558         }
   3559         try {
   3560             Arrays.copyOf((String[]) null, arraySize);
   3561             fail("should throw NullPointerException");
   3562         } catch (NullPointerException e) {
   3563             // expected
   3564         }
   3565         try {
   3566             Arrays.copyOf(objArray, -1);
   3567             fail("should throw NegativeArraySizeException");
   3568         } catch (NegativeArraySizeException e) {
   3569             // expected
   3570         }
   3571         try {
   3572             Arrays.copyOf((String[]) null, -1);
   3573             fail("should throw NullPointerException");
   3574         } catch (NullPointerException e) {
   3575             // expected
   3576         }
   3577 
   3578         Date[] component = new Date[0];
   3579         Object object[] = new Date[0];
   3580 
   3581         object = Arrays.copyOf(component, 2);
   3582         assertNotNull(object);
   3583         component = Arrays.copyOf(component, 2);
   3584         assertNotNull(component);
   3585         assertEquals(2, component.length);
   3586     }
   3587 
   3588     /**
   3589      * {@link java.util.Arrays#copyOf(T[], int, Class<? extends Object[]>))
   3590      */
   3591     public void test_copyOf_$TILClass() throws Exception {
   3592         Object[] result = Arrays.copyOf(objArray, arraySize * 2, Object[].class);
   3593         int i = 0;
   3594         for (; i < arraySize; i++) {
   3595             assertEquals(objArray[i], result[i]);
   3596         }
   3597         for (; i < result.length; i++) {
   3598             assertNull(result[i]);
   3599         }
   3600         result = Arrays.copyOf(objArray, arraySize / 2, Object[].class);
   3601         i = 0;
   3602         for (; i < result.length; i++) {
   3603             assertEquals(objArray[i], result[i]);
   3604         }
   3605         result = Arrays.copyOf(objArray, arraySize / 2, Integer[].class);
   3606         i = 0;
   3607         for (; i < result.length; i++) {
   3608             assertEquals(objArray[i], result[i]);
   3609         }
   3610         try {
   3611             Arrays.copyOf((Object[]) null, arraySize, LinkedList[].class);
   3612             fail("should throw NullPointerException");
   3613         } catch (NullPointerException e) {
   3614             // expected
   3615         }
   3616         try {
   3617             Arrays.copyOf(objArray, arraySize, LinkedList[].class);
   3618             fail("should throw ArrayStoreException ");
   3619         } catch (ArrayStoreException e) {
   3620             // expected
   3621         }
   3622         try {
   3623             Arrays.copyOf((Object[]) null, arraySize, Object[].class);
   3624             fail("should throw NullPointerException");
   3625         } catch (NullPointerException e) {
   3626             // expected
   3627         }
   3628         try {
   3629             Arrays.copyOf(objArray, -1, Object[].class);
   3630             fail("should throw NegativeArraySizeException");
   3631         } catch (NegativeArraySizeException e) {
   3632             // expected
   3633         }
   3634         try {
   3635             Arrays.copyOf((Object[]) null, -1, Object[].class);
   3636             fail("should throw NegativeArraySizeException");
   3637         } catch (NegativeArraySizeException e) {
   3638             // expected
   3639         }
   3640         try {
   3641             Arrays.copyOf((Object[]) null, -1, LinkedList[].class);
   3642             fail("should throw NegativeArraySizeException");
   3643         } catch (NegativeArraySizeException e) {
   3644             // expected
   3645         }
   3646         try {
   3647             Arrays.copyOf((Object[]) null, 0, LinkedList[].class);
   3648             fail("should throw NullPointerException");
   3649         } catch (NullPointerException e) {
   3650             // expected
   3651         }
   3652         assertEquals(0, Arrays.copyOf(objArray, 0, LinkedList[].class).length);
   3653     }
   3654 
   3655     /**
   3656      * {@link java.util.Arrays#copyOfRange(byte[], int, int)
   3657      */
   3658     public void test_copyOfRange_$BII() throws Exception {
   3659         byte[] result = Arrays.copyOfRange(byteArray, 0, arraySize * 2);
   3660         int i = 0;
   3661         for (; i < arraySize; i++) {
   3662             assertEquals(i, result[i]);
   3663         }
   3664         for (; i < result.length; i++) {
   3665             assertEquals(0, result[i]);
   3666         }
   3667         result = Arrays.copyOfRange(byteArray, 0, arraySize / 2);
   3668         i = 0;
   3669         for (; i < result.length; i++) {
   3670             assertEquals(i, result[i]);
   3671         }
   3672         result = Arrays.copyOfRange(byteArray, 0, 0);
   3673         assertEquals(0, result.length);
   3674         try {
   3675             Arrays.copyOfRange((byte[]) null, 0, arraySize);
   3676             fail("should throw NullPointerException");
   3677         } catch (NullPointerException e) {
   3678             // expected
   3679         }
   3680         try {
   3681             Arrays.copyOfRange((byte[]) null, -1, arraySize);
   3682             fail("should throw NullPointerException");
   3683         } catch (NullPointerException e) {
   3684             // expected
   3685         }
   3686         try {
   3687             Arrays.copyOfRange((byte[]) null, 0, -1);
   3688             fail("should throw IllegalArgumentException");
   3689         } catch (IllegalArgumentException e) {
   3690             // expected
   3691         }
   3692         try {
   3693             Arrays.copyOfRange(byteArray, -1, arraySize);
   3694             fail("should throw ArrayIndexOutOfBoundsException");
   3695         } catch (ArrayIndexOutOfBoundsException e) {
   3696             // expected
   3697         }
   3698         try {
   3699             Arrays.copyOfRange(byteArray, 0, -1);
   3700             fail("should throw IllegalArgumentException");
   3701         } catch (IllegalArgumentException e) {
   3702             // expected
   3703         }
   3704         assertEquals(byteArray.length + 1, Arrays.copyOfRange(byteArray, 0,
   3705                 byteArray.length + 1).length);
   3706     }
   3707 
   3708     /**
   3709      * {@link java.util.Arrays#copyOfRange(short[], int, int)
   3710      */
   3711     public void test_copyOfRange_$SII() throws Exception {
   3712         short[] result = Arrays.copyOfRange(shortArray, 0, arraySize * 2);
   3713         int i = 0;
   3714         for (; i < arraySize; i++) {
   3715             assertEquals(i, result[i]);
   3716         }
   3717         for (; i < result.length; i++) {
   3718             assertEquals(0, result[i]);
   3719         }
   3720         result = Arrays.copyOfRange(shortArray, 0, arraySize / 2);
   3721         i = 0;
   3722         for (; i < result.length; i++) {
   3723             assertEquals(i, result[i]);
   3724         }
   3725         result = Arrays.copyOfRange(shortArray, 0, 0);
   3726         assertEquals(0, result.length);
   3727         try {
   3728             Arrays.copyOfRange((short[]) null, 0, arraySize);
   3729             fail("should throw NullPointerException");
   3730         } catch (NullPointerException e) {
   3731             // expected
   3732         }
   3733         try {
   3734             Arrays.copyOfRange((short[]) null, -1, arraySize);
   3735             fail("should throw NullPointerException");
   3736         } catch (NullPointerException e) {
   3737             // expected
   3738         }
   3739         try {
   3740             Arrays.copyOfRange((short[]) null, 0, -1);
   3741             fail("should throw IllegalArgumentException");
   3742         } catch (IllegalArgumentException e) {
   3743             // expected
   3744         }
   3745         try {
   3746             Arrays.copyOfRange(shortArray, -1, arraySize);
   3747             fail("should throw ArrayIndexOutOfBoundsException");
   3748         } catch (ArrayIndexOutOfBoundsException e) {
   3749             // expected
   3750         }
   3751         try {
   3752             Arrays.copyOfRange(shortArray, 0, -1);
   3753             fail("should throw IllegalArgumentException");
   3754         } catch (IllegalArgumentException e) {
   3755             // expected
   3756         }
   3757         assertEquals(shortArray.length + 1, Arrays.copyOfRange(shortArray, 0,
   3758                 shortArray.length + 1).length);
   3759     }
   3760 
   3761     /**
   3762      * {@link java.util.Arrays#copyOfRange(int[], int, int)
   3763      */
   3764     public void test_copyOfRange_$III() throws Exception {
   3765         int[] result = Arrays.copyOfRange(intArray, 0, arraySize * 2);
   3766         int i = 0;
   3767         for (; i < arraySize; i++) {
   3768             assertEquals(i, result[i]);
   3769         }
   3770         for (; i < result.length; i++) {
   3771             assertEquals(0, result[i]);
   3772         }
   3773         result = Arrays.copyOfRange(intArray, 0, arraySize / 2);
   3774         i = 0;
   3775         for (; i < result.length; i++) {
   3776             assertEquals(i, result[i]);
   3777         }
   3778         result = Arrays.copyOfRange(intArray, 0, 0);
   3779         assertEquals(0, result.length);
   3780         try {
   3781             Arrays.copyOfRange((int[]) null, 0, arraySize);
   3782             fail("should throw NullPointerException");
   3783         } catch (NullPointerException e) {
   3784             // expected
   3785         }
   3786         try {
   3787             Arrays.copyOfRange((int[]) null, -1, arraySize);
   3788             fail("should throw NullPointerException");
   3789         } catch (NullPointerException e) {
   3790             // expected
   3791         }
   3792         try {
   3793             Arrays.copyOfRange((int[]) null, 0, -1);
   3794             fail("should throw IllegalArgumentException");
   3795         } catch (IllegalArgumentException e) {
   3796             // expected
   3797         }
   3798         try {
   3799             Arrays.copyOfRange(intArray, -1, arraySize);
   3800             fail("should throw ArrayIndexOutOfBoundsException");
   3801         } catch (ArrayIndexOutOfBoundsException e) {
   3802             // expected
   3803         }
   3804         try {
   3805             Arrays.copyOfRange(intArray, 0, -1);
   3806             fail("should throw IllegalArgumentException");
   3807         } catch (IllegalArgumentException e) {
   3808             // expected
   3809         }
   3810         assertEquals(intArray.length + 1, Arrays.copyOfRange(intArray, 0,
   3811                 intArray.length + 1).length);
   3812     }
   3813 
   3814     /**
   3815      * {@link java.util.Arrays#copyOfRange(long[], int, int)
   3816      */
   3817     public void test_copyOfRange_$JII() throws Exception {
   3818         long[] result = Arrays.copyOfRange(longArray, 0, arraySize * 2);
   3819         int i = 0;
   3820         for (; i < arraySize; i++) {
   3821             assertEquals(i, result[i]);
   3822         }
   3823         for (; i < result.length; i++) {
   3824             assertEquals(0, result[i]);
   3825         }
   3826         result = Arrays.copyOfRange(longArray, 0, arraySize / 2);
   3827         i = 0;
   3828         for (; i < result.length; i++) {
   3829             assertEquals(i, result[i]);
   3830         }
   3831         result = Arrays.copyOfRange(longArray, 0, 0);
   3832         assertEquals(0, result.length);
   3833         try {
   3834             Arrays.copyOfRange((long[]) null, 0, arraySize);
   3835             fail("should throw NullPointerException");
   3836         } catch (NullPointerException e) {
   3837             // expected
   3838         }
   3839         try {
   3840             Arrays.copyOfRange((long[]) null, -1, arraySize);
   3841             fail("should throw NullPointerException");
   3842         } catch (NullPointerException e) {
   3843             // expected
   3844         }
   3845         try {
   3846             Arrays.copyOfRange((long[]) null, 0, -1);
   3847             fail("should throw IllegalArgumentException");
   3848         } catch (IllegalArgumentException e) {
   3849             // expected
   3850         }
   3851         try {
   3852             Arrays.copyOfRange(longArray, -1, arraySize);
   3853             fail("should throw ArrayIndexOutOfBoundsException");
   3854         } catch (ArrayIndexOutOfBoundsException e) {
   3855             // expected
   3856         }
   3857         try {
   3858             Arrays.copyOfRange(longArray, 0, -1);
   3859             fail("should throw IllegalArgumentException");
   3860         } catch (IllegalArgumentException e) {
   3861             // expected
   3862         }
   3863         assertEquals(longArray.length + 1, Arrays.copyOfRange(longArray, 0,
   3864                 longArray.length + 1).length);
   3865     }
   3866 
   3867     /**
   3868      * {@link java.util.Arrays#copyOfRange(char[], int, int)
   3869      */
   3870     public void test_copyOfRange_$CII() throws Exception {
   3871         char[] result = Arrays.copyOfRange(charArray, 0, arraySize * 2);
   3872         int i = 0;
   3873         for (; i < arraySize; i++) {
   3874             assertEquals(i + 1, result[i]);
   3875         }
   3876         for (; i < result.length; i++) {
   3877             assertEquals(0, result[i]);
   3878         }
   3879         result = Arrays.copyOfRange(charArray, 0, arraySize / 2);
   3880         i = 0;
   3881         for (; i < result.length; i++) {
   3882             assertEquals(i + 1, result[i]);
   3883         }
   3884         result = Arrays.copyOfRange(charArray, 0, 0);
   3885         assertEquals(0, result.length);
   3886         try {
   3887             Arrays.copyOfRange((char[]) null, 0, arraySize);
   3888             fail("should throw NullPointerException");
   3889         } catch (NullPointerException e) {
   3890             // expected
   3891         }
   3892         try {
   3893             Arrays.copyOfRange((char[]) null, -1, arraySize);
   3894             fail("should throw NullPointerException");
   3895         } catch (NullPointerException e) {
   3896             // expected
   3897         }
   3898         try {
   3899             Arrays.copyOfRange((char[]) null, 0, -1);
   3900             fail("should throw IllegalArgumentException");
   3901         } catch (IllegalArgumentException e) {
   3902             // expected
   3903         }
   3904         try {
   3905             Arrays.copyOfRange(charArray, -1, arraySize);
   3906             fail("should throw ArrayIndexOutOfBoundsException");
   3907         } catch (ArrayIndexOutOfBoundsException e) {
   3908             // expected
   3909         }
   3910         try {
   3911             Arrays.copyOfRange(charArray, 0, -1);
   3912             fail("should throw IllegalArgumentException");
   3913         } catch (IllegalArgumentException e) {
   3914             // expected
   3915         }
   3916         assertEquals(charArray.length + 1, Arrays.copyOfRange(charArray, 0,
   3917                 charArray.length + 1).length);
   3918     }
   3919 
   3920     public void test_copyOfRange_$FII() throws Exception {
   3921         float[] result = Arrays.copyOfRange(floatArray, 0, arraySize * 2);
   3922         int i = 0;
   3923         for (; i < arraySize; i++) {
   3924             assertEquals((float) i, result[i]);
   3925         }
   3926         for (; i < result.length; i++) {
   3927             assertEquals(0.0f, result[i]);
   3928         }
   3929         result = Arrays.copyOfRange(floatArray, 0, arraySize / 2);
   3930         i = 0;
   3931         for (; i < result.length; i++) {
   3932             assertEquals((float) i, result[i]);
   3933         }
   3934         result = Arrays.copyOfRange(floatArray, 0, 0);
   3935         assertEquals(0, result.length);
   3936         try {
   3937             Arrays.copyOfRange((float[]) null, 0, arraySize);
   3938             fail("should throw NullPointerException");
   3939         } catch (NullPointerException e) {
   3940             // expected
   3941         }
   3942         try {
   3943             Arrays.copyOfRange((float[]) null, -1, arraySize);
   3944             fail("should throw NullPointerException");
   3945         } catch (NullPointerException e) {
   3946             // expected
   3947         }
   3948         try {
   3949             Arrays.copyOfRange((float[]) null, 0, -1);
   3950             fail("should throw IllegalArgumentException");
   3951         } catch (IllegalArgumentException e) {
   3952             // expected
   3953         }
   3954         try {
   3955             Arrays.copyOfRange(floatArray, -1, arraySize);
   3956             fail("should throw ArrayIndexOutOfBoundsException");
   3957         } catch (ArrayIndexOutOfBoundsException e) {
   3958             // expected
   3959         }
   3960         try {
   3961             Arrays.copyOfRange(floatArray, 0, -1);
   3962             fail("should throw IllegalArgumentException");
   3963         } catch (IllegalArgumentException e) {
   3964             // expected
   3965         }
   3966         assertEquals(floatArray.length + 1, Arrays.copyOfRange(floatArray, 0,
   3967                 floatArray.length + 1).length);
   3968     }
   3969 
   3970     /**
   3971      * {@link java.util.Arrays#copyOfRange(double[], int, int)
   3972      */
   3973     public void test_copyOfRange_$DII() throws Exception {
   3974         double[] result = Arrays.copyOfRange(doubleArray, 0, arraySize * 2);
   3975         int i = 0;
   3976         for (; i < arraySize; i++) {
   3977             assertEquals((double) i, result[i]);
   3978         }
   3979         for (; i < result.length; i++) {
   3980             assertEquals(0.0, result[i]);
   3981         }
   3982         result = Arrays.copyOfRange(doubleArray, 0, arraySize / 2);
   3983         i = 0;
   3984         for (; i < result.length; i++) {
   3985             assertEquals((double) i, result[i]);
   3986         }
   3987         result = Arrays.copyOfRange(doubleArray, 0, 0);
   3988         assertEquals(0, result.length);
   3989         try {
   3990             Arrays.copyOfRange((double[]) null, 0, arraySize);
   3991             fail("should throw NullPointerException");
   3992         } catch (NullPointerException e) {
   3993             // expected
   3994         }
   3995         try {
   3996             Arrays.copyOfRange((double[]) null, -1, arraySize);
   3997             fail("should throw NullPointerException");
   3998         } catch (NullPointerException e) {
   3999             // expected
   4000         }
   4001         try {
   4002             Arrays.copyOfRange((double[]) null, 0, -1);
   4003             fail("should throw IllegalArgumentException");
   4004         } catch (IllegalArgumentException e) {
   4005             // expected
   4006         }
   4007         try {
   4008             Arrays.copyOfRange(doubleArray, -1, arraySize);
   4009             fail("should throw ArrayIndexOutOfBoundsException");
   4010         } catch (ArrayIndexOutOfBoundsException e) {
   4011             // expected
   4012         }
   4013         try {
   4014             Arrays.copyOfRange(doubleArray, 0, -1);
   4015             fail("should throw IllegalArgumentException");
   4016         } catch (IllegalArgumentException e) {
   4017             // expected
   4018         }
   4019         assertEquals(doubleArray.length + 1, Arrays.copyOfRange(doubleArray, 0,
   4020                 doubleArray.length + 1).length);
   4021     }
   4022 
   4023     /**
   4024      * {@link java.util.Arrays#copyOfRange(boolean[], int, int)
   4025      */
   4026     public void test_copyOfRange_$ZII() throws Exception {
   4027         boolean[] result = Arrays.copyOfRange(booleanArray, 0, arraySize * 2);
   4028         int i = 0;
   4029         for (; i < arraySize; i++) {
   4030             assertEquals(booleanArray[i], result[i]);
   4031         }
   4032         for (; i < result.length; i++) {
   4033             assertEquals(false, result[i]);
   4034         }
   4035         result = Arrays.copyOfRange(booleanArray, 0, arraySize / 2);
   4036         i = 0;
   4037         for (; i < result.length; i++) {
   4038             assertEquals(booleanArray[i], result[i]);
   4039         }
   4040         result = Arrays.copyOfRange(booleanArray, 0, 0);
   4041         assertEquals(0, result.length);
   4042         try {
   4043             Arrays.copyOfRange((boolean[]) null, 0, arraySize);
   4044             fail("should throw NullPointerException");
   4045         } catch (NullPointerException e) {
   4046             // expected
   4047         }
   4048         try {
   4049             Arrays.copyOfRange((boolean[]) null, -1, arraySize);
   4050             fail("should throw NullPointerException");
   4051         } catch (NullPointerException e) {
   4052             // expected
   4053         }
   4054         try {
   4055             Arrays.copyOfRange((boolean[]) null, 0, -1);
   4056             fail("should throw IllegalArgumentException");
   4057         } catch (IllegalArgumentException e) {
   4058             // expected
   4059         }
   4060         try {
   4061             Arrays.copyOfRange(booleanArray, -1, arraySize);
   4062             fail("should throw ArrayIndexOutOfBoundsException");
   4063         } catch (ArrayIndexOutOfBoundsException e) {
   4064             // expected
   4065         }
   4066         try {
   4067             Arrays.copyOfRange(booleanArray, 0, -1);
   4068             fail("should throw IllegalArgumentException");
   4069         } catch (IllegalArgumentException e) {
   4070             // expected
   4071         }
   4072         assertEquals(booleanArray.length + 1, Arrays.copyOfRange(booleanArray, 0,
   4073                 booleanArray.length + 1).length);
   4074     }
   4075 
   4076     /**
   4077      * {@link java.util.Arrays#copyOfRange(Object[], int, int)
   4078      */
   4079     public void test_copyOfRange_$TII() throws Exception {
   4080         Object[] result = Arrays.copyOfRange(objArray, 0, arraySize * 2);
   4081         int i = 0;
   4082         for (; i < arraySize; i++) {
   4083             assertEquals(objArray[i], result[i]);
   4084         }
   4085         for (; i < result.length; i++) {
   4086             assertEquals(null, result[i]);
   4087         }
   4088         result = Arrays.copyOfRange(objArray, 0, arraySize / 2);
   4089         i = 0;
   4090         for (; i < result.length; i++) {
   4091             assertEquals(objArray[i], result[i]);
   4092         }
   4093         result = Arrays.copyOfRange(objArray, 0, 0);
   4094         assertEquals(0, result.length);
   4095         try {
   4096             Arrays.copyOfRange((Object[]) null, 0, arraySize);
   4097             fail("should throw NullPointerException");
   4098         } catch (NullPointerException e) {
   4099             // expected
   4100         }
   4101         try {
   4102             Arrays.copyOfRange((Object[]) null, -1, arraySize);
   4103             fail("should throw NullPointerException");
   4104         } catch (NullPointerException e) {
   4105             // expected
   4106         }
   4107         try {
   4108             Arrays.copyOfRange((Object[]) null, 0, -1);
   4109             fail("should throw NullPointerException");
   4110         } catch (NullPointerException e) {
   4111             // expected
   4112         }
   4113         try {
   4114             Arrays.copyOfRange((Object[]) objArray, -1, arraySize);
   4115             fail("should throw ArrayIndexOutOfBoundsException");
   4116         } catch (ArrayIndexOutOfBoundsException e) {
   4117             // expected
   4118         }
   4119         try {
   4120             Arrays.copyOfRange((Object[]) objArray, 0, -1);
   4121             fail("should throw IllegalArgumentException");
   4122         } catch (IllegalArgumentException e) {
   4123             // expected
   4124         }
   4125         assertEquals(objArray.length + 1, Arrays.copyOfRange(objArray, 0,
   4126                 objArray.length + 1).length);
   4127     }
   4128 
   4129     public void test_copyOfRange_$TIILClass() throws Exception {
   4130         Object[] result = Arrays.copyOfRange(objArray, 0, arraySize * 2, Integer[].class);
   4131         int i = 0;
   4132         for (; i < arraySize; i++) {
   4133             assertEquals(objArray[i], result[i]);
   4134         }
   4135         for (; i < result.length; i++) {
   4136             assertEquals(null, result[i]);
   4137         }
   4138         result = Arrays.copyOfRange(objArray, 0, arraySize / 2, Integer[].class);
   4139         i = 0;
   4140         for (; i < result.length; i++) {
   4141             assertEquals(objArray[i], result[i]);
   4142         }
   4143         result = Arrays.copyOfRange(objArray, 0, 0, Integer[].class);
   4144         assertEquals(0, result.length);
   4145         try {
   4146             Arrays.copyOfRange(null, 0, arraySize, Integer[].class);
   4147             fail("should throw NullPointerException");
   4148         } catch (NullPointerException e) {
   4149             // expected
   4150         }
   4151         try {
   4152             Arrays.copyOfRange(null, -1, arraySize, Integer[].class);
   4153             fail("should throw NullPointerException");
   4154         } catch (NullPointerException e) {
   4155             // expected
   4156         }
   4157         try {
   4158             Arrays.copyOfRange(null, 0, -1, Integer[].class);
   4159             fail("should throw IllegalArgumentException");
   4160         } catch (IllegalArgumentException e) {
   4161             // expected
   4162         }
   4163         try {
   4164             Arrays.copyOfRange(objArray, -1, arraySize, Integer[].class);
   4165             fail("should throw ArrayIndexOutOfBoundsException");
   4166         } catch (ArrayIndexOutOfBoundsException e) {
   4167             // expected
   4168         }
   4169         try {
   4170             Arrays.copyOfRange(objArray, 0, -1, Integer[].class);
   4171             fail("should throw IllegalArgumentException");
   4172         } catch (IllegalArgumentException e) {
   4173             // expected
   4174         }
   4175         try {
   4176             Arrays.copyOfRange(objArray, 0, -1, LinkedList[].class);
   4177             fail("should throw IllegalArgumentException");
   4178         } catch (IllegalArgumentException e) {
   4179             // expected
   4180         }
   4181         try {
   4182             Arrays.copyOfRange(objArray, 0, 1, LinkedList[].class);
   4183             fail("should throw ArrayStoreException");
   4184         } catch (ArrayStoreException e) {
   4185             // expected
   4186         }
   4187         try {
   4188             Arrays.copyOfRange(null, 0, 1, LinkedList[].class);
   4189             fail("should throw NullPointerException");
   4190         } catch (NullPointerException e) {
   4191             // expected
   4192         }
   4193         try {
   4194             assertEquals(objArray.length + 1, Arrays.copyOfRange(objArray, 0,
   4195                     objArray.length + 1, LinkedList[].class).length);
   4196             fail("should throw ArrayStoreException");
   4197         } catch (ArrayStoreException e) {
   4198             // expected
   4199         }
   4200         assertEquals(0,
   4201                 Arrays.copyOfRange(objArray, 0, 0, LinkedList[].class).length);
   4202     }
   4203 
   4204     public void test_asList_spliterator() {
   4205         List<String> list = Arrays.asList(
   4206                 "a", "b", "c", "d", "e", "f", "g", "h",
   4207                 "i", "j", "k", "l", "m", "n", "o", "p");
   4208         ArrayList<String> expected = new ArrayList<>(list);
   4209 
   4210         SpliteratorTester.runBasicIterationTests(list.spliterator(), expected);
   4211         SpliteratorTester.runBasicSplitTests(list, expected);
   4212         SpliteratorTester.testSpliteratorNPE(list.spliterator());
   4213 
   4214         assertTrue(list.spliterator().hasCharacteristics(Spliterator.ORDERED));
   4215 
   4216         SpliteratorTester.runOrderedTests(list);
   4217         SpliteratorTester.assertSupportsTrySplit(list);
   4218     }
   4219 
   4220     public void test_spliterator_ref() {
   4221         String[] elements = {
   4222                 "a", "b", "c", "d", "e", "f", "g", "h",
   4223                 "i", "j", "k", "l", "m", "n", "o", "p" };
   4224 
   4225         ArrayList<String> expected = new ArrayList<>(Arrays.asList(elements));
   4226 
   4227         SpliteratorTester.runBasicIterationTests(Arrays.spliterator(elements), expected);
   4228         SpliteratorTester.testSpliteratorNPE(Arrays.spliterator(elements));
   4229         assertNotNull(Arrays.spliterator(elements).trySplit());
   4230 
   4231         Spliterator<String> sp = Arrays.spliterator(elements);
   4232         assertTrue(sp.hasCharacteristics(Spliterator.ORDERED));
   4233 
   4234         // Basic split tests.
   4235         Spliterator<String> sp1 =  sp.trySplit();
   4236         assertNotNull(sp1);
   4237 
   4238         ArrayList<String> recorder = new ArrayList<>();
   4239         sp1.forEachRemaining(value -> recorder.add(value));
   4240         sp.forEachRemaining(value -> recorder.add(value));
   4241         Collections.sort(recorder);
   4242         assertEquals(expected, recorder);
   4243     }
   4244 
   4245     public void test_spliterator_ref_bounds() {
   4246         String[] elements = { "BAD", "EVIL", "a", "b", "c", "d", "e", "f", "g", "h",
   4247                 "i", "j", "k", "l", "m", "n", "o", "p", "DO", "NOT", "INCLUDE" };
   4248 
   4249         ArrayList<String> expected = new ArrayList<>(
   4250                 Arrays.asList(Arrays.copyOfRange(elements, 2, 16)));
   4251 
   4252         SpliteratorTester.runBasicIterationTests(Arrays.spliterator(elements, 2, 16), expected);
   4253         SpliteratorTester.testSpliteratorNPE(Arrays.spliterator(elements, 2, 16));
   4254         assertNotNull(Arrays.spliterator(elements, 2, 16).trySplit());
   4255 
   4256         Spliterator<String> sp = Arrays.spliterator(elements, 2, 16);
   4257         assertTrue(sp.hasCharacteristics(Spliterator.ORDERED));
   4258 
   4259         // Basic split tests.
   4260         Spliterator<String> sp1 =  sp.trySplit();
   4261         assertNotNull(sp1);
   4262 
   4263         ArrayList<String> recorder = new ArrayList<>();
   4264         sp1.forEachRemaining(value -> recorder.add(value));
   4265         sp.forEachRemaining(value -> recorder.add(value));
   4266         Collections.sort(recorder);
   4267         assertEquals(expected, recorder);
   4268     }
   4269 
   4270     private static class PrimitiveIntArrayList {
   4271         final int[] array;
   4272         int idx;
   4273 
   4274         PrimitiveIntArrayList(int size) {
   4275             array = new int[size];
   4276         }
   4277 
   4278         public void add(int element) {
   4279             array[idx++] = element;
   4280         }
   4281 
   4282         public int[] toSortedArray() {
   4283             Arrays.sort(array);
   4284             return array;
   4285         }
   4286     }
   4287 
   4288     private static class PrimitiveLongArrayList {
   4289         final long[] array;
   4290         int idx;
   4291 
   4292         PrimitiveLongArrayList(int size) {
   4293             array = new long[size];
   4294         }
   4295 
   4296         public void add(long element) {
   4297             array[idx++] = element;
   4298         }
   4299 
   4300         public long[] toSortedArray() {
   4301             Arrays.sort(array);
   4302             return array;
   4303         }
   4304     }
   4305 
   4306     private static class PrimitiveDoubleArrayList {
   4307         final double[] array;
   4308         int idx;
   4309 
   4310         PrimitiveDoubleArrayList(int size) {
   4311             array = new double[size];
   4312         }
   4313 
   4314         public void add(double element) {
   4315             array[idx++] = element;
   4316         }
   4317 
   4318         public double[] toSortedArray() {
   4319             Arrays.sort(array);
   4320             return array;
   4321         }
   4322     }
   4323 
   4324     public void test_spliterator_int() {
   4325         int[] elements = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
   4326 
   4327         Spliterator.OfInt intSp = Arrays.spliterator(elements);
   4328 
   4329         assertEquals(16, intSp.estimateSize());
   4330         assertEquals(16, intSp.getExactSizeIfKnown());
   4331         assertTrue(intSp.hasCharacteristics(Spliterator.ORDERED));
   4332 
   4333         assertTrue(intSp.tryAdvance((Integer value) -> assertEquals(1, (int) value)));
   4334         assertTrue(intSp.tryAdvance((int value) -> assertEquals(2, (int) value)));
   4335 
   4336         PrimitiveIntArrayList recorder = new PrimitiveIntArrayList(16);
   4337         // Record elements observed by previous tests.
   4338         recorder.add(1);
   4339         recorder.add(2);
   4340 
   4341         Spliterator.OfInt split1 = intSp.trySplit();
   4342         assertNotNull(split1);
   4343         assertTrue(split1.tryAdvance((int value) -> recorder.add(value)));
   4344         assertTrue(split1.tryAdvance((Integer value) -> recorder.add(value)));
   4345 
   4346         // Assert that splits can themselves resplit.
   4347         Spliterator.OfInt split2 = split1.trySplit();
   4348         assertNotNull(split2);
   4349         split2.forEachRemaining((int value) -> recorder.add(value));
   4350         assertFalse(split2.tryAdvance((int value) -> fail()));
   4351         assertFalse(split2.tryAdvance((Integer value) -> fail()));
   4352 
   4353         // Iterate over the remaning elements so we can make sure we've looked at
   4354         // everything.
   4355         split1.forEachRemaining((int value) -> recorder.add(value));
   4356         intSp.forEachRemaining((int value) -> recorder.add(value));
   4357 
   4358         int[] recorded = recorder.toSortedArray();
   4359         assertEquals(Arrays.toString(elements), Arrays.toString(recorded));
   4360     }
   4361 
   4362     public void test_spliterator_intOffsetBasic() {
   4363         int[] elements = { 123123, 131321312, 1, 2, 3, 4, 32323232, 45454};
   4364         Spliterator.OfInt sp = Arrays.spliterator(elements, 2, 6);
   4365 
   4366         PrimitiveIntArrayList recorder = new PrimitiveIntArrayList(4);
   4367         sp.tryAdvance((Integer value) -> recorder.add((int) value));
   4368         sp.tryAdvance((int value) -> recorder.add(value));
   4369         sp.forEachRemaining((int value) -> recorder.add(value));
   4370 
   4371         int[] recorded = recorder.toSortedArray();
   4372         assertEquals(Arrays.toString(new int[] { 1, 2, 3, 4 }), Arrays.toString(recorded));
   4373     }
   4374 
   4375     public void test_spliterator_longOffsetBasic() {
   4376         long[] elements = { 123123, 131321312, 1, 2, 3, 4, 32323232, 45454};
   4377         Spliterator.OfLong sp = Arrays.spliterator(elements, 2, 6);
   4378 
   4379         PrimitiveLongArrayList recorder = new PrimitiveLongArrayList(4);
   4380         sp.tryAdvance((Long value) -> recorder.add((long) value));
   4381         sp.tryAdvance((long value) -> recorder.add(value));
   4382         sp.forEachRemaining((long value) -> recorder.add(value));
   4383 
   4384         long[] recorded = recorder.toSortedArray();
   4385         assertEquals(Arrays.toString(new long[] { 1, 2, 3, 4 }), Arrays.toString(recorded));
   4386     }
   4387 
   4388     public void test_spliterator_doubleOffsetBasic() {
   4389         double[] elements = { 123123, 131321312, 1, 2, 3, 4, 32323232, 45454};
   4390         Spliterator.OfDouble sp = Arrays.spliterator(elements, 2, 6);
   4391 
   4392         PrimitiveDoubleArrayList recorder = new PrimitiveDoubleArrayList(4);
   4393         sp.tryAdvance((Double value) -> recorder.add((double) value));
   4394         sp.tryAdvance((double value) -> recorder.add(value));
   4395         sp.forEachRemaining((double value) -> recorder.add(value));
   4396 
   4397         double[] recorded = recorder.toSortedArray();
   4398         assertEquals(Arrays.toString(new double[] { 1, 2, 3, 4 }), Arrays.toString(recorded));
   4399     }
   4400 
   4401     public void test_spliterator_long() {
   4402         long[] elements = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
   4403 
   4404         Spliterator.OfLong longSp = Arrays.spliterator(elements);
   4405 
   4406         assertEquals(16, longSp.estimateSize());
   4407         assertEquals(16, longSp.getExactSizeIfKnown());
   4408         assertTrue(longSp.hasCharacteristics(Spliterator.ORDERED));
   4409 
   4410         assertTrue(longSp.tryAdvance((Long value) -> assertEquals(1, (long) value)));
   4411         assertTrue(longSp.tryAdvance((long value) -> assertEquals(2, (long) value)));
   4412 
   4413         PrimitiveLongArrayList recorder = new PrimitiveLongArrayList(16);
   4414         // Record elements observed by previous tests.
   4415         recorder.add(1);
   4416         recorder.add(2);
   4417 
   4418         Spliterator.OfLong split1 = longSp.trySplit();
   4419         assertNotNull(split1);
   4420         assertTrue(split1.tryAdvance((long value) -> recorder.add(value)));
   4421         assertTrue(split1.tryAdvance((Long value) -> recorder.add(value)));
   4422 
   4423         // Assert that splits can themselves resplit.
   4424         Spliterator.OfLong split2 = split1.trySplit();
   4425         assertNotNull(split2);
   4426         split2.forEachRemaining((long value) -> recorder.add(value));
   4427         assertFalse(split2.tryAdvance((long value) -> fail()));
   4428         assertFalse(split2.tryAdvance((Long value) -> fail()));
   4429 
   4430         // Iterate over the remaning elements so we can make sure we've looked at
   4431         // everything.
   4432         split1.forEachRemaining((long value) -> recorder.add(value));
   4433         longSp.forEachRemaining((long value) -> recorder.add(value));
   4434 
   4435         long[] recorded = recorder.toSortedArray();
   4436         assertEquals(Arrays.toString(elements), Arrays.toString(recorded));
   4437     }
   4438 
   4439 
   4440     public void test_spliterator_double() {
   4441         double[] elements = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
   4442 
   4443         Spliterator.OfDouble doubleSp = Arrays.spliterator(elements);
   4444 
   4445         assertEquals(16, doubleSp.estimateSize());
   4446         assertEquals(16, doubleSp.getExactSizeIfKnown());
   4447         assertTrue(doubleSp.hasCharacteristics(Spliterator.ORDERED));
   4448 
   4449         assertTrue(doubleSp.tryAdvance((Double value) -> assertEquals(1.0, (double) value)));
   4450         assertTrue(doubleSp.tryAdvance((double value) -> assertEquals(2.0, (double) value)));
   4451 
   4452         PrimitiveDoubleArrayList recorder = new PrimitiveDoubleArrayList(16);
   4453         // Record elements observed by previous tests.
   4454         recorder.add(1);
   4455         recorder.add(2);
   4456 
   4457         Spliterator.OfDouble split1 = doubleSp.trySplit();
   4458         assertNotNull(split1);
   4459         assertTrue(split1.tryAdvance((double value) -> recorder.add(value)));
   4460         assertTrue(split1.tryAdvance((Double value) -> recorder.add(value)));
   4461 
   4462         // Assert that splits can themselves resplit.
   4463         Spliterator.OfDouble split2 = split1.trySplit();
   4464         assertNotNull(split2);
   4465         split2.forEachRemaining((double value) -> recorder.add(value));
   4466         assertFalse(split2.tryAdvance((double value) -> fail()));
   4467         assertFalse(split2.tryAdvance((Double value) -> fail()));
   4468 
   4469         // Iterate over the remaining elements so we can make sure we've looked at
   4470         // everything.
   4471         split1.forEachRemaining((double value) -> recorder.add(value));
   4472         doubleSp.forEachRemaining((double value) -> recorder.add(value));
   4473 
   4474         double[] recorded = recorder.toSortedArray();
   4475         assertEquals(Arrays.toString(elements), Arrays.toString(recorded));
   4476     }
   4477 
   4478     public void test_primitive_spliterators_NPE() {
   4479         final int[] elements = { 1, 2, 3, 4, 5, 6};
   4480         Spliterator.OfInt intSp = Arrays.spliterator(elements);
   4481         try {
   4482             intSp.forEachRemaining((Consumer<Integer>) null);
   4483             fail();
   4484         } catch (NullPointerException expected) {
   4485         }
   4486 
   4487         try {
   4488             intSp.tryAdvance((Consumer<Integer>) null);
   4489             fail();
   4490         } catch (NullPointerException expected) {
   4491         }
   4492 
   4493         try {
   4494             intSp.forEachRemaining((IntConsumer) null);
   4495             fail();
   4496         } catch (NullPointerException expected) {
   4497         }
   4498 
   4499         try {
   4500             intSp.tryAdvance((IntConsumer) null);
   4501             fail();
   4502         } catch (NullPointerException expected) {
   4503         }
   4504 
   4505         final long[] longElements = { 1, 2, 3, 4, 5, 6};
   4506         Spliterator.OfLong longSp = Arrays.spliterator(longElements);
   4507         try {
   4508             longSp.forEachRemaining((Consumer<Long>) null);
   4509             fail();
   4510         } catch (NullPointerException expected) {
   4511         }
   4512 
   4513         try {
   4514             longSp.tryAdvance((Consumer<Long>) null);
   4515             fail();
   4516         } catch (NullPointerException expected) {
   4517         }
   4518 
   4519         try {
   4520             longSp.forEachRemaining((LongConsumer) null);
   4521             fail();
   4522         } catch (NullPointerException expected) {
   4523         }
   4524 
   4525         try {
   4526             longSp.tryAdvance((LongConsumer) null);
   4527             fail();
   4528         } catch (NullPointerException expected) {
   4529         }
   4530 
   4531         final double[] doubleElements = { 1, 2, 3, 4, 5, 6};
   4532         Spliterator.OfDouble doubleSp = Arrays.spliterator(doubleElements);
   4533         try {
   4534             doubleSp.forEachRemaining((Consumer<Double>) null);
   4535             fail();
   4536         } catch (NullPointerException expected) {
   4537         }
   4538 
   4539         try {
   4540             doubleSp.tryAdvance((Consumer<Double>) null);
   4541             fail();
   4542         } catch (NullPointerException expected) {
   4543         }
   4544 
   4545         try {
   4546             doubleSp.forEachRemaining((DoubleConsumer) null);
   4547             fail();
   4548         } catch (NullPointerException expected) {
   4549         }
   4550 
   4551         try {
   4552             doubleSp.tryAdvance((DoubleConsumer) null);
   4553             fail();
   4554         } catch (NullPointerException expected) {
   4555         }
   4556     }
   4557 
   4558     private void test_parallelSort$B(int size) {
   4559         if (size % 256 != 0) {
   4560             fail("test_parallelSort$B size needs to be dividable by 256");
   4561         }
   4562         int mul256Count = size / 256;
   4563         byte[] sortedArray = new byte[size];
   4564         byte curentValue = Byte.MIN_VALUE;
   4565         for (int counter = 0; counter < size; counter++) {
   4566             sortedArray[counter] = curentValue;
   4567             if (counter != 0 && counter % mul256Count == 0) {
   4568                 curentValue++;
   4569             }
   4570         }
   4571         byte[] reversedArray = new byte[size];
   4572         for (int counter = 0; counter < size; counter++) {
   4573             reversedArray[counter] = sortedArray[size - counter - 1];
   4574         }
   4575 
   4576         Arrays.parallelSort(reversedArray);
   4577         assertTrue(Arrays.equals(sortedArray, reversedArray));
   4578     }
   4579 
   4580     /**
   4581      * java.util.Arrays#parallelSort(byte[])
   4582      */
   4583     public void test_parallelSort$B() {
   4584         // This will result in single thread sort
   4585         assertTrue(256 <= Arrays.MIN_ARRAY_SORT_GRAN);
   4586         test_parallelSort$B(256);
   4587         // This should trigger true parallel sort
   4588         if (ForkJoinPool.getCommonPoolParallelism() > 1) {
   4589             assertTrue(256 * 64 > Arrays.MIN_ARRAY_SORT_GRAN);
   4590             test_parallelSort$B(256 * 64);
   4591         }
   4592     }
   4593 
   4594     private void test_parallelSort$BII(int size) {
   4595         int startIndex = 100;
   4596         int endIndex = size - 100;
   4597         byte[] reversedArray = new byte[size];
   4598         byte[] originalReversedArray = new byte[size];
   4599         Arrays.fill(reversedArray, 0 , startIndex, (byte)100);
   4600         Arrays.fill(reversedArray, endIndex, size, (byte)100);
   4601         for (int counter = startIndex; counter < endIndex; counter++) {
   4602             reversedArray[counter] = (byte) (size - counter - startIndex - 1);
   4603         }
   4604         System.arraycopy(reversedArray, 0, originalReversedArray, 0, size);
   4605 
   4606         Arrays.parallelSort(reversedArray, startIndex, endIndex);
   4607         for (int counter = 0; counter < startIndex; counter++)
   4608             assertTrue("Array modified outside of bounds",
   4609                  reversedArray[counter] == originalReversedArray[counter]);
   4610         for (int counter = startIndex; counter < endIndex - 1; counter++)
   4611             assertTrue("Array not sorted within bounds",
   4612                        reversedArray[counter] <= reversedArray[counter + 1]);
   4613         for (int counter = endIndex; counter < arraySize; counter++)
   4614             assertTrue("Array modified outside of bounds",
   4615                        reversedArray[counter] == originalReversedArray[counter]);
   4616 
   4617         //exception testing
   4618         try {
   4619             Arrays.parallelSort(reversedArray, startIndex + 1, startIndex);
   4620             fail("IllegalArgumentException expected");
   4621         } catch (IllegalArgumentException ignore) {
   4622         }
   4623 
   4624         try {
   4625             Arrays.parallelSort(reversedArray, -1, startIndex);
   4626             fail("ArrayIndexOutOfBoundsException expected (1)");
   4627         } catch (ArrayIndexOutOfBoundsException ignore) {
   4628         }
   4629 
   4630         try {
   4631             Arrays.parallelSort(reversedArray, startIndex, reversedArray.length + 1);
   4632             fail("ArrayIndexOutOfBoundsException expected (2)");
   4633         } catch (ArrayIndexOutOfBoundsException ignore) {
   4634         }
   4635     }
   4636 
   4637     /**
   4638      * java.util.Arrays#parallelSort(byte[], int, int)
   4639      */
   4640     public void test_parallelSort$BII() {
   4641         // This will result in single thread sort
   4642         assertTrue(256 <= Arrays.MIN_ARRAY_SORT_GRAN);
   4643         test_parallelSort$BII(256);
   4644         // This should trigger true parallel sort
   4645         if (ForkJoinPool.getCommonPoolParallelism() > 1) {
   4646             assertTrue(256 * 64 > Arrays.MIN_ARRAY_SORT_GRAN);
   4647             test_parallelSort$BII(256 * 64);
   4648         }
   4649     }
   4650 
   4651     /**
   4652      * java.util.Arrays#parallelSort(byte[]) & (byte[], int, int) NPE
   4653      */
   4654     public void test_parallelSort$B_NPE() {
   4655         byte[] byte_array_null = null;
   4656         try {
   4657             java.util.Arrays.parallelSort(byte_array_null);
   4658             fail("Should throw java.lang.NullPointerException");
   4659         } catch (NullPointerException expected) {
   4660         }
   4661         try {
   4662             java.util.Arrays.parallelSort(byte_array_null, (int) -1, (int) 1);
   4663             fail("Should throw java.lang.NullPointerException");
   4664         } catch (NullPointerException expected) {
   4665         }
   4666     }
   4667 
   4668     private void test_parallelSort$C(int size) {
   4669         char[] sortedArray = new char[size];
   4670         for (int counter = 0; counter < size; counter++)
   4671             sortedArray[counter] = (char)(Short.MIN_VALUE + counter);
   4672         char[] reversedArray = new char[size];
   4673         for (int counter = 0; counter < size; counter++) {
   4674             reversedArray[counter] = sortedArray[size - counter - 1];
   4675         }
   4676         Arrays.parallelSort(reversedArray);
   4677         assertTrue(Arrays.equals(sortedArray, reversedArray));
   4678     }
   4679 
   4680     /**
   4681      * java.util.Arrays#parallelSort(char[])
   4682      */
   4683     public void test_parallelSort$C() {
   4684         // This will result in single thread sort
   4685         assertTrue(256 <= Arrays.MIN_ARRAY_SORT_GRAN);
   4686         test_parallelSort$C(256);
   4687         // This should trigger true parallel sort
   4688         if (ForkJoinPool.getCommonPoolParallelism() > 1) {
   4689             assertTrue(256 * 64 > Arrays.MIN_ARRAY_SORT_GRAN);
   4690             test_parallelSort$C(256 * 64);
   4691         }
   4692     }
   4693 
   4694     private void test_parallelSort$CII(int size) {
   4695         int startIndex = 100;
   4696         int endIndex = size - 100;
   4697         char[] reversedArray = new char[size];
   4698         char[] originalReversedArray = new char[size];
   4699 
   4700         Arrays.fill(reversedArray, 0 , startIndex, (char)100);
   4701         Arrays.fill(reversedArray, endIndex, size, (char)100);
   4702         for (int counter = startIndex; counter < endIndex; counter++) {
   4703             reversedArray[counter] = (char)(size - counter - startIndex - 1);
   4704         }
   4705         System.arraycopy(reversedArray, 0, originalReversedArray, 0, size);
   4706 
   4707         Arrays.parallelSort(reversedArray, startIndex, endIndex);
   4708         for (int counter = 0; counter < startIndex; counter++)
   4709             assertTrue("Array modified outside of bounds",
   4710                  reversedArray[counter] == originalReversedArray[counter]);
   4711         for (int counter = startIndex; counter < endIndex - 1; counter++)
   4712             assertTrue("Array not sorted within bounds",
   4713                        reversedArray[counter] <= reversedArray[counter + 1]);
   4714         for (int counter = endIndex; counter < arraySize; counter++)
   4715             assertTrue("Array modified outside of bounds",
   4716                        reversedArray[counter] == originalReversedArray[counter]);
   4717 
   4718         //exception testing
   4719         try {
   4720             Arrays.parallelSort(reversedArray, startIndex + 1, startIndex);
   4721             fail("IllegalArgumentException expected");
   4722         } catch (IllegalArgumentException ignore) {
   4723         }
   4724 
   4725         try {
   4726             Arrays.parallelSort(reversedArray, -1, startIndex);
   4727             fail("ArrayIndexOutOfBoundsException expected (1)");
   4728         } catch (ArrayIndexOutOfBoundsException ignore) {
   4729         }
   4730 
   4731         try {
   4732             Arrays.parallelSort(reversedArray, startIndex, reversedArray.length + 1);
   4733             fail("ArrayIndexOutOfBoundsException expected (2)");
   4734         } catch (ArrayIndexOutOfBoundsException ignore) {
   4735         }
   4736     }
   4737 
   4738     /**
   4739      * java.util.Arrays#parallelSort(char[], int, int)
   4740      */
   4741     public void test_parallelSort$CII() {
   4742         // This will result in single thread sort
   4743         assertTrue(256 <= Arrays.MIN_ARRAY_SORT_GRAN);
   4744         test_parallelSort$CII(256);
   4745         // This should trigger true parallel sort
   4746         if (ForkJoinPool.getCommonPoolParallelism() > 1) {
   4747             assertTrue(256 * 64 > Arrays.MIN_ARRAY_SORT_GRAN);
   4748             test_parallelSort$CII(256 * 64);
   4749         }
   4750     }
   4751 
   4752     /**
   4753      * java.util.Arrays#parallelSort(char[]) & (char[], int, int) NPE
   4754      */
   4755     public void test_parallelSort$C_NPE() {
   4756         char[] char_array_null = null;
   4757         try {
   4758             java.util.Arrays.parallelSort(char_array_null);
   4759             fail("Should throw java.lang.NullPointerException");
   4760         } catch (NullPointerException expected) {
   4761         }
   4762         try {
   4763             java.util.Arrays.parallelSort(char_array_null, (int) -1, (int) 1);
   4764             fail("Should throw java.lang.NullPointerException");
   4765         } catch (NullPointerException expected) {
   4766         }
   4767     }
   4768 
   4769     private void test_parallelSort$S(int size) {
   4770         short[] sortedArray = new short[size];
   4771         for (int counter = 0; counter < size; counter++)
   4772             sortedArray[counter] = (short)(Short.MIN_VALUE + counter);
   4773         short[] reversedArray = new short[size];
   4774         for (int counter = 0; counter < size; counter++) {
   4775             reversedArray[counter] = sortedArray[size - counter - 1];
   4776         }
   4777         Arrays.parallelSort(reversedArray);
   4778         assertTrue(Arrays.equals(sortedArray, reversedArray));
   4779     }
   4780 
   4781     /**
   4782      * java.util.Arrays#parallelSort(short[])
   4783      */
   4784     public void test_parallelSort$S() {
   4785         // This will result in single thread sort
   4786         assertTrue(256 <= Arrays.MIN_ARRAY_SORT_GRAN);
   4787         test_parallelSort$S(256);
   4788         // This should trigger true parallel sort
   4789         if (ForkJoinPool.getCommonPoolParallelism() > 1) {
   4790             assertTrue(256 * 64 > Arrays.MIN_ARRAY_SORT_GRAN);
   4791             test_parallelSort$S(256 * 64);
   4792         }
   4793     }
   4794 
   4795     private void test_parallelSort$SII(int size) {
   4796         int startIndex = 100;
   4797         int endIndex = size - 100;
   4798         short[] reversedArray = new short[size];
   4799         short[] originalReversedArray = new short[size];
   4800 
   4801         Arrays.fill(reversedArray, 0 , startIndex, (short)100);
   4802         Arrays.fill(reversedArray, endIndex, size, (short)100);
   4803         for (int counter = startIndex; counter < endIndex; counter++) {
   4804             reversedArray[counter] = (short)(size - counter - startIndex - 1);
   4805         }
   4806         System.arraycopy(reversedArray, 0, originalReversedArray, 0, size);
   4807 
   4808         Arrays.parallelSort(reversedArray, startIndex, endIndex);
   4809         for (int counter = 0; counter < startIndex; counter++)
   4810             assertTrue("Array modified outside of bounds",
   4811                  reversedArray[counter] == originalReversedArray[counter]);
   4812         for (int counter = startIndex; counter < endIndex - 1; counter++)
   4813             assertTrue("Array not sorted within bounds",
   4814                        reversedArray[counter] <= reversedArray[counter + 1]);
   4815         for (int counter = endIndex; counter < arraySize; counter++)
   4816             assertTrue("Array modified outside of bounds",
   4817                        reversedArray[counter] == originalReversedArray[counter]);
   4818 
   4819         //exception testing
   4820         try {
   4821             Arrays.parallelSort(reversedArray, startIndex + 1, startIndex);
   4822             fail("IllegalArgumentException expected");
   4823         } catch (IllegalArgumentException ignore) {
   4824         }
   4825 
   4826         try {
   4827             Arrays.parallelSort(reversedArray, -1, startIndex);
   4828             fail("ArrayIndexOutOfBoundsException expected (1)");
   4829         } catch (ArrayIndexOutOfBoundsException ignore) {
   4830         }
   4831 
   4832         try {
   4833             Arrays.parallelSort(reversedArray, startIndex, reversedArray.length + 1);
   4834             fail("ArrayIndexOutOfBoundsException expected (2)");
   4835         } catch (ArrayIndexOutOfBoundsException ignore) {
   4836         }
   4837     }
   4838 
   4839     /**
   4840      * java.util.Arrays#parallelSort(short[], int, int)
   4841      */
   4842     public void test_parallelSort$SII() {
   4843         // This will result in single thread sort
   4844         assertTrue(256 <= Arrays.MIN_ARRAY_SORT_GRAN);
   4845         test_parallelSort$SII(256);
   4846         // This should trigger true parallel sort
   4847         if (ForkJoinPool.getCommonPoolParallelism() > 1) {
   4848             assertTrue(256 * 64 > Arrays.MIN_ARRAY_SORT_GRAN);
   4849             test_parallelSort$SII(256 * 64);
   4850         }
   4851     }
   4852 
   4853     /**
   4854      * java.util.Arrays#parallelSort(short[]) & (short[], int, int) NPE
   4855      */
   4856     public void test_parallelSort$S_NPE() {
   4857         short[] array_null = null;
   4858         try {
   4859             java.util.Arrays.parallelSort(array_null);
   4860             fail("Should throw java.lang.NullPointerException");
   4861         } catch (NullPointerException expected) {
   4862         }
   4863         try {
   4864             java.util.Arrays.parallelSort(array_null, (int) -1, (int) 1);
   4865             fail("Should throw java.lang.NullPointerException");
   4866         } catch (NullPointerException expected) {
   4867         }
   4868     }
   4869 
   4870     private void test_parallelSort$I(int size) {
   4871         int[] sortedArray = new int[size];
   4872         for (int counter = 0; counter < size; counter++)
   4873             sortedArray[counter] = (int)(Integer.MIN_VALUE + counter);
   4874         int[] reversedArray = new int[size];
   4875         for (int counter = 0; counter < size; counter++) {
   4876             reversedArray[counter] = sortedArray[size - counter - 1];
   4877         }
   4878         Arrays.parallelSort(reversedArray);
   4879         assertTrue(Arrays.equals(sortedArray, reversedArray));
   4880     }
   4881 
   4882     /**
   4883      * java.util.Arrays#parallelSort(int[])
   4884      */
   4885     public void test_parallelSort$I() {
   4886         // This will result in single thread sort
   4887         assertTrue(256 <= Arrays.MIN_ARRAY_SORT_GRAN);
   4888         test_parallelSort$I(256);
   4889         // This should trigger true parallel sort
   4890         if (ForkJoinPool.getCommonPoolParallelism() > 1) {
   4891             assertTrue(256 * 64 > Arrays.MIN_ARRAY_SORT_GRAN);
   4892             test_parallelSort$I(256 * 64);
   4893         }
   4894     }
   4895 
   4896     private void test_parallelSort$III(int size) {
   4897         int startIndex = 100;
   4898         int endIndex = size - 100;
   4899         int[] reversedArray = new int[size];
   4900         int[] originalReversedArray = new int[size];
   4901 
   4902         Arrays.fill(reversedArray, 0 , startIndex, (int)100);
   4903         Arrays.fill(reversedArray, endIndex, size, (int)100);
   4904         for (int counter = startIndex; counter < endIndex; counter++) {
   4905             reversedArray[counter] = (int)(size - counter - startIndex - 1);
   4906         }
   4907         System.arraycopy(reversedArray, 0, originalReversedArray, 0, size);
   4908 
   4909         Arrays.parallelSort(reversedArray, startIndex, endIndex);
   4910         for (int counter = 0; counter < startIndex; counter++)
   4911             assertTrue("Array modified outside of bounds",
   4912                  reversedArray[counter] == originalReversedArray[counter]);
   4913         for (int counter = startIndex; counter < endIndex - 1; counter++)
   4914             assertTrue("Array not sorted within bounds",
   4915                        reversedArray[counter] <= reversedArray[counter + 1]);
   4916         for (int counter = endIndex; counter < arraySize; counter++)
   4917             assertTrue("Array modified outside of bounds",
   4918                        reversedArray[counter] == originalReversedArray[counter]);
   4919 
   4920         //exception testing
   4921         try {
   4922             Arrays.parallelSort(reversedArray, startIndex + 1, startIndex);
   4923             fail("IllegalArgumentException expected");
   4924         } catch (IllegalArgumentException ignore) {
   4925         }
   4926 
   4927         try {
   4928             Arrays.parallelSort(reversedArray, -1, startIndex);
   4929             fail("ArrayIndexOutOfBoundsException expected (1)");
   4930         } catch (ArrayIndexOutOfBoundsException ignore) {
   4931         }
   4932 
   4933         try {
   4934             Arrays.parallelSort(reversedArray, startIndex, reversedArray.length + 1);
   4935             fail("ArrayIndexOutOfBoundsException expected (2)");
   4936         } catch (ArrayIndexOutOfBoundsException ignore) {
   4937         }
   4938     }
   4939 
   4940     /**
   4941      * java.util.Arrays#parallelSort(int[], int, int)
   4942      */
   4943     public void test_parallelSort$III() {
   4944         // This will result in single thread sort
   4945         assertTrue(256 <= Arrays.MIN_ARRAY_SORT_GRAN);
   4946         test_parallelSort$III(256);
   4947         // This should trigger true parallel sort
   4948         if (ForkJoinPool.getCommonPoolParallelism() > 1) {
   4949             assertTrue(256 * 64 > Arrays.MIN_ARRAY_SORT_GRAN);
   4950             test_parallelSort$III(256 * 64);
   4951         }
   4952     }
   4953 
   4954     /**
   4955      * java.util.Arrays#parallelSort(int[]) & (int[], int, int) NPE
   4956      */
   4957     public void test_parallelSort$I_NPE() {
   4958         int[] array_null = null;
   4959         try {
   4960             java.util.Arrays.parallelSort(array_null);
   4961             fail("Should throw java.lang.NullPointerException");
   4962         } catch (NullPointerException expected) {
   4963         }
   4964         try {
   4965             java.util.Arrays.parallelSort(array_null, (int) -1, (int) 1);
   4966             fail("Should throw java.lang.NullPointerException");
   4967         } catch (NullPointerException expected) {
   4968         }
   4969     }
   4970 
   4971     private void test_parallelSort$J(int size) {
   4972         long[] reversedArray = new long[size];
   4973         for (int counter = 0; counter < size; counter++)
   4974             reversedArray[counter] = (long)(size - counter - 1);
   4975         Arrays.parallelSort(reversedArray);
   4976 
   4977         for (int counter = 0; counter < size; counter++)
   4978             assertTrue("Resulting array not sorted",
   4979                     reversedArray[counter] == (long) counter);
   4980     }
   4981 
   4982     /**
   4983      * java.util.Arrays#parallelSort(long[])
   4984      */
   4985     public void test_parallelSort$J() {
   4986         // This will result in single thread sort
   4987         assertTrue(256 <= Arrays.MIN_ARRAY_SORT_GRAN);
   4988         test_parallelSort$J(256);
   4989         // This should trigger true parallel sort
   4990         if (ForkJoinPool.getCommonPoolParallelism() > 1) {
   4991             assertTrue(256 * 64 > Arrays.MIN_ARRAY_SORT_GRAN);
   4992             test_parallelSort$J(256 * 64);
   4993         }
   4994     }
   4995 
   4996     private void test_parallelSort$JII(int size) {
   4997         int startIndex = 100;
   4998         int endIndex = size - 100;
   4999         long[] reversedArray = new long[size];
   5000         long[] originalReversedArray = new long[size];
   5001 
   5002         Arrays.fill(reversedArray, 0 , startIndex, (long)100);
   5003         Arrays.fill(reversedArray, endIndex, size, (long)100);
   5004         for (int counter = startIndex; counter < endIndex; counter++) {
   5005             reversedArray[counter] = (long)(size - counter - startIndex - 1);
   5006         }
   5007         System.arraycopy(reversedArray, 0, originalReversedArray, 0, size);
   5008 
   5009         Arrays.parallelSort(reversedArray, startIndex, endIndex);
   5010         for (int counter = 0; counter < startIndex; counter++)
   5011             assertTrue("Array modified outside of bounds",
   5012                  reversedArray[counter] == originalReversedArray[counter]);
   5013         for (int counter = startIndex; counter < endIndex - 1; counter++)
   5014             assertTrue("Array not sorted within bounds",
   5015                        reversedArray[counter] <= reversedArray[counter + 1]);
   5016         for (int counter = endIndex; counter < arraySize; counter++)
   5017             assertTrue("Array modified outside of bounds",
   5018                        reversedArray[counter] == originalReversedArray[counter]);
   5019 
   5020         //exception testing
   5021         try {
   5022             Arrays.parallelSort(reversedArray, startIndex + 1, startIndex);
   5023             fail("IllegalArgumentException expected");
   5024         } catch (IllegalArgumentException ignore) {
   5025         }
   5026 
   5027         try {
   5028             Arrays.parallelSort(reversedArray, -1, startIndex);
   5029             fail("ArrayIndexOutOfBoundsException expected (1)");
   5030         } catch (ArrayIndexOutOfBoundsException ignore) {
   5031         }
   5032 
   5033         try {
   5034             Arrays.parallelSort(reversedArray, startIndex, reversedArray.length + 1);
   5035             fail("ArrayIndexOutOfBoundsException expected (2)");
   5036         } catch (ArrayIndexOutOfBoundsException ignore) {
   5037         }
   5038     }
   5039 
   5040     /**
   5041      * java.util.Arrays#parallelSort(long[], int, int)
   5042      */
   5043     public void test_parallelSort$JII() {
   5044         // This will result in single thread sort
   5045         assertTrue(256 <= Arrays.MIN_ARRAY_SORT_GRAN);
   5046         test_parallelSort$JII(256);
   5047         // This should trigger true parallel sort
   5048         if (ForkJoinPool.getCommonPoolParallelism() > 1) {
   5049             assertTrue(256 * 64 > Arrays.MIN_ARRAY_SORT_GRAN);
   5050             test_parallelSort$JII(256 * 64);
   5051         }
   5052     }
   5053 
   5054     /**
   5055      * java.util.Arrays#parallelSort(long[]) & (long[], int, int) NPE
   5056      */
   5057     public void test_parallelSort$J_NPE() {
   5058         long[] array_null = null;
   5059         try {
   5060             java.util.Arrays.parallelSort(array_null);
   5061             fail("Should throw java.lang.NullPointerException");
   5062         } catch (NullPointerException expected) {
   5063         }
   5064         try {
   5065             java.util.Arrays.parallelSort(array_null, (int) -1, (int) 1);
   5066             fail("Should throw java.lang.NullPointerException");
   5067         } catch (NullPointerException expected) {
   5068         }
   5069     }
   5070 
   5071     private void test_parallelSort$D(int size) {
   5072         double[] sortedArray = new double[size];
   5073         for (int counter = 0; counter < size; counter++)
   5074             sortedArray[counter] = (double)(counter);
   5075         double[] reversedArray = new double[size];
   5076         for (int counter = 0; counter < size; counter++) {
   5077             reversedArray[counter] = sortedArray[size - counter - 1];
   5078         }
   5079         Arrays.parallelSort(reversedArray);
   5080         assertTrue(Arrays.equals(sortedArray, reversedArray));
   5081     }
   5082 
   5083     /**
   5084      * java.util.Arrays#parallelSort(double[])
   5085      */
   5086     public void test_parallelSort$D() {
   5087         // This will result in single thread sort
   5088         assertTrue(256 <= Arrays.MIN_ARRAY_SORT_GRAN);
   5089         test_parallelSort$D(256);
   5090         // This should trigger true parallel sort
   5091         if (ForkJoinPool.getCommonPoolParallelism() > 1) {
   5092             assertTrue(256 * 64 > Arrays.MIN_ARRAY_SORT_GRAN);
   5093             test_parallelSort$D(256 * 64);
   5094         }
   5095     }
   5096 
   5097     private void test_parallelSort$DII(int size) {
   5098         int startIndex = 100;
   5099         int endIndex = size-100;
   5100         double[] reversedArray = new double[size];
   5101         double[] originalReversedArray = new double[size];
   5102 
   5103         Arrays.fill(reversedArray, 0 , startIndex, (double)100);
   5104         Arrays.fill(reversedArray, endIndex, size, (double)100);
   5105         for (int counter = startIndex; counter < endIndex; counter++) {
   5106             reversedArray[counter] = (double) (size - counter - startIndex - 1);
   5107         }
   5108         System.arraycopy(reversedArray, 0, originalReversedArray, 0, size);
   5109 
   5110         Arrays.parallelSort(reversedArray, startIndex, endIndex);
   5111         for (int counter = 0; counter < startIndex; counter++)
   5112             assertTrue("Array modified outside of bounds",
   5113                  reversedArray[counter] == originalReversedArray[counter]);
   5114         for (int counter = startIndex; counter < endIndex - 1; counter++)
   5115             assertTrue("Array not sorted within bounds",
   5116                        reversedArray[counter] <= reversedArray[counter + 1]);
   5117         for (int counter = endIndex; counter < arraySize; counter++)
   5118             assertTrue("Array modified outside of bounds",
   5119                        reversedArray[counter] == originalReversedArray[counter]);
   5120 
   5121         //exception testing
   5122         try {
   5123             Arrays.parallelSort(reversedArray, startIndex + 1, startIndex);
   5124             fail("IllegalArgumentException expected");
   5125         } catch (IllegalArgumentException ignore) {
   5126         }
   5127 
   5128         try {
   5129             Arrays.parallelSort(reversedArray, -1, startIndex);
   5130             fail("ArrayIndexOutOfBoundsException expected (1)");
   5131         } catch (ArrayIndexOutOfBoundsException ignore) {
   5132         }
   5133 
   5134         try {
   5135             Arrays.parallelSort(reversedArray, startIndex, reversedArray.length + 1);
   5136             fail("ArrayIndexOutOfBoundsException expected (2)");
   5137         } catch (ArrayIndexOutOfBoundsException ignore) {
   5138         }
   5139     }
   5140 
   5141     /**
   5142      * java.util.Arrays#parallelSort(double[], int, int)
   5143      */
   5144     public void test_parallelSort$DII() {
   5145         // This will result in single thread sort
   5146         assertTrue(256 <= Arrays.MIN_ARRAY_SORT_GRAN);
   5147         test_parallelSort$DII(256);
   5148         // This should trigger true parallel sort
   5149         if (ForkJoinPool.getCommonPoolParallelism() > 1) {
   5150             assertTrue(256 * 64 > Arrays.MIN_ARRAY_SORT_GRAN);
   5151             test_parallelSort$DII(64*256);
   5152         }
   5153     }
   5154 
   5155     /**
   5156      * java.util.Arrays#parallelSort(double[]) & (double[], int, int) NPE
   5157      */
   5158     public void test_parallelSort$D_NPE() {
   5159         double[] array_null = null;
   5160         try {
   5161             java.util.Arrays.parallelSort(array_null);
   5162             fail("Should throw java.lang.NullPointerException");
   5163         } catch (NullPointerException expected) {
   5164         }
   5165         try {
   5166             java.util.Arrays.parallelSort(array_null, (int) -1, (int) 1);
   5167             fail("Should throw java.lang.NullPointerException");
   5168         } catch (NullPointerException expected) {
   5169         }
   5170     }
   5171 
   5172     private void test_parallelSort$F(int size) {
   5173         float[] sortedArray = new float[size];
   5174         for (int counter = 0; counter < size; counter++)
   5175             sortedArray[counter] = (float)(counter);
   5176         float[] reversedArray = new float[size];
   5177         for (int counter = 0; counter < size; counter++) {
   5178             reversedArray[counter] = sortedArray[size - counter - 1];
   5179         }
   5180         Arrays.parallelSort(reversedArray);
   5181         assertTrue(Arrays.equals(sortedArray, reversedArray));
   5182     }
   5183 
   5184     /**
   5185      * java.util.Arrays#parallelSort(float[])
   5186      */
   5187     public void test_parallelSort$F() {
   5188         // This will result in single thread sort
   5189         assertTrue(256 <= Arrays.MIN_ARRAY_SORT_GRAN);
   5190         test_parallelSort$F(256);
   5191         // This should trigger true parallel sort
   5192         if (ForkJoinPool.getCommonPoolParallelism() > 1) {
   5193             assertTrue(256 * 64 > Arrays.MIN_ARRAY_SORT_GRAN);
   5194             test_parallelSort$F(256 * 64);
   5195         }
   5196     }
   5197 
   5198     private void test_parallelSort$FII(int size) {
   5199         int startIndex = 100;
   5200         int endIndex = size-100;
   5201         float[] reversedArray = new float[size];
   5202         float[] originalReversedArray = new float[size];
   5203 
   5204         Arrays.fill(reversedArray, 0 , startIndex, (float)100);
   5205         Arrays.fill(reversedArray, endIndex, size, (float)100);
   5206         for (int counter = startIndex; counter < endIndex; counter++) {
   5207             reversedArray[counter] = (float) (size - counter - startIndex - 1);
   5208         }
   5209         System.arraycopy(reversedArray, 0, originalReversedArray, 0, size);
   5210 
   5211         Arrays.parallelSort(reversedArray, startIndex, endIndex);
   5212         for (int counter = 0; counter < startIndex; counter++)
   5213             assertTrue("Array modified outside of bounds",
   5214                  reversedArray[counter] == originalReversedArray[counter]);
   5215         for (int counter = startIndex; counter < endIndex - 1; counter++)
   5216             assertTrue("Array not sorted within bounds",
   5217                        reversedArray[counter] <= reversedArray[counter + 1]);
   5218         for (int counter = endIndex; counter < arraySize; counter++)
   5219             assertTrue("Array modified outside of bounds",
   5220                        reversedArray[counter] == originalReversedArray[counter]);
   5221 
   5222         //exception testing
   5223         try {
   5224             Arrays.parallelSort(reversedArray, startIndex + 1, startIndex);
   5225             fail("IllegalArgumentException expected");
   5226         } catch (IllegalArgumentException ignore) {
   5227         }
   5228 
   5229         try {
   5230             Arrays.parallelSort(reversedArray, -1, startIndex);
   5231             fail("ArrayIndexOutOfBoundsException expected (1)");
   5232         } catch (ArrayIndexOutOfBoundsException ignore) {
   5233         }
   5234 
   5235         try {
   5236             Arrays.parallelSort(reversedArray, startIndex, reversedArray.length + 1);
   5237             fail("ArrayIndexOutOfBoundsException expected (2)");
   5238         } catch (ArrayIndexOutOfBoundsException ignore) {
   5239         }
   5240     }
   5241 
   5242     /**
   5243      * java.util.Arrays#parallelSort(float[], int, int)
   5244      */
   5245     public void test_parallelSort$FII() {
   5246         // This will result in single thread sort
   5247         assertTrue(256 <= Arrays.MIN_ARRAY_SORT_GRAN);
   5248         test_parallelSort$FII(256);
   5249         // This should trigger true parallel sort
   5250         if (ForkJoinPool.getCommonPoolParallelism() > 1) {
   5251             assertTrue(256 * 64 > Arrays.MIN_ARRAY_SORT_GRAN);
   5252             test_parallelSort$FII(64*256);
   5253         }
   5254     }
   5255 
   5256     /**
   5257      * java.util.Arrays#parallelSort(float[]) & (float[], int, int) NPE
   5258      */
   5259     public void test_parallelSort$F_NPE() {
   5260         float[] array_null = null;
   5261         try {
   5262             java.util.Arrays.parallelSort(array_null);
   5263             fail("Should throw java.lang.NullPointerException");
   5264         } catch (NullPointerException expected) {
   5265 
   5266         }
   5267         try {
   5268             java.util.Arrays.parallelSort(array_null, (int) -1, (int) 1);
   5269             fail("Should throw java.lang.NullPointerException");
   5270         } catch (NullPointerException expected) {
   5271         }
   5272     }
   5273 
   5274     private void test_parallelSort$Ljava_lang_Comparable(int size) {
   5275         Comparable[] sortedArray = new Comparable[size];
   5276         for (int counter = 0; counter < size; counter++)
   5277             sortedArray[counter] = new Integer(counter);
   5278         Comparable[] reversedArray = new Comparable[size];
   5279         for (int counter = 0; counter < size; counter++) {
   5280             reversedArray[counter] = sortedArray[size - counter - 1];
   5281         }
   5282         Arrays.parallelSort(reversedArray);
   5283         assertTrue(Arrays.equals(sortedArray, reversedArray));
   5284 
   5285         Arrays.fill(reversedArray, 0, reversedArray.length/2, "String");
   5286         Arrays.fill(reversedArray, reversedArray.length/2, reversedArray.length, new Integer(1));
   5287 
   5288         try {
   5289             Arrays.sort(reversedArray);
   5290             fail("ClassCastException expected");
   5291         } catch (ClassCastException expected) {
   5292         }
   5293     }
   5294 
   5295     /**
   5296      * java.util.Arrays#parallelSort(java.lang.Comparable[])
   5297      */
   5298     public void test_parallelSort$Ljava_lang_Comparable() {
   5299         // This will result in single thread sort
   5300         assertTrue(256 <= Arrays.MIN_ARRAY_SORT_GRAN);
   5301         test_parallelSort$Ljava_lang_Comparable(256);
   5302         // This should trigger true parallel sort
   5303         if (ForkJoinPool.getCommonPoolParallelism() > 1) {
   5304             assertTrue(256 * 64 > Arrays.MIN_ARRAY_SORT_GRAN);
   5305             test_parallelSort$Ljava_lang_Comparable(256 * 64);
   5306         }
   5307     }
   5308 
   5309     private void test_parallelSort$Ljava_lang_ComparableII(int size) {
   5310         int startIndex = 100;
   5311         int endIndex = size-100;
   5312         Comparable[] reversedArray = new Comparable[size];
   5313         Comparable[] originalReversedArray = new Comparable[size];
   5314         Arrays.fill(reversedArray, 0 , startIndex, new Integer(100));
   5315         Arrays.fill(reversedArray, endIndex, size, new Integer(100));
   5316         for (int counter = startIndex; counter < endIndex; counter++) {
   5317             reversedArray[counter] = new Integer(size - counter - startIndex - 1);
   5318         }
   5319         System.arraycopy(reversedArray, 0, originalReversedArray, 0, size);
   5320 
   5321         Arrays.parallelSort(reversedArray, startIndex, endIndex);
   5322         for (int counter = 0; counter < startIndex; counter++)
   5323             assertTrue("Array modified outside of bounds",
   5324                  reversedArray[counter] == originalReversedArray[counter]);
   5325         for (int counter = startIndex; counter < endIndex - 1; counter++)
   5326             assertTrue("Array not sorted within bounds",
   5327                        (int)(Integer)reversedArray[counter] <= (int)reversedArray[counter + 1]);
   5328         for (int counter = endIndex; counter < arraySize; counter++)
   5329             assertTrue("Array modified outside of bounds",
   5330                        reversedArray[counter] == originalReversedArray[counter]);
   5331 
   5332         //exception testing
   5333         try {
   5334             Arrays.parallelSort(reversedArray, startIndex + 1, startIndex);
   5335             fail("IllegalArgumentException expected");
   5336         } catch (IllegalArgumentException ignore) {
   5337         }
   5338 
   5339         try {
   5340             Arrays.parallelSort(reversedArray, -1, startIndex);
   5341             fail("ArrayIndexOutOfBoundsException expected (1)");
   5342         } catch (ArrayIndexOutOfBoundsException ignore) {
   5343         }
   5344 
   5345         try {
   5346             Arrays.parallelSort(reversedArray, startIndex, reversedArray.length + 1);
   5347             fail("ArrayIndexOutOfBoundsException expected (2)");
   5348         } catch (ArrayIndexOutOfBoundsException ignore) {
   5349         }
   5350     }
   5351 
   5352     /**
   5353      * java.util.Arrays#parallelSort(java.lang.Comparable[], int, int)
   5354      */
   5355     public void test_parallelSort$Ljava_lang_ComparableII() {
   5356         // This will result in single thread sort
   5357         assertTrue(256 <= Arrays.MIN_ARRAY_SORT_GRAN);
   5358         test_parallelSort$Ljava_lang_ComparableII(256);
   5359         // This should trigger true parallel sort
   5360         if (ForkJoinPool.getCommonPoolParallelism() > 1) {
   5361             assertTrue(256 * 64 > Arrays.MIN_ARRAY_SORT_GRAN);
   5362             test_parallelSort$Ljava_lang_ComparableII(64*256);
   5363         }
   5364     }
   5365 
   5366 
   5367     /**
   5368      * java.util.Arrays#parallelSort(java_lang_Comparable[]) & (java_lang_Comparable[], int, int) NPE
   5369      */
   5370     public void test_parallelSort$Ljava_lang_Comparable_NPE() {
   5371         Comparable[] array_null = null;
   5372         try {
   5373             java.util.Arrays.parallelSort(array_null);
   5374             fail("Should throw java.lang.NullPointerException");
   5375         } catch (NullPointerException expected) {
   5376 
   5377         }
   5378         try {
   5379             java.util.Arrays.parallelSort(array_null, (int) -1, (int) 1);
   5380             fail("Should throw java.lang.NullPointerException");
   5381         } catch (NullPointerException expected) {
   5382         }
   5383     }
   5384 
   5385     private void test_parallelSort$Ljava_lang_ObjectLjava_util_Comparator(int size) {
   5386         Object[] reversedArray = new Object[size];
   5387         for (int counter = 0; counter < size; counter++)
   5388             reversedArray[counter] = new Integer(counter);
   5389         Comparator comparator = new ReversedIntegerComparator();
   5390         Arrays.parallelSort(reversedArray, comparator);
   5391 
   5392         for (int counter = 0; counter < size; counter++)
   5393             assertTrue("Resulting array not sorted",
   5394                        (int)(reversedArray[counter]) == (size - counter -1 ));
   5395 
   5396         Arrays.fill(reversedArray, 0, reversedArray.length/2, "String");
   5397         Arrays.fill(reversedArray, reversedArray.length/2, reversedArray.length, new Integer(1));
   5398 
   5399         try {
   5400             Arrays.sort(reversedArray, comparator);
   5401             fail("ClassCastException expected");
   5402         } catch (ClassCastException expected) {
   5403         }
   5404     }
   5405 
   5406     /**
   5407      * java.util.Arrays#parallelSort(java.lang.Object[], java.util.Comparator)
   5408      */
   5409     public void test_parallelSort$Ljava_lang_Objectjava_util_Comparator() {
   5410         // This will result in single thread sort
   5411         assertTrue(256 <= Arrays.MIN_ARRAY_SORT_GRAN);
   5412         test_parallelSort$Ljava_lang_ObjectLjava_util_Comparator(256);
   5413         // This should trigger true parallel sort
   5414         if (ForkJoinPool.getCommonPoolParallelism() > 1) {
   5415             assertTrue(256 * 64 > Arrays.MIN_ARRAY_SORT_GRAN);
   5416             test_parallelSort$Ljava_lang_ObjectLjava_util_Comparator(256 * 64);
   5417         }
   5418     }
   5419 
   5420     private void test_parallelSort$Ljava_lang_ObjectLjava_util_ComparatorII(int size) {
   5421         int startIndex = 100;
   5422         int endIndex = size-100;
   5423         Integer[] reversedArray = new Integer[size];
   5424         Integer[] originalReversedArray = new Integer[size];
   5425         Arrays.fill(reversedArray, 0 , startIndex, new Integer(100));
   5426         Arrays.fill(reversedArray, endIndex, size, new Integer(100));
   5427         for (int counter = startIndex; counter < endIndex; counter++) {
   5428             reversedArray[counter] = new Integer(counter - startIndex);
   5429         }
   5430         System.arraycopy(reversedArray, 0, originalReversedArray, 0, size);
   5431 
   5432         Comparator comparator = new ReversedIntegerComparator();
   5433         Arrays.parallelSort(reversedArray, startIndex, endIndex, comparator);
   5434         for (int counter = 0; counter < startIndex; counter++)
   5435             assertTrue("Array modified outside of bounds",
   5436                  reversedArray[counter] == originalReversedArray[counter]);
   5437         for (int counter = startIndex; counter < endIndex - 1; counter++)
   5438             assertTrue("Array not sorted within bounds",
   5439                        (int)(Integer)reversedArray[counter] >= (int)reversedArray[counter + 1]);
   5440         for (int counter = endIndex; counter < arraySize; counter++)
   5441             assertTrue("Array modified outside of bounds",
   5442                        reversedArray[counter] == originalReversedArray[counter]);
   5443 
   5444         //exception testing
   5445         try {
   5446             Arrays.parallelSort(reversedArray, startIndex + 1, startIndex, comparator);
   5447             fail("IllegalArgumentException expected");
   5448         } catch (IllegalArgumentException ignore) {
   5449         }
   5450 
   5451         try {
   5452             Arrays.parallelSort(reversedArray, -1, startIndex, comparator);
   5453             fail("ArrayIndexOutOfBoundsException expected (1)");
   5454         } catch (ArrayIndexOutOfBoundsException ignore) {
   5455         }
   5456 
   5457         try {
   5458             Arrays.parallelSort(reversedArray, startIndex, reversedArray.length + 1, comparator);
   5459             fail("ArrayIndexOutOfBoundsException expected (2)");
   5460         } catch (ArrayIndexOutOfBoundsException ignore) {
   5461         }
   5462     }
   5463 
   5464     /**
   5465      * java.util.Arrays#parallelSort(java.lang.Object[], int, int, java.util.Comparator)
   5466      */
   5467     public void test_parallelSort$Ljava_lang_ObjectLjava_util_ComparatorII() {
   5468         // This will result in single thread sort
   5469         assertTrue(256 <= Arrays.MIN_ARRAY_SORT_GRAN);
   5470         test_parallelSort$Ljava_lang_ObjectLjava_util_ComparatorII(256);
   5471         // This should trigger true parallel sort
   5472         if (ForkJoinPool.getCommonPoolParallelism() > 1) {
   5473             assertTrue(256 * 64 > Arrays.MIN_ARRAY_SORT_GRAN);
   5474             test_parallelSort$Ljava_lang_ObjectLjava_util_ComparatorII(64*256);
   5475         }
   5476     }
   5477 
   5478     /**
   5479      * java.util.Arrays#parallelSort(Object[],Comparator) & (Object[], int, int, Comparator) NPE
   5480      */
   5481     public void test_parallelSort$Ljava_lang_ObjectLjava_util_Comparator_NPE() {
   5482         Object[] array_null = null;
   5483         Comparator comparator = new ReversedIntegerComparator();
   5484         try {
   5485             java.util.Arrays.parallelSort(array_null, comparator);
   5486             fail("Should throw java.lang.NullPointerException");
   5487         } catch (NullPointerException expected) {
   5488 
   5489         }
   5490         try {
   5491             java.util.Arrays.parallelSort(array_null, (int) -1, (int) 1, comparator);
   5492             fail("Should throw java.lang.NullPointerException");
   5493         } catch (NullPointerException expected) {
   5494         }
   5495     }
   5496 
   5497 
   5498     /**
   5499      * Tears down the fixture, for example, close a network connection. This
   5500      * method is called after a test is executed.
   5501      */
   5502     protected void tearDown() {
   5503         objArray = null;
   5504         booleanArray = null;
   5505         byteArray = null;
   5506         charArray = null;
   5507         doubleArray = null;
   5508         floatArray = null;
   5509         intArray = null;
   5510         longArray = null;
   5511         objectArray = null;
   5512         shortArray = null;
   5513     }
   5514 }
   5515