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 tests.support.Support_UnmodifiableCollectionTest;
     20 import java.lang.reflect.Method;
     21 import java.util.Arrays;
     22 import java.util.Comparator;
     23 import java.util.Date;
     24 import java.util.LinkedList;
     25 import java.util.List;
     26 import java.util.Random;
     27 
     28 public class ArraysTest extends junit.framework.TestCase {
     29 
     30     public static class ReversedIntegerComparator implements Comparator {
     31         public int compare(Object o1, Object o2) {
     32             return -(((Integer) o1).compareTo((Integer) o2));
     33         }
     34 
     35         public boolean equals(Object o1, Object o2) {
     36             return ((Integer) o1).compareTo((Integer) o2) == 0;
     37         }
     38     }
     39 
     40     static class MockComparable implements Comparable {
     41         public int compareTo(Object o) {
     42             return 0;
     43         }
     44     }
     45 
     46     final static int arraySize = 100;
     47 
     48     Object[] objArray;
     49 
     50     boolean[] booleanArray;
     51 
     52     byte[] byteArray;
     53 
     54     char[] charArray;
     55 
     56     double[] doubleArray;
     57 
     58     float[] floatArray;
     59 
     60     int[] intArray;
     61 
     62     long[] longArray;
     63 
     64     Object[] objectArray;
     65 
     66     short[] shortArray;
     67 
     68     /**
     69      * java.util.Arrays#asList(java.lang.Object[])
     70      */
     71     public void test_asList$Ljava_lang_Object() {
     72         // Test for method java.util.List
     73         // java.util.Arrays.asList(java.lang.Object [])
     74         List convertedList = Arrays.asList(objectArray);
     75         for (int counter = 0; counter < arraySize; counter++) {
     76             assertTrue(
     77                     "Array and List converted from array do not contain identical elements",
     78                     convertedList.get(counter) == objectArray[counter]);
     79         }
     80         convertedList.set(50, new Integer(1000));
     81         assertTrue("set/get did not work on coverted list", convertedList.get(
     82                 50).equals(new Integer(1000)));
     83         convertedList.set(50, new Integer(50));
     84         new Support_UnmodifiableCollectionTest("", convertedList).runTest();
     85 
     86         Object[] myArray = (Object[]) (objectArray.clone());
     87         myArray[30] = null;
     88         myArray[60] = null;
     89         convertedList = Arrays.asList(myArray);
     90         for (int counter = 0; counter < arraySize; counter++) {
     91             assertTrue(
     92                     "Array and List converted from array do not contain identical elements",
     93                     convertedList.get(counter) == myArray[counter]);
     94         }
     95 
     96         try {
     97             Arrays.asList((Object[]) null);
     98             fail("asList with null arg didn't throw NPE");
     99         } catch (NullPointerException e) {
    100             // Expected
    101         }
    102     }
    103 
    104     /**
    105      * java.util.Arrays#binarySearch(byte[], byte)
    106      */
    107     public void test_binarySearch$BB() {
    108         // Test for method int java.util.Arrays.binarySearch(byte [], byte)
    109         for (byte counter = 0; counter < arraySize; counter++)
    110             assertTrue("Binary search on byte[] answered incorrect position",
    111                     Arrays.binarySearch(byteArray, counter) == counter);
    112         assertEquals("Binary search succeeded for value not present in array 1",
    113                 -1, Arrays.binarySearch(intArray, (byte) -1));
    114         assertTrue(
    115                 "Binary search succeeded for value not present in array 2",
    116                 Arrays.binarySearch(intArray, (byte) arraySize) == -(arraySize + 1));
    117         for (byte counter = 0; counter < arraySize; counter++)
    118             byteArray[counter] -= 50;
    119         for (byte counter = 0; counter < arraySize; counter++)
    120             assertTrue(
    121                     "Binary search on byte[] involving negative numbers answered incorrect position",
    122                     Arrays.binarySearch(byteArray, (byte) (counter - 50)) == counter);
    123     }
    124 
    125     /**
    126      * java.util.Arrays#binarySearch(char[], char)
    127      */
    128     public void test_binarySearch$CC() {
    129         // Test for method int java.util.Arrays.binarySearch(char [], char)
    130         for (char counter = 0; counter < arraySize; counter++)
    131             assertTrue(
    132                     "Binary search on char[] answered incorrect position",
    133                     Arrays.binarySearch(charArray, (char) (counter + 1)) == counter);
    134         assertEquals("Binary search succeeded for value not present in array 1",
    135                 -1, Arrays.binarySearch(charArray, '\u0000'));
    136         assertTrue(
    137                 "Binary search succeeded for value not present in array 2",
    138                 Arrays.binarySearch(charArray, (char) (arraySize + 1)) == -(arraySize + 1));
    139     }
    140 
    141     /**
    142      * java.util.Arrays#binarySearch(double[], double)
    143      */
    144     public void test_binarySearch$DD() {
    145         // Test for method int java.util.Arrays.binarySearch(double [], double)
    146         for (int counter = 0; counter < arraySize; counter++)
    147             assertTrue(
    148                     "Binary search on double[] answered incorrect position",
    149                     Arrays.binarySearch(doubleArray, (double) counter) == (double) counter);
    150         assertEquals("Binary search succeeded for value not present in array 1",
    151                 -1, Arrays.binarySearch(doubleArray, (double) -1));
    152         assertTrue(
    153                 "Binary search succeeded for value not present in array 2",
    154                 Arrays.binarySearch(doubleArray, (double) arraySize) == -(arraySize + 1));
    155         for (int counter = 0; counter < arraySize; counter++)
    156             doubleArray[counter] -= (double) 50;
    157         for (int counter = 0; counter < arraySize; counter++)
    158             assertTrue(
    159                     "Binary search on double[] involving negative numbers answered incorrect position",
    160                     Arrays.binarySearch(doubleArray, (double) (counter - 50)) == (double) counter);
    161 
    162         double[] specials = new double[] { Double.NEGATIVE_INFINITY,
    163                 -Double.MAX_VALUE, -2d, -Double.MIN_VALUE, -0d, 0d,
    164                 Double.MIN_VALUE, 2d, Double.MAX_VALUE,
    165                 Double.POSITIVE_INFINITY, Double.NaN };
    166         for (int i = 0; i < specials.length; i++) {
    167             int result = Arrays.binarySearch(specials, specials[i]);
    168             assertTrue(specials[i] + " invalid: " + result, result == i);
    169         }
    170         assertEquals("-1d", -4, Arrays.binarySearch(specials, -1d));
    171         assertEquals("1d", -8, Arrays.binarySearch(specials, 1d));
    172 
    173     }
    174 
    175     /**
    176      * java.util.Arrays#binarySearch(float[], float)
    177      */
    178     public void test_binarySearch$FF() {
    179         // Test for method int java.util.Arrays.binarySearch(float [], float)
    180         for (int counter = 0; counter < arraySize; counter++)
    181             assertTrue(
    182                     "Binary search on float[] answered incorrect position",
    183                     Arrays.binarySearch(floatArray, (float) counter) == (float) counter);
    184         assertEquals("Binary search succeeded for value not present in array 1",
    185                 -1, Arrays.binarySearch(floatArray, (float) -1));
    186         assertTrue(
    187                 "Binary search succeeded for value not present in array 2",
    188                 Arrays.binarySearch(floatArray, (float) arraySize) == -(arraySize + 1));
    189         for (int counter = 0; counter < arraySize; counter++)
    190             floatArray[counter] -= (float) 50;
    191         for (int counter = 0; counter < arraySize; counter++)
    192             assertTrue(
    193                     "Binary search on float[] involving negative numbers answered incorrect position",
    194                     Arrays.binarySearch(floatArray, (float) counter - 50) == (float) counter);
    195 
    196         float[] specials = new float[] { Float.NEGATIVE_INFINITY,
    197                 -Float.MAX_VALUE, -2f, -Float.MIN_VALUE, -0f, 0f,
    198                 Float.MIN_VALUE, 2f, Float.MAX_VALUE, Float.POSITIVE_INFINITY,
    199                 Float.NaN };
    200         for (int i = 0; i < specials.length; i++) {
    201             int result = Arrays.binarySearch(specials, specials[i]);
    202             assertTrue(specials[i] + " invalid: " + result, result == i);
    203         }
    204         assertEquals("-1f", -4, Arrays.binarySearch(specials, -1f));
    205         assertEquals("1f", -8, Arrays.binarySearch(specials, 1f));
    206     }
    207 
    208     /**
    209      * java.util.Arrays#binarySearch(int[], int)
    210      */
    211     public void test_binarySearch$II() {
    212         // Test for method int java.util.Arrays.binarySearch(int [], int)
    213         for (int counter = 0; counter < arraySize; counter++)
    214             assertTrue("Binary search on int[] answered incorrect position",
    215                     Arrays.binarySearch(intArray, counter) == counter);
    216         assertEquals("Binary search succeeded for value not present in array 1",
    217                 -1, Arrays.binarySearch(intArray, -1));
    218         assertTrue("Binary search succeeded for value not present in array 2",
    219                 Arrays.binarySearch(intArray, arraySize) == -(arraySize + 1));
    220         for (int counter = 0; counter < arraySize; counter++)
    221             intArray[counter] -= 50;
    222         for (int counter = 0; counter < arraySize; counter++)
    223             assertTrue(
    224                     "Binary search on int[] involving negative numbers answered incorrect position",
    225                     Arrays.binarySearch(intArray, counter - 50) == counter);
    226     }
    227 
    228     /**
    229      * java.util.Arrays#binarySearch(long[], long)
    230      */
    231     public void test_binarySearch$JJ() {
    232         // Test for method int java.util.Arrays.binarySearch(long [], long)
    233         for (long counter = 0; counter < arraySize; counter++)
    234             assertTrue("Binary search on long[] answered incorrect position",
    235                     Arrays.binarySearch(longArray, counter) == counter);
    236         assertEquals("Binary search succeeded for value not present in array 1",
    237                 -1, Arrays.binarySearch(longArray, (long) -1));
    238         assertTrue(
    239                 "Binary search succeeded for value not present in array 2",
    240                 Arrays.binarySearch(longArray, (long) arraySize) == -(arraySize + 1));
    241         for (long counter = 0; counter < arraySize; counter++)
    242             longArray[(int) counter] -= (long) 50;
    243         for (long counter = 0; counter < arraySize; counter++)
    244             assertTrue(
    245                     "Binary search on long[] involving negative numbers answered incorrect position",
    246                     Arrays.binarySearch(longArray, counter - (long) 50) == counter);
    247     }
    248 
    249     /**
    250      * java.util.Arrays#binarySearch(java.lang.Object[],
    251      *        java.lang.Object)
    252      */
    253     public void test_binarySearch$Ljava_lang_ObjectLjava_lang_Object() {
    254         // Test for method int java.util.Arrays.binarySearch(java.lang.Object
    255         // [], java.lang.Object)
    256         assertEquals(
    257                 "Binary search succeeded for non-comparable value in empty array",
    258                 -1, Arrays.binarySearch(new Object[] {}, new Object()));
    259         assertEquals(
    260                 "Binary search succeeded for comparable value in empty array",
    261                 -1, Arrays.binarySearch(new Object[] {}, new Integer(-1)));
    262         for (int counter = 0; counter < arraySize; counter++)
    263             assertTrue(
    264                     "Binary search on Object[] answered incorrect position",
    265                     Arrays.binarySearch(objectArray, objArray[counter]) == counter);
    266         assertEquals("Binary search succeeded for value not present in array 1",
    267                 -1, Arrays.binarySearch(objectArray, new Integer(-1)));
    268         assertTrue(
    269                 "Binary search succeeded for value not present in array 2",
    270                 Arrays.binarySearch(objectArray, new Integer(arraySize)) == -(arraySize + 1));
    271 
    272         Object object = new Object();
    273         Object[] objects = new MockComparable[] { new MockComparable() };
    274         assertEquals("Should always return 0", 0, Arrays.binarySearch(objects, object));
    275 
    276         Object[] string_objects = new String[] { "one" };
    277         try {
    278             Arrays.binarySearch(string_objects, object);
    279             fail("No expected ClassCastException");
    280         } catch (ClassCastException e) {
    281             // Expected
    282         }
    283     }
    284 
    285     /**
    286      * java.util.Arrays#binarySearch(java.lang.Object[],
    287      *        java.lang.Object, java.util.Comparator)
    288      */
    289     public void test_binarySearch$Ljava_lang_ObjectLjava_lang_ObjectLjava_util_Comparator() {
    290         // Test for method int java.util.Arrays.binarySearch(java.lang.Object
    291         // [], java.lang.Object, java.util.Comparator)
    292         Comparator comp = new ReversedIntegerComparator();
    293         for (int counter = 0; counter < arraySize; counter++)
    294             objectArray[counter] = objArray[arraySize - counter - 1];
    295         assertTrue(
    296                 "Binary search succeeded for value not present in array 1",
    297                 Arrays.binarySearch(objectArray, new Integer(-1), comp) == -(arraySize + 1));
    298         assertEquals("Binary search succeeded for value not present in array 2",
    299                 -1, Arrays.binarySearch(objectArray, new Integer(arraySize), comp));
    300         for (int counter = 0; counter < arraySize; counter++)
    301             assertTrue(
    302                     "Binary search on Object[] with custom comparator answered incorrect position",
    303                     Arrays.binarySearch(objectArray, objArray[counter], comp) == arraySize
    304                             - counter - 1);
    305     }
    306 
    307     /**
    308      * java.util.Arrays#binarySearch(short[], short)
    309      */
    310     public void test_binarySearch$SS() {
    311         // Test for method int java.util.Arrays.binarySearch(short [], short)
    312         for (short counter = 0; counter < arraySize; counter++)
    313             assertTrue("Binary search on short[] answered incorrect position",
    314                     Arrays.binarySearch(shortArray, counter) == counter);
    315         assertEquals("Binary search succeeded for value not present in array 1",
    316                 -1, Arrays.binarySearch(intArray, (short) -1));
    317         assertTrue(
    318                 "Binary search succeeded for value not present in array 2",
    319                 Arrays.binarySearch(intArray, (short) arraySize) == -(arraySize + 1));
    320         for (short counter = 0; counter < arraySize; counter++)
    321             shortArray[counter] -= 50;
    322         for (short counter = 0; counter < arraySize; counter++)
    323             assertTrue(
    324                     "Binary search on short[] involving negative numbers answered incorrect position",
    325                     Arrays.binarySearch(shortArray, (short) (counter - 50)) == counter);
    326     }
    327 
    328     public void test_Arrays_binaraySearch_byte() {
    329         assertEquals(-1, Arrays.binarySearch(new byte[] { '0' }, 0, 0,
    330                 (byte) '1'));
    331         assertEquals(-2, Arrays.binarySearch(new byte[] { '0' }, 1, 1,
    332                 (byte) '1'));
    333         assertEquals(-2, Arrays.binarySearch(new byte[] { '0', '1' }, 1, 1,
    334                 (byte) '2'));
    335         assertEquals(-3, Arrays.binarySearch(new byte[] { '0', '1' }, 2, 2,
    336                 (byte) '2'));
    337     }
    338 
    339     public void test_Arrays_binaraySearch_char() {
    340         assertEquals(-1, Arrays.binarySearch(new char[] { '0' }, 0, 0, '1'));
    341         assertEquals(-2, Arrays.binarySearch(new char[] { '0' }, 1, 1, '1'));
    342         assertEquals(-2, Arrays
    343                 .binarySearch(new char[] { '0', '1' }, 1, 1, '2'));
    344         assertEquals(-3, Arrays
    345                 .binarySearch(new char[] { '0', '1' }, 2, 2, '2'));
    346     }
    347 
    348     public void test_Arrays_binaraySearch_float() {
    349         assertEquals(-1, Arrays.binarySearch(new float[] { -1.0f }, 0, 0, 0.0f));
    350         assertEquals(-2, Arrays.binarySearch(new float[] { -1.0f }, 1, 1, 0.0f));
    351         assertEquals(-2, Arrays.binarySearch(new float[] { -1.0f, 0f }, 1, 1,
    352                 1f));
    353         assertEquals(-3, Arrays.binarySearch(new float[] { -1.0f, 0f }, 2, 2,
    354                 1f));
    355     }
    356 
    357     public void test_Arrays_binaraySearch_double() {
    358         assertEquals(-1, Arrays.binarySearch(new double[] { -1.0 }, 0, 0, 0.0));
    359         assertEquals(-2, Arrays.binarySearch(new double[] { -1.0 }, 1, 1, 0.0));
    360         assertEquals(-2, Arrays.binarySearch(new double[] { -1.0, 0 }, 1, 1, 1));
    361         assertEquals(-3, Arrays.binarySearch(new double[] { -1.0, 0 }, 2, 2, 1));
    362     }
    363 
    364     public void test_Arrays_binaraySearch_int() {
    365         assertEquals(-1, Arrays.binarySearch(new int[] { -1 }, 0, 0, 0));
    366         assertEquals(-2, Arrays.binarySearch(new int[] { -1 }, 1, 1, 0));
    367         assertEquals(-2, Arrays.binarySearch(new int[] { -1, 0 }, 1, 1, 1));
    368         assertEquals(-3, Arrays.binarySearch(new int[] { -1, 0 }, 2, 2, 1));
    369     }
    370 
    371     public void test_Arrays_binaraySearch_long() {
    372         assertEquals(-1, Arrays.binarySearch(new long[] { -1l }, 0, 0, 0l));
    373         assertEquals(-2, Arrays.binarySearch(new long[] { -1l }, 1, 1, 0l));
    374         assertEquals(-2, Arrays.binarySearch(new long[] { -1l, 0l }, 1, 1, 1l));
    375         assertEquals(-3, Arrays.binarySearch(new long[] { -1l, 0l }, 2, 2, 1l));
    376     }
    377 
    378     public void test_Arrays_binaraySearch_short() {
    379         assertEquals(-1, Arrays.binarySearch(new short[] { (short) -1 }, 0, 0,
    380                 (short) 0));
    381         assertEquals(-2, Arrays.binarySearch(new short[] { (short) -1 }, 1, 1,
    382                 (short) 0));
    383         assertEquals(-2, Arrays.binarySearch(new short[] { (short) -1,
    384                 (short) 0 }, 1, 1, (short) 1));
    385         assertEquals(-3, Arrays.binarySearch(new short[] { (short) -1,
    386                 (short) 0 }, 2, 2, (short) 1));
    387     }
    388 
    389     public void test_Arrays_binaraySearch_Object() {
    390         assertEquals(-1, Arrays.binarySearch(new Object[] { new Integer(-1) },
    391                 0, 0, new Integer(0)));
    392         assertEquals(-2, Arrays.binarySearch(new Object[] { new Integer(-1) },
    393                 1, 1, new Integer(0)));
    394         assertEquals(-2, Arrays.binarySearch(new Object[] { new Integer(-1),
    395                 new Integer(0) }, 1, 1, new Integer(1)));
    396         assertEquals(-3, Arrays.binarySearch(new Object[] { new Integer(-1),
    397                 new Integer(0) }, 2, 2, new Integer(1)));
    398     }
    399 
    400     public void test_Arrays_binaraySearch_T() {
    401         ReversedIntegerComparator reversedComparator = new ReversedIntegerComparator();
    402         assertEquals(-1, Arrays.binarySearch(new Integer[] { new Integer(-1) },
    403                 0, 0, new Integer(0), reversedComparator));
    404         assertEquals(-2, Arrays.binarySearch(new Integer[] { new Integer(-1) },
    405                 1, 1, new Integer(0), reversedComparator));
    406         assertEquals(-2, Arrays.binarySearch(new Integer[] { new Integer(-1),
    407                 new Integer(0) }, 1, 1, new Integer(1), reversedComparator));
    408         assertEquals(-3, Arrays.binarySearch(new Integer[] { new Integer(-1),
    409                 new Integer(0) }, 2, 2, new Integer(1), reversedComparator));
    410     }
    411 
    412     /**
    413      * java.util.Arrays#fill(byte[], byte)
    414      */
    415     public void test_fill$BB() {
    416         // Test for method void java.util.Arrays.fill(byte [], byte)
    417 
    418         byte d[] = new byte[1000];
    419         Arrays.fill(d, Byte.MAX_VALUE);
    420         for (int i = 0; i < d.length; i++)
    421             assertTrue("Failed to fill byte array correctly",
    422                     d[i] == Byte.MAX_VALUE);
    423     }
    424 
    425     /**
    426      * java.util.Arrays#fill(byte[], int, int, byte)
    427      */
    428     public void test_fill$BIIB() {
    429         // Test for method void java.util.Arrays.fill(byte [], int, int, byte)
    430         byte val = Byte.MAX_VALUE;
    431         byte d[] = new byte[1000];
    432         Arrays.fill(d, 400, d.length, val);
    433         for (int i = 0; i < 400; i++)
    434             assertTrue("Filled elements not in range", !(d[i] == val));
    435         for (int i = 400; i < d.length; i++)
    436             assertTrue("Failed to fill byte array correctly", d[i] == val);
    437 
    438         int result;
    439         try {
    440             Arrays.fill(new byte[2], 2, 1, (byte) 27);
    441             result = 0;
    442         } catch (ArrayIndexOutOfBoundsException e) {
    443             result = 1;
    444         } catch (IllegalArgumentException e) {
    445             result = 2;
    446         }
    447         assertEquals("Wrong exception1", 2, result);
    448         try {
    449             Arrays.fill(new byte[2], -1, 1, (byte) 27);
    450             result = 0;
    451         } catch (ArrayIndexOutOfBoundsException e) {
    452             result = 1;
    453         } catch (IllegalArgumentException e) {
    454             result = 2;
    455         }
    456         assertEquals("Wrong exception2", 1, result);
    457         try {
    458             Arrays.fill(new byte[2], 1, 4, (byte) 27);
    459             result = 0;
    460         } catch (ArrayIndexOutOfBoundsException e) {
    461             result = 1;
    462         } catch (IllegalArgumentException e) {
    463             result = 2;
    464         }
    465         assertEquals("Wrong exception", 1, result);
    466     }
    467 
    468     /**
    469      * java.util.Arrays#fill(short[], short)
    470      */
    471     public void test_fill$SS() {
    472         // Test for method void java.util.Arrays.fill(short [], short)
    473 
    474         short d[] = new short[1000];
    475         Arrays.fill(d, Short.MAX_VALUE);
    476         for (int i = 0; i < d.length; i++)
    477             assertTrue("Failed to fill short array correctly",
    478                     d[i] == Short.MAX_VALUE);
    479     }
    480 
    481     /**
    482      * java.util.Arrays#fill(short[], int, int, short)
    483      */
    484     public void test_fill$SIIS() {
    485         // Test for method void java.util.Arrays.fill(short [], int, int, short)
    486         short val = Short.MAX_VALUE;
    487         short d[] = new short[1000];
    488         Arrays.fill(d, 400, d.length, val);
    489         for (int i = 0; i < 400; i++)
    490             assertTrue("Filled elements not in range", !(d[i] == val));
    491         for (int i = 400; i < d.length; i++)
    492             assertTrue("Failed to fill short array correctly", d[i] == val);
    493 
    494         try {
    495             Arrays.fill(d, 10, 0, val);
    496             fail("IllegalArgumentException expected");
    497         } catch (IllegalArgumentException e) {
    498             //expected
    499         }
    500 
    501         try {
    502             Arrays.fill(d, -10, 0, val);
    503             fail("ArrayIndexOutOfBoundsException expected");
    504         } catch (ArrayIndexOutOfBoundsException e) {
    505             //expected
    506         }
    507 
    508         try {
    509             Arrays.fill(d, 10, d.length+1, val);
    510             fail("ArrayIndexOutOfBoundsException expected");
    511         } catch (ArrayIndexOutOfBoundsException e) {
    512             //expected
    513         }
    514     }
    515 
    516     /**
    517      * java.util.Arrays#fill(char[], char)
    518      */
    519     public void test_fill$CC() {
    520         // Test for method void java.util.Arrays.fill(char [], char)
    521 
    522         char d[] = new char[1000];
    523         Arrays.fill(d, 'V');
    524         for (int i = 0; i < d.length; i++)
    525             assertEquals("Failed to fill char array correctly", 'V', d[i]);
    526     }
    527 
    528     /**
    529      * java.util.Arrays#fill(char[], int, int, char)
    530      */
    531     public void test_fill$CIIC() {
    532         // Test for method void java.util.Arrays.fill(char [], int, int, char)
    533         char val = 'T';
    534         char d[] = new char[1000];
    535         Arrays.fill(d, 400, d.length, val);
    536         for (int i = 0; i < 400; i++)
    537             assertTrue("Filled elements not in range", !(d[i] == val));
    538         for (int i = 400; i < d.length; i++)
    539             assertTrue("Failed to fill char array correctly", d[i] == val);
    540 
    541         try {
    542             Arrays.fill(d, 10, 0, val);
    543             fail("IllegalArgumentException expected");
    544         } catch (IllegalArgumentException e) {
    545             //expected
    546         }
    547 
    548         try {
    549             Arrays.fill(d, -10, 0, val);
    550             fail("ArrayIndexOutOfBoundsException expected");
    551         } catch (ArrayIndexOutOfBoundsException e) {
    552             //expected
    553         }
    554 
    555         try {
    556             Arrays.fill(d, 10, d.length+1, val);
    557             fail("ArrayIndexOutOfBoundsException expected");
    558         } catch (ArrayIndexOutOfBoundsException e) {
    559             //expected
    560         }
    561     }
    562 
    563     /**
    564      * java.util.Arrays#fill(int[], int)
    565      */
    566     public void test_fill$II() {
    567         // Test for method void java.util.Arrays.fill(int [], int)
    568 
    569         int d[] = new int[1000];
    570         Arrays.fill(d, Integer.MAX_VALUE);
    571         for (int i = 0; i < d.length; i++)
    572             assertTrue("Failed to fill int array correctly",
    573                     d[i] == Integer.MAX_VALUE);
    574     }
    575 
    576     /**
    577      * java.util.Arrays#fill(int[], int, int, int)
    578      */
    579     public void test_fill$IIII() {
    580         // Test for method void java.util.Arrays.fill(int [], int, int, int)
    581         int val = Integer.MAX_VALUE;
    582         int d[] = new int[1000];
    583         Arrays.fill(d, 400, d.length, val);
    584         for (int i = 0; i < 400; i++)
    585             assertTrue("Filled elements not in range", !(d[i] == val));
    586         for (int i = 400; i < d.length; i++)
    587             assertTrue("Failed to fill int array correctly", d[i] == val);
    588 
    589         try {
    590             Arrays.fill(d, 10, 0, val);
    591             fail("IllegalArgumentException expected");
    592         } catch (IllegalArgumentException e) {
    593             //expected
    594         }
    595 
    596         try {
    597             Arrays.fill(d, -10, 0, val);
    598             fail("ArrayIndexOutOfBoundsException expected");
    599         } catch (ArrayIndexOutOfBoundsException e) {
    600             //expected
    601         }
    602 
    603         try {
    604             Arrays.fill(d, 10, d.length+1, val);
    605             fail("ArrayIndexOutOfBoundsException expected");
    606         } catch (ArrayIndexOutOfBoundsException e) {
    607             //expected
    608         }
    609     }
    610 
    611     /**
    612      * java.util.Arrays#fill(long[], long)
    613      */
    614     public void test_fill$JJ() {
    615         // Test for method void java.util.Arrays.fill(long [], long)
    616 
    617         long d[] = new long[1000];
    618         Arrays.fill(d, Long.MAX_VALUE);
    619         for (int i = 0; i < d.length; i++)
    620             assertTrue("Failed to fill long array correctly",
    621                     d[i] == Long.MAX_VALUE);
    622     }
    623 
    624     /**
    625      * java.util.Arrays#fill(long[], int, int, long)
    626      */
    627     public void test_fill$JIIJ() {
    628         // Test for method void java.util.Arrays.fill(long [], int, int, long)
    629         long d[] = new long[1000];
    630         Arrays.fill(d, 400, d.length, Long.MAX_VALUE);
    631         for (int i = 0; i < 400; i++)
    632             assertTrue("Filled elements not in range", !(d[i] == Long.MAX_VALUE));
    633         for (int i = 400; i < d.length; i++)
    634             assertTrue("Failed to fill long array correctly",
    635                     d[i] == Long.MAX_VALUE);
    636 
    637         try {
    638             Arrays.fill(d, 10, 0, Long.MIN_VALUE);
    639             fail("IllegalArgumentException expected");
    640         } catch (IllegalArgumentException e) {
    641             //expected
    642         }
    643 
    644         try {
    645             Arrays.fill(d, -10, 0, Long.MAX_VALUE);
    646             fail("ArrayIndexOutOfBoundsException expected");
    647         } catch (ArrayIndexOutOfBoundsException e) {
    648             //expected
    649         }
    650 
    651         try {
    652             Arrays.fill(d, 10, d.length+1, Long.MAX_VALUE);
    653             fail("ArrayIndexOutOfBoundsException expected");
    654         } catch (ArrayIndexOutOfBoundsException e) {
    655             //expected
    656         }
    657     }
    658 
    659     /**
    660      * java.util.Arrays#fill(float[], float)
    661      */
    662     public void test_fill$FF() {
    663         // Test for method void java.util.Arrays.fill(float [], float)
    664         float d[] = new float[1000];
    665         Arrays.fill(d, Float.MAX_VALUE);
    666         for (int i = 0; i < d.length; i++)
    667             assertTrue("Failed to fill float array correctly",
    668                     d[i] == Float.MAX_VALUE);
    669     }
    670 
    671     /**
    672      * java.util.Arrays#fill(float[], int, int, float)
    673      */
    674     public void test_fill$FIIF() {
    675         // Test for method void java.util.Arrays.fill(float [], int, int, float)
    676         float val = Float.MAX_VALUE;
    677         float d[] = new float[1000];
    678         Arrays.fill(d, 400, d.length, val);
    679         for (int i = 0; i < 400; i++)
    680             assertTrue("Filled elements not in range", !(d[i] == val));
    681         for (int i = 400; i < d.length; i++)
    682             assertTrue("Failed to fill float array correctly", d[i] == val);
    683 
    684         try {
    685             Arrays.fill(d, 10, 0, val);
    686             fail("IllegalArgumentException expected");
    687         } catch (IllegalArgumentException e) {
    688             //expected
    689         }
    690 
    691         try {
    692             Arrays.fill(d, -10, 0, val);
    693             fail("ArrayIndexOutOfBoundsException expected");
    694         } catch (ArrayIndexOutOfBoundsException e) {
    695             //expected
    696         }
    697 
    698         try {
    699             Arrays.fill(d, 10, d.length+1, val);
    700             fail("ArrayIndexOutOfBoundsException expected");
    701         } catch (ArrayIndexOutOfBoundsException e) {
    702             //expected
    703         }
    704     }
    705 
    706     /**
    707      * java.util.Arrays#fill(double[], double)
    708      */
    709     public void test_fill$DD() {
    710         // Test for method void java.util.Arrays.fill(double [], double)
    711 
    712         double d[] = new double[1000];
    713         Arrays.fill(d, Double.MAX_VALUE);
    714         for (int i = 0; i < d.length; i++)
    715             assertTrue("Failed to fill double array correctly",
    716                     d[i] == Double.MAX_VALUE);
    717     }
    718 
    719     /**
    720      * java.util.Arrays#fill(double[], int, int, double)
    721      */
    722     public void test_fill$DIID() {
    723         // Test for method void java.util.Arrays.fill(double [], int, int,
    724         // double)
    725         double val = Double.MAX_VALUE;
    726         double d[] = new double[1000];
    727         Arrays.fill(d, 400, d.length, val);
    728         for (int i = 0; i < 400; i++)
    729             assertTrue("Filled elements not in range", !(d[i] == val));
    730         for (int i = 400; i < d.length; i++)
    731             assertTrue("Failed to fill double array correctly", d[i] == val);
    732 
    733         try {
    734             Arrays.fill(d, 10, 0, val);
    735             fail("IllegalArgumentException expected");
    736         } catch (IllegalArgumentException e) {
    737             //expected
    738         }
    739 
    740         try {
    741             Arrays.fill(d, -10, 0, val);
    742             fail("ArrayIndexOutOfBoundsException expected");
    743         } catch (ArrayIndexOutOfBoundsException e) {
    744             //expected
    745         }
    746 
    747         try {
    748             Arrays.fill(d, 10, d.length+1, val);
    749             fail("ArrayIndexOutOfBoundsException expected");
    750         } catch (ArrayIndexOutOfBoundsException e) {
    751             //expected
    752         }
    753     }
    754 
    755     /**
    756      * java.util.Arrays#fill(boolean[], boolean)
    757      */
    758     public void test_fill$ZZ() {
    759         // Test for method void java.util.Arrays.fill(boolean [], boolean)
    760 
    761         boolean d[] = new boolean[1000];
    762         Arrays.fill(d, true);
    763         for (int i = 0; i < d.length; i++)
    764             assertTrue("Failed to fill boolean array correctly", d[i]);
    765     }
    766 
    767     /**
    768      * java.util.Arrays#fill(boolean[], int, int, boolean)
    769      */
    770     public void test_fill$ZIIZ() {
    771         // Test for method void java.util.Arrays.fill(boolean [], int, int,
    772         // boolean)
    773         boolean val = true;
    774         boolean d[] = new boolean[1000];
    775         Arrays.fill(d, 400, d.length, val);
    776         for (int i = 0; i < 400; i++)
    777             assertTrue("Filled elements not in range", !(d[i] == val));
    778         for (int i = 400; i < d.length; i++)
    779             assertTrue("Failed to fill boolean array correctly", d[i] == val);
    780 
    781         try {
    782             Arrays.fill(d, 10, 0, val);
    783             fail("IllegalArgumentException expected");
    784         } catch (IllegalArgumentException e) {
    785             //expected
    786         }
    787 
    788         try {
    789             Arrays.fill(d, -10, 0, val);
    790             fail("ArrayIndexOutOfBoundsException expected");
    791         } catch (ArrayIndexOutOfBoundsException e) {
    792             //expected
    793         }
    794 
    795         try {
    796             Arrays.fill(d, 10, d.length+1, val);
    797             fail("ArrayIndexOutOfBoundsException expected");
    798         } catch (ArrayIndexOutOfBoundsException e) {
    799             //expected
    800         }
    801     }
    802 
    803     /**
    804      * java.util.Arrays#fill(java.lang.Object[], java.lang.Object)
    805      */
    806     public void test_fill$Ljava_lang_ObjectLjava_lang_Object() {
    807         // Test for method void java.util.Arrays.fill(java.lang.Object [],
    808         // java.lang.Object)
    809         Object val = new Object();
    810         Object d[] = new Object[1000];
    811         Arrays.fill(d, 0, d.length, val);
    812         for (int i = 0; i < d.length; i++)
    813             assertTrue("Failed to fill Object array correctly", d[i] == val);
    814     }
    815 
    816     /**
    817      * java.util.Arrays#fill(java.lang.Object[], int, int,
    818      *        java.lang.Object)
    819      */
    820     public void test_fill$Ljava_lang_ObjectIILjava_lang_Object() {
    821         // Test for method void java.util.Arrays.fill(java.lang.Object [], int,
    822         // int, java.lang.Object)
    823         Object val = new Object();
    824         Object d[] = new Object[1000];
    825         Arrays.fill(d, 400, d.length, val);
    826         for (int i = 0; i < 400; i++)
    827             assertTrue("Filled elements not in range", !(d[i] == val));
    828         for (int i = 400; i < d.length; i++)
    829             assertTrue("Failed to fill Object array correctly", d[i] == val);
    830 
    831         Arrays.fill(d, 400, d.length, null);
    832         for (int i = 400; i < d.length; i++)
    833             assertNull("Failed to fill Object array correctly with nulls",
    834                     d[i]);
    835 
    836         try {
    837             Arrays.fill(d, 10, 0, val);
    838             fail("IllegalArgumentException expected");
    839         } catch (IllegalArgumentException e) {
    840             //expected
    841         }
    842 
    843         try {
    844             Arrays.fill(d, -10, 0, val);
    845             fail("ArrayIndexOutOfBoundsException expected");
    846         } catch (ArrayIndexOutOfBoundsException e) {
    847             //expected
    848         }
    849 
    850         try {
    851             Arrays.fill(d, 10, d.length+1, val);
    852             fail("ArrayIndexOutOfBoundsException expected");
    853         } catch (ArrayIndexOutOfBoundsException e) {
    854             //expected
    855         }
    856     }
    857 
    858     /**
    859      * java.util.Arrays#equals(byte[], byte[])
    860      */
    861     public void test_equals$B$B() {
    862         // Test for method boolean java.util.Arrays.equals(byte [], byte [])
    863         byte d[] = new byte[1000];
    864         byte x[] = new byte[1000];
    865         Arrays.fill(d, Byte.MAX_VALUE);
    866         Arrays.fill(x, Byte.MIN_VALUE);
    867         assertTrue("Inequal arrays returned true", !Arrays.equals(d, x));
    868         Arrays.fill(x, Byte.MAX_VALUE);
    869         assertTrue("equal arrays returned false", Arrays.equals(d, x));
    870     }
    871 
    872     /**
    873      * java.util.Arrays#equals(short[], short[])
    874      */
    875     public void test_equals$S$S() {
    876         // Test for method boolean java.util.Arrays.equals(short [], short [])
    877         short d[] = new short[1000];
    878         short x[] = new short[1000];
    879         Arrays.fill(d, Short.MAX_VALUE);
    880         Arrays.fill(x, Short.MIN_VALUE);
    881         assertTrue("Inequal arrays returned true", !Arrays.equals(d, x));
    882         Arrays.fill(x, Short.MAX_VALUE);
    883         assertTrue("equal arrays returned false", Arrays.equals(d, x));
    884     }
    885 
    886     /**
    887      * java.util.Arrays#equals(char[], char[])
    888      */
    889     public void test_equals$C$C() {
    890         // Test for method boolean java.util.Arrays.equals(char [], char [])
    891         char d[] = new char[1000];
    892         char x[] = new char[1000];
    893         char c = 'T';
    894         Arrays.fill(d, c);
    895         Arrays.fill(x, 'L');
    896         assertTrue("Inequal arrays returned true", !Arrays.equals(d, x));
    897         Arrays.fill(x, c);
    898         assertTrue("equal arrays returned false", Arrays.equals(d, x));
    899     }
    900 
    901     /**
    902      * java.util.Arrays#equals(int[], int[])
    903      */
    904     public void test_equals$I$I() {
    905         // Test for method boolean java.util.Arrays.equals(int [], int [])
    906         int d[] = new int[1000];
    907         int x[] = new int[1000];
    908         Arrays.fill(d, Integer.MAX_VALUE);
    909         Arrays.fill(x, Integer.MIN_VALUE);
    910         assertTrue("Inequal arrays returned true", !Arrays.equals(d, x));
    911         Arrays.fill(x, Integer.MAX_VALUE);
    912         assertTrue("equal arrays returned false", Arrays.equals(d, x));
    913 
    914         assertTrue("wrong result for null array1", !Arrays.equals(new int[2],
    915                 null));
    916         assertTrue("wrong result for null array2", !Arrays.equals(null,
    917                 new int[2]));
    918     }
    919 
    920     /**
    921      * java.util.Arrays#equals(long[], long[])
    922      */
    923     public void test_equals$J$J() {
    924         // Test for method boolean java.util.Arrays.equals(long [], long [])
    925         long d[] = new long[1000];
    926         long x[] = new long[1000];
    927         Arrays.fill(d, Long.MAX_VALUE);
    928         Arrays.fill(x, Long.MIN_VALUE);
    929         assertTrue("Inequal arrays returned true", !Arrays.equals(d, x));
    930         Arrays.fill(x, Long.MAX_VALUE);
    931         assertTrue("equal arrays returned false", Arrays.equals(d, x));
    932 
    933         assertTrue("should be false", !Arrays.equals(
    934                 new long[] { 0x100000000L }, new long[] { 0x200000000L }));
    935 
    936     }
    937 
    938     /**
    939      * java.util.Arrays#equals(float[], float[])
    940      */
    941     public void test_equals$F$F() {
    942         // Test for method boolean java.util.Arrays.equals(float [], float [])
    943         float d[] = new float[1000];
    944         float x[] = new float[1000];
    945         Arrays.fill(d, Float.MAX_VALUE);
    946         Arrays.fill(x, Float.MIN_VALUE);
    947         assertTrue("Inequal arrays returned true", !Arrays.equals(d, x));
    948         Arrays.fill(x, Float.MAX_VALUE);
    949         assertTrue("equal arrays returned false", Arrays.equals(d, x));
    950 
    951         assertTrue("NaN not equals", Arrays.equals(new float[] { Float.NaN },
    952                 new float[] { Float.NaN }));
    953         assertTrue("0f equals -0f", !Arrays.equals(new float[] { 0f },
    954                 new float[] { -0f }));
    955     }
    956 
    957     /**
    958      * java.util.Arrays#equals(double[], double[])
    959      */
    960     public void test_equals$D$D() {
    961         // Test for method boolean java.util.Arrays.equals(double [], double [])
    962         double d[] = new double[1000];
    963         double x[] = new double[1000];
    964         Arrays.fill(d, Double.MAX_VALUE);
    965         Arrays.fill(x, Double.MIN_VALUE);
    966         assertTrue("Inequal arrays returned true", !Arrays.equals(d, x));
    967         Arrays.fill(x, Double.MAX_VALUE);
    968         assertTrue("equal arrays returned false", Arrays.equals(d, x));
    969 
    970         assertTrue("should be false", !Arrays.equals(new double[] { 1.0 },
    971                 new double[] { 2.0 }));
    972 
    973         assertTrue("NaN not equals", Arrays.equals(new double[] { Double.NaN },
    974                 new double[] { Double.NaN }));
    975         assertTrue("0d equals -0d", !Arrays.equals(new double[] { 0d },
    976                 new double[] { -0d }));
    977     }
    978 
    979     /**
    980      * java.util.Arrays#equals(boolean[], boolean[])
    981      */
    982     public void test_equals$Z$Z() {
    983         // Test for method boolean java.util.Arrays.equals(boolean [], boolean
    984         // [])
    985         boolean d[] = new boolean[1000];
    986         boolean x[] = new boolean[1000];
    987         Arrays.fill(d, true);
    988         Arrays.fill(x, false);
    989         assertTrue("Inequal arrays returned true", !Arrays.equals(d, x));
    990         Arrays.fill(x, true);
    991         assertTrue("equal arrays returned false", Arrays.equals(d, x));
    992     }
    993 
    994     /**
    995      * java.util.Arrays#equals(java.lang.Object[], java.lang.Object[])
    996      */
    997     public void test_equals$Ljava_lang_Object$Ljava_lang_Object() {
    998         // Test for method boolean java.util.Arrays.equals(java.lang.Object [],
    999         // java.lang.Object [])
   1000         Object d[] = new Object[1000];
   1001         Object x[] = new Object[1000];
   1002         Object o = new Object();
   1003         Arrays.fill(d, o);
   1004         Arrays.fill(x, new Object());
   1005         assertTrue("Inequal arrays returned true", !Arrays.equals(d, x));
   1006         Arrays.fill(x, o);
   1007         d[50] = null;
   1008         x[50] = null;
   1009         assertTrue("equal arrays returned false", Arrays.equals(d, x));
   1010     }
   1011 
   1012     /**
   1013      * java.util.Arrays#sort(byte[])
   1014      */
   1015     public void test_sort$B() {
   1016         // Test for method void java.util.Arrays.sort(byte [])
   1017         byte[] reversedArray = new byte[arraySize];
   1018         for (int counter = 0; counter < arraySize; counter++)
   1019             reversedArray[counter] = (byte) (arraySize - counter - 1);
   1020         Arrays.sort(reversedArray);
   1021         for (int counter = 0; counter < arraySize; counter++)
   1022             assertTrue("Resulting array not sorted",
   1023                     reversedArray[counter] == (byte) counter);
   1024     }
   1025 
   1026     /**
   1027      * java.util.Arrays#sort(byte[], int, int)
   1028      */
   1029     public void test_sort$BII() {
   1030         // Test for method void java.util.Arrays.sort(byte [], int, int)
   1031         int startIndex = arraySize / 4;
   1032         int endIndex = 3 * arraySize / 4;
   1033         byte[] reversedArray = new byte[arraySize];
   1034         byte[] originalReversedArray = new byte[arraySize];
   1035         for (int counter = 0; counter < arraySize; counter++) {
   1036             reversedArray[counter] = (byte) (arraySize - counter - 1);
   1037             originalReversedArray[counter] = reversedArray[counter];
   1038         }
   1039         Arrays.sort(reversedArray, startIndex, endIndex);
   1040         for (int counter = 0; counter < startIndex; counter++)
   1041             assertTrue("Array modified outside of bounds",
   1042                     reversedArray[counter] == originalReversedArray[counter]);
   1043         for (int counter = startIndex; counter < endIndex - 1; counter++)
   1044             assertTrue("Array not sorted within bounds",
   1045                     reversedArray[counter] <= reversedArray[counter + 1]);
   1046         for (int counter = endIndex; counter < arraySize; counter++)
   1047             assertTrue("Array modified outside of bounds",
   1048                     reversedArray[counter] == originalReversedArray[counter]);
   1049 
   1050         //exception testing
   1051         try {
   1052             Arrays.sort(reversedArray, startIndex + 1, startIndex);
   1053             fail("IllegalArgumentException expected");
   1054         } catch (IllegalArgumentException ignore) {
   1055         }
   1056 
   1057         try {
   1058             Arrays.sort(reversedArray, -1, startIndex);
   1059             fail("ArrayIndexOutOfBoundsException expected (1)");
   1060         } catch (ArrayIndexOutOfBoundsException ignore) {
   1061         }
   1062 
   1063         try {
   1064             Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
   1065             fail("ArrayIndexOutOfBoundsException expected (2)");
   1066         } catch (ArrayIndexOutOfBoundsException ignore) {
   1067         }
   1068     }
   1069 
   1070     /**
   1071      * java.util.Arrays#sort(char[])
   1072      */
   1073     public void test_sort$C() {
   1074         // Test for method void java.util.Arrays.sort(char [])
   1075         char[] reversedArray = new char[arraySize];
   1076         for (int counter = 0; counter < arraySize; counter++)
   1077             reversedArray[counter] = (char) (arraySize - counter - 1);
   1078         Arrays.sort(reversedArray);
   1079         for (int counter = 0; counter < arraySize; counter++)
   1080             assertTrue("Resulting array not sorted",
   1081                     reversedArray[counter] == (char) counter);
   1082 
   1083     }
   1084 
   1085     /**
   1086      * java.util.Arrays#sort(char[], int, int)
   1087      */
   1088     public void test_sort$CII() {
   1089         // Test for method void java.util.Arrays.sort(char [], int, int)
   1090         int startIndex = arraySize / 4;
   1091         int endIndex = 3 * arraySize / 4;
   1092         char[] reversedArray = new char[arraySize];
   1093         char[] originalReversedArray = new char[arraySize];
   1094         for (int counter = 0; counter < arraySize; counter++) {
   1095             reversedArray[counter] = (char) (arraySize - counter - 1);
   1096             originalReversedArray[counter] = reversedArray[counter];
   1097         }
   1098         Arrays.sort(reversedArray, startIndex, endIndex);
   1099         for (int counter = 0; counter < startIndex; counter++)
   1100             assertTrue("Array modified outside of bounds",
   1101                     reversedArray[counter] == originalReversedArray[counter]);
   1102         for (int counter = startIndex; counter < endIndex - 1; counter++)
   1103             assertTrue("Array not sorted within bounds",
   1104                     reversedArray[counter] <= reversedArray[counter + 1]);
   1105         for (int counter = endIndex; counter < arraySize; counter++)
   1106             assertTrue("Array modified outside of bounds",
   1107                     reversedArray[counter] == originalReversedArray[counter]);
   1108 
   1109         //exception testing
   1110         try {
   1111             Arrays.sort(reversedArray, startIndex + 1, startIndex);
   1112             fail("IllegalArgumentException expected");
   1113         } catch (IllegalArgumentException ignore) {
   1114         }
   1115 
   1116         try {
   1117             Arrays.sort(reversedArray, -1, startIndex);
   1118             fail("ArrayIndexOutOfBoundsException expected (1)");
   1119         } catch (ArrayIndexOutOfBoundsException ignore) {
   1120         }
   1121 
   1122         try {
   1123             Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
   1124             fail("ArrayIndexOutOfBoundsException expected (2)");
   1125         } catch (ArrayIndexOutOfBoundsException ignore) {
   1126         }
   1127     }
   1128 
   1129     /**
   1130      * java.util.Arrays#sort(double[])
   1131      */
   1132     public void test_sort$D() {
   1133         // Test for method void java.util.Arrays.sort(double [])
   1134         double[] reversedArray = new double[arraySize];
   1135         for (int counter = 0; counter < arraySize; counter++)
   1136             reversedArray[counter] = (double) (arraySize - counter - 1);
   1137         Arrays.sort(reversedArray);
   1138         for (int counter = 0; counter < arraySize; counter++)
   1139             assertTrue("Resulting array not sorted",
   1140                     reversedArray[counter] == (double) counter);
   1141 
   1142         double[] specials1 = new double[] { Double.NaN, Double.MAX_VALUE,
   1143                 Double.MIN_VALUE, 0d, -0d, Double.POSITIVE_INFINITY,
   1144                 Double.NEGATIVE_INFINITY };
   1145         double[] specials2 = new double[] { 0d, Double.POSITIVE_INFINITY, -0d,
   1146                 Double.NEGATIVE_INFINITY, Double.MIN_VALUE, Double.NaN,
   1147                 Double.MAX_VALUE };
   1148         double[] specials3 = new double[] { 0.0, Double.NaN, 1.0, 2.0, Double.NaN,
   1149                 Double.NaN, 1.0, 3.0, -0.0 };
   1150         double[] answer = new double[] { Double.NEGATIVE_INFINITY, -0d, 0d,
   1151                 Double.MIN_VALUE, Double.MAX_VALUE, Double.POSITIVE_INFINITY,
   1152                 Double.NaN };
   1153         double[] answer3 = new double[] { -0.0, 0.0, 1.0, 1.0, 2.0, 3.0, Double.NaN,
   1154                 Double.NaN, Double.NaN };
   1155 
   1156         Arrays.sort(specials1);
   1157         Object[] print1 = new Object[specials1.length];
   1158         for (int i = 0; i < specials1.length; i++)
   1159             print1[i] = new Double(specials1[i]);
   1160         assertTrue("specials sort incorrectly 1: " + Arrays.asList(print1),
   1161                 Arrays.equals(specials1, answer));
   1162 
   1163         Arrays.sort(specials2);
   1164         Object[] print2 = new Object[specials2.length];
   1165         for (int i = 0; i < specials2.length; i++)
   1166             print2[i] = new Double(specials2[i]);
   1167         assertTrue("specials sort incorrectly 2: " + Arrays.asList(print2),
   1168                 Arrays.equals(specials2, answer));
   1169 
   1170         Arrays.sort(specials3);
   1171         Object[] print3 = new Object[specials3.length];
   1172         for (int i = 0; i < specials3.length; i++)
   1173             print3[i] = new Double(specials3[i]);
   1174         assertTrue("specials sort incorrectly 3: " + Arrays.asList(print3),
   1175                 Arrays.equals(specials3, answer3));
   1176     }
   1177 
   1178     /**
   1179      * java.util.Arrays#sort(double[], int, int)
   1180      */
   1181     public void test_sort$DII() {
   1182         // Test for method void java.util.Arrays.sort(double [], int, int)
   1183         int startIndex = arraySize / 4;
   1184         int endIndex = 3 * arraySize / 4;
   1185         double[] reversedArray = new double[arraySize];
   1186         double[] originalReversedArray = new double[arraySize];
   1187         for (int counter = 0; counter < arraySize; counter++) {
   1188             reversedArray[counter] = (double) (arraySize - counter - 1);
   1189             originalReversedArray[counter] = reversedArray[counter];
   1190         }
   1191         Arrays.sort(reversedArray, startIndex, endIndex);
   1192         for (int counter = 0; counter < startIndex; counter++)
   1193             assertTrue("Array modified outside of bounds",
   1194                     reversedArray[counter] == originalReversedArray[counter]);
   1195         for (int counter = startIndex; counter < endIndex - 1; counter++)
   1196             assertTrue("Array not sorted within bounds",
   1197                     reversedArray[counter] <= reversedArray[counter + 1]);
   1198         for (int counter = endIndex; counter < arraySize; counter++)
   1199             assertTrue("Array modified outside of bounds",
   1200                     reversedArray[counter] == originalReversedArray[counter]);
   1201 
   1202         //exception testing
   1203         try {
   1204             Arrays.sort(reversedArray, startIndex + 1, startIndex);
   1205             fail("IllegalArgumentException expected");
   1206         } catch (IllegalArgumentException ignore) {
   1207         }
   1208 
   1209         try {
   1210             Arrays.sort(reversedArray, -1, startIndex);
   1211             fail("ArrayIndexOutOfBoundsException expected (1)");
   1212         } catch (ArrayIndexOutOfBoundsException ignore) {
   1213         }
   1214 
   1215         try {
   1216             Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
   1217             fail("ArrayIndexOutOfBoundsException expected (2)");
   1218         } catch (ArrayIndexOutOfBoundsException ignore) {
   1219         }
   1220     }
   1221 
   1222     /**
   1223      * java.util.Arrays#sort(float[])
   1224      */
   1225     public void test_sort$F() {
   1226         // Test for method void java.util.Arrays.sort(float [])
   1227         float[] reversedArray = new float[arraySize];
   1228         for (int counter = 0; counter < arraySize; counter++)
   1229             reversedArray[counter] = (float) (arraySize - counter - 1);
   1230         Arrays.sort(reversedArray);
   1231         for (int counter = 0; counter < arraySize; counter++)
   1232             assertTrue("Resulting array not sorted",
   1233                     reversedArray[counter] == (float) counter);
   1234 
   1235         float[] specials1 = new float[] { Float.NaN, Float.MAX_VALUE,
   1236                 Float.MIN_VALUE, 0f, -0f, Float.POSITIVE_INFINITY,
   1237                 Float.NEGATIVE_INFINITY };
   1238         float[] specials2 = new float[] { 0f, Float.POSITIVE_INFINITY, -0f,
   1239                 Float.NEGATIVE_INFINITY, Float.MIN_VALUE, Float.NaN,
   1240                 Float.MAX_VALUE };
   1241         float[] answer = new float[] { Float.NEGATIVE_INFINITY, -0f, 0f,
   1242                 Float.MIN_VALUE, Float.MAX_VALUE, Float.POSITIVE_INFINITY,
   1243                 Float.NaN };
   1244 
   1245         Arrays.sort(specials1);
   1246         Object[] print1 = new Object[specials1.length];
   1247         for (int i = 0; i < specials1.length; i++)
   1248             print1[i] = new Float(specials1[i]);
   1249         assertTrue("specials sort incorrectly 1: " + Arrays.asList(print1),
   1250                 Arrays.equals(specials1, answer));
   1251 
   1252         Arrays.sort(specials2);
   1253         Object[] print2 = new Object[specials2.length];
   1254         for (int i = 0; i < specials2.length; i++)
   1255             print2[i] = new Float(specials2[i]);
   1256         assertTrue("specials sort incorrectly 2: " + Arrays.asList(print2),
   1257                 Arrays.equals(specials2, answer));
   1258     }
   1259 
   1260     /**
   1261      * java.util.Arrays#sort(float[], int, int)
   1262      */
   1263     public void test_sort$FII() {
   1264         // Test for method void java.util.Arrays.sort(float [], int, int)
   1265         int startIndex = arraySize / 4;
   1266         int endIndex = 3 * arraySize / 4;
   1267         float[] reversedArray = new float[arraySize];
   1268         float[] originalReversedArray = new float[arraySize];
   1269         for (int counter = 0; counter < arraySize; counter++) {
   1270             reversedArray[counter] = (float) (arraySize - counter - 1);
   1271             originalReversedArray[counter] = reversedArray[counter];
   1272         }
   1273         Arrays.sort(reversedArray, startIndex, endIndex);
   1274         for (int counter = 0; counter < startIndex; counter++)
   1275             assertTrue("Array modified outside of bounds",
   1276                     reversedArray[counter] == originalReversedArray[counter]);
   1277         for (int counter = startIndex; counter < endIndex - 1; counter++)
   1278             assertTrue("Array not sorted within bounds",
   1279                     reversedArray[counter] <= reversedArray[counter + 1]);
   1280         for (int counter = endIndex; counter < arraySize; counter++)
   1281             assertTrue("Array modified outside of bounds",
   1282                     reversedArray[counter] == originalReversedArray[counter]);
   1283 
   1284         //exception testing
   1285         try {
   1286             Arrays.sort(reversedArray, startIndex + 1, startIndex);
   1287             fail("IllegalArgumentException expected");
   1288         } catch (IllegalArgumentException ignore) {
   1289         }
   1290 
   1291         try {
   1292             Arrays.sort(reversedArray, -1, startIndex);
   1293             fail("ArrayIndexOutOfBoundsException expected (1)");
   1294         } catch (ArrayIndexOutOfBoundsException ignore) {
   1295         }
   1296 
   1297         try {
   1298             Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
   1299             fail("ArrayIndexOutOfBoundsException expected (2)");
   1300         } catch (ArrayIndexOutOfBoundsException ignore) {
   1301         }
   1302     }
   1303 
   1304     /**
   1305      * java.util.Arrays#sort(int[])
   1306      */
   1307     public void test_sort$I() {
   1308         // Test for method void java.util.Arrays.sort(int [])
   1309         int[] reversedArray = new int[arraySize];
   1310         for (int counter = 0; counter < arraySize; counter++)
   1311             reversedArray[counter] = arraySize - counter - 1;
   1312         Arrays.sort(reversedArray);
   1313         for (int counter = 0; counter < arraySize; counter++)
   1314             assertTrue("Resulting array not sorted",
   1315                     reversedArray[counter] == counter);
   1316     }
   1317 
   1318     /**
   1319      * java.util.Arrays#sort(int[], int, int)
   1320      */
   1321     public void test_sort$III() {
   1322         // Test for method void java.util.Arrays.sort(int [], int, int)
   1323         int startIndex = arraySize / 4;
   1324         int endIndex = 3 * arraySize / 4;
   1325         int[] reversedArray = new int[arraySize];
   1326         int[] originalReversedArray = new int[arraySize];
   1327         for (int counter = 0; counter < arraySize; counter++) {
   1328             reversedArray[counter] = arraySize - counter - 1;
   1329             originalReversedArray[counter] = reversedArray[counter];
   1330         }
   1331         Arrays.sort(reversedArray, startIndex, endIndex);
   1332         for (int counter = 0; counter < startIndex; counter++)
   1333             assertTrue("Array modified outside of bounds",
   1334                     reversedArray[counter] == originalReversedArray[counter]);
   1335         for (int counter = startIndex; counter < endIndex - 1; counter++)
   1336             assertTrue("Array not sorted within bounds",
   1337                     reversedArray[counter] <= reversedArray[counter + 1]);
   1338         for (int counter = endIndex; counter < arraySize; counter++)
   1339             assertTrue("Array modified outside of bounds",
   1340                     reversedArray[counter] == originalReversedArray[counter]);
   1341 
   1342         //exception testing
   1343         try {
   1344             Arrays.sort(reversedArray, startIndex + 1, startIndex);
   1345             fail("IllegalArgumentException expected");
   1346         } catch (IllegalArgumentException ignore) {
   1347         }
   1348 
   1349         try {
   1350             Arrays.sort(reversedArray, -1, startIndex);
   1351             fail("ArrayIndexOutOfBoundsException expected (1)");
   1352         } catch (ArrayIndexOutOfBoundsException ignore) {
   1353         }
   1354 
   1355         try {
   1356             Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
   1357             fail("ArrayIndexOutOfBoundsException expected (2)");
   1358         } catch (ArrayIndexOutOfBoundsException ignore) {
   1359         }
   1360     }
   1361 
   1362     /**
   1363      * java.util.Arrays#sort(long[])
   1364      */
   1365     public void test_sort$J() {
   1366         // Test for method void java.util.Arrays.sort(long [])
   1367         long[] reversedArray = new long[arraySize];
   1368         for (int counter = 0; counter < arraySize; counter++)
   1369             reversedArray[counter] = (long) (arraySize - counter - 1);
   1370         Arrays.sort(reversedArray);
   1371         for (int counter = 0; counter < arraySize; counter++)
   1372             assertTrue("Resulting array not sorted",
   1373                     reversedArray[counter] == (long) counter);
   1374 
   1375     }
   1376 
   1377     /**
   1378      * java.util.Arrays#sort(long[], int, int)
   1379      */
   1380     public void test_sort$JII() {
   1381         // Test for method void java.util.Arrays.sort(long [], int, int)
   1382         int startIndex = arraySize / 4;
   1383         int endIndex = 3 * arraySize / 4;
   1384         long[] reversedArray = new long[arraySize];
   1385         long[] originalReversedArray = new long[arraySize];
   1386         for (int counter = 0; counter < arraySize; counter++) {
   1387             reversedArray[counter] = (long) (arraySize - counter - 1);
   1388             originalReversedArray[counter] = reversedArray[counter];
   1389         }
   1390         Arrays.sort(reversedArray, startIndex, endIndex);
   1391         for (int counter = 0; counter < startIndex; counter++)
   1392             assertTrue("Array modified outside of bounds",
   1393                     reversedArray[counter] == originalReversedArray[counter]);
   1394         for (int counter = startIndex; counter < endIndex - 1; counter++)
   1395             assertTrue("Array not sorted within bounds",
   1396                     reversedArray[counter] <= reversedArray[counter + 1]);
   1397         for (int counter = endIndex; counter < arraySize; counter++)
   1398             assertTrue("Array modified outside of bounds",
   1399                     reversedArray[counter] == originalReversedArray[counter]);
   1400 
   1401         //exception testing
   1402         try {
   1403             Arrays.sort(reversedArray, startIndex + 1, startIndex);
   1404             fail("IllegalArgumentException expected");
   1405         } catch (IllegalArgumentException ignore) {
   1406         }
   1407 
   1408         try {
   1409             Arrays.sort(reversedArray, -1, startIndex);
   1410             fail("ArrayIndexOutOfBoundsException expected (1)");
   1411         } catch (ArrayIndexOutOfBoundsException ignore) {
   1412         }
   1413 
   1414         try {
   1415             Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
   1416             fail("ArrayIndexOutOfBoundsException expected (2)");
   1417         } catch (ArrayIndexOutOfBoundsException ignore) {
   1418         }
   1419     }
   1420 
   1421     /**
   1422      * java.util.Arrays#sort(java.lang.Object[])
   1423      */
   1424     public void test_sort$Ljava_lang_Object() {
   1425         // Test for method void java.util.Arrays.sort(java.lang.Object [])
   1426         Object[] reversedArray = new Object[arraySize];
   1427         for (int counter = 0; counter < arraySize; counter++)
   1428             reversedArray[counter] = objectArray[arraySize - counter - 1];
   1429         Arrays.sort(reversedArray);
   1430         for (int counter = 0; counter < arraySize; counter++)
   1431             assertTrue("Resulting array not sorted",
   1432                     reversedArray[counter] == objectArray[counter]);
   1433 
   1434         Arrays.fill(reversedArray, 0, reversedArray.length/2, "String");
   1435         Arrays.fill(reversedArray, reversedArray.length/2, reversedArray.length, new Integer(1));
   1436 
   1437         try {
   1438             Arrays.sort(reversedArray);
   1439             fail("ClassCastException expected");
   1440         } catch (ClassCastException e) {
   1441             //expected
   1442         }
   1443     }
   1444 
   1445     /**
   1446      * java.util.Arrays#sort(java.lang.Object[], int, int)
   1447      */
   1448     public void test_sort$Ljava_lang_ObjectII() {
   1449         // Test for method void java.util.Arrays.sort(java.lang.Object [], int,
   1450         // int)
   1451         int startIndex = arraySize / 4;
   1452         int endIndex = 3 * arraySize / 4;
   1453         Object[] reversedArray = new Object[arraySize];
   1454         Object[] originalReversedArray = new Object[arraySize];
   1455         for (int counter = 0; counter < arraySize; counter++) {
   1456             reversedArray[counter] = objectArray[arraySize - counter - 1];
   1457             originalReversedArray[counter] = reversedArray[counter];
   1458         }
   1459         Arrays.sort(reversedArray, startIndex, endIndex);
   1460         for (int counter = 0; counter < startIndex; counter++)
   1461             assertTrue("Array modified outside of bounds",
   1462                     reversedArray[counter] == originalReversedArray[counter]);
   1463         for (int counter = startIndex; counter < endIndex - 1; counter++)
   1464             assertTrue("Array not sorted within bounds",
   1465                     ((Comparable) reversedArray[counter])
   1466                             .compareTo(reversedArray[counter + 1]) <= 0);
   1467         for (int counter = endIndex; counter < arraySize; counter++)
   1468             assertTrue("Array modified outside of bounds",
   1469                     reversedArray[counter] == originalReversedArray[counter]);
   1470 
   1471         //exception testing
   1472         try {
   1473             Arrays.sort(reversedArray, startIndex + 1, startIndex);
   1474             fail("IllegalArgumentException expected");
   1475         } catch (IllegalArgumentException ignore) {
   1476         }
   1477 
   1478         try {
   1479             Arrays.sort(reversedArray, -1, startIndex);
   1480             fail("ArrayIndexOutOfBoundsException expected (1)");
   1481         } catch (ArrayIndexOutOfBoundsException ignore) {
   1482         }
   1483 
   1484         try {
   1485             Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
   1486             fail("ArrayIndexOutOfBoundsException expected (2)");
   1487         } catch (ArrayIndexOutOfBoundsException ignore) {
   1488         }
   1489 
   1490         Arrays.fill(reversedArray, 0, reversedArray.length/2, "String");
   1491         Arrays.fill(reversedArray, reversedArray.length/2, reversedArray.length, new Integer(1));
   1492 
   1493         try {
   1494             Arrays.sort(reversedArray, reversedArray.length/4, 3*reversedArray.length/4);
   1495             fail("ClassCastException expected");
   1496         } catch (ClassCastException e) {
   1497             //expected
   1498         }
   1499 
   1500         Arrays.sort(reversedArray, 0, reversedArray.length/4);
   1501         Arrays.sort(reversedArray, 3*reversedArray.length/4, reversedArray.length);
   1502     }
   1503 
   1504     /**
   1505      * java.util.Arrays#sort(java.lang.Object[], int, int,
   1506      *        java.util.Comparator)
   1507      */
   1508     public void test_sort$Ljava_lang_ObjectIILjava_util_Comparator() {
   1509         // Test for method void java.util.Arrays.sort(java.lang.Object [], int,
   1510         // int, java.util.Comparator)
   1511         int startIndex = arraySize / 4;
   1512         int endIndex = 3 * arraySize / 4;
   1513         ReversedIntegerComparator comp = new ReversedIntegerComparator();
   1514         Object[] originalArray = new Object[arraySize];
   1515         for (int counter = 0; counter < arraySize; counter++)
   1516             originalArray[counter] = objectArray[counter];
   1517         Arrays.sort(objectArray, startIndex, endIndex, comp);
   1518         for (int counter = 0; counter < startIndex; counter++)
   1519             assertTrue("Array modified outside of bounds",
   1520                     objectArray[counter] == originalArray[counter]);
   1521         for (int counter = startIndex; counter < endIndex - 1; counter++)
   1522             assertTrue("Array not sorted within bounds", comp.compare(
   1523                     objectArray[counter], objectArray[counter + 1]) <= 0);
   1524         for (int counter = endIndex; counter < arraySize; counter++)
   1525             assertTrue("Array modified outside of bounds",
   1526                     objectArray[counter] == originalArray[counter]);
   1527 
   1528         Arrays.fill(originalArray, 0, originalArray.length/2, "String");
   1529         Arrays.fill(originalArray, originalArray.length/2, originalArray.length, new Integer(1));
   1530 
   1531         try {
   1532             Arrays.sort(originalArray, startIndex, endIndex, comp);
   1533             fail("ClassCastException expected");
   1534         } catch (ClassCastException e) {
   1535             //expected
   1536         }
   1537 
   1538         Arrays.sort(originalArray, endIndex, originalArray.length, comp);
   1539 
   1540         try {
   1541             Arrays.sort(originalArray, endIndex, originalArray.length + 1, comp);
   1542             fail("ArrayIndexOutOfBoundsException expected");
   1543         } catch(ArrayIndexOutOfBoundsException e) {
   1544             //expected
   1545         }
   1546 
   1547         try {
   1548             Arrays.sort(originalArray, -1, startIndex, comp);
   1549             fail("ArrayIndexOutOfBoundsException expected");
   1550         } catch(ArrayIndexOutOfBoundsException e) {
   1551             //expected
   1552         }
   1553 
   1554         try {
   1555             Arrays.sort(originalArray, originalArray.length, endIndex, comp);
   1556             fail("IllegalArgumentException expected");
   1557         } catch(IllegalArgumentException e) {
   1558             //expected
   1559         }
   1560     }
   1561 
   1562     /**
   1563      * java.util.Arrays#sort(java.lang.Object[], java.util.Comparator)
   1564      */
   1565     public void test_sort$Ljava_lang_ObjectLjava_util_Comparator() {
   1566         // Test for method void java.util.Arrays.sort(java.lang.Object [],
   1567         // java.util.Comparator)
   1568         ReversedIntegerComparator comp = new ReversedIntegerComparator();
   1569         Arrays.sort(objectArray, comp);
   1570         for (int counter = 0; counter < arraySize - 1; counter++)
   1571             assertTrue("Array not sorted correctly with custom comparator",
   1572                     comp
   1573                             .compare(objectArray[counter],
   1574                                     objectArray[counter + 1]) <= 0);
   1575 
   1576         Arrays.fill(objectArray, 0, objectArray.length/2, "String");
   1577         Arrays.fill(objectArray, objectArray.length/2, objectArray.length, new Integer(1));
   1578 
   1579         try {
   1580             Arrays.sort(objectArray, comp);
   1581             fail("ClassCastException expected");
   1582         } catch (ClassCastException e) {
   1583             //expected
   1584         }
   1585     }
   1586 
   1587     // Regression HARMONY-6076
   1588     public void test_sort$Ljava_lang_ObjectLjava_util_Comparator_stable() {
   1589         Element[] array = new Element[11];
   1590         array[0] = new Element(122);
   1591         array[1] = new Element(146);
   1592         array[2] = new Element(178);
   1593         array[3] = new Element(208);
   1594         array[4] = new Element(117);
   1595         array[5] = new Element(146);
   1596         array[6] = new Element(173);
   1597         array[7] = new Element(203);
   1598         array[8] = new Element(56);
   1599         array[9] = new Element(208);
   1600         array[10] = new Element(96);
   1601 
   1602         Comparator<Element> comparator = new Comparator<Element>() {
   1603             public int compare(Element object1, Element object2) {
   1604                 return object1.value - object2.value;
   1605             }
   1606         };
   1607 
   1608         Arrays.sort(array, comparator);
   1609 
   1610         for (int i = 1; i < array.length; i++) {
   1611             assertTrue(comparator.compare(array[i - 1], array[i]) <= 0);
   1612             if (comparator.compare(array[i - 1], array[i]) == 0) {
   1613                 assertTrue(array[i - 1].index < array[i].index);
   1614             }
   1615         }
   1616     }
   1617 
   1618     public static class Element {
   1619         public int value;
   1620 
   1621         public int index;
   1622 
   1623         private static int count = 0;
   1624 
   1625         public Element(int value) {
   1626             this.value = value;
   1627             index = count++;
   1628         }
   1629     }
   1630 
   1631     /**
   1632      * java.util.Arrays#sort(short[])
   1633      */
   1634     public void test_sort$S() {
   1635         // Test for method void java.util.Arrays.sort(short [])
   1636         short[] reversedArray = new short[arraySize];
   1637         for (int counter = 0; counter < arraySize; counter++)
   1638             reversedArray[counter] = (short) (arraySize - counter - 1);
   1639         Arrays.sort(reversedArray);
   1640         for (int counter = 0; counter < arraySize; counter++)
   1641             assertTrue("Resulting array not sorted",
   1642                     reversedArray[counter] == (short) counter);
   1643     }
   1644 
   1645     /**
   1646      * java.util.Arrays#sort(short[], int, int)
   1647      */
   1648     public void test_sort$SII() {
   1649         // Test for method void java.util.Arrays.sort(short [], int, int)
   1650         int startIndex = arraySize / 4;
   1651         int endIndex = 3 * arraySize / 4;
   1652         short[] reversedArray = new short[arraySize];
   1653         short[] originalReversedArray = new short[arraySize];
   1654         for (int counter = 0; counter < arraySize; counter++) {
   1655             reversedArray[counter] = (short) (arraySize - counter - 1);
   1656             originalReversedArray[counter] = reversedArray[counter];
   1657         }
   1658         Arrays.sort(reversedArray, startIndex, endIndex);
   1659         for (int counter = 0; counter < startIndex; counter++)
   1660             assertTrue("Array modified outside of bounds",
   1661                     reversedArray[counter] == originalReversedArray[counter]);
   1662         for (int counter = startIndex; counter < endIndex - 1; counter++)
   1663             assertTrue("Array not sorted within bounds",
   1664                     reversedArray[counter] <= reversedArray[counter + 1]);
   1665         for (int counter = endIndex; counter < arraySize; counter++)
   1666             assertTrue("Array modified outside of bounds",
   1667                     reversedArray[counter] == originalReversedArray[counter]);
   1668 
   1669         //exception testing
   1670         try {
   1671             Arrays.sort(reversedArray, startIndex + 1, startIndex);
   1672             fail("IllegalArgumentException expected");
   1673         } catch (IllegalArgumentException ignore) {
   1674         }
   1675 
   1676         try {
   1677             Arrays.sort(reversedArray, -1, startIndex);
   1678             fail("ArrayIndexOutOfBoundsException expected (1)");
   1679         } catch (ArrayIndexOutOfBoundsException ignore) {
   1680         }
   1681 
   1682         try {
   1683             Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
   1684             fail("ArrayIndexOutOfBoundsException expected (2)");
   1685         } catch (ArrayIndexOutOfBoundsException ignore) {
   1686         }
   1687     }
   1688 
   1689     /**
   1690      * java.util.Arrays#sort(byte[], int, int)
   1691      */
   1692     public void test_java_util_Arrays_sort_byte_array_NPE() {
   1693         byte[] byte_array_null = null;
   1694         try {
   1695             java.util.Arrays.sort(byte_array_null);
   1696             fail("Should throw java.lang.NullPointerException");
   1697         } catch (NullPointerException e) {
   1698             // Expected
   1699         }
   1700         try {
   1701             // Regression for HARMONY-378
   1702             java.util.Arrays.sort(byte_array_null, (int) -1, (int) 1);
   1703             fail("Should throw java.lang.NullPointerException");
   1704         } catch (NullPointerException e) {
   1705             // Expected
   1706         }
   1707     }
   1708 
   1709     /**
   1710      * java.util.Arrays#sort(char[], int, int)
   1711      */
   1712     public void test_java_util_Arrays_sort_char_array_NPE() {
   1713         char[] char_array_null = null;
   1714         try {
   1715             java.util.Arrays.sort(char_array_null);
   1716             fail("Should throw java.lang.NullPointerException");
   1717         } catch (NullPointerException e) {
   1718             // Expected
   1719         }
   1720         try {
   1721             // Regression for HARMONY-378
   1722             java.util.Arrays.sort(char_array_null, (int) -1, (int) 1);
   1723             fail("Should throw java.lang.NullPointerException");
   1724         } catch (NullPointerException e) {
   1725             // Expected
   1726         }
   1727     }
   1728 
   1729     /**
   1730      * java.util.Arrays#sort(double[], int, int)
   1731      */
   1732     public void test_java_util_Arrays_sort_double_array_NPE() {
   1733         double[] double_array_null = null;
   1734         try {
   1735             java.util.Arrays.sort(double_array_null);
   1736             fail("Should throw java.lang.NullPointerException");
   1737         } catch (NullPointerException e) {
   1738             // Expected
   1739         }
   1740         try {
   1741             // Regression for HARMONY-378
   1742             java.util.Arrays.sort(double_array_null, (int) -1, (int) 1);
   1743             fail("Should throw java.lang.NullPointerException");
   1744         } catch (NullPointerException e) {
   1745             // Expected
   1746         }
   1747     }
   1748 
   1749     /**
   1750      * java.util.Arrays#sort(float[], int, int)
   1751      */
   1752     public void test_java_util_Arrays_sort_float_array_NPE() {
   1753         float[] float_array_null = null;
   1754         try {
   1755             java.util.Arrays.sort(float_array_null);
   1756             fail("Should throw java.lang.NullPointerException");
   1757         } catch (NullPointerException e) {
   1758             // Expected
   1759         }
   1760         try {
   1761             // Regression for HARMONY-378
   1762             java.util.Arrays.sort(float_array_null, (int) -1, (int) 1);
   1763             fail("Should throw java.lang.NullPointerException");
   1764         } catch (NullPointerException e) {
   1765             // Expected
   1766         }
   1767     }
   1768 
   1769     /**
   1770      * java.util.Arrays#sort(int[], int, int)
   1771      */
   1772     public void test_java_util_Arrays_sort_int_array_NPE() {
   1773         int[] int_array_null = null;
   1774         try {
   1775             java.util.Arrays.sort(int_array_null);
   1776             fail("Should throw java.lang.NullPointerException");
   1777         } catch (NullPointerException e) {
   1778             // Expected
   1779         }
   1780         try {
   1781             // Regression for HARMONY-378
   1782             java.util.Arrays.sort(int_array_null, (int) -1, (int) 1);
   1783             fail("Should throw java.lang.NullPointerException");
   1784         } catch (NullPointerException e) {
   1785             // Expected
   1786         }
   1787     }
   1788 
   1789     /**
   1790      * java.util.Arrays#sort(Object[], int, int)
   1791      */
   1792     public void test_java_util_Arrays_sort_object_array_NPE() {
   1793         Object[] object_array_null = null;
   1794         try {
   1795             java.util.Arrays.sort(object_array_null);
   1796             fail("Should throw java.lang.NullPointerException");
   1797         } catch (NullPointerException e) {
   1798             // Expected
   1799         }
   1800         try {
   1801             // Regression for HARMONY-378
   1802             java.util.Arrays.sort(object_array_null, (int) -1, (int) 1);
   1803             fail("Should throw java.lang.NullPointerException");
   1804         } catch (NullPointerException e) {
   1805             // Expected
   1806         }
   1807         try {
   1808             // Regression for HARMONY-378
   1809             java.util.Arrays.sort(object_array_null, (int) -1, (int) 1, null);
   1810             fail("Should throw java.lang.NullPointerException");
   1811         } catch (NullPointerException e) {
   1812             // Expected
   1813         }
   1814     }
   1815 
   1816     /**
   1817      * java.util.Arrays#sort(long[], int, int)
   1818      */
   1819     public void test_java_util_Arrays_sort_long_array_NPE() {
   1820         long[] long_array_null = null;
   1821         try {
   1822             java.util.Arrays.sort(long_array_null);
   1823             fail("Should throw java.lang.NullPointerException");
   1824         } catch (NullPointerException e) {
   1825             // Expected
   1826         }
   1827         try {
   1828             // Regression for HARMONY-378
   1829             java.util.Arrays.sort(long_array_null, (int) -1, (int) 1);
   1830             fail("Should throw java.lang.NullPointerException");
   1831         } catch (NullPointerException e) {
   1832             // Expected
   1833         }
   1834     }
   1835 
   1836     /**
   1837      * java.util.Arrays#sort(short[], int, int)
   1838      */
   1839     public void test_java_util_Arrays_sort_short_array_NPE() {
   1840         short[] short_array_null = null;
   1841         try {
   1842             java.util.Arrays.sort(short_array_null);
   1843             fail("Should throw java.lang.NullPointerException");
   1844         } catch (NullPointerException e) {
   1845             // Expected
   1846         }
   1847         try {
   1848             // Regression for HARMONY-378
   1849             java.util.Arrays.sort(short_array_null, (int) -1, (int) 1);
   1850             fail("Should throw java.lang.NullPointerException");
   1851         } catch (NullPointerException e) {
   1852             // Expected
   1853         }
   1854     }
   1855 
   1856     // Lenghts of arrays to test in test_sort;
   1857     private static final int[] LENGTHS = { 0, 1, 2, 3, 5, 8, 13, 21, 34, 55, 100, 1000, 10000 };
   1858 
   1859     /**
   1860      * java.util.Arrays#sort()
   1861      */
   1862     public void test_sort() {
   1863         for (int len : LENGTHS) {
   1864             PrimitiveTypeArrayBuilder.reset();
   1865             int[] golden = new int[len];
   1866             for (int m = 1; m < 2 * len; m *= 2) {
   1867                 for (PrimitiveTypeArrayBuilder builder : PrimitiveTypeArrayBuilder.values()) {
   1868                     builder.build(golden, m);
   1869                     int[] test = golden.clone();
   1870 
   1871                     for (PrimitiveTypeConverter converter : PrimitiveTypeConverter.values()) {
   1872                         Object convertedGolden = converter.convert(golden);
   1873                         Object convertedTest = converter.convert(test);
   1874                         sort(convertedTest);
   1875                         checkSorted(convertedTest);
   1876                         assertEquals(checkSum(convertedGolden), checkSum(convertedTest));
   1877                     }
   1878                 }
   1879             }
   1880         }
   1881     }
   1882 
   1883     private void sort(Object array) {
   1884         if (array instanceof int[]) {
   1885             Arrays.sort((int[]) array);
   1886         }
   1887         else if (array instanceof long[]) {
   1888             Arrays.sort((long[]) array);
   1889         } else if (array instanceof short[]) {
   1890             Arrays.sort((short[]) array);
   1891         } else if (array instanceof byte[]) {
   1892             Arrays.sort((byte[]) array);
   1893         } else if (array instanceof char[]) {
   1894             Arrays.sort((char[]) array);
   1895         } else if (array instanceof float[]) {
   1896             Arrays.sort((float[]) array);
   1897         } else if (array instanceof double[]) {
   1898             Arrays.sort((double[]) array);
   1899         } else {
   1900             fail("Unknow type of array: " + array.getClass());
   1901         }
   1902     }
   1903 
   1904     private void checkSorted(Object array) {
   1905         if (array instanceof int[]) {
   1906             checkSorted((int[]) array);
   1907         } else if (array instanceof long[]) {
   1908             checkSorted((long[]) array);
   1909         } else if (array instanceof short[]) {
   1910             checkSorted((short[]) array);
   1911         } else if (array instanceof byte[]) {
   1912             checkSorted((byte[]) array);
   1913         } else if (array instanceof char[]) {
   1914             checkSorted((char[]) array);
   1915         } else if (array instanceof float[]) {
   1916             checkSorted((float[]) array);
   1917         } else if (array instanceof double[]) {
   1918             checkSorted((double[]) array);
   1919         } else {
   1920             fail("Unknow type of array: " + array.getClass());
   1921         }
   1922     }
   1923 
   1924     private void checkSorted(int[] a) {
   1925         for (int i = 0; i < a.length - 1; i++) {
   1926             if (a[i] > a[i + 1]) {
   1927                 orderFail(i, "" + a[i], "" + a[i + 1]);
   1928             }
   1929         }
   1930     }
   1931 
   1932     private void checkSorted(long[] a) {
   1933         for (int i = 0; i < a.length - 1; i++) {
   1934             if (a[i] > a[i + 1]) {
   1935                 orderFail(i, "" + a[i], "" + a[i + 1]);
   1936             }
   1937         }
   1938     }
   1939 
   1940     private void checkSorted(short[] a) {
   1941         for (int i = 0; i < a.length - 1; i++) {
   1942             if (a[i] > a[i + 1]) {
   1943                 orderFail(i, "" + a[i], "" + a[i + 1]);
   1944             }
   1945         }
   1946     }
   1947 
   1948     private void checkSorted(byte[] a) {
   1949         for (int i = 0; i < a.length - 1; i++) {
   1950             if (a[i] > a[i + 1]) {
   1951                 orderFail(i, "" + a[i], "" + a[i + 1]);
   1952             }
   1953         }
   1954     }
   1955 
   1956     private void checkSorted(char[] a) {
   1957         for (int i = 0; i < a.length - 1; i++) {
   1958             if (a[i] > a[i + 1]) {
   1959                 orderFail(i, "" + a[i], "" + a[i + 1]);
   1960             }
   1961         }
   1962     }
   1963 
   1964     private void checkSorted(float[] a) {
   1965         for (int i = 0; i < a.length - 1; i++) {
   1966             if (a[i] > a[i + 1]) {
   1967                 orderFail(i, "" + a[i], "" + a[i + 1]);
   1968             }
   1969         }
   1970     }
   1971 
   1972     private void checkSorted(double[] a) {
   1973         for (int i = 0; i < a.length - 1; i++) {
   1974             if (a[i] > a[i + 1]) {
   1975                 orderFail(i, "" + a[i], "" + a[i + 1]);
   1976             }
   1977         }
   1978     }
   1979 
   1980 
   1981     private void orderFail(int index, String value1, String value2) {
   1982         fail("Array is not sorted at " + index + "-th position: " + value1 + " and " + value2);
   1983     }
   1984 
   1985     private int checkSum(Object array) {
   1986         if (array instanceof int[]) {
   1987             return checkSum((int[]) array);
   1988         } else if (array instanceof long[]) {
   1989             return checkSum((long[]) array);
   1990         } else if (array instanceof short[]) {
   1991             return checkSum((short[]) array);
   1992         } else if (array instanceof byte[]) {
   1993             return checkSum((byte[]) array);
   1994         } else if (array instanceof char[]) {
   1995             return checkSum((char[]) array);
   1996         } else if (array instanceof float[]) {
   1997             return checkSum((float[]) array);
   1998         } else if (array instanceof double[]) {
   1999             return checkSum((double[]) array);
   2000         } else {
   2001             fail("Unknow type of array: " + array.getClass());
   2002         }
   2003         throw new AssertionError(); // Needed to shut up compiler
   2004     }
   2005 
   2006     private int checkSum(int[] a) {
   2007         int checkSum = 0;
   2008 
   2009         for (int e : a) {
   2010             checkSum ^= e; // xor
   2011         }
   2012         return checkSum;
   2013     }
   2014 
   2015     private int checkSum(long[] a) {
   2016         long checkSum = 0;
   2017 
   2018         for (long e : a) {
   2019             checkSum ^= e; // xor
   2020         }
   2021         return (int) checkSum;
   2022     }
   2023 
   2024     private int checkSum(short[] a) {
   2025         short checkSum = 0;
   2026 
   2027         for (short e : a) {
   2028             checkSum ^= e; // xor
   2029         }
   2030         return (int) checkSum;
   2031     }
   2032 
   2033     private int checkSum(byte[] a) {
   2034         byte checkSum = 0;
   2035 
   2036         for (byte e : a) {
   2037             checkSum ^= e; // xor
   2038         }
   2039         return (int) checkSum;
   2040     }
   2041 
   2042     private int checkSum(char[] a) {
   2043         char checkSum = 0;
   2044 
   2045         for (char e : a) {
   2046             checkSum ^= e; // xor
   2047         }
   2048         return (int) checkSum;
   2049     }
   2050 
   2051     private int checkSum(float[] a) {
   2052         int checkSum = 0;
   2053 
   2054         for (float e : a) {
   2055             checkSum ^= (int) e; // xor
   2056         }
   2057         return checkSum;
   2058     }
   2059 
   2060     private int checkSum(double[] a) {
   2061         int checkSum = 0;
   2062 
   2063         for (double e : a) {
   2064             checkSum ^= (int) e; // xor
   2065         }
   2066         return checkSum;
   2067     }
   2068 
   2069     private enum PrimitiveTypeArrayBuilder {
   2070 
   2071         RANDOM {
   2072             void build(int[] a, int m) {
   2073                 for (int i = 0; i < a.length; i++) {
   2074                     a[i] = ourRandom.nextInt();
   2075                 }
   2076             }
   2077         },
   2078 
   2079         ASCENDING {
   2080             void build(int[] a, int m) {
   2081                 for (int i = 0; i < a.length; i++) {
   2082                     a[i] = m + i;
   2083                 }
   2084             }
   2085         },
   2086 
   2087         DESCENDING {
   2088             void build(int[] a, int m) {
   2089                 for (int i = 0; i < a.length; i++) {
   2090                     a[i] = a.length - m - i;
   2091                 }
   2092             }
   2093         },
   2094 
   2095         ALL_EQUAL {
   2096             void build(int[] a, int m) {
   2097                 for (int i = 0; i < a.length; i++) {
   2098                     a[i] = m;
   2099                 }
   2100             }
   2101         },
   2102 
   2103         SAW {
   2104             void build(int[] a, int m) {
   2105                 int incCount = 1;
   2106                 int decCount = a.length;
   2107                 int i = 0;
   2108                 int period = m;
   2109                 m--;
   2110 
   2111                 while (true) {
   2112                     for (int k = 1; k <= period; k++) {
   2113                         if (i >= a.length) {
   2114                             return;
   2115                         }
   2116                         a[i++] = incCount++;
   2117                     }
   2118                     period += m;
   2119 
   2120                     for (int k = 1; k <= period; k++) {
   2121                         if (i >= a.length) {
   2122                             return;
   2123                         }
   2124                         a[i++] = decCount--;
   2125                     }
   2126                     period += m;
   2127                 }
   2128             }
   2129         },
   2130 
   2131         REPEATED {
   2132             void build(int[] a, int m) {
   2133                 for (int i = 0; i < a.length; i++) {
   2134                     a[i] = i % m;
   2135                 }
   2136             }
   2137         },
   2138 
   2139         DUPLICATED {
   2140             void build(int[] a, int m) {
   2141                 for (int i = 0; i < a.length; i++) {
   2142                     a[i] = ourRandom.nextInt(m);
   2143                 }
   2144             }
   2145         },
   2146 
   2147         ORGAN_PIPES {
   2148             void build(int[] a, int m) {
   2149                 int middle = a.length / (m + 1);
   2150 
   2151                 for (int i = 0; i < middle; i++) {
   2152                     a[i] = i;
   2153                 }
   2154                 for (int i = middle; i < a.length ; i++) {
   2155                     a[i] = a.length - i - 1;
   2156                 }
   2157             }
   2158         },
   2159 
   2160         STAGGER {
   2161             void build(int[] a, int m) {
   2162                 for (int i = 0; i < a.length; i++) {
   2163                     a[i] = (i * m + i) % a.length;
   2164                 }
   2165             }
   2166         },
   2167 
   2168         PLATEAU {
   2169             void build(int[] a, int m) {
   2170                 for (int i = 0; i < a.length; i++) {
   2171                     a[i] =  Math.min(i, m);
   2172                 }
   2173             }
   2174         },
   2175 
   2176         SHUFFLE {
   2177             void build(int[] a, int m) {
   2178                 for (int i = 0; i < a.length; i++) {
   2179                     a[i] = ourRandom.nextBoolean() ? (ourFirst += 2) : (ourSecond += 2);
   2180                 }
   2181             }
   2182         };
   2183 
   2184         abstract void build(int[] a, int m);
   2185 
   2186         static void reset() {
   2187             ourRandom = new Random(666);
   2188             ourFirst = 0;
   2189             ourSecond = 0;
   2190         }
   2191 
   2192         @Override
   2193         public String toString() {
   2194             String name = name();
   2195 
   2196             for (int i = name.length(); i < 12; i++) {
   2197                 name += " " ;
   2198             }
   2199             return name;
   2200         }
   2201 
   2202         private static int ourFirst;
   2203         private static int ourSecond;
   2204         private static Random ourRandom = new Random(666);
   2205     }
   2206 
   2207     private enum PrimitiveTypeConverter {
   2208 
   2209         INT {
   2210             Object convert(int[] a) {
   2211                 return a;
   2212             }
   2213         },
   2214 
   2215         LONG {
   2216             Object convert(int[] a) {
   2217                 long[] b = new long[a.length];
   2218 
   2219                 for (int i = 0; i < a.length; i++) {
   2220                     b[i] = (int) a[i];
   2221                 }
   2222                 return b;
   2223             }
   2224         },
   2225 
   2226         BYTE {
   2227             Object convert(int[] a) {
   2228                 byte[] b = new byte[a.length];
   2229 
   2230                 for (int i = 0; i < a.length; i++) {
   2231                     b[i] = (byte) a[i];
   2232                 }
   2233                 return b;
   2234             }
   2235         },
   2236 
   2237         SHORT {
   2238             Object convert(int[] a) {
   2239                 short[] b = new short[a.length];
   2240 
   2241                 for (int i = 0; i < a.length; i++) {
   2242                     b[i] = (short) a[i];
   2243                 }
   2244                 return b;
   2245             }
   2246         },
   2247 
   2248         CHAR {
   2249             Object convert(int[] a) {
   2250                 char[] b = new char[a.length];
   2251 
   2252                 for (int i = 0; i < a.length; i++) {
   2253                     b[i] = (char) a[i];
   2254                 }
   2255                 return b;
   2256             }
   2257         },
   2258 
   2259         FLOAT {
   2260             Object convert(int[] a) {
   2261                 float[] b = new float[a.length];
   2262 
   2263                 for (int i = 0; i < a.length; i++) {
   2264                     b[i] = (float) a[i];
   2265                 }
   2266                 return b;
   2267             }
   2268         },
   2269 
   2270         DOUBLE {
   2271             Object convert(int[] a) {
   2272                 double[] b = new double[a.length];
   2273 
   2274                 for (int i = 0; i < a.length; i++) {
   2275                     b[i] = (double) a[i];
   2276                 }
   2277                 return b;
   2278             }
   2279         };
   2280 
   2281         abstract Object convert(int[] a);
   2282 
   2283         public String toString() {
   2284             String name = name();
   2285 
   2286             for (int i = name.length(); i < 9; i++) {
   2287                 name += " " ;
   2288             }
   2289             return name;
   2290         }
   2291     }
   2292 
   2293 
   2294     /**
   2295      * java.util.Arrays#deepEquals(Object[], Object[])
   2296      */
   2297     public void test_deepEquals$Ljava_lang_ObjectLjava_lang_Object() {
   2298         int[] a1 = { 1, 2, 3 };
   2299         short[] a2 = { 0, 1 };
   2300         Object[] a3 = { new Integer(1), a2 };
   2301         int[] a4 = { 6, 5, 4 };
   2302 
   2303         int[] b1 = { 1, 2, 3 };
   2304         short[] b2 = { 0, 1 };
   2305         Object[] b3 = { new Integer(1), b2 };
   2306 
   2307         Object a[] = { a1, a2, a3 };
   2308         Object b[] = { b1, b2, b3 };
   2309 
   2310         assertFalse(Arrays.equals(a, b));
   2311         assertTrue(Arrays.deepEquals(a, b));
   2312 
   2313         a[2] = a4;
   2314 
   2315         assertFalse(Arrays.deepEquals(a, b));
   2316     }
   2317 
   2318     /**
   2319      * java.util.Arrays#deepHashCode(Object[])
   2320      */
   2321     public void test_deepHashCode$Ljava_lang_Object() {
   2322         int[] a1 = { 1, 2, 3 };
   2323         short[] a2 = { 0, 1 };
   2324         Object[] a3 = { new Integer(1), a2 };
   2325 
   2326         int[] b1 = { 1, 2, 3 };
   2327         short[] b2 = { 0, 1 };
   2328         Object[] b3 = { new Integer(1), b2 };
   2329 
   2330         Object a[] = { a1, a2, a3 };
   2331         Object b[] = { b1, b2, b3 };
   2332 
   2333         int deep_hash_a = Arrays.deepHashCode(a);
   2334         int deep_hash_b = Arrays.deepHashCode(b);
   2335 
   2336         assertEquals(deep_hash_a, deep_hash_b);
   2337     }
   2338 
   2339     /**
   2340      * java.util.Arrays#hashCode(boolean[] a)
   2341      */
   2342     public void test_hashCode$LZ() {
   2343         int listHashCode;
   2344         int arrayHashCode;
   2345 
   2346         boolean[] boolArr = { true, false, false, true, false };
   2347         List listOfBoolean = new LinkedList();
   2348         for (int i = 0; i < boolArr.length; i++) {
   2349             listOfBoolean.add(new Boolean(boolArr[i]));
   2350         }
   2351         listHashCode = listOfBoolean.hashCode();
   2352         arrayHashCode = Arrays.hashCode(boolArr);
   2353         assertEquals(listHashCode, arrayHashCode);
   2354     }
   2355 
   2356     /**
   2357      * java.util.Arrays#hashCode(int[] a)
   2358      */
   2359     public void test_hashCode$LI() {
   2360         int listHashCode;
   2361         int arrayHashCode;
   2362 
   2363         int[] intArr = { 10, 5, 134, 7, 19 };
   2364         List listOfInteger = new LinkedList();
   2365 
   2366         for (int i = 0; i < intArr.length; i++) {
   2367             listOfInteger.add(new Integer(intArr[i]));
   2368         }
   2369         listHashCode = listOfInteger.hashCode();
   2370         arrayHashCode = Arrays.hashCode(intArr);
   2371         assertEquals(listHashCode, arrayHashCode);
   2372 
   2373         int[] intArr2 = { 10, 5, 134, 7, 19 };
   2374         assertEquals(Arrays.hashCode(intArr2), Arrays.hashCode(intArr));
   2375     }
   2376 
   2377     /**
   2378      * java.util.Arrays#hashCode(char[] a)
   2379      */
   2380     public void test_hashCode$LC() {
   2381         int listHashCode;
   2382         int arrayHashCode;
   2383 
   2384         char[] charArr = { 'a', 'g', 'x', 'c', 'm' };
   2385         List listOfCharacter = new LinkedList();
   2386         for (int i = 0; i < charArr.length; i++) {
   2387             listOfCharacter.add(new Character(charArr[i]));
   2388         }
   2389         listHashCode = listOfCharacter.hashCode();
   2390         arrayHashCode = Arrays.hashCode(charArr);
   2391         assertEquals(listHashCode, arrayHashCode);
   2392     }
   2393 
   2394     /**
   2395      * java.util.Arrays#hashCode(byte[] a)
   2396      */
   2397     public void test_hashCode$LB() {
   2398         int listHashCode;
   2399         int arrayHashCode;
   2400 
   2401         byte[] byteArr = { 5, 9, 7, 6, 17 };
   2402         List listOfByte = new LinkedList();
   2403         for (int i = 0; i < byteArr.length; i++) {
   2404             listOfByte.add(new Byte(byteArr[i]));
   2405         }
   2406         listHashCode = listOfByte.hashCode();
   2407         arrayHashCode = Arrays.hashCode(byteArr);
   2408         assertEquals(listHashCode, arrayHashCode);
   2409     }
   2410 
   2411     /**
   2412      * java.util.Arrays#hashCode(long[] a)
   2413      */
   2414     public void test_hashCode$LJ() {
   2415         int listHashCode;
   2416         int arrayHashCode;
   2417 
   2418         long[] longArr = { 67890234512l, 97587236923425l, 257421912912l,
   2419                 6754268100l, 5 };
   2420         List listOfLong = new LinkedList();
   2421         for (int i = 0; i < longArr.length; i++) {
   2422             listOfLong.add(new Long(longArr[i]));
   2423         }
   2424         listHashCode = listOfLong.hashCode();
   2425         arrayHashCode = Arrays.hashCode(longArr);
   2426         assertEquals(listHashCode, arrayHashCode);
   2427     }
   2428 
   2429     /**
   2430      * java.util.Arrays#hashCode(float[] a)
   2431      */
   2432     public void test_hashCode$LF() {
   2433         int listHashCode;
   2434         int arrayHashCode;
   2435 
   2436         float[] floatArr = { 0.13497f, 0.268934f, 12e-5f, -3e+2f, 10e-4f };
   2437         List listOfFloat = new LinkedList();
   2438         for (int i = 0; i < floatArr.length; i++) {
   2439             listOfFloat.add(new Float(floatArr[i]));
   2440         }
   2441         listHashCode = listOfFloat.hashCode();
   2442         arrayHashCode = Arrays.hashCode(floatArr);
   2443         assertEquals(listHashCode, arrayHashCode);
   2444 
   2445         float[] floatArr2 = { 0.13497f, 0.268934f, 12e-5f, -3e+2f, 10e-4f };
   2446         assertEquals(Arrays.hashCode(floatArr2), Arrays.hashCode(floatArr));
   2447     }
   2448 
   2449     /**
   2450      * java.util.Arrays#hashCode(double[] a)
   2451      */
   2452     public void test_hashCode$LD() {
   2453         int listHashCode;
   2454         int arrayHashCode;
   2455 
   2456         double[] doubleArr = { 0.134945657, 0.0038754, 11e-150, -30e-300, 10e-4 };
   2457         List listOfDouble = new LinkedList();
   2458         for (int i = 0; i < doubleArr.length; i++) {
   2459             listOfDouble.add(new Double(doubleArr[i]));
   2460         }
   2461         listHashCode = listOfDouble.hashCode();
   2462         arrayHashCode = Arrays.hashCode(doubleArr);
   2463         assertEquals(listHashCode, arrayHashCode);
   2464     }
   2465 
   2466     /**
   2467      * java.util.Arrays#hashCode(short[] a)
   2468      */
   2469     public void test_hashCode$LS() {
   2470         int listHashCode;
   2471         int arrayHashCode;
   2472 
   2473         short[] shortArr = { 35, 13, 45, 2, 91 };
   2474         List listOfShort = new LinkedList();
   2475         for (int i = 0; i < shortArr.length; i++) {
   2476             listOfShort.add(new Short(shortArr[i]));
   2477         }
   2478         listHashCode = listOfShort.hashCode();
   2479         arrayHashCode = Arrays.hashCode(shortArr);
   2480         assertEquals(listHashCode, arrayHashCode);
   2481     }
   2482 
   2483     /**
   2484      * java.util.Arrays#hashCode(Object[] a)
   2485      */
   2486     public void test_hashCode$Ljava_lang_Object() {
   2487         int listHashCode;
   2488         int arrayHashCode;
   2489 
   2490         Object[] objectArr = { new Integer(1), new Float(10e-12f), null };
   2491         List listOfObject = new LinkedList();
   2492         for (int i = 0; i < objectArr.length; i++) {
   2493             listOfObject.add(objectArr[i]);
   2494         }
   2495         listHashCode = listOfObject.hashCode();
   2496         arrayHashCode = Arrays.hashCode(objectArr);
   2497         assertEquals(listHashCode, arrayHashCode);
   2498     }
   2499 
   2500     /**
   2501      * Sets up the fixture, for example, open a network connection. This method
   2502      * is called before a test is executed.
   2503      */
   2504     protected void setUp() {
   2505         objArray = new Object[arraySize];
   2506         for (int i = 0; i < objArray.length; i++)
   2507             objArray[i] = new Integer(i);
   2508 
   2509         booleanArray = new boolean[arraySize];
   2510         byteArray = new byte[arraySize];
   2511         charArray = new char[arraySize];
   2512         doubleArray = new double[arraySize];
   2513         floatArray = new float[arraySize];
   2514         intArray = new int[arraySize];
   2515         longArray = new long[arraySize];
   2516         objectArray = new Object[arraySize];
   2517         shortArray = new short[arraySize];
   2518 
   2519         for (int counter = 0; counter < arraySize; counter++) {
   2520             byteArray[counter] = (byte) counter;
   2521             charArray[counter] = (char) (counter + 1);
   2522             doubleArray[counter] = counter;
   2523             floatArray[counter] = counter;
   2524             intArray[counter] = counter;
   2525             longArray[counter] = counter;
   2526             objectArray[counter] = objArray[counter];
   2527             shortArray[counter] = (short) counter;
   2528         }
   2529         for (int counter = 0; counter < arraySize; counter += 2) {
   2530             booleanArray[counter] = false;
   2531             booleanArray[counter + 1] = true;
   2532         }
   2533     }
   2534 
   2535     /**
   2536      * java.util.Arrays#binarySearch(byte[], int, int, byte)
   2537      */
   2538     public void test_binarySearch$BIIB() {
   2539         for (byte counter = 0; counter < arraySize; counter++) {
   2540             assertTrue(
   2541                     "Binary search on byte[] answered incorrect position",
   2542                     Arrays.binarySearch(byteArray, counter, arraySize, counter) == counter);
   2543         }
   2544         assertEquals(
   2545                 "Binary search succeeded for value not present in array 1", -1,
   2546                 Arrays.binarySearch(byteArray, 0, arraySize, (byte) -1));
   2547         assertTrue(
   2548                 "Binary search succeeded for value not present in array 2",
   2549                 Arrays.binarySearch(byteArray, (byte) arraySize) == -(arraySize + 1));
   2550         for (byte counter = 0; counter < arraySize; counter++) {
   2551             byteArray[counter] -= 50;
   2552         }
   2553         for (byte counter = 0; counter < arraySize; counter++) {
   2554             assertTrue(
   2555                     "Binary search on byte[] involving negative numbers answered incorrect position",
   2556                     Arrays.binarySearch(byteArray, counter, arraySize,
   2557                             (byte) (counter - 50)) == counter);
   2558         }
   2559         try {
   2560             Arrays.binarySearch((byte[]) null, 2, 1, (byte) arraySize);
   2561             fail("should throw NullPointerException");
   2562         } catch (NullPointerException e) {
   2563             // expected
   2564         }
   2565         try {
   2566             Arrays.binarySearch((byte[]) null, -1, 0, (byte) arraySize);
   2567             fail("should throw NullPointerException");
   2568         } catch (NullPointerException e) {
   2569             // expected
   2570         }
   2571         try {
   2572             Arrays.binarySearch((byte[]) null, -1, -2, (byte) arraySize);
   2573             fail("should throw NullPointerException");
   2574         } catch (NullPointerException e) {
   2575             // expected
   2576         }
   2577         try {
   2578             Arrays.binarySearch(byteArray, 2, 1, (byte) arraySize);
   2579             fail("should throw IllegalArgumentException");
   2580         } catch (IllegalArgumentException e) {
   2581             // expected
   2582         }
   2583         assertEquals(-1, Arrays.binarySearch(byteArray, 0, 0, (byte) arraySize));
   2584         try {
   2585             Arrays.binarySearch(byteArray, -1, -2, (byte) arraySize);
   2586             fail("should throw IllegalArgumentException");
   2587         } catch (IllegalArgumentException e) {
   2588             // expected
   2589         }
   2590         try {
   2591             Arrays.binarySearch(byteArray, arraySize + 2, arraySize + 1,
   2592                     (byte) arraySize);
   2593             fail("should throw IllegalArgumentException");
   2594         } catch (IllegalArgumentException e) {
   2595             // expected
   2596         }
   2597         try {
   2598             Arrays.binarySearch(byteArray, -1, 0, (byte) arraySize);
   2599             fail("should throw ArrayIndexOutOfBoundsException");
   2600         } catch (ArrayIndexOutOfBoundsException e) {
   2601             // expected
   2602         }
   2603         try {
   2604             Arrays.binarySearch(byteArray, 0, arraySize + 1, (byte) arraySize);
   2605             fail("should throw ArrayIndexOutOfBoundsException");
   2606         } catch (ArrayIndexOutOfBoundsException e) {
   2607             // expected
   2608         }
   2609     }
   2610 
   2611     /**
   2612      * java.util.Arrays#binarySearch(char[], char)
   2613      */
   2614     public void test_binarySearch$CIIC() {
   2615         for (char counter = 0; counter < arraySize; counter++) {
   2616             assertTrue("Binary search on char[] answered incorrect position",
   2617                     Arrays.binarySearch(charArray, counter, arraySize,
   2618                             (char) (counter + 1)) == counter);
   2619         }
   2620         assertEquals(
   2621                 "Binary search succeeded for value not present in array 1", -1,
   2622                 Arrays.binarySearch(charArray, 0, arraySize, '\u0000'));
   2623         assertTrue("Binary search succeeded for value not present in array 2",
   2624                 Arrays.binarySearch(charArray, 0, arraySize,
   2625                         (char) (arraySize + 1)) == -(arraySize + 1));
   2626         try {
   2627             Arrays.binarySearch(charArray, 2, 1, (char) arraySize);
   2628             fail("should throw IllegalArgumentException");
   2629         } catch (IllegalArgumentException e) {
   2630             // expected
   2631         }
   2632         try {
   2633             Arrays.binarySearch((char[]) null, 2, 1, (char) arraySize);
   2634             fail("should throw NullPointerException");
   2635         } catch (NullPointerException e) {
   2636             // expected
   2637         }
   2638         try {
   2639             Arrays.binarySearch((char[]) null, -1, 0, (char) arraySize);
   2640             fail("should throw NullPointerException");
   2641         } catch (NullPointerException e) {
   2642             // expected
   2643         }
   2644         try {
   2645             Arrays.binarySearch((char[]) null, -1, -2, (char) arraySize);
   2646             fail("should throw NullPointerException");
   2647         } catch (NullPointerException e) {
   2648             // expected
   2649         }
   2650         assertEquals(-1, Arrays.binarySearch(charArray, 0, 0, (char) arraySize));
   2651         try {
   2652             Arrays.binarySearch(charArray, -1, -2, (char) arraySize);
   2653             fail("should throw IllegalArgumentException");
   2654         } catch (IllegalArgumentException e) {
   2655             // expected
   2656         }
   2657         try {
   2658             Arrays.binarySearch(charArray, arraySize + 2, arraySize + 1,
   2659                     (char) arraySize);
   2660             fail("should throw IllegalArgumentException");
   2661         } catch (IllegalArgumentException e) {
   2662             // expected
   2663         }
   2664         try {
   2665             Arrays.binarySearch(charArray, -1, 0, (char) arraySize);
   2666             fail("should throw ArrayIndexOutOfBoundsException");
   2667         } catch (ArrayIndexOutOfBoundsException e) {
   2668             // expected
   2669         }
   2670         try {
   2671             Arrays.binarySearch(charArray, 0, arraySize + 1, (char) arraySize);
   2672             fail("should throw ArrayIndexOutOfBoundsException");
   2673         } catch (ArrayIndexOutOfBoundsException e) {
   2674             // expected
   2675         }
   2676     }
   2677 
   2678     /**
   2679      * java.util.Arrays#binarySearch(double[], double)
   2680      */
   2681     public void test_binarySearch$DIID() {
   2682         for (int counter = 0; counter < arraySize; counter++) {
   2683             assertTrue("Binary search on double[] answered incorrect position",
   2684                     Arrays.binarySearch(doubleArray, counter, arraySize,
   2685                             (double) counter) == (double) counter);
   2686         }
   2687         assertEquals(
   2688                 "Binary search succeeded for value not present in array 1", -1,
   2689                 Arrays.binarySearch(doubleArray, 0, arraySize, (double) -1));
   2690         assertTrue("Binary search succeeded for value not present in array 2",
   2691                 Arrays.binarySearch(doubleArray, 0, arraySize,
   2692                         (double) arraySize) == -(arraySize + 1));
   2693         for (int counter = 0; counter < arraySize; counter++) {
   2694             doubleArray[counter] -= (double) 50;
   2695         }
   2696         for (int counter = 0; counter < arraySize; counter++) {
   2697             assertTrue(
   2698                     "Binary search on double[] involving negative numbers answered incorrect position",
   2699                     Arrays.binarySearch(doubleArray, counter, arraySize, (double) (counter - 50)) == (double) counter);
   2700         }
   2701         double[] specials = new double[] { Double.NEGATIVE_INFINITY,
   2702                 -Double.MAX_VALUE, -2d, -Double.MIN_VALUE, -0d, 0d,
   2703                 Double.MIN_VALUE, 2d, Double.MAX_VALUE,
   2704                 Double.POSITIVE_INFINITY, Double.NaN };
   2705         for (int i = 0; i < specials.length; i++) {
   2706             int result = Arrays.binarySearch(specials, i, specials.length, specials[i]);
   2707             assertTrue(specials[i] + " invalid: " + result, result == i);
   2708         }
   2709         assertEquals("-1d", -4, Arrays.binarySearch(specials, 0, specials.length, -1d));
   2710         assertEquals("1d", -8, Arrays.binarySearch(specials, 0, specials.length, 1d));
   2711         try {
   2712             Arrays.binarySearch((double[]) null, 2, 1, (double) arraySize);
   2713             fail("should throw NullPointerException");
   2714         } catch (NullPointerException e) {
   2715             // expected
   2716         }
   2717         try {
   2718             Arrays.binarySearch((double[]) null, -1, 0, (double) arraySize);
   2719             fail("should throw NullPointerException");
   2720         } catch (NullPointerException e) {
   2721             // expected
   2722         }
   2723         try {
   2724             Arrays.binarySearch((double[]) null, -1, -2, (double) arraySize);
   2725             fail("should throw NullPointerException");
   2726         } catch (NullPointerException e) {
   2727             // expected
   2728         }
   2729         try {
   2730             Arrays.binarySearch(doubleArray, 2, 1, (char) arraySize);
   2731             fail("should throw IllegalArgumentException");
   2732         } catch (IllegalArgumentException e) {
   2733             // expected
   2734         }
   2735         assertEquals(-1, Arrays.binarySearch(doubleArray, 0, 0, (char) arraySize));
   2736         try {
   2737             Arrays.binarySearch(doubleArray, -1, -2, (char) arraySize);
   2738             fail("should throw IllegalArgumentException");
   2739         } catch (IllegalArgumentException e) {
   2740             // expected
   2741         }
   2742         try {
   2743             Arrays.binarySearch(doubleArray, arraySize + 2, arraySize + 1,
   2744                     (char) arraySize);
   2745             fail("should throw IllegalArgumentException");
   2746         } catch (IllegalArgumentException e) {
   2747             // expected
   2748         }
   2749         try {
   2750             Arrays.binarySearch(doubleArray, -1, 0, (char) arraySize);
   2751             fail("should throw ArrayIndexOutOfBoundsException");
   2752         } catch (ArrayIndexOutOfBoundsException e) {
   2753             // expected
   2754         }
   2755         try {
   2756             Arrays.binarySearch(doubleArray, 0, arraySize + 1, (char) arraySize);
   2757             fail("should throw ArrayIndexOutOfBoundsException");
   2758         } catch (ArrayIndexOutOfBoundsException e) {
   2759             // expected
   2760         }
   2761     }
   2762 
   2763     /**
   2764      * java.util.Arrays#binarySearch(float[], float)
   2765      */
   2766     public void test_binarySearch$FIIF() {
   2767         for (int counter = 0; counter < arraySize; counter++) {
   2768             assertTrue("Binary search on float[] answered incorrect position",
   2769                     Arrays.binarySearch(floatArray, counter, arraySize,
   2770                             (float) counter) == (float) counter);
   2771         }
   2772         assertEquals(
   2773                 "Binary search succeeded for value not present in array 1", -1,
   2774                 Arrays.binarySearch(floatArray, 0, arraySize, (float) -1));
   2775         assertTrue("Binary search succeeded for value not present in array 2",
   2776                 Arrays
   2777                         .binarySearch(floatArray, 0, arraySize,
   2778                                 (float) arraySize) == -(arraySize + 1));
   2779         for (int counter = 0; counter < arraySize; counter++) {
   2780             floatArray[counter] -= (float) 50;
   2781         }
   2782         for (int counter = 0; counter < arraySize; counter++) {
   2783             assertTrue(
   2784                     "Binary search on float[] involving negative numbers answered incorrect position",
   2785                     Arrays.binarySearch(floatArray, 0, arraySize,
   2786                             (float) counter - 50) == (float) counter);
   2787         }
   2788         float[] specials = new float[] { Float.NEGATIVE_INFINITY,
   2789                 -Float.MAX_VALUE, -2f, -Float.MIN_VALUE, -0f, 0f,
   2790                 Float.MIN_VALUE, 2f, Float.MAX_VALUE, Float.POSITIVE_INFINITY,
   2791                 Float.NaN };
   2792         for (int i = 0; i < specials.length; i++) {
   2793             int result = Arrays.binarySearch(specials, i, specials.length, specials[i]);
   2794             assertTrue(specials[i] + " invalid: " + result, result == i);
   2795         }
   2796         assertEquals("-1f", -4, Arrays.binarySearch(specials, 0, specials.length, -1f));
   2797         assertEquals("1f", -8, Arrays.binarySearch(specials, 0, specials.length, 1f));
   2798         try {
   2799             Arrays.binarySearch((float[]) null, 2, 1, (float) arraySize);
   2800             fail("should throw NullPointerException");
   2801         } catch (NullPointerException e) {
   2802             // expected
   2803         }
   2804         try {
   2805             Arrays.binarySearch((float[]) null, -1, 0, (float) arraySize);
   2806             fail("should throw NullPointerException");
   2807         } catch (NullPointerException e) {
   2808             // expected
   2809         }
   2810         try {
   2811             Arrays.binarySearch((float[]) null, -1, -2, (float) arraySize);
   2812             fail("should throw NullPointerException");
   2813         } catch (NullPointerException e) {
   2814             // expected
   2815         }
   2816         try {
   2817             Arrays.binarySearch(floatArray, 2, 1, (char) arraySize);
   2818             fail("should throw IllegalArgumentException");
   2819         } catch (IllegalArgumentException e) {
   2820             // expected
   2821         }
   2822         assertEquals(-1, Arrays.binarySearch(floatArray, 0, 0,
   2823                 (char) arraySize));
   2824         try {
   2825             Arrays.binarySearch(floatArray, -1, -2, (char) arraySize);
   2826             fail("should throw IllegalArgumentException");
   2827         } catch (IllegalArgumentException e) {
   2828             // expected
   2829         }
   2830         try {
   2831             Arrays.binarySearch(floatArray, arraySize + 2, arraySize + 1,
   2832                     (char) arraySize);
   2833             fail("should throw IllegalArgumentException");
   2834         } catch (IllegalArgumentException e) {
   2835             // expected
   2836         }
   2837         try {
   2838             Arrays.binarySearch(floatArray, -1, 0, (char) arraySize);
   2839             fail("should throw ArrayIndexOutOfBoundsException");
   2840         } catch (ArrayIndexOutOfBoundsException e) {
   2841             // expected
   2842         }
   2843         try {
   2844             Arrays
   2845                     .binarySearch(floatArray, 0, arraySize + 1,
   2846                             (char) arraySize);
   2847             fail("should throw ArrayIndexOutOfBoundsException");
   2848         } catch (ArrayIndexOutOfBoundsException e) {
   2849             // expected
   2850         }
   2851     }
   2852 
   2853     /**
   2854      * java.util.Arrays#binarySearch(int[], int)
   2855      */
   2856     public void test_binarySearch$IIII() {
   2857         for (int counter = 0; counter < arraySize; counter++) {
   2858             assertTrue(
   2859                     "Binary search on int[] answered incorrect position",
   2860                     Arrays.binarySearch(intArray, counter, arraySize, counter) == counter);
   2861         }
   2862         assertEquals(
   2863                 "Binary search succeeded for value not present in array 1", -1,
   2864                 Arrays.binarySearch(intArray, 0, arraySize, -1));
   2865         assertTrue("Binary search succeeded for value not present in array 2",
   2866                 Arrays.binarySearch(intArray, 0, arraySize, arraySize) == -(arraySize + 1));
   2867         for (int counter = 0; counter < arraySize; counter++) {
   2868             intArray[counter] -= 50;
   2869         }
   2870         for (int counter = 0; counter < arraySize; counter++) {
   2871             assertTrue(
   2872                     "Binary search on int[] involving negative numbers answered incorrect position",
   2873                     Arrays.binarySearch(intArray, 0, arraySize, counter - 50) == counter);
   2874         }
   2875         try {
   2876             Arrays.binarySearch((int[]) null, 2, 1, (int) arraySize);
   2877             fail("should throw NullPointerException");
   2878         } catch (NullPointerException e) {
   2879             // expected
   2880         }
   2881         try {
   2882             Arrays.binarySearch((int[]) null, -1, 0, (int) arraySize);
   2883             fail("should throw NullPointerException");
   2884         } catch (NullPointerException e) {
   2885             // expected
   2886         }
   2887         try {
   2888             Arrays.binarySearch((int[]) null, -1, -2, (int) arraySize);
   2889             fail("should throw NullPointerException");
   2890         } catch (NullPointerException e) {
   2891             // expected
   2892         }
   2893         try {
   2894             Arrays.binarySearch(intArray, 2, 1, (char) arraySize);
   2895             fail("should throw IllegalArgumentException");
   2896         } catch (IllegalArgumentException e) {
   2897             // expected
   2898         }
   2899         assertEquals(-1, Arrays
   2900                 .binarySearch(intArray, 0, 0, (char) arraySize));
   2901         try {
   2902             Arrays.binarySearch(intArray, -1, -2, (char) arraySize);
   2903             fail("should throw IllegalArgumentException");
   2904         } catch (IllegalArgumentException e) {
   2905             // expected
   2906         }
   2907         try {
   2908             Arrays.binarySearch(intArray, arraySize + 2, arraySize + 1,
   2909                     (char) arraySize);
   2910             fail("should throw IllegalArgumentException");
   2911         } catch (IllegalArgumentException e) {
   2912             // expected
   2913         }
   2914         try {
   2915             Arrays.binarySearch(intArray, -1, 0, (char) arraySize);
   2916             fail("should throw ArrayIndexOutOfBoundsException");
   2917         } catch (ArrayIndexOutOfBoundsException e) {
   2918             // expected
   2919         }
   2920         try {
   2921             Arrays.binarySearch(intArray, 0, arraySize + 1, (char) arraySize);
   2922             fail("should throw ArrayIndexOutOfBoundsException");
   2923         } catch (ArrayIndexOutOfBoundsException e) {
   2924             // expected
   2925         }
   2926     }
   2927 
   2928     /**
   2929      * java.util.Arrays#binarySearch(long[], long)
   2930      */
   2931     public void test_binarySearch$JIIJ() {
   2932         for (long counter = 0; counter < arraySize; counter++) {
   2933             assertTrue("Binary search on long[] answered incorrect position",
   2934                     Arrays.binarySearch(longArray, 0, arraySize, counter) == counter);
   2935         }
   2936         assertEquals("Binary search succeeded for value not present in array 1",
   2937                 -1, Arrays.binarySearch(longArray, 0, arraySize, (long) -1));
   2938         assertTrue(
   2939                 "Binary search succeeded for value not present in array 2",
   2940                 Arrays.binarySearch(longArray, 0, arraySize, (long) arraySize) == -(arraySize + 1));
   2941         for (long counter = 0; counter < arraySize; counter++) {
   2942             longArray[(int) counter] -= (long) 50;
   2943         }
   2944         for (long counter = 0; counter < arraySize; counter++) {
   2945             assertTrue(
   2946                     "Binary search on long[] involving negative numbers answered incorrect position",
   2947                     Arrays.binarySearch(longArray, 0, arraySize, counter - (long) 50) == counter);
   2948         }
   2949         try {
   2950             Arrays.binarySearch((long[]) null, 2, 1, (long) arraySize);
   2951             fail("should throw NullPointerException");
   2952         } catch (NullPointerException e) {
   2953             // expected
   2954         }
   2955         try {
   2956             Arrays.binarySearch((long[]) null, -1, 0, (long) arraySize);
   2957             fail("should throw NullPointerException");
   2958         } catch (NullPointerException e) {
   2959             // expected
   2960         }
   2961         try {
   2962             Arrays.binarySearch((long[]) null, -1, -2, (long) arraySize);
   2963             fail("should throw NullPointerException");
   2964         } catch (NullPointerException e) {
   2965             // expected
   2966         }
   2967         try {
   2968             Arrays.binarySearch(longArray, 2, 1, (char) arraySize);
   2969             fail("should throw IllegalArgumentException");
   2970         } catch (IllegalArgumentException e) {
   2971             // expected
   2972         }
   2973         assertEquals(-1, Arrays
   2974                 .binarySearch(longArray, 0, 0, (char) arraySize));
   2975         try {
   2976             Arrays.binarySearch(longArray, -1, -2, (char) arraySize);
   2977             fail("should throw IllegalArgumentException");
   2978         } catch (IllegalArgumentException e) {
   2979             // expected
   2980         }
   2981         try {
   2982             Arrays.binarySearch(longArray, arraySize + 2, arraySize + 1,
   2983                     (char) arraySize);
   2984             fail("should throw IllegalArgumentException");
   2985         } catch (IllegalArgumentException e) {
   2986             // expected
   2987         }
   2988         try {
   2989             Arrays.binarySearch(longArray, -1, 0, (char) arraySize);
   2990             fail("should throw ArrayIndexOutOfBoundsException");
   2991         } catch (ArrayIndexOutOfBoundsException e) {
   2992             // expected
   2993         }
   2994         try {
   2995             Arrays.binarySearch(longArray, 0, arraySize + 1, (char) arraySize);
   2996             fail("should throw ArrayIndexOutOfBoundsException");
   2997         } catch (ArrayIndexOutOfBoundsException e) {
   2998             // expected
   2999         }
   3000     }
   3001 
   3002     /**
   3003      * java.util.Arrays#binarySearch(java.lang.Object[],
   3004      *java.lang.Object)
   3005      */
   3006     public void test_binarySearch$Ljava_lang_ObjectIILjava_lang_Object() {
   3007         assertEquals(
   3008                 "Binary search succeeded for non-comparable value in empty array",
   3009                 -1, Arrays.binarySearch(new Object[] { }, 0, 0, new Object()));
   3010         assertEquals(
   3011                 "Binary search succeeded for comparable value in empty array",
   3012                 -1, Arrays.binarySearch(new Object[] { }, 0, 0, new Integer(-1)));
   3013         for (int counter = 0; counter < arraySize; counter++) {
   3014             assertTrue(
   3015                     "Binary search on Object[] answered incorrect position",
   3016                     Arrays.binarySearch(objectArray, counter, arraySize, objArray[counter]) == counter);
   3017         }
   3018         assertEquals("Binary search succeeded for value not present in array 1",
   3019                 -1, Arrays.binarySearch(objectArray, 0, arraySize, new Integer(-1)));
   3020         assertTrue(
   3021                 "Binary search succeeded for value not present in array 2",
   3022                 Arrays.binarySearch(objectArray, 0, arraySize, new Integer(arraySize)) == -(arraySize + 1));
   3023         try {
   3024             Arrays.binarySearch((Object[]) null, 2, 1, (byte) arraySize);
   3025             fail("should throw NullPointerException");
   3026         } catch (NullPointerException e) {
   3027             // expected
   3028         }
   3029         try {
   3030             Arrays.binarySearch((Object[]) null, -1, 0, (byte) arraySize);
   3031             fail("should throw NullPointerException");
   3032         } catch (NullPointerException e) {
   3033             // expected
   3034         }
   3035         try {
   3036             Arrays.binarySearch((Object[]) null, -1, -2, (byte) arraySize);
   3037             fail("should throw NullPointerException");
   3038         } catch (NullPointerException e) {
   3039             // expected
   3040         }
   3041         try {
   3042             Arrays.binarySearch(objectArray, 2, 1, (char) arraySize);
   3043             fail("should throw IllegalArgumentException");
   3044         } catch (IllegalArgumentException e) {
   3045             // expected
   3046         }
   3047         assertEquals(-1, Arrays
   3048                 .binarySearch(objectArray, 0, 0, (char) arraySize));
   3049         try {
   3050             Arrays.binarySearch(objectArray, -1, -2, (char) arraySize);
   3051             fail("should throw IllegalArgumentException");
   3052         } catch (IllegalArgumentException e) {
   3053             // expected
   3054         }
   3055         try {
   3056             Arrays.binarySearch(objectArray, arraySize + 2, arraySize + 1,
   3057                     (char) arraySize);
   3058             fail("should throw IllegalArgumentException");
   3059         } catch (IllegalArgumentException e) {
   3060             // expected
   3061         }
   3062         try {
   3063             Arrays.binarySearch(objectArray, -1, 0, (char) arraySize);
   3064             fail("should throw ArrayIndexOutOfBoundsException");
   3065         } catch (ArrayIndexOutOfBoundsException e) {
   3066             // expected
   3067         }
   3068         try {
   3069             Arrays.binarySearch(objectArray, 0, arraySize + 1, (char) arraySize);
   3070             fail("should throw ArrayIndexOutOfBoundsException");
   3071         } catch (ArrayIndexOutOfBoundsException e) {
   3072             // expected
   3073         }
   3074     }
   3075 
   3076     /**
   3077      * java.util.Arrays#binarySearch(java.lang.Object[],
   3078      *java.lang.Object, java.util.Comparator)
   3079      */
   3080     public void test_binarySearch$Ljava_lang_ObjectIILjava_lang_ObjectLjava_util_Comparator() {
   3081         Comparator comp = new ReversedIntegerComparator();
   3082         for (int counter = 0; counter < arraySize; counter++) {
   3083             objectArray[counter] = objArray[arraySize - counter - 1];
   3084         }
   3085         assertTrue("Binary search succeeded for value not present in array 1",
   3086                 Arrays.binarySearch(objectArray, 0, arraySize, new Integer(-1),
   3087                         comp) == -(arraySize + 1));
   3088         assertEquals(
   3089                 "Binary search succeeded for value not present in array 2", -1,
   3090                 Arrays.binarySearch(objectArray, 0, arraySize, new Integer(
   3091                         arraySize), comp));
   3092         for (int counter = 0; counter < arraySize; counter++) {
   3093             assertTrue(
   3094                     "Binary search on Object[] with custom comparator answered incorrect position",
   3095                     Arrays.binarySearch(objectArray, objArray[counter], comp) == arraySize
   3096                             - counter - 1);
   3097         }
   3098         try {
   3099             Arrays.binarySearch((Object[]) null, 2, 1, (byte) arraySize);
   3100             fail("should throw NullPointerException");
   3101         } catch (NullPointerException e) {
   3102             // expected
   3103         }
   3104         try {
   3105             Arrays.binarySearch((Object[]) null, -1, 0, (byte) arraySize);
   3106             fail("should throw NullPointerException");
   3107         } catch (NullPointerException e) {
   3108             // expected
   3109         }
   3110         try {
   3111             Arrays.binarySearch((Object[]) null, -1, -2, (byte) arraySize);
   3112             fail("should throw NullPointerException");
   3113         } catch (NullPointerException e) {
   3114             // expected
   3115         }
   3116         try {
   3117             Arrays.binarySearch(objectArray, 2, 1, (char) arraySize, comp);
   3118             fail("should throw IllegalArgumentException");
   3119         } catch (IllegalArgumentException e) {
   3120             // expected
   3121         }
   3122         assertEquals(-1, Arrays.binarySearch(objectArray, 0, 0,
   3123                 (char) arraySize, comp));
   3124         try {
   3125             Arrays.binarySearch(objectArray, -1, -2, (char) arraySize, comp);
   3126             fail("should throw IllegalArgumentException");
   3127         } catch (IllegalArgumentException e) {
   3128             // expected
   3129         }
   3130         try {
   3131             Arrays.binarySearch(objectArray, arraySize + 2, arraySize + 1,
   3132                     (char) arraySize, comp);
   3133             fail("should throw IllegalArgumentException");
   3134         } catch (IllegalArgumentException e) {
   3135             // expected
   3136         }
   3137         try {
   3138             Arrays.binarySearch(objectArray, -1, 0, (char) arraySize, comp);
   3139             fail("should throw ArrayIndexOutOfBoundsException");
   3140         } catch (ArrayIndexOutOfBoundsException e) {
   3141             // expected
   3142         }
   3143         try {
   3144             Arrays.binarySearch(objectArray, 0, arraySize + 1,
   3145                     (char) arraySize, comp);
   3146             fail("should throw ArrayIndexOutOfBoundsException");
   3147         } catch (ArrayIndexOutOfBoundsException e) {
   3148             // expected
   3149         }
   3150         try {
   3151             Arrays.binarySearch(objectArray, 0, arraySize,
   3152                     new LinkedList(), comp);
   3153             fail("should throw ClassCastException");
   3154         } catch (ClassCastException e) {
   3155             // expected
   3156         }
   3157     }
   3158 
   3159     /**
   3160      * java.util.Arrays#binarySearch(short[], short)
   3161      */
   3162     public void test_binarySearch$SIIS() {
   3163         for (short counter = 0; counter < arraySize; counter++) {
   3164             assertTrue("Binary search on short[] answered incorrect position",
   3165                     Arrays.binarySearch(shortArray, counter, arraySize, counter) == counter);
   3166         }
   3167         assertEquals("Binary search succeeded for value not present in array 1",
   3168                 -1, Arrays.binarySearch(shortArray, 0, arraySize, (short) -1));
   3169         assertTrue(
   3170                 "Binary search succeeded for value not present in array 2",
   3171                 Arrays.binarySearch(shortArray, 0, arraySize, (short) arraySize) == -(arraySize + 1));
   3172         for (short counter = 0; counter < arraySize; counter++) {
   3173             shortArray[counter] -= 50;
   3174         }
   3175         for (short counter = 0; counter < arraySize; counter++) {
   3176             assertTrue(
   3177                     "Binary search on short[] involving negative numbers answered incorrect position",
   3178                     Arrays.binarySearch(shortArray, counter, arraySize, (short) (counter - 50)) == counter);
   3179         }
   3180         try {
   3181             Arrays.binarySearch((String[]) null, 2, 1, (byte) arraySize);
   3182             fail("should throw NullPointerException");
   3183         } catch (NullPointerException e) {
   3184             // expected
   3185         }
   3186         try {
   3187             Arrays.binarySearch((String[]) null, -1, 0, (byte) arraySize);
   3188             fail("should throw NullPointerException");
   3189         } catch (NullPointerException e) {
   3190             // expected
   3191         }
   3192         try {
   3193             Arrays.binarySearch((String[]) null, -1, -2, (byte) arraySize);
   3194             fail("should throw NullPointerException");
   3195         } catch (NullPointerException e) {
   3196             // expected
   3197         }
   3198         try {
   3199             Arrays.binarySearch(shortArray, 2, 1, (short) arraySize);
   3200             fail("should throw IllegalArgumentException");
   3201         } catch (IllegalArgumentException e) {
   3202             // expected
   3203         }
   3204         assertEquals(-1, Arrays
   3205                 .binarySearch(shortArray, 0, 0, (short) arraySize));
   3206         try {
   3207             Arrays.binarySearch(shortArray, -1, -2, (short) arraySize);
   3208             fail("should throw IllegalArgumentException");
   3209         } catch (IllegalArgumentException e) {
   3210             // expected
   3211         }
   3212         try {
   3213             Arrays.binarySearch(shortArray, arraySize + 2, arraySize + 1,
   3214                     (short) arraySize);
   3215             fail("should throw IllegalArgumentException");
   3216         } catch (IllegalArgumentException e) {
   3217             // expected
   3218         }
   3219         try {
   3220             Arrays.binarySearch(shortArray, -1, 0, (short) arraySize);
   3221             fail("should throw ArrayIndexOutOfBoundsException");
   3222         } catch (ArrayIndexOutOfBoundsException e) {
   3223             // expected
   3224         }
   3225         try {
   3226             Arrays.binarySearch(shortArray, 0, arraySize + 1, (short) arraySize);
   3227             fail("should throw ArrayIndexOutOfBoundsException");
   3228         } catch (ArrayIndexOutOfBoundsException e) {
   3229             // expected
   3230         }
   3231         String[] array = { "a", "b", "c" };
   3232         assertEquals(-2, Arrays.binarySearch(array, 1, 2, "a", null));
   3233     }
   3234 
   3235     /**
   3236      * {@link java.util.Arrays#copyOf(byte[], int)
   3237      */
   3238     public void test_copyOf_$BI() throws Exception {
   3239         byte[] result = Arrays.copyOf(byteArray, arraySize * 2);
   3240         int i = 0;
   3241         for (; i < arraySize; i++) {
   3242             assertEquals(i, result[i]);
   3243         }
   3244         for (; i < result.length; i++) {
   3245             assertEquals(0, result[i]);
   3246         }
   3247         result = Arrays.copyOf(byteArray, arraySize / 2);
   3248         i = 0;
   3249         for (; i < result.length; i++) {
   3250             assertEquals(i, result[i]);
   3251         }
   3252         try {
   3253             Arrays.copyOf((byte[]) null, arraySize);
   3254             fail("should throw NullPointerException");
   3255         } catch (NullPointerException e) {
   3256             // expected
   3257         }
   3258         try {
   3259             Arrays.copyOf(byteArray, -1);
   3260             fail("should throw NegativeArraySizeException");
   3261         } catch (NegativeArraySizeException e) {
   3262             // expected
   3263         }
   3264         try {
   3265             Arrays.copyOf((byte[]) null, -1);
   3266             fail("should throw NegativeArraySizeException");
   3267         } catch (NegativeArraySizeException e) {
   3268             // expected
   3269         }
   3270     }
   3271 
   3272     /**
   3273      * {@link java.util.Arrays#copyOf(short[], int)
   3274      */
   3275     public void test_copyOf_$SI() throws Exception {
   3276         short[] result = Arrays.copyOf(shortArray, arraySize * 2);
   3277         int i = 0;
   3278         for (; i < arraySize; i++) {
   3279             assertEquals(i, result[i]);
   3280         }
   3281         for (; i < result.length; i++) {
   3282             assertEquals(0, result[i]);
   3283         }
   3284         result = Arrays.copyOf(shortArray, arraySize / 2);
   3285         i = 0;
   3286         for (; i < result.length; i++) {
   3287             assertEquals(i, result[i]);
   3288         }
   3289         try {
   3290             Arrays.copyOf((short[]) null, arraySize);
   3291             fail("should throw NullPointerException");
   3292         } catch (NullPointerException e) {
   3293             // expected
   3294         }
   3295         try {
   3296             Arrays.copyOf(shortArray, -1);
   3297             fail("should throw NegativeArraySizeException");
   3298         } catch (NegativeArraySizeException e) {
   3299             // expected
   3300         }
   3301         try {
   3302             Arrays.copyOf((short[]) null, -1);
   3303             fail("should throw NegativeArraySizeException");
   3304         } catch (NegativeArraySizeException e) {
   3305             // expected
   3306         }
   3307     }
   3308 
   3309     /**
   3310      * {@link java.util.Arrays#copyOf(int[], int)
   3311      */
   3312     public void test_copyOf_$II() throws Exception {
   3313         int[] result = Arrays.copyOf(intArray, arraySize * 2);
   3314         int i = 0;
   3315         for (; i < arraySize; i++) {
   3316             assertEquals(i, result[i]);
   3317         }
   3318         for (; i < result.length; i++) {
   3319             assertEquals(0, result[i]);
   3320         }
   3321         result = Arrays.copyOf(intArray, arraySize / 2);
   3322         i = 0;
   3323         for (; i < result.length; i++) {
   3324             assertEquals(i, result[i]);
   3325         }
   3326         try {
   3327             Arrays.copyOf((int[]) null, arraySize);
   3328             fail("should throw NullPointerException");
   3329         } catch (NullPointerException e) {
   3330             // expected
   3331         }
   3332         try {
   3333             Arrays.copyOf(intArray, -1);
   3334             fail("should throw NegativeArraySizeException");
   3335         } catch (NegativeArraySizeException e) {
   3336             // expected
   3337         }
   3338         try {
   3339             Arrays.copyOf((int[]) null, -1);
   3340             fail("should throw NegativeArraySizeException");
   3341         } catch (NegativeArraySizeException e) {
   3342             // expected
   3343         }
   3344     }
   3345 
   3346     /**
   3347      * {@link java.util.Arrays#copyOf(boolean[], int)
   3348      */
   3349     public void test_copyOf_$ZI() throws Exception {
   3350         boolean[] result = Arrays.copyOf(booleanArray, arraySize * 2);
   3351         int i = 0;
   3352         for (; i < arraySize; i++) {
   3353             assertEquals(booleanArray[i], result[i]);
   3354         }
   3355         for (; i < result.length; i++) {
   3356             assertEquals(false, result[i]);
   3357         }
   3358         result = Arrays.copyOf(booleanArray, arraySize / 2);
   3359         i = 0;
   3360         for (; i < result.length; i++) {
   3361             assertEquals(booleanArray[i], result[i]);
   3362         }
   3363         try {
   3364             Arrays.copyOf((boolean[]) null, arraySize);
   3365             fail("should throw NullPointerException");
   3366         } catch (NullPointerException e) {
   3367             // expected
   3368         }
   3369         try {
   3370             Arrays.copyOf(booleanArray, -1);
   3371             fail("should throw NegativeArraySizeException");
   3372         } catch (NegativeArraySizeException e) {
   3373             // expected
   3374         }
   3375         try {
   3376             Arrays.copyOf((boolean[]) null, -1);
   3377             fail("should throw NegativeArraySizeException");
   3378         } catch (NegativeArraySizeException e) {
   3379             // expected
   3380         }
   3381     }
   3382 
   3383     /**
   3384      * {@link java.util.Arrays#copyOf(char[], int)
   3385      */
   3386     public void test_copyOf_$CI() throws Exception {
   3387         char[] result = Arrays.copyOf(charArray, arraySize * 2);
   3388         int i = 0;
   3389         for (; i < arraySize; i++) {
   3390             assertEquals(i + 1, result[i]);
   3391         }
   3392         for (; i < result.length; i++) {
   3393             assertEquals(0, result[i]);
   3394         }
   3395         result = Arrays.copyOf(charArray, arraySize / 2);
   3396         i = 0;
   3397         for (; i < result.length; i++) {
   3398             assertEquals(i + 1, result[i]);
   3399         }
   3400         try {
   3401             Arrays.copyOf((char[]) null, arraySize);
   3402             fail("should throw NullPointerException");
   3403         } catch (NullPointerException e) {
   3404             // expected
   3405         }
   3406         try {
   3407             Arrays.copyOf(charArray, -1);
   3408             fail("should throw NegativeArraySizeException");
   3409         } catch (NegativeArraySizeException e) {
   3410             // expected
   3411         }
   3412         try {
   3413             Arrays.copyOf((char[]) null, -1);
   3414             fail("should throw NegativeArraySizeException");
   3415         } catch (NegativeArraySizeException e) {
   3416             // expected
   3417         }
   3418     }
   3419 
   3420     /**
   3421      * {@link java.util.Arrays#copyOf(float[], int)
   3422      */
   3423     public void test_copyOf_$FI() throws Exception {
   3424         float[] result = Arrays.copyOf(floatArray, arraySize * 2);
   3425         int i = 0;
   3426         for (; i < arraySize; i++) {
   3427             assertEquals(floatArray[i], result[i]);
   3428         }
   3429         for (; i < result.length; i++) {
   3430             assertEquals(0.0f, result[i]);
   3431         }
   3432         result = Arrays.copyOf(floatArray, arraySize / 2);
   3433         i = 0;
   3434         for (; i < result.length; i++) {
   3435             assertEquals(floatArray[i], result[i]);
   3436         }
   3437         try {
   3438             Arrays.copyOf((float[]) null, arraySize);
   3439             fail("should throw NullPointerException");
   3440         } catch (NullPointerException e) {
   3441             // expected
   3442         }
   3443         try {
   3444             Arrays.copyOf(floatArray, -1);
   3445             fail("should throw NegativeArraySizeException");
   3446         } catch (NegativeArraySizeException e) {
   3447             // expected
   3448         }
   3449         try {
   3450             Arrays.copyOf((float[]) null, -1);
   3451             fail("should throw NegativeArraySizeException");
   3452         } catch (NegativeArraySizeException e) {
   3453             // expected
   3454         }
   3455     }
   3456 
   3457     /**
   3458      * {@link java.util.Arrays#copyOf(double[], int)
   3459      */
   3460     public void test_copyOf_$DI() throws Exception {
   3461         double[] result = Arrays.copyOf(doubleArray, arraySize * 2);
   3462         int i = 0;
   3463         for (; i < arraySize; i++) {
   3464             assertEquals(doubleArray[i], result[i]);
   3465         }
   3466         for (; i < result.length; i++) {
   3467             assertEquals(0.0, result[i]);
   3468         }
   3469         result = Arrays.copyOf(doubleArray, arraySize / 2);
   3470         i = 0;
   3471         for (; i < result.length; i++) {
   3472             assertEquals(doubleArray[i], result[i]);
   3473         }
   3474         try {
   3475             Arrays.copyOf((double[]) null, arraySize);
   3476             fail("should throw NullPointerException");
   3477         } catch (NullPointerException e) {
   3478             // expected
   3479         }
   3480         try {
   3481             Arrays.copyOf(doubleArray, -1);
   3482             fail("should throw NegativeArraySizeException");
   3483         } catch (NegativeArraySizeException e) {
   3484             // expected
   3485         }
   3486         try {
   3487             Arrays.copyOf((double[]) null, -1);
   3488             fail("should throw NegativeArraySizeException");
   3489         } catch (NegativeArraySizeException e) {
   3490             // expected
   3491         }
   3492     }
   3493 
   3494     /**
   3495      * {@link java.util.Arrays#copyOf(long[], int)
   3496      */
   3497     public void test_copyOf_$JI() throws Exception {
   3498         long[] result = Arrays.copyOf(longArray, arraySize * 2);
   3499         int i = 0;
   3500         for (; i < arraySize; i++) {
   3501             assertEquals(longArray[i], result[i]);
   3502         }
   3503         for (; i < result.length; i++) {
   3504             assertEquals(0, result[i]);
   3505         }
   3506         result = Arrays.copyOf(longArray, arraySize / 2);
   3507         i = 0;
   3508         for (; i < result.length; i++) {
   3509             assertEquals(longArray[i], result[i]);
   3510         }
   3511         try {
   3512             Arrays.copyOf((long[]) null, arraySize);
   3513             fail("should throw NullPointerException");
   3514         } catch (NullPointerException e) {
   3515             // expected
   3516         }
   3517         try {
   3518             Arrays.copyOf(longArray, -1);
   3519             fail("should throw NegativeArraySizeException");
   3520         } catch (NegativeArraySizeException e) {
   3521             // expected
   3522         }
   3523         try {
   3524             Arrays.copyOf((long[]) null, -1);
   3525             fail("should throw NegativeArraySizeException");
   3526         } catch (NegativeArraySizeException e) {
   3527             // expected
   3528         }
   3529     }
   3530 
   3531     /**
   3532      * {@link java.util.Arrays#copyOf(T[], int)
   3533      */
   3534     public void test_copyOf_$TI() throws Exception {
   3535         Object[] result = Arrays.copyOf(objArray, arraySize * 2);
   3536         int i = 0;
   3537         for (; i < arraySize; i++) {
   3538             assertEquals(objArray[i], result[i]);
   3539         }
   3540         for (; i < result.length; i++) {
   3541             assertNull(result[i]);
   3542         }
   3543         result = Arrays.copyOf(objArray, arraySize / 2);
   3544         i = 0;
   3545         for (; i < result.length; i++) {
   3546             assertEquals(objArray[i], result[i]);
   3547         }
   3548         try {
   3549             Arrays.copyOf((String[]) null, arraySize);
   3550             fail("should throw NullPointerException");
   3551         } catch (NullPointerException e) {
   3552             // expected
   3553         }
   3554         try {
   3555             Arrays.copyOf(objArray, -1);
   3556             fail("should throw NegativeArraySizeException");
   3557         } catch (NegativeArraySizeException e) {
   3558             // expected
   3559         }
   3560         try {
   3561             Arrays.copyOf((String[]) null, -1);
   3562             fail("should throw NullPointerException");
   3563         } catch (NullPointerException e) {
   3564             // expected
   3565         }
   3566 
   3567         Date[] component = new Date[0];
   3568         Object object[] = new Date[0];
   3569 
   3570         object = Arrays.copyOf(component, 2);
   3571         assertNotNull(object);
   3572         component = Arrays.copyOf(component, 2);
   3573         assertNotNull(component);
   3574         assertEquals(2, component.length);
   3575     }
   3576 
   3577     /**
   3578      * {@link java.util.Arrays#copyOf(T[], int, Class<? extends Object[]>))
   3579      */
   3580     public void test_copyOf_$TILClass() throws Exception {
   3581         Object[] result = Arrays.copyOf(objArray, arraySize * 2, Object[].class);
   3582         int i = 0;
   3583         for (; i < arraySize; i++) {
   3584             assertEquals(objArray[i], result[i]);
   3585         }
   3586         for (; i < result.length; i++) {
   3587             assertNull(result[i]);
   3588         }
   3589         result = Arrays.copyOf(objArray, arraySize / 2, Object[].class);
   3590         i = 0;
   3591         for (; i < result.length; i++) {
   3592             assertEquals(objArray[i], result[i]);
   3593         }
   3594         result = Arrays.copyOf(objArray, arraySize / 2, Integer[].class);
   3595         i = 0;
   3596         for (; i < result.length; i++) {
   3597             assertEquals(objArray[i], result[i]);
   3598         }
   3599         try {
   3600             Arrays.copyOf((Object[]) null, arraySize, LinkedList[].class);
   3601             fail("should throw NullPointerException");
   3602         } catch (NullPointerException e) {
   3603             // expected
   3604         }
   3605         try {
   3606             Arrays.copyOf(objArray, arraySize, LinkedList[].class);
   3607             fail("should throw ArrayStoreException ");
   3608         } catch (ArrayStoreException e) {
   3609             // expected
   3610         }
   3611         try {
   3612             Arrays.copyOf((Object[]) null, arraySize, Object[].class);
   3613             fail("should throw NullPointerException");
   3614         } catch (NullPointerException e) {
   3615             // expected
   3616         }
   3617         try {
   3618             Arrays.copyOf(objArray, -1, Object[].class);
   3619             fail("should throw NegativeArraySizeException");
   3620         } catch (NegativeArraySizeException e) {
   3621             // expected
   3622         }
   3623         try {
   3624             Arrays.copyOf((Object[]) null, -1, Object[].class);
   3625             fail("should throw NegativeArraySizeException");
   3626         } catch (NegativeArraySizeException e) {
   3627             // expected
   3628         }
   3629         try {
   3630             Arrays.copyOf((Object[]) null, -1, LinkedList[].class);
   3631             fail("should throw NegativeArraySizeException");
   3632         } catch (NegativeArraySizeException e) {
   3633             // expected
   3634         }
   3635         try {
   3636             Arrays.copyOf((Object[]) null, 0, LinkedList[].class);
   3637             fail("should throw NullPointerException");
   3638         } catch (NullPointerException e) {
   3639             // expected
   3640         }
   3641         assertEquals(0, Arrays.copyOf(objArray, 0, LinkedList[].class).length);
   3642     }
   3643 
   3644     /**
   3645      * {@link java.util.Arrays#copyOfRange(byte[], int, int)
   3646      */
   3647     public void test_copyOfRange_$BII() throws Exception {
   3648         byte[] result = Arrays.copyOfRange(byteArray, 0, arraySize * 2);
   3649         int i = 0;
   3650         for (; i < arraySize; i++) {
   3651             assertEquals(i, result[i]);
   3652         }
   3653         for (; i < result.length; i++) {
   3654             assertEquals(0, result[i]);
   3655         }
   3656         result = Arrays.copyOfRange(byteArray, 0, arraySize / 2);
   3657         i = 0;
   3658         for (; i < result.length; i++) {
   3659             assertEquals(i, result[i]);
   3660         }
   3661         result = Arrays.copyOfRange(byteArray, 0, 0);
   3662         assertEquals(0, result.length);
   3663         try {
   3664             Arrays.copyOfRange((byte[]) null, 0, arraySize);
   3665             fail("should throw NullPointerException");
   3666         } catch (NullPointerException e) {
   3667             // expected
   3668         }
   3669         try {
   3670             Arrays.copyOfRange((byte[]) null, -1, arraySize);
   3671             fail("should throw NullPointerException");
   3672         } catch (NullPointerException e) {
   3673             // expected
   3674         }
   3675         try {
   3676             Arrays.copyOfRange((byte[]) null, 0, -1);
   3677             fail("should throw IllegalArgumentException");
   3678         } catch (IllegalArgumentException e) {
   3679             // expected
   3680         }
   3681         try {
   3682             Arrays.copyOfRange(byteArray, -1, arraySize);
   3683             fail("should throw ArrayIndexOutOfBoundsException");
   3684         } catch (ArrayIndexOutOfBoundsException e) {
   3685             // expected
   3686         }
   3687         try {
   3688             Arrays.copyOfRange(byteArray, 0, -1);
   3689             fail("should throw IllegalArgumentException");
   3690         } catch (IllegalArgumentException e) {
   3691             // expected
   3692         }
   3693         assertEquals(byteArray.length + 1, Arrays.copyOfRange(byteArray, 0,
   3694                 byteArray.length + 1).length);
   3695     }
   3696 
   3697     /**
   3698      * {@link java.util.Arrays#copyOfRange(short[], int, int)
   3699      */
   3700     public void test_copyOfRange_$SII() throws Exception {
   3701         short[] result = Arrays.copyOfRange(shortArray, 0, arraySize * 2);
   3702         int i = 0;
   3703         for (; i < arraySize; i++) {
   3704             assertEquals(i, result[i]);
   3705         }
   3706         for (; i < result.length; i++) {
   3707             assertEquals(0, result[i]);
   3708         }
   3709         result = Arrays.copyOfRange(shortArray, 0, arraySize / 2);
   3710         i = 0;
   3711         for (; i < result.length; i++) {
   3712             assertEquals(i, result[i]);
   3713         }
   3714         result = Arrays.copyOfRange(shortArray, 0, 0);
   3715         assertEquals(0, result.length);
   3716         try {
   3717             Arrays.copyOfRange((short[]) null, 0, arraySize);
   3718             fail("should throw NullPointerException");
   3719         } catch (NullPointerException e) {
   3720             // expected
   3721         }
   3722         try {
   3723             Arrays.copyOfRange((short[]) null, -1, arraySize);
   3724             fail("should throw NullPointerException");
   3725         } catch (NullPointerException e) {
   3726             // expected
   3727         }
   3728         try {
   3729             Arrays.copyOfRange((short[]) null, 0, -1);
   3730             fail("should throw IllegalArgumentException");
   3731         } catch (IllegalArgumentException e) {
   3732             // expected
   3733         }
   3734         try {
   3735             Arrays.copyOfRange(shortArray, -1, arraySize);
   3736             fail("should throw ArrayIndexOutOfBoundsException");
   3737         } catch (ArrayIndexOutOfBoundsException e) {
   3738             // expected
   3739         }
   3740         try {
   3741             Arrays.copyOfRange(shortArray, 0, -1);
   3742             fail("should throw IllegalArgumentException");
   3743         } catch (IllegalArgumentException e) {
   3744             // expected
   3745         }
   3746         assertEquals(shortArray.length + 1, Arrays.copyOfRange(shortArray, 0,
   3747                 shortArray.length + 1).length);
   3748     }
   3749 
   3750     /**
   3751      * {@link java.util.Arrays#copyOfRange(int[], int, int)
   3752      */
   3753     public void test_copyOfRange_$III() throws Exception {
   3754         int[] result = Arrays.copyOfRange(intArray, 0, arraySize * 2);
   3755         int i = 0;
   3756         for (; i < arraySize; i++) {
   3757             assertEquals(i, result[i]);
   3758         }
   3759         for (; i < result.length; i++) {
   3760             assertEquals(0, result[i]);
   3761         }
   3762         result = Arrays.copyOfRange(intArray, 0, arraySize / 2);
   3763         i = 0;
   3764         for (; i < result.length; i++) {
   3765             assertEquals(i, result[i]);
   3766         }
   3767         result = Arrays.copyOfRange(intArray, 0, 0);
   3768         assertEquals(0, result.length);
   3769         try {
   3770             Arrays.copyOfRange((int[]) null, 0, arraySize);
   3771             fail("should throw NullPointerException");
   3772         } catch (NullPointerException e) {
   3773             // expected
   3774         }
   3775         try {
   3776             Arrays.copyOfRange((int[]) null, -1, arraySize);
   3777             fail("should throw NullPointerException");
   3778         } catch (NullPointerException e) {
   3779             // expected
   3780         }
   3781         try {
   3782             Arrays.copyOfRange((int[]) null, 0, -1);
   3783             fail("should throw IllegalArgumentException");
   3784         } catch (IllegalArgumentException e) {
   3785             // expected
   3786         }
   3787         try {
   3788             Arrays.copyOfRange(intArray, -1, arraySize);
   3789             fail("should throw ArrayIndexOutOfBoundsException");
   3790         } catch (ArrayIndexOutOfBoundsException e) {
   3791             // expected
   3792         }
   3793         try {
   3794             Arrays.copyOfRange(intArray, 0, -1);
   3795             fail("should throw IllegalArgumentException");
   3796         } catch (IllegalArgumentException e) {
   3797             // expected
   3798         }
   3799         assertEquals(intArray.length + 1, Arrays.copyOfRange(intArray, 0,
   3800                 intArray.length + 1).length);
   3801     }
   3802 
   3803     /**
   3804      * {@link java.util.Arrays#copyOfRange(long[], int, int)
   3805      */
   3806     public void test_copyOfRange_$JII() throws Exception {
   3807         long[] result = Arrays.copyOfRange(longArray, 0, arraySize * 2);
   3808         int i = 0;
   3809         for (; i < arraySize; i++) {
   3810             assertEquals(i, result[i]);
   3811         }
   3812         for (; i < result.length; i++) {
   3813             assertEquals(0, result[i]);
   3814         }
   3815         result = Arrays.copyOfRange(longArray, 0, arraySize / 2);
   3816         i = 0;
   3817         for (; i < result.length; i++) {
   3818             assertEquals(i, result[i]);
   3819         }
   3820         result = Arrays.copyOfRange(longArray, 0, 0);
   3821         assertEquals(0, result.length);
   3822         try {
   3823             Arrays.copyOfRange((long[]) null, 0, arraySize);
   3824             fail("should throw NullPointerException");
   3825         } catch (NullPointerException e) {
   3826             // expected
   3827         }
   3828         try {
   3829             Arrays.copyOfRange((long[]) null, -1, arraySize);
   3830             fail("should throw NullPointerException");
   3831         } catch (NullPointerException e) {
   3832             // expected
   3833         }
   3834         try {
   3835             Arrays.copyOfRange((long[]) null, 0, -1);
   3836             fail("should throw IllegalArgumentException");
   3837         } catch (IllegalArgumentException e) {
   3838             // expected
   3839         }
   3840         try {
   3841             Arrays.copyOfRange(longArray, -1, arraySize);
   3842             fail("should throw ArrayIndexOutOfBoundsException");
   3843         } catch (ArrayIndexOutOfBoundsException e) {
   3844             // expected
   3845         }
   3846         try {
   3847             Arrays.copyOfRange(longArray, 0, -1);
   3848             fail("should throw IllegalArgumentException");
   3849         } catch (IllegalArgumentException e) {
   3850             // expected
   3851         }
   3852         assertEquals(longArray.length + 1, Arrays.copyOfRange(longArray, 0,
   3853                 longArray.length + 1).length);
   3854     }
   3855 
   3856     /**
   3857      * {@link java.util.Arrays#copyOfRange(char[], int, int)
   3858      */
   3859     public void test_copyOfRange_$CII() throws Exception {
   3860         char[] result = Arrays.copyOfRange(charArray, 0, arraySize * 2);
   3861         int i = 0;
   3862         for (; i < arraySize; i++) {
   3863             assertEquals(i + 1, result[i]);
   3864         }
   3865         for (; i < result.length; i++) {
   3866             assertEquals(0, result[i]);
   3867         }
   3868         result = Arrays.copyOfRange(charArray, 0, arraySize / 2);
   3869         i = 0;
   3870         for (; i < result.length; i++) {
   3871             assertEquals(i + 1, result[i]);
   3872         }
   3873         result = Arrays.copyOfRange(charArray, 0, 0);
   3874         assertEquals(0, result.length);
   3875         try {
   3876             Arrays.copyOfRange((char[]) null, 0, arraySize);
   3877             fail("should throw NullPointerException");
   3878         } catch (NullPointerException e) {
   3879             // expected
   3880         }
   3881         try {
   3882             Arrays.copyOfRange((char[]) null, -1, arraySize);
   3883             fail("should throw NullPointerException");
   3884         } catch (NullPointerException e) {
   3885             // expected
   3886         }
   3887         try {
   3888             Arrays.copyOfRange((char[]) null, 0, -1);
   3889             fail("should throw IllegalArgumentException");
   3890         } catch (IllegalArgumentException e) {
   3891             // expected
   3892         }
   3893         try {
   3894             Arrays.copyOfRange(charArray, -1, arraySize);
   3895             fail("should throw ArrayIndexOutOfBoundsException");
   3896         } catch (ArrayIndexOutOfBoundsException e) {
   3897             // expected
   3898         }
   3899         try {
   3900             Arrays.copyOfRange(charArray, 0, -1);
   3901             fail("should throw IllegalArgumentException");
   3902         } catch (IllegalArgumentException e) {
   3903             // expected
   3904         }
   3905         assertEquals(charArray.length + 1, Arrays.copyOfRange(charArray, 0,
   3906                 charArray.length + 1).length);
   3907     }
   3908 
   3909     public void test_copyOfRange_$FII() throws Exception {
   3910         float[] result = Arrays.copyOfRange(floatArray, 0, arraySize * 2);
   3911         int i = 0;
   3912         for (; i < arraySize; i++) {
   3913             assertEquals((float) i, result[i]);
   3914         }
   3915         for (; i < result.length; i++) {
   3916             assertEquals(0.0f, result[i]);
   3917         }
   3918         result = Arrays.copyOfRange(floatArray, 0, arraySize / 2);
   3919         i = 0;
   3920         for (; i < result.length; i++) {
   3921             assertEquals((float) i, result[i]);
   3922         }
   3923         result = Arrays.copyOfRange(floatArray, 0, 0);
   3924         assertEquals(0, result.length);
   3925         try {
   3926             Arrays.copyOfRange((float[]) null, 0, arraySize);
   3927             fail("should throw NullPointerException");
   3928         } catch (NullPointerException e) {
   3929             // expected
   3930         }
   3931         try {
   3932             Arrays.copyOfRange((float[]) null, -1, arraySize);
   3933             fail("should throw NullPointerException");
   3934         } catch (NullPointerException e) {
   3935             // expected
   3936         }
   3937         try {
   3938             Arrays.copyOfRange((float[]) null, 0, -1);
   3939             fail("should throw IllegalArgumentException");
   3940         } catch (IllegalArgumentException e) {
   3941             // expected
   3942         }
   3943         try {
   3944             Arrays.copyOfRange(floatArray, -1, arraySize);
   3945             fail("should throw ArrayIndexOutOfBoundsException");
   3946         } catch (ArrayIndexOutOfBoundsException e) {
   3947             // expected
   3948         }
   3949         try {
   3950             Arrays.copyOfRange(floatArray, 0, -1);
   3951             fail("should throw IllegalArgumentException");
   3952         } catch (IllegalArgumentException e) {
   3953             // expected
   3954         }
   3955         assertEquals(floatArray.length + 1, Arrays.copyOfRange(floatArray, 0,
   3956                 floatArray.length + 1).length);
   3957     }
   3958 
   3959     /**
   3960      * {@link java.util.Arrays#copyOfRange(double[], int, int)
   3961      */
   3962     public void test_copyOfRange_$DII() throws Exception {
   3963         double[] result = Arrays.copyOfRange(doubleArray, 0, arraySize * 2);
   3964         int i = 0;
   3965         for (; i < arraySize; i++) {
   3966             assertEquals((double) i, result[i]);
   3967         }
   3968         for (; i < result.length; i++) {
   3969             assertEquals(0.0, result[i]);
   3970         }
   3971         result = Arrays.copyOfRange(doubleArray, 0, arraySize / 2);
   3972         i = 0;
   3973         for (; i < result.length; i++) {
   3974             assertEquals((double) i, result[i]);
   3975         }
   3976         result = Arrays.copyOfRange(doubleArray, 0, 0);
   3977         assertEquals(0, result.length);
   3978         try {
   3979             Arrays.copyOfRange((double[]) null, 0, arraySize);
   3980             fail("should throw NullPointerException");
   3981         } catch (NullPointerException e) {
   3982             // expected
   3983         }
   3984         try {
   3985             Arrays.copyOfRange((double[]) null, -1, arraySize);
   3986             fail("should throw NullPointerException");
   3987         } catch (NullPointerException e) {
   3988             // expected
   3989         }
   3990         try {
   3991             Arrays.copyOfRange((double[]) null, 0, -1);
   3992             fail("should throw IllegalArgumentException");
   3993         } catch (IllegalArgumentException e) {
   3994             // expected
   3995         }
   3996         try {
   3997             Arrays.copyOfRange(doubleArray, -1, arraySize);
   3998             fail("should throw ArrayIndexOutOfBoundsException");
   3999         } catch (ArrayIndexOutOfBoundsException e) {
   4000             // expected
   4001         }
   4002         try {
   4003             Arrays.copyOfRange(doubleArray, 0, -1);
   4004             fail("should throw IllegalArgumentException");
   4005         } catch (IllegalArgumentException e) {
   4006             // expected
   4007         }
   4008         assertEquals(doubleArray.length + 1, Arrays.copyOfRange(doubleArray, 0,
   4009                 doubleArray.length + 1).length);
   4010     }
   4011 
   4012     /**
   4013      * {@link java.util.Arrays#copyOfRange(boolean[], int, int)
   4014      */
   4015     public void test_copyOfRange_$ZII() throws Exception {
   4016         boolean[] result = Arrays.copyOfRange(booleanArray, 0, arraySize * 2);
   4017         int i = 0;
   4018         for (; i < arraySize; i++) {
   4019             assertEquals(booleanArray[i], result[i]);
   4020         }
   4021         for (; i < result.length; i++) {
   4022             assertEquals(false, result[i]);
   4023         }
   4024         result = Arrays.copyOfRange(booleanArray, 0, arraySize / 2);
   4025         i = 0;
   4026         for (; i < result.length; i++) {
   4027             assertEquals(booleanArray[i], result[i]);
   4028         }
   4029         result = Arrays.copyOfRange(booleanArray, 0, 0);
   4030         assertEquals(0, result.length);
   4031         try {
   4032             Arrays.copyOfRange((boolean[]) null, 0, arraySize);
   4033             fail("should throw NullPointerException");
   4034         } catch (NullPointerException e) {
   4035             // expected
   4036         }
   4037         try {
   4038             Arrays.copyOfRange((boolean[]) null, -1, arraySize);
   4039             fail("should throw NullPointerException");
   4040         } catch (NullPointerException e) {
   4041             // expected
   4042         }
   4043         try {
   4044             Arrays.copyOfRange((boolean[]) null, 0, -1);
   4045             fail("should throw IllegalArgumentException");
   4046         } catch (IllegalArgumentException e) {
   4047             // expected
   4048         }
   4049         try {
   4050             Arrays.copyOfRange(booleanArray, -1, arraySize);
   4051             fail("should throw ArrayIndexOutOfBoundsException");
   4052         } catch (ArrayIndexOutOfBoundsException e) {
   4053             // expected
   4054         }
   4055         try {
   4056             Arrays.copyOfRange(booleanArray, 0, -1);
   4057             fail("should throw IllegalArgumentException");
   4058         } catch (IllegalArgumentException e) {
   4059             // expected
   4060         }
   4061         assertEquals(booleanArray.length + 1, Arrays.copyOfRange(booleanArray, 0,
   4062                 booleanArray.length + 1).length);
   4063     }
   4064 
   4065     /**
   4066      * {@link java.util.Arrays#copyOfRange(Object[], int, int)
   4067      */
   4068     public void test_copyOfRange_$TII() throws Exception {
   4069         Object[] result = Arrays.copyOfRange(objArray, 0, arraySize * 2);
   4070         int i = 0;
   4071         for (; i < arraySize; i++) {
   4072             assertEquals(objArray[i], result[i]);
   4073         }
   4074         for (; i < result.length; i++) {
   4075             assertEquals(null, result[i]);
   4076         }
   4077         result = Arrays.copyOfRange(objArray, 0, arraySize / 2);
   4078         i = 0;
   4079         for (; i < result.length; i++) {
   4080             assertEquals(objArray[i], result[i]);
   4081         }
   4082         result = Arrays.copyOfRange(objArray, 0, 0);
   4083         assertEquals(0, result.length);
   4084         try {
   4085             Arrays.copyOfRange((Object[]) null, 0, arraySize);
   4086             fail("should throw NullPointerException");
   4087         } catch (NullPointerException e) {
   4088             // expected
   4089         }
   4090         try {
   4091             Arrays.copyOfRange((Object[]) null, -1, arraySize);
   4092             fail("should throw NullPointerException");
   4093         } catch (NullPointerException e) {
   4094             // expected
   4095         }
   4096         try {
   4097             Arrays.copyOfRange((Object[]) null, 0, -1);
   4098             fail("should throw NullPointerException");
   4099         } catch (NullPointerException e) {
   4100             // expected
   4101         }
   4102         try {
   4103             Arrays.copyOfRange((Object[]) objArray, -1, arraySize);
   4104             fail("should throw ArrayIndexOutOfBoundsException");
   4105         } catch (ArrayIndexOutOfBoundsException e) {
   4106             // expected
   4107         }
   4108         try {
   4109             Arrays.copyOfRange((Object[]) objArray, 0, -1);
   4110             fail("should throw IllegalArgumentException");
   4111         } catch (IllegalArgumentException e) {
   4112             // expected
   4113         }
   4114         assertEquals(objArray.length + 1, Arrays.copyOfRange(objArray, 0,
   4115                 objArray.length + 1).length);
   4116     }
   4117 
   4118     public void test_copyOfRange_$TIILClass() throws Exception {
   4119         Object[] result = Arrays.copyOfRange(objArray, 0, arraySize * 2, Integer[].class);
   4120         int i = 0;
   4121         for (; i < arraySize; i++) {
   4122             assertEquals(objArray[i], result[i]);
   4123         }
   4124         for (; i < result.length; i++) {
   4125             assertEquals(null, result[i]);
   4126         }
   4127         result = Arrays.copyOfRange(objArray, 0, arraySize / 2, Integer[].class);
   4128         i = 0;
   4129         for (; i < result.length; i++) {
   4130             assertEquals(objArray[i], result[i]);
   4131         }
   4132         result = Arrays.copyOfRange(objArray, 0, 0, Integer[].class);
   4133         assertEquals(0, result.length);
   4134         try {
   4135             Arrays.copyOfRange(null, 0, arraySize, Integer[].class);
   4136             fail("should throw NullPointerException");
   4137         } catch (NullPointerException e) {
   4138             // expected
   4139         }
   4140         try {
   4141             Arrays.copyOfRange(null, -1, arraySize, Integer[].class);
   4142             fail("should throw NullPointerException");
   4143         } catch (NullPointerException e) {
   4144             // expected
   4145         }
   4146         try {
   4147             Arrays.copyOfRange(null, 0, -1, Integer[].class);
   4148             fail("should throw IllegalArgumentException");
   4149         } catch (IllegalArgumentException e) {
   4150             // expected
   4151         }
   4152         try {
   4153             Arrays.copyOfRange(objArray, -1, arraySize, Integer[].class);
   4154             fail("should throw ArrayIndexOutOfBoundsException");
   4155         } catch (ArrayIndexOutOfBoundsException e) {
   4156             // expected
   4157         }
   4158         try {
   4159             Arrays.copyOfRange(objArray, 0, -1, Integer[].class);
   4160             fail("should throw IllegalArgumentException");
   4161         } catch (IllegalArgumentException e) {
   4162             // expected
   4163         }
   4164         try {
   4165             Arrays.copyOfRange(objArray, 0, -1, LinkedList[].class);
   4166             fail("should throw IllegalArgumentException");
   4167         } catch (IllegalArgumentException e) {
   4168             // expected
   4169         }
   4170         try {
   4171             Arrays.copyOfRange(objArray, 0, 1, LinkedList[].class);
   4172             fail("should throw ArrayStoreException");
   4173         } catch (ArrayStoreException e) {
   4174             // expected
   4175         }
   4176         try {
   4177             Arrays.copyOfRange(null, 0, 1, LinkedList[].class);
   4178             fail("should throw NullPointerException");
   4179         } catch (NullPointerException e) {
   4180             // expected
   4181         }
   4182         try {
   4183             assertEquals(objArray.length + 1, Arrays.copyOfRange(objArray, 0,
   4184                     objArray.length + 1, LinkedList[].class).length);
   4185             fail("should throw ArrayStoreException");
   4186         } catch (ArrayStoreException e) {
   4187             // expected
   4188         }
   4189         assertEquals(0,
   4190                 Arrays.copyOfRange(objArray, 0, 0, LinkedList[].class).length);
   4191     }
   4192 
   4193     /**
   4194      * Tears down the fixture, for example, close a network connection. This
   4195      * method is called after a test is executed.
   4196      */
   4197     protected void tearDown() {
   4198         objArray = null;
   4199         booleanArray = null;
   4200         byteArray = null;
   4201         charArray = null;
   4202         doubleArray = null;
   4203         floatArray = null;
   4204         intArray = null;
   4205         longArray = null;
   4206         objectArray = null;
   4207         shortArray = null;
   4208     }
   4209 }
   4210