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 tests.api.java.util;
     18 
     19 import dalvik.annotation.TestTargetNew;
     20 import dalvik.annotation.TestLevel;
     21 import dalvik.annotation.TestTargetClass;
     22 
     23 import java.util.Arrays;
     24 import java.util.Comparator;
     25 import java.util.LinkedList;
     26 import java.util.List;
     27 import java.util.Random;
     28 
     29 import tests.support.Support_UnmodifiableCollectionTest;
     30 
     31 @TestTargetClass(Arrays.class)
     32 public class ArraysTest extends junit.framework.TestCase {
     33 
     34     public static class ReversedIntegerComparator implements Comparator {
     35         public int compare(Object o1, Object o2) {
     36             return -(((Integer) o1).compareTo((Integer) o2));
     37         }
     38 
     39         public boolean equals(Object o1, Object o2) {
     40             return ((Integer) o1).compareTo((Integer) o2) == 0;
     41         }
     42     }
     43 
     44     final static int arraySize = 100;
     45 
     46     Object[] objArray;
     47 
     48     boolean[] booleanArray;
     49 
     50     byte[] byteArray;
     51 
     52     char[] charArray;
     53 
     54     double[] doubleArray;
     55 
     56     float[] floatArray;
     57 
     58     int[] intArray;
     59 
     60     long[] longArray;
     61 
     62     Object[] objectArray;
     63 
     64     short[] shortArray;
     65 
     66     /**
     67      * @tests java.util.Arrays#asList(java.lang.Object[])
     68      */
     69     @TestTargetNew(
     70         level = TestLevel.COMPLETE,
     71         notes = "",
     72         method = "asList",
     73         args = {java.lang.Object[].class}
     74     )
     75     public void test_asList$Ljava_lang_Object() {
     76         // Test for method java.util.List
     77         // java.util.Arrays.asList(java.lang.Object [])
     78         List convertedList = Arrays.asList(objectArray);
     79         for (int counter = 0; counter < arraySize; counter++) {
     80             assertTrue(
     81                     "Array and List converted from array do not contain identical elements",
     82                     convertedList.get(counter) == objectArray[counter]);
     83         }
     84         convertedList.set(50, new Integer(1000));
     85         assertTrue("set/get did not work on coverted list", convertedList.get(
     86                 50).equals(new Integer(1000)));
     87         convertedList.set(50, new Integer(50));
     88         new Support_UnmodifiableCollectionTest("", convertedList).runTest();
     89 
     90         Object[] myArray = (Object[]) (objectArray.clone());
     91         myArray[30] = null;
     92         myArray[60] = null;
     93         convertedList = Arrays.asList(myArray);
     94         for (int counter = 0; counter < arraySize; counter++) {
     95             assertTrue(
     96                     "Array and List converted from array do not contain identical elements",
     97                     convertedList.get(counter) == myArray[counter]);
     98         }
     99 
    100         try {
    101             Arrays.asList((Object[])null);
    102             fail("asList with null arg didn't throw NPE");
    103         } catch (NullPointerException e) {
    104             // Expected
    105         }
    106     }
    107 
    108     /**
    109      * @tests java.util.Arrays#binarySearch(byte[], byte)
    110      */
    111     @TestTargetNew(
    112         level = TestLevel.COMPLETE,
    113         notes = "",
    114         method = "binarySearch",
    115         args = {byte[].class, byte.class}
    116     )
    117     public void test_binarySearch$BB() {
    118         // Test for method int java.util.Arrays.binarySearch(byte [], byte)
    119         for (byte counter = 0; counter < arraySize; counter++)
    120             assertTrue("Binary search on byte[] answered incorrect position",
    121                     Arrays.binarySearch(byteArray, counter) == counter);
    122         assertEquals("Binary search succeeded for value not present in array 1",
    123                 -1, Arrays.binarySearch(intArray, (byte) -1));
    124         assertTrue(
    125                 "Binary search succeeded for value not present in array 2",
    126                 Arrays.binarySearch(intArray, (byte) arraySize) == -(arraySize + 1));
    127         for (byte counter = 0; counter < arraySize; counter++)
    128             byteArray[counter] -= 50;
    129         for (byte counter = 0; counter < arraySize; counter++)
    130             assertTrue(
    131                     "Binary search on byte[] involving negative numbers answered incorrect position",
    132                     Arrays.binarySearch(byteArray, (byte) (counter - 50)) == counter);
    133     }
    134 
    135     /**
    136      * @tests java.util.Arrays#binarySearch(char[], char)
    137      */
    138     @TestTargetNew(
    139         level = TestLevel.COMPLETE,
    140         notes = "",
    141         method = "binarySearch",
    142         args = {char[].class, char.class}
    143     )
    144     public void test_binarySearch$CC() {
    145         // Test for method int java.util.Arrays.binarySearch(char [], char)
    146         for (char counter = 0; counter < arraySize; counter++)
    147             assertTrue(
    148                     "Binary search on char[] answered incorrect position",
    149                     Arrays.binarySearch(charArray, (char) (counter + 1)) == counter);
    150         assertEquals("Binary search succeeded for value not present in array 1",
    151                 -1, Arrays.binarySearch(charArray, '\u0000'));
    152         assertTrue(
    153                 "Binary search succeeded for value not present in array 2",
    154                 Arrays.binarySearch(charArray, (char) (arraySize + 1)) == -(arraySize + 1));
    155     }
    156 
    157     /**
    158      * @tests java.util.Arrays#binarySearch(double[], double)
    159      */
    160     @TestTargetNew(
    161         level = TestLevel.COMPLETE,
    162         notes = "",
    163         method = "binarySearch",
    164         args = {double[].class, double.class}
    165     )
    166     public void test_binarySearch$DD() {
    167         // Test for method int java.util.Arrays.binarySearch(double [], double)
    168         for (int counter = 0; counter < arraySize; counter++)
    169             assertTrue(
    170                     "Binary search on double[] answered incorrect position",
    171                     Arrays.binarySearch(doubleArray, (double) counter) == (double) counter);
    172         assertEquals("Binary search succeeded for value not present in array 1",
    173                 -1, Arrays.binarySearch(doubleArray, (double) -1));
    174         assertTrue(
    175                 "Binary search succeeded for value not present in array 2",
    176                 Arrays.binarySearch(doubleArray, (double) arraySize) == -(arraySize + 1));
    177         for (int counter = 0; counter < arraySize; counter++)
    178             doubleArray[counter] -= (double) 50;
    179         for (int counter = 0; counter < arraySize; counter++)
    180             assertTrue(
    181                     "Binary search on double[] involving negative numbers answered incorrect position",
    182                     Arrays.binarySearch(doubleArray, (double) (counter - 50)) == (double) counter);
    183 
    184         double[] specials = new double[] { Double.NEGATIVE_INFINITY,
    185                 -Double.MAX_VALUE, -2d, -Double.MIN_VALUE, -0d, 0d,
    186                 Double.MIN_VALUE, 2d, Double.MAX_VALUE,
    187                 Double.POSITIVE_INFINITY, Double.NaN };
    188         for (int i = 0; i < specials.length; i++) {
    189             int result = Arrays.binarySearch(specials, specials[i]);
    190             assertTrue(specials[i] + " invalid: " + result, result == i);
    191         }
    192         assertEquals("-1d", -4, Arrays.binarySearch(specials, -1d));
    193         assertEquals("1d", -8, Arrays.binarySearch(specials, 1d));
    194 
    195     }
    196 
    197     /**
    198      * @tests java.util.Arrays#binarySearch(float[], float)
    199      */
    200     @TestTargetNew(
    201         level = TestLevel.COMPLETE,
    202         notes = "",
    203         method = "binarySearch",
    204         args = {float[].class, float.class}
    205     )
    206     public void test_binarySearch$FF() {
    207         // Test for method int java.util.Arrays.binarySearch(float [], float)
    208         for (int counter = 0; counter < arraySize; counter++)
    209             assertTrue(
    210                     "Binary search on float[] answered incorrect position",
    211                     Arrays.binarySearch(floatArray, (float) counter) == (float) counter);
    212         assertEquals("Binary search succeeded for value not present in array 1",
    213                 -1, Arrays.binarySearch(floatArray, (float) -1));
    214         assertTrue(
    215                 "Binary search succeeded for value not present in array 2",
    216                 Arrays.binarySearch(floatArray, (float) arraySize) == -(arraySize + 1));
    217         for (int counter = 0; counter < arraySize; counter++)
    218             floatArray[counter] -= (float) 50;
    219         for (int counter = 0; counter < arraySize; counter++)
    220             assertTrue(
    221                     "Binary search on float[] involving negative numbers answered incorrect position",
    222                     Arrays.binarySearch(floatArray, (float) counter - 50) == (float) counter);
    223 
    224         float[] specials = new float[] { Float.NEGATIVE_INFINITY,
    225                 -Float.MAX_VALUE, -2f, -Float.MIN_VALUE, -0f, 0f,
    226                 Float.MIN_VALUE, 2f, Float.MAX_VALUE, Float.POSITIVE_INFINITY,
    227                 Float.NaN };
    228         for (int i = 0; i < specials.length; i++) {
    229             int result = Arrays.binarySearch(specials, specials[i]);
    230             assertTrue(specials[i] + " invalid: " + result, result == i);
    231         }
    232         assertEquals("-1f", -4, Arrays.binarySearch(specials, -1f));
    233         assertEquals("1f", -8, Arrays.binarySearch(specials, 1f));
    234     }
    235 
    236     /**
    237      * @tests java.util.Arrays#binarySearch(int[], int)
    238      */
    239     @TestTargetNew(
    240         level = TestLevel.COMPLETE,
    241         notes = "",
    242         method = "binarySearch",
    243         args = {int[].class, int.class}
    244     )
    245     public void test_binarySearch$II() {
    246         // Test for method int java.util.Arrays.binarySearch(int [], int)
    247         for (int counter = 0; counter < arraySize; counter++)
    248             assertTrue("Binary search on int[] answered incorrect position",
    249                     Arrays.binarySearch(intArray, counter) == counter);
    250         assertEquals("Binary search succeeded for value not present in array 1",
    251                 -1, Arrays.binarySearch(intArray, -1));
    252         assertTrue("Binary search succeeded for value not present in array 2",
    253                 Arrays.binarySearch(intArray, arraySize) == -(arraySize + 1));
    254         for (int counter = 0; counter < arraySize; counter++)
    255             intArray[counter] -= 50;
    256         for (int counter = 0; counter < arraySize; counter++)
    257             assertTrue(
    258                     "Binary search on int[] involving negative numbers answered incorrect position",
    259                     Arrays.binarySearch(intArray, counter - 50) == counter);
    260     }
    261 
    262     /**
    263      * @tests java.util.Arrays#binarySearch(long[], long)
    264      */
    265     @TestTargetNew(
    266         level = TestLevel.COMPLETE,
    267         notes = "",
    268         method = "binarySearch",
    269         args = {long[].class, long.class}
    270     )
    271     public void test_binarySearch$JJ() {
    272         // Test for method int java.util.Arrays.binarySearch(long [], long)
    273         for (long counter = 0; counter < arraySize; counter++)
    274             assertTrue("Binary search on long[] answered incorrect position",
    275                     Arrays.binarySearch(longArray, counter) == counter);
    276         assertEquals("Binary search succeeded for value not present in array 1",
    277                 -1, Arrays.binarySearch(longArray, (long) -1));
    278         assertTrue(
    279                 "Binary search succeeded for value not present in array 2",
    280                 Arrays.binarySearch(longArray, (long) arraySize) == -(arraySize + 1));
    281         for (long counter = 0; counter < arraySize; counter++)
    282             longArray[(int) counter] -= (long) 50;
    283         for (long counter = 0; counter < arraySize; counter++)
    284             assertTrue(
    285                     "Binary search on long[] involving negative numbers answered incorrect position",
    286                     Arrays.binarySearch(longArray, counter - (long) 50) == counter);
    287     }
    288 
    289     /**
    290      * @tests java.util.Arrays#binarySearch(java.lang.Object[],
    291      *        java.lang.Object)
    292      */
    293     @TestTargetNew(
    294         level = TestLevel.COMPLETE,
    295         notes = "",
    296         method = "binarySearch",
    297         args = {java.lang.Object[].class, java.lang.Object.class}
    298     )
    299     public void test_binarySearch$Ljava_lang_ObjectLjava_lang_Object() {
    300         // Test for method int java.util.Arrays.binarySearch(java.lang.Object
    301         // [], java.lang.Object)
    302         assertEquals(
    303                 "Binary search succeeded for non-comparable value in empty array",
    304                 -1, Arrays.binarySearch(new Object[] {}, new Object()));
    305         assertEquals(
    306                 "Binary search succeeded for comparable value in empty array",
    307                 -1, Arrays.binarySearch(new Object[] {}, new Integer(-1)));
    308         for (int counter = 0; counter < arraySize; counter++)
    309             assertTrue(
    310                     "Binary search on Object[] answered incorrect position",
    311                     Arrays.binarySearch(objectArray, objArray[counter]) == counter);
    312         assertEquals("Binary search succeeded for value not present in array 1",
    313                 -1, Arrays.binarySearch(objectArray, new Integer(-1)));
    314         assertTrue(
    315                 "Binary search succeeded for value not present in array 2",
    316                 Arrays.binarySearch(objectArray, new Integer(arraySize)) == -(arraySize + 1));
    317 
    318         String[] sArray = new String[]{"1", "2", "3", "4", ""};
    319         Object[] oArray = sArray;
    320 
    321         try {
    322             Arrays.binarySearch(oArray, new Integer(10));
    323             fail("ClassCastException expected");
    324         } catch (ClassCastException e) {
    325             //expected
    326         }
    327     }
    328 
    329     /**
    330      * @tests java.util.Arrays#binarySearch(java.lang.Object[],
    331      *        java.lang.Object, java.util.Comparator)
    332      */
    333     @TestTargetNew(
    334         level = TestLevel.PARTIAL_COMPLETE,
    335         notes = "Doesn't verify ClassCastException.",
    336         method = "binarySearch",
    337         args = {java.lang.Object[].class, java.lang.Object.class, java.util.Comparator.class}
    338     )
    339     public void test_binarySearch$Ljava_lang_ObjectLjava_lang_ObjectLjava_util_Comparator() {
    340         // Test for method int java.util.Arrays.binarySearch(java.lang.Object
    341         // [], java.lang.Object, java.util.Comparator)
    342         Comparator comp = new ReversedIntegerComparator();
    343         for (int counter = 0; counter < arraySize; counter++)
    344             objectArray[counter] = objArray[arraySize - counter - 1];
    345         assertTrue(
    346                 "Binary search succeeded for value not present in array 1",
    347                 Arrays.binarySearch(objectArray, new Integer(-1), comp) == -(arraySize + 1));
    348         assertEquals("Binary search succeeded for value not present in array 2",
    349                 -1, Arrays.binarySearch(objectArray, new Integer(arraySize), comp));
    350         for (int counter = 0; counter < arraySize; counter++)
    351             assertTrue(
    352                     "Binary search on Object[] with custom comparator answered incorrect position",
    353                     Arrays.binarySearch(objectArray, objArray[counter], comp) == arraySize
    354                             - counter - 1);
    355     }
    356 
    357     /**
    358      * @tests java.util.Arrays#binarySearch(short[], short)
    359      */
    360     @TestTargetNew(
    361         level = TestLevel.COMPLETE,
    362         notes = "",
    363         method = "binarySearch",
    364         args = {short[].class, short.class}
    365     )
    366     public void test_binarySearch$SS() {
    367         // Test for method int java.util.Arrays.binarySearch(short [], short)
    368         for (short counter = 0; counter < arraySize; counter++)
    369             assertTrue("Binary search on short[] answered incorrect position",
    370                     Arrays.binarySearch(shortArray, counter) == counter);
    371         assertEquals("Binary search succeeded for value not present in array 1",
    372                 -1, Arrays.binarySearch(intArray, (short) -1));
    373         assertTrue(
    374                 "Binary search succeeded for value not present in array 2",
    375                 Arrays.binarySearch(intArray, (short) arraySize) == -(arraySize + 1));
    376         for (short counter = 0; counter < arraySize; counter++)
    377             shortArray[counter] -= 50;
    378         for (short counter = 0; counter < arraySize; counter++)
    379             assertTrue(
    380                     "Binary search on short[] involving negative numbers answered incorrect position",
    381                     Arrays.binarySearch(shortArray, (short) (counter - 50)) == counter);
    382     }
    383 
    384     /**
    385      * @tests java.util.Arrays#fill(byte[], byte)
    386      */
    387     @TestTargetNew(
    388         level = TestLevel.COMPLETE,
    389         notes = "",
    390         method = "fill",
    391         args = {byte[].class, byte.class}
    392     )
    393     public void test_fill$BB() {
    394         // Test for method void java.util.Arrays.fill(byte [], byte)
    395 
    396         byte d[] = new byte[1000];
    397         Arrays.fill(d, Byte.MAX_VALUE);
    398         for (int i = 0; i < d.length; i++)
    399             assertTrue("Failed to fill byte array correctly",
    400                     d[i] == Byte.MAX_VALUE);
    401     }
    402 
    403     /**
    404      * @tests java.util.Arrays#fill(byte[], int, int, byte)
    405      */
    406     @TestTargetNew(
    407         level = TestLevel.COMPLETE,
    408         notes = "",
    409         method = "fill",
    410         args = {byte[].class, int.class, int.class, byte.class}
    411     )
    412     public void test_fill$BIIB() {
    413         // Test for method void java.util.Arrays.fill(byte [], int, int, byte)
    414         byte val = Byte.MAX_VALUE;
    415         byte d[] = new byte[1000];
    416         Arrays.fill(d, 400, d.length, val);
    417         for (int i = 0; i < 400; i++)
    418             assertTrue("Filled elements not in range", !(d[i] == val));
    419         for (int i = 400; i < d.length; i++)
    420             assertTrue("Failed to fill byte array correctly", d[i] == val);
    421 
    422         int result;
    423         try {
    424             Arrays.fill(new byte[2], 2, 1, (byte) 27);
    425             result = 0;
    426         } catch (ArrayIndexOutOfBoundsException e) {
    427             result = 1;
    428         } catch (IllegalArgumentException e) {
    429             result = 2;
    430         }
    431         assertEquals("Wrong exception1", 2, result);
    432         try {
    433             Arrays.fill(new byte[2], -1, 1, (byte) 27);
    434             result = 0;
    435         } catch (ArrayIndexOutOfBoundsException e) {
    436             result = 1;
    437         } catch (IllegalArgumentException e) {
    438             result = 2;
    439         }
    440         assertEquals("Wrong exception2", 1, result);
    441         try {
    442             Arrays.fill(new byte[2], 1, 4, (byte) 27);
    443             result = 0;
    444         } catch (ArrayIndexOutOfBoundsException e) {
    445             result = 1;
    446         } catch (IllegalArgumentException e) {
    447             result = 2;
    448         }
    449         assertEquals("Wrong exception", 1, result);
    450     }
    451 
    452     /**
    453      * @tests java.util.Arrays#fill(short[], short)
    454      */
    455     @TestTargetNew(
    456         level = TestLevel.COMPLETE,
    457         notes = "",
    458         method = "fill",
    459         args = {short[].class, short.class}
    460     )
    461     public void test_fill$SS() {
    462         // Test for method void java.util.Arrays.fill(short [], short)
    463 
    464         short d[] = new short[1000];
    465         Arrays.fill(d, Short.MAX_VALUE);
    466         for (int i = 0; i < d.length; i++)
    467             assertTrue("Failed to fill short array correctly",
    468                     d[i] == Short.MAX_VALUE);
    469     }
    470 
    471     /**
    472      * @tests java.util.Arrays#fill(short[], int, int, short)
    473      */
    474     @TestTargetNew(
    475         level = TestLevel.COMPLETE,
    476         notes = "",
    477         method = "fill",
    478         args = {short[].class, int.class, int.class, short.class}
    479     )
    480     public void test_fill$SIIS() {
    481         // Test for method void java.util.Arrays.fill(short [], int, int, short)
    482         short val = Short.MAX_VALUE;
    483         short d[] = new short[1000];
    484         Arrays.fill(d, 400, d.length, val);
    485         for (int i = 0; i < 400; i++)
    486             assertTrue("Filled elements not in range", !(d[i] == val));
    487         for (int i = 400; i < d.length; i++)
    488             assertTrue("Failed to fill short array correctly", d[i] == val);
    489 
    490         try {
    491             Arrays.fill(d, 10, 0, val);
    492             fail("IllegalArgumentException expected");
    493         } catch (IllegalArgumentException e) {
    494             //expected
    495         }
    496 
    497         try {
    498             Arrays.fill(d, -10, 0, val);
    499             fail("ArrayIndexOutOfBoundsException expected");
    500         } catch (ArrayIndexOutOfBoundsException e) {
    501             //expected
    502         }
    503 
    504         try {
    505             Arrays.fill(d, 10, d.length+1, val);
    506             fail("ArrayIndexOutOfBoundsException expected");
    507         } catch (ArrayIndexOutOfBoundsException e) {
    508             //expected
    509         }
    510     }
    511 
    512     /**
    513      * @tests java.util.Arrays#fill(char[], char)
    514      */
    515     @TestTargetNew(
    516         level = TestLevel.COMPLETE,
    517         notes = "",
    518         method = "fill",
    519         args = {char[].class, char.class}
    520     )
    521     public void test_fill$CC() {
    522         // Test for method void java.util.Arrays.fill(char [], char)
    523 
    524         char d[] = new char[1000];
    525         Arrays.fill(d, 'V');
    526         for (int i = 0; i < d.length; i++)
    527             assertEquals("Failed to fill char array correctly", 'V', d[i]);
    528     }
    529 
    530     /**
    531      * @tests java.util.Arrays#fill(char[], int, int, char)
    532      */
    533     @TestTargetNew(
    534         level = TestLevel.COMPLETE,
    535         notes = "",
    536         method = "fill",
    537         args = {char[].class, int.class, int.class, char.class}
    538     )
    539     public void test_fill$CIIC() {
    540         // Test for method void java.util.Arrays.fill(char [], int, int, char)
    541         char val = 'T';
    542         char d[] = new char[1000];
    543         Arrays.fill(d, 400, d.length, val);
    544         for (int i = 0; i < 400; i++)
    545             assertTrue("Filled elements not in range", !(d[i] == val));
    546         for (int i = 400; i < d.length; i++)
    547             assertTrue("Failed to fill char array correctly", d[i] == val);
    548 
    549         try {
    550             Arrays.fill(d, 10, 0, val);
    551             fail("IllegalArgumentException expected");
    552         } catch (IllegalArgumentException e) {
    553             //expected
    554         }
    555 
    556         try {
    557             Arrays.fill(d, -10, 0, val);
    558             fail("ArrayIndexOutOfBoundsException expected");
    559         } catch (ArrayIndexOutOfBoundsException e) {
    560             //expected
    561         }
    562 
    563         try {
    564             Arrays.fill(d, 10, d.length+1, val);
    565             fail("ArrayIndexOutOfBoundsException expected");
    566         } catch (ArrayIndexOutOfBoundsException e) {
    567             //expected
    568         }
    569     }
    570 
    571     /**
    572      * @tests java.util.Arrays#fill(int[], int)
    573      */
    574     @TestTargetNew(
    575         level = TestLevel.COMPLETE,
    576         notes = "",
    577         method = "fill",
    578         args = {int[].class, int.class}
    579     )
    580     public void test_fill$II() {
    581         // Test for method void java.util.Arrays.fill(int [], int)
    582 
    583         int d[] = new int[1000];
    584         Arrays.fill(d, Integer.MAX_VALUE);
    585         for (int i = 0; i < d.length; i++)
    586             assertTrue("Failed to fill int array correctly",
    587                     d[i] == Integer.MAX_VALUE);
    588     }
    589 
    590     /**
    591      * @tests java.util.Arrays#fill(int[], int, int, int)
    592      */
    593     @TestTargetNew(
    594         level = TestLevel.COMPLETE,
    595         notes = "",
    596         method = "fill",
    597         args = {int[].class, int.class, int.class, int.class}
    598     )
    599     public void test_fill$IIII() {
    600         // Test for method void java.util.Arrays.fill(int [], int, int, int)
    601         int val = Integer.MAX_VALUE;
    602         int d[] = new int[1000];
    603         Arrays.fill(d, 400, d.length, val);
    604         for (int i = 0; i < 400; i++)
    605             assertTrue("Filled elements not in range", !(d[i] == val));
    606         for (int i = 400; i < d.length; i++)
    607             assertTrue("Failed to fill int array correctly", d[i] == val);
    608 
    609         try {
    610             Arrays.fill(d, 10, 0, val);
    611             fail("IllegalArgumentException expected");
    612         } catch (IllegalArgumentException e) {
    613             //expected
    614         }
    615 
    616         try {
    617             Arrays.fill(d, -10, 0, val);
    618             fail("ArrayIndexOutOfBoundsException expected");
    619         } catch (ArrayIndexOutOfBoundsException e) {
    620             //expected
    621         }
    622 
    623         try {
    624             Arrays.fill(d, 10, d.length+1, val);
    625             fail("ArrayIndexOutOfBoundsException expected");
    626         } catch (ArrayIndexOutOfBoundsException e) {
    627             //expected
    628         }
    629     }
    630 
    631     /**
    632      * @tests java.util.Arrays#fill(long[], long)
    633      */
    634     @TestTargetNew(
    635         level = TestLevel.COMPLETE,
    636         notes = "",
    637         method = "fill",
    638         args = {long[].class, long.class}
    639     )
    640     public void test_fill$JJ() {
    641         // Test for method void java.util.Arrays.fill(long [], long)
    642 
    643         long d[] = new long[1000];
    644         Arrays.fill(d, Long.MAX_VALUE);
    645         for (int i = 0; i < d.length; i++)
    646             assertTrue("Failed to fill long array correctly",
    647                     d[i] == Long.MAX_VALUE);
    648     }
    649 
    650     /**
    651      * @tests java.util.Arrays#fill(long[], int, int, long)
    652      */
    653     @TestTargetNew(
    654         level = TestLevel.COMPLETE,
    655         notes = "",
    656         method = "fill",
    657         args = {long[].class, int.class, int.class, long.class}
    658     )
    659     public void test_fill$JIIJ() {
    660         // Test for method void java.util.Arrays.fill(long [], int, int, long)
    661         long d[] = new long[1000];
    662         Arrays.fill(d, 400, d.length, Long.MAX_VALUE);
    663         for (int i = 0; i < 400; i++)
    664             assertTrue("Filled elements not in range", !(d[i] == Long.MAX_VALUE));
    665         for (int i = 400; i < d.length; i++)
    666             assertTrue("Failed to fill long array correctly",
    667                     d[i] == Long.MAX_VALUE);
    668 
    669         try {
    670             Arrays.fill(d, 10, 0, Long.MIN_VALUE);
    671             fail("IllegalArgumentException expected");
    672         } catch (IllegalArgumentException e) {
    673             //expected
    674         }
    675 
    676         try {
    677             Arrays.fill(d, -10, 0, Long.MAX_VALUE);
    678             fail("ArrayIndexOutOfBoundsException expected");
    679         } catch (ArrayIndexOutOfBoundsException e) {
    680             //expected
    681         }
    682 
    683         try {
    684             Arrays.fill(d, 10, d.length+1, Long.MAX_VALUE);
    685             fail("ArrayIndexOutOfBoundsException expected");
    686         } catch (ArrayIndexOutOfBoundsException e) {
    687             //expected
    688         }
    689     }
    690 
    691     /**
    692      * @tests java.util.Arrays#fill(float[], float)
    693      */
    694     @TestTargetNew(
    695         level = TestLevel.COMPLETE,
    696         notes = "",
    697         method = "fill",
    698         args = {float[].class, float.class}
    699     )
    700     public void test_fill$FF() {
    701         // Test for method void java.util.Arrays.fill(float [], float)
    702         float d[] = new float[1000];
    703         Arrays.fill(d, Float.MAX_VALUE);
    704         for (int i = 0; i < d.length; i++)
    705             assertTrue("Failed to fill float array correctly",
    706                     d[i] == Float.MAX_VALUE);
    707     }
    708 
    709     /**
    710      * @tests java.util.Arrays#fill(float[], int, int, float)
    711      */
    712     @TestTargetNew(
    713         level = TestLevel.COMPLETE,
    714         notes = "",
    715         method = "fill",
    716         args = {float[].class, int.class, int.class, float.class}
    717     )
    718     public void test_fill$FIIF() {
    719         // Test for method void java.util.Arrays.fill(float [], int, int, float)
    720         float val = Float.MAX_VALUE;
    721         float d[] = new float[1000];
    722         Arrays.fill(d, 400, d.length, val);
    723         for (int i = 0; i < 400; i++)
    724             assertTrue("Filled elements not in range", !(d[i] == val));
    725         for (int i = 400; i < d.length; i++)
    726             assertTrue("Failed to fill float array correctly", d[i] == val);
    727 
    728         try {
    729             Arrays.fill(d, 10, 0, val);
    730             fail("IllegalArgumentException expected");
    731         } catch (IllegalArgumentException e) {
    732             //expected
    733         }
    734 
    735         try {
    736             Arrays.fill(d, -10, 0, val);
    737             fail("ArrayIndexOutOfBoundsException expected");
    738         } catch (ArrayIndexOutOfBoundsException e) {
    739             //expected
    740         }
    741 
    742         try {
    743             Arrays.fill(d, 10, d.length+1, val);
    744             fail("ArrayIndexOutOfBoundsException expected");
    745         } catch (ArrayIndexOutOfBoundsException e) {
    746             //expected
    747         }
    748     }
    749 
    750     /**
    751      * @tests java.util.Arrays#fill(double[], double)
    752      */
    753     @TestTargetNew(
    754         level = TestLevel.COMPLETE,
    755         notes = "",
    756         method = "fill",
    757         args = {double[].class, double.class}
    758     )
    759     public void test_fill$DD() {
    760         // Test for method void java.util.Arrays.fill(double [], double)
    761 
    762         double d[] = new double[1000];
    763         Arrays.fill(d, Double.MAX_VALUE);
    764         for (int i = 0; i < d.length; i++)
    765             assertTrue("Failed to fill double array correctly",
    766                     d[i] == Double.MAX_VALUE);
    767     }
    768 
    769     /**
    770      * @tests java.util.Arrays#fill(double[], int, int, double)
    771      */
    772     @TestTargetNew(
    773         level = TestLevel.COMPLETE,
    774         notes = "",
    775         method = "fill",
    776         args = {double[].class, int.class, int.class, double.class}
    777     )
    778     public void test_fill$DIID() {
    779         // Test for method void java.util.Arrays.fill(double [], int, int,
    780         // double)
    781         double val = Double.MAX_VALUE;
    782         double d[] = new double[1000];
    783         Arrays.fill(d, 400, d.length, val);
    784         for (int i = 0; i < 400; i++)
    785             assertTrue("Filled elements not in range", !(d[i] == val));
    786         for (int i = 400; i < d.length; i++)
    787             assertTrue("Failed to fill double array correctly", d[i] == val);
    788 
    789         try {
    790             Arrays.fill(d, 10, 0, val);
    791             fail("IllegalArgumentException expected");
    792         } catch (IllegalArgumentException e) {
    793             //expected
    794         }
    795 
    796         try {
    797             Arrays.fill(d, -10, 0, val);
    798             fail("ArrayIndexOutOfBoundsException expected");
    799         } catch (ArrayIndexOutOfBoundsException e) {
    800             //expected
    801         }
    802 
    803         try {
    804             Arrays.fill(d, 10, d.length+1, val);
    805             fail("ArrayIndexOutOfBoundsException expected");
    806         } catch (ArrayIndexOutOfBoundsException e) {
    807             //expected
    808         }
    809     }
    810 
    811     /**
    812      * @tests java.util.Arrays#fill(boolean[], boolean)
    813      */
    814     @TestTargetNew(
    815         level = TestLevel.COMPLETE,
    816         notes = "",
    817         method = "fill",
    818         args = {boolean[].class, boolean.class}
    819     )
    820     public void test_fill$ZZ() {
    821         // Test for method void java.util.Arrays.fill(boolean [], boolean)
    822 
    823         boolean d[] = new boolean[1000];
    824         Arrays.fill(d, true);
    825         for (int i = 0; i < d.length; i++)
    826             assertTrue("Failed to fill boolean array correctly", d[i]);
    827     }
    828 
    829     /**
    830      * @tests java.util.Arrays#fill(boolean[], int, int, boolean)
    831      */
    832     @TestTargetNew(
    833         level = TestLevel.COMPLETE,
    834         notes = "",
    835         method = "fill",
    836         args = {boolean[].class, int.class, int.class, boolean.class}
    837     )
    838     public void test_fill$ZIIZ() {
    839         // Test for method void java.util.Arrays.fill(boolean [], int, int,
    840         // boolean)
    841         boolean val = true;
    842         boolean d[] = new boolean[1000];
    843         Arrays.fill(d, 400, d.length, val);
    844         for (int i = 0; i < 400; i++)
    845             assertTrue("Filled elements not in range", !(d[i] == val));
    846         for (int i = 400; i < d.length; i++)
    847             assertTrue("Failed to fill boolean array correctly", d[i] == val);
    848 
    849         try {
    850             Arrays.fill(d, 10, 0, val);
    851             fail("IllegalArgumentException expected");
    852         } catch (IllegalArgumentException e) {
    853             //expected
    854         }
    855 
    856         try {
    857             Arrays.fill(d, -10, 0, val);
    858             fail("ArrayIndexOutOfBoundsException expected");
    859         } catch (ArrayIndexOutOfBoundsException e) {
    860             //expected
    861         }
    862 
    863         try {
    864             Arrays.fill(d, 10, d.length+1, val);
    865             fail("ArrayIndexOutOfBoundsException expected");
    866         } catch (ArrayIndexOutOfBoundsException e) {
    867             //expected
    868         }
    869     }
    870 
    871     /**
    872      * @tests java.util.Arrays#fill(java.lang.Object[], java.lang.Object)
    873      */
    874     @TestTargetNew(
    875         level = TestLevel.COMPLETE,
    876         notes = "",
    877         method = "fill",
    878         args = {java.lang.Object[].class, java.lang.Object.class}
    879     )
    880     public void test_fill$Ljava_lang_ObjectLjava_lang_Object() {
    881         // Test for method void java.util.Arrays.fill(java.lang.Object [],
    882         // java.lang.Object)
    883         Object val = new Object();
    884         Object d[] = new Object[1000];
    885         Arrays.fill(d, 0, d.length, val);
    886         for (int i = 0; i < d.length; i++)
    887             assertTrue("Failed to fill Object array correctly", d[i] == val);
    888     }
    889 
    890     /**
    891      * @tests java.util.Arrays#fill(java.lang.Object[], int, int,
    892      *        java.lang.Object)
    893      */
    894     @TestTargetNew(
    895         level = TestLevel.COMPLETE,
    896         notes = "",
    897         method = "fill",
    898         args = {java.lang.Object[].class, int.class, int.class, java.lang.Object.class}
    899     )
    900     public void test_fill$Ljava_lang_ObjectIILjava_lang_Object() {
    901         // Test for method void java.util.Arrays.fill(java.lang.Object [], int,
    902         // int, java.lang.Object)
    903         Object val = new Object();
    904         Object d[] = new Object[1000];
    905         Arrays.fill(d, 400, d.length, val);
    906         for (int i = 0; i < 400; i++)
    907             assertTrue("Filled elements not in range", !(d[i] == val));
    908         for (int i = 400; i < d.length; i++)
    909             assertTrue("Failed to fill Object array correctly", d[i] == val);
    910 
    911         Arrays.fill(d, 400, d.length, null);
    912         for (int i = 400; i < d.length; i++)
    913             assertNull("Failed to fill Object array correctly with nulls",
    914                     d[i]);
    915 
    916         try {
    917             Arrays.fill(d, 10, 0, val);
    918             fail("IllegalArgumentException expected");
    919         } catch (IllegalArgumentException e) {
    920             //expected
    921         }
    922 
    923         try {
    924             Arrays.fill(d, -10, 0, val);
    925             fail("ArrayIndexOutOfBoundsException expected");
    926         } catch (ArrayIndexOutOfBoundsException e) {
    927             //expected
    928         }
    929 
    930         try {
    931             Arrays.fill(d, 10, d.length+1, val);
    932             fail("ArrayIndexOutOfBoundsException expected");
    933         } catch (ArrayIndexOutOfBoundsException e) {
    934             //expected
    935         }
    936     }
    937 
    938     /**
    939      * @tests java.util.Arrays#equals(byte[], byte[])
    940      */
    941     @TestTargetNew(
    942         level = TestLevel.COMPLETE,
    943         notes = "",
    944         method = "equals",
    945         args = {byte[].class, byte[].class}
    946     )
    947     public void test_equals$B$B() {
    948         // Test for method boolean java.util.Arrays.equals(byte [], byte [])
    949         byte d[] = new byte[1000];
    950         byte x[] = new byte[1000];
    951         Arrays.fill(d, Byte.MAX_VALUE);
    952         Arrays.fill(x, Byte.MIN_VALUE);
    953         assertTrue("Inequal arrays returned true", !Arrays.equals(d, x));
    954         Arrays.fill(x, Byte.MAX_VALUE);
    955         assertTrue("equal arrays returned false", Arrays.equals(d, x));
    956     }
    957 
    958     /**
    959      * @tests java.util.Arrays#equals(short[], short[])
    960      */
    961     @TestTargetNew(
    962         level = TestLevel.COMPLETE,
    963         notes = "",
    964         method = "equals",
    965         args = {short[].class, short[].class}
    966     )
    967     public void test_equals$S$S() {
    968         // Test for method boolean java.util.Arrays.equals(short [], short [])
    969         short d[] = new short[1000];
    970         short x[] = new short[1000];
    971         Arrays.fill(d, Short.MAX_VALUE);
    972         Arrays.fill(x, Short.MIN_VALUE);
    973         assertTrue("Inequal arrays returned true", !Arrays.equals(d, x));
    974         Arrays.fill(x, Short.MAX_VALUE);
    975         assertTrue("equal arrays returned false", Arrays.equals(d, x));
    976     }
    977 
    978     /**
    979      * @tests java.util.Arrays#equals(char[], char[])
    980      */
    981     @TestTargetNew(
    982         level = TestLevel.COMPLETE,
    983         notes = "",
    984         method = "equals",
    985         args = {char[].class, char[].class}
    986     )
    987     public void test_equals$C$C() {
    988         // Test for method boolean java.util.Arrays.equals(char [], char [])
    989         char d[] = new char[1000];
    990         char x[] = new char[1000];
    991         char c = 'T';
    992         Arrays.fill(d, c);
    993         Arrays.fill(x, 'L');
    994         assertTrue("Inequal arrays returned true", !Arrays.equals(d, x));
    995         Arrays.fill(x, c);
    996         assertTrue("equal arrays returned false", Arrays.equals(d, x));
    997     }
    998 
    999     /**
   1000      * @tests java.util.Arrays#equals(int[], int[])
   1001      */
   1002     @TestTargetNew(
   1003         level = TestLevel.COMPLETE,
   1004         notes = "",
   1005         method = "equals",
   1006         args = {int[].class, int[].class}
   1007     )
   1008     public void test_equals$I$I() {
   1009         // Test for method boolean java.util.Arrays.equals(int [], int [])
   1010         int d[] = new int[1000];
   1011         int x[] = new int[1000];
   1012         Arrays.fill(d, Integer.MAX_VALUE);
   1013         Arrays.fill(x, Integer.MIN_VALUE);
   1014         assertTrue("Inequal arrays returned true", !Arrays.equals(d, x));
   1015         Arrays.fill(x, Integer.MAX_VALUE);
   1016         assertTrue("equal arrays returned false", Arrays.equals(d, x));
   1017 
   1018         assertTrue("wrong result for null array1", !Arrays.equals(new int[2],
   1019                 null));
   1020         assertTrue("wrong result for null array2", !Arrays.equals(null,
   1021                 new int[2]));
   1022     }
   1023 
   1024     /**
   1025      * @tests java.util.Arrays#equals(long[], long[])
   1026      */
   1027     @TestTargetNew(
   1028         level = TestLevel.COMPLETE,
   1029         notes = "",
   1030         method = "equals",
   1031         args = {long[].class, long[].class}
   1032     )
   1033     public void test_equals$J$J() {
   1034         // Test for method boolean java.util.Arrays.equals(long [], long [])
   1035         long d[] = new long[1000];
   1036         long x[] = new long[1000];
   1037         Arrays.fill(d, Long.MAX_VALUE);
   1038         Arrays.fill(x, Long.MIN_VALUE);
   1039         assertTrue("Inequal arrays returned true", !Arrays.equals(d, x));
   1040         Arrays.fill(x, Long.MAX_VALUE);
   1041         assertTrue("equal arrays returned false", Arrays.equals(d, x));
   1042 
   1043         assertTrue("should be false", !Arrays.equals(
   1044                 new long[] { 0x100000000L }, new long[] { 0x200000000L }));
   1045 
   1046     }
   1047 
   1048     /**
   1049      * @tests java.util.Arrays#equals(float[], float[])
   1050      */
   1051     @TestTargetNew(
   1052         level = TestLevel.COMPLETE,
   1053         notes = "",
   1054         method = "equals",
   1055         args = {float[].class, float[].class}
   1056     )
   1057     public void test_equals$F$F() {
   1058         // Test for method boolean java.util.Arrays.equals(float [], float [])
   1059         float d[] = new float[1000];
   1060         float x[] = new float[1000];
   1061         Arrays.fill(d, Float.MAX_VALUE);
   1062         Arrays.fill(x, Float.MIN_VALUE);
   1063         assertTrue("Inequal arrays returned true", !Arrays.equals(d, x));
   1064         Arrays.fill(x, Float.MAX_VALUE);
   1065         assertTrue("equal arrays returned false", Arrays.equals(d, x));
   1066 
   1067         assertTrue("NaN not equals", Arrays.equals(new float[] { Float.NaN },
   1068                 new float[] { Float.NaN }));
   1069         assertTrue("0f equals -0f", !Arrays.equals(new float[] { 0f },
   1070                 new float[] { -0f }));
   1071     }
   1072 
   1073     /**
   1074      * @tests java.util.Arrays#equals(double[], double[])
   1075      */
   1076     @TestTargetNew(
   1077         level = TestLevel.COMPLETE,
   1078         notes = "",
   1079         method = "equals",
   1080         args = {double[].class, double[].class}
   1081     )
   1082     public void test_equals$D$D() {
   1083         // Test for method boolean java.util.Arrays.equals(double [], double [])
   1084         double d[] = new double[1000];
   1085         double x[] = new double[1000];
   1086         Arrays.fill(d, Double.MAX_VALUE);
   1087         Arrays.fill(x, Double.MIN_VALUE);
   1088         assertTrue("Inequal arrays returned true", !Arrays.equals(d, x));
   1089         Arrays.fill(x, Double.MAX_VALUE);
   1090         assertTrue("equal arrays returned false", Arrays.equals(d, x));
   1091 
   1092         assertTrue("should be false", !Arrays.equals(new double[] { 1.0 },
   1093                 new double[] { 2.0 }));
   1094 
   1095         assertTrue("NaN not equals", Arrays.equals(new double[] { Double.NaN },
   1096                 new double[] { Double.NaN }));
   1097         assertTrue("0d equals -0d", !Arrays.equals(new double[] { 0d },
   1098                 new double[] { -0d }));
   1099     }
   1100 
   1101     /**
   1102      * @tests java.util.Arrays#equals(boolean[], boolean[])
   1103      */
   1104     @TestTargetNew(
   1105         level = TestLevel.COMPLETE,
   1106         notes = "",
   1107         method = "equals",
   1108         args = {boolean[].class, boolean[].class}
   1109     )
   1110     public void test_equals$Z$Z() {
   1111         // Test for method boolean java.util.Arrays.equals(boolean [], boolean
   1112         // [])
   1113         boolean d[] = new boolean[1000];
   1114         boolean x[] = new boolean[1000];
   1115         Arrays.fill(d, true);
   1116         Arrays.fill(x, false);
   1117         assertTrue("Inequal arrays returned true", !Arrays.equals(d, x));
   1118         Arrays.fill(x, true);
   1119         assertTrue("equal arrays returned false", Arrays.equals(d, x));
   1120     }
   1121 
   1122     /**
   1123      * @tests java.util.Arrays#equals(java.lang.Object[], java.lang.Object[])
   1124      */
   1125     @TestTargetNew(
   1126         level = TestLevel.COMPLETE,
   1127         notes = "",
   1128         method = "equals",
   1129         args = {java.lang.Object[].class, java.lang.Object[].class}
   1130     )
   1131     public void test_equals$Ljava_lang_Object$Ljava_lang_Object() {
   1132         // Test for method boolean java.util.Arrays.equals(java.lang.Object [],
   1133         // java.lang.Object [])
   1134         Object d[] = new Object[1000];
   1135         Object x[] = new Object[1000];
   1136         Object o = new Object();
   1137         Arrays.fill(d, o);
   1138         Arrays.fill(x, new Object());
   1139         assertTrue("Inequal arrays returned true", !Arrays.equals(d, x));
   1140         Arrays.fill(x, o);
   1141         d[50] = null;
   1142         x[50] = null;
   1143         assertTrue("equal arrays returned false", Arrays.equals(d, x));
   1144     }
   1145 
   1146     /**
   1147      * @tests java.util.Arrays#sort(byte[])
   1148      */
   1149     @TestTargetNew(
   1150         level = TestLevel.COMPLETE,
   1151         notes = "",
   1152         method = "sort",
   1153         args = {byte[].class}
   1154     )
   1155     public void test_sort$B() {
   1156         // Test for method void java.util.Arrays.sort(byte [])
   1157         byte[] reversedArray = new byte[arraySize];
   1158         for (int counter = 0; counter < arraySize; counter++)
   1159             reversedArray[counter] = (byte) (arraySize - counter - 1);
   1160         Arrays.sort(reversedArray);
   1161         for (int counter = 0; counter < arraySize; counter++)
   1162             assertTrue("Resulting array not sorted",
   1163                     reversedArray[counter] == (byte) counter);
   1164     }
   1165 
   1166     /**
   1167      * @tests java.util.Arrays#sort(byte[], int, int)
   1168      */
   1169     @TestTargetNew(
   1170         level = TestLevel.COMPLETE,
   1171         notes = "",
   1172         method = "sort",
   1173         args = {byte[].class, int.class, int.class}
   1174     )
   1175     public void test_sort$BII() {
   1176         // Test for method void java.util.Arrays.sort(byte [], int, int)
   1177         int startIndex = arraySize / 4;
   1178         int endIndex = 3 * arraySize / 4;
   1179         byte[] reversedArray = new byte[arraySize];
   1180         byte[] originalReversedArray = new byte[arraySize];
   1181         for (int counter = 0; counter < arraySize; counter++) {
   1182             reversedArray[counter] = (byte) (arraySize - counter - 1);
   1183             originalReversedArray[counter] = reversedArray[counter];
   1184         }
   1185         Arrays.sort(reversedArray, startIndex, endIndex);
   1186         for (int counter = 0; counter < startIndex; counter++)
   1187             assertTrue("Array modified outside of bounds",
   1188                     reversedArray[counter] == originalReversedArray[counter]);
   1189         for (int counter = startIndex; counter < endIndex - 1; counter++)
   1190             assertTrue("Array not sorted within bounds",
   1191                     reversedArray[counter] <= reversedArray[counter + 1]);
   1192         for (int counter = endIndex; counter < arraySize; counter++)
   1193             assertTrue("Array modified outside of bounds",
   1194                     reversedArray[counter] == originalReversedArray[counter]);
   1195 
   1196         //exception testing
   1197         try {
   1198             Arrays.sort(reversedArray, startIndex + 1, startIndex);
   1199             fail("IllegalArgumentException expected");
   1200         } catch (IllegalArgumentException ignore) {
   1201         }
   1202 
   1203         try {
   1204             Arrays.sort(reversedArray, -1, startIndex);
   1205             fail("ArrayIndexOutOfBoundsException expected (1)");
   1206         } catch (ArrayIndexOutOfBoundsException ignore) {
   1207         }
   1208 
   1209         try {
   1210             Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
   1211             fail("ArrayIndexOutOfBoundsException expected (2)");
   1212         } catch (ArrayIndexOutOfBoundsException ignore) {
   1213         }
   1214 
   1215         //exception order testing
   1216         try {
   1217             Arrays.sort(new byte[1], startIndex + 1, startIndex);
   1218             fail("IllegalArgumentException expected");
   1219         } catch (IllegalArgumentException ignore) {
   1220         }
   1221     }
   1222 
   1223     /**
   1224      * @tests java.util.Arrays#sort(char[])
   1225      */
   1226     @TestTargetNew(
   1227         level = TestLevel.COMPLETE,
   1228         notes = "",
   1229         method = "sort",
   1230         args = {char[].class}
   1231     )
   1232     public void test_sort$C() {
   1233         // Test for method void java.util.Arrays.sort(char [])
   1234         char[] reversedArray = new char[arraySize];
   1235         for (int counter = 0; counter < arraySize; counter++)
   1236             reversedArray[counter] = (char) (arraySize - counter - 1);
   1237         Arrays.sort(reversedArray);
   1238         for (int counter = 0; counter < arraySize; counter++)
   1239             assertTrue("Resulting array not sorted",
   1240                     reversedArray[counter] == (char) counter);
   1241 
   1242     }
   1243 
   1244     /**
   1245      * @tests java.util.Arrays#sort(char[], int, int)
   1246      */
   1247     @TestTargetNew(
   1248         level = TestLevel.COMPLETE,
   1249         notes = "",
   1250         method = "sort",
   1251         args = {char[].class, int.class, int.class}
   1252     )
   1253     public void test_sort$CII() {
   1254         // Test for method void java.util.Arrays.sort(char [], int, int)
   1255         int startIndex = arraySize / 4;
   1256         int endIndex = 3 * arraySize / 4;
   1257         char[] reversedArray = new char[arraySize];
   1258         char[] originalReversedArray = new char[arraySize];
   1259         for (int counter = 0; counter < arraySize; counter++) {
   1260             reversedArray[counter] = (char) (arraySize - counter - 1);
   1261             originalReversedArray[counter] = reversedArray[counter];
   1262         }
   1263         Arrays.sort(reversedArray, startIndex, endIndex);
   1264         for (int counter = 0; counter < startIndex; counter++)
   1265             assertTrue("Array modified outside of bounds",
   1266                     reversedArray[counter] == originalReversedArray[counter]);
   1267         for (int counter = startIndex; counter < endIndex - 1; counter++)
   1268             assertTrue("Array not sorted within bounds",
   1269                     reversedArray[counter] <= reversedArray[counter + 1]);
   1270         for (int counter = endIndex; counter < arraySize; counter++)
   1271             assertTrue("Array modified outside of bounds",
   1272                     reversedArray[counter] == originalReversedArray[counter]);
   1273 
   1274         //exception testing
   1275         try {
   1276             Arrays.sort(reversedArray, startIndex + 1, startIndex);
   1277             fail("IllegalArgumentException expected");
   1278         } catch (IllegalArgumentException ignore) {
   1279         }
   1280 
   1281         try {
   1282             Arrays.sort(reversedArray, -1, startIndex);
   1283             fail("ArrayIndexOutOfBoundsException expected (1)");
   1284         } catch (ArrayIndexOutOfBoundsException ignore) {
   1285         }
   1286 
   1287         try {
   1288             Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
   1289             fail("ArrayIndexOutOfBoundsException expected (2)");
   1290         } catch (ArrayIndexOutOfBoundsException ignore) {
   1291         }
   1292 
   1293         //exception order testing
   1294         try {
   1295             Arrays.sort(new char[1], startIndex + 1, startIndex);
   1296             fail("IllegalArgumentException expected");
   1297         } catch (IllegalArgumentException ignore) {
   1298         }
   1299     }
   1300 
   1301     /**
   1302      * @tests java.util.Arrays#sort(double[])
   1303      */
   1304     @TestTargetNew(
   1305         level = TestLevel.COMPLETE,
   1306         notes = "",
   1307         method = "sort",
   1308         args = {double[].class}
   1309     )
   1310     public void test_sort$D() {
   1311         // Test for method void java.util.Arrays.sort(double [])
   1312         double[] reversedArray = new double[arraySize];
   1313         for (int counter = 0; counter < arraySize; counter++)
   1314             reversedArray[counter] = (double) (arraySize - counter - 1);
   1315         Arrays.sort(reversedArray);
   1316         for (int counter = 0; counter < arraySize; counter++)
   1317             assertTrue("Resulting array not sorted",
   1318                     reversedArray[counter] == (double) counter);
   1319 
   1320         double[] specials1 = new double[] { Double.NaN, Double.MAX_VALUE,
   1321                 Double.MIN_VALUE, 0d, -0d, Double.POSITIVE_INFINITY,
   1322                 Double.NEGATIVE_INFINITY };
   1323         double[] specials2 = new double[] { 0d, Double.POSITIVE_INFINITY, -0d,
   1324                 Double.NEGATIVE_INFINITY, Double.MIN_VALUE, Double.NaN,
   1325                 Double.MAX_VALUE };
   1326         double[] answer = new double[] { Double.NEGATIVE_INFINITY, -0d, 0d,
   1327                 Double.MIN_VALUE, Double.MAX_VALUE, Double.POSITIVE_INFINITY,
   1328                 Double.NaN };
   1329 
   1330         Arrays.sort(specials1);
   1331         Object[] print1 = new Object[specials1.length];
   1332         for (int i = 0; i < specials1.length; i++)
   1333             print1[i] = new Double(specials1[i]);
   1334         assertTrue("specials sort incorrectly 1: " + Arrays.asList(print1),
   1335                 Arrays.equals(specials1, answer));
   1336 
   1337         Arrays.sort(specials2);
   1338         Object[] print2 = new Object[specials2.length];
   1339         for (int i = 0; i < specials2.length; i++)
   1340             print2[i] = new Double(specials2[i]);
   1341         assertTrue("specials sort incorrectly 2: " + Arrays.asList(print2),
   1342                 Arrays.equals(specials2, answer));
   1343     }
   1344 
   1345     /**
   1346      * @tests java.util.Arrays#sort(double[], int, int)
   1347      */
   1348     @TestTargetNew(
   1349         level = TestLevel.COMPLETE,
   1350         notes = "",
   1351         method = "sort",
   1352         args = {double[].class, int.class, int.class}
   1353     )
   1354     public void test_sort$DII() {
   1355         // Test for method void java.util.Arrays.sort(double [], int, int)
   1356         int startIndex = arraySize / 4;
   1357         int endIndex = 3 * arraySize / 4;
   1358         double[] reversedArray = new double[arraySize];
   1359         double[] originalReversedArray = new double[arraySize];
   1360         for (int counter = 0; counter < arraySize; counter++) {
   1361             reversedArray[counter] = (double) (arraySize - counter - 1);
   1362             originalReversedArray[counter] = reversedArray[counter];
   1363         }
   1364         Arrays.sort(reversedArray, startIndex, endIndex);
   1365         for (int counter = 0; counter < startIndex; counter++)
   1366             assertTrue("Array modified outside of bounds",
   1367                     reversedArray[counter] == originalReversedArray[counter]);
   1368         for (int counter = startIndex; counter < endIndex - 1; counter++)
   1369             assertTrue("Array not sorted within bounds",
   1370                     reversedArray[counter] <= reversedArray[counter + 1]);
   1371         for (int counter = endIndex; counter < arraySize; counter++)
   1372             assertTrue("Array modified outside of bounds",
   1373                     reversedArray[counter] == originalReversedArray[counter]);
   1374 
   1375         //exception testing
   1376         try {
   1377             Arrays.sort(reversedArray, startIndex + 1, startIndex);
   1378             fail("IllegalArgumentException expected");
   1379         } catch (IllegalArgumentException ignore) {
   1380         }
   1381 
   1382         try {
   1383             Arrays.sort(reversedArray, -1, startIndex);
   1384             fail("ArrayIndexOutOfBoundsException expected (1)");
   1385         } catch (ArrayIndexOutOfBoundsException ignore) {
   1386         }
   1387 
   1388         try {
   1389             Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
   1390             fail("ArrayIndexOutOfBoundsException expected (2)");
   1391         } catch (ArrayIndexOutOfBoundsException ignore) {
   1392         }
   1393 
   1394         //exception order testing
   1395         try {
   1396             Arrays.sort(new double[1], startIndex + 1, startIndex);
   1397             fail("IllegalArgumentException expected");
   1398         } catch (IllegalArgumentException ignore) {
   1399         }
   1400     }
   1401 
   1402     /**
   1403      * @tests java.util.Arrays#sort(float[])
   1404      */
   1405     @TestTargetNew(
   1406         level = TestLevel.COMPLETE,
   1407         notes = "",
   1408         method = "sort",
   1409         args = {float[].class}
   1410     )
   1411     public void test_sort$F() {
   1412         // Test for method void java.util.Arrays.sort(float [])
   1413         float[] reversedArray = new float[arraySize];
   1414         for (int counter = 0; counter < arraySize; counter++)
   1415             reversedArray[counter] = (float) (arraySize - counter - 1);
   1416         Arrays.sort(reversedArray);
   1417         for (int counter = 0; counter < arraySize; counter++)
   1418             assertTrue("Resulting array not sorted",
   1419                     reversedArray[counter] == (float) counter);
   1420 
   1421         float[] specials1 = new float[] { Float.NaN, Float.MAX_VALUE,
   1422                 Float.MIN_VALUE, 0f, -0f, Float.POSITIVE_INFINITY,
   1423                 Float.NEGATIVE_INFINITY };
   1424         float[] specials2 = new float[] { 0f, Float.POSITIVE_INFINITY, -0f,
   1425                 Float.NEGATIVE_INFINITY, Float.MIN_VALUE, Float.NaN,
   1426                 Float.MAX_VALUE };
   1427         float[] answer = new float[] { Float.NEGATIVE_INFINITY, -0f, 0f,
   1428                 Float.MIN_VALUE, Float.MAX_VALUE, Float.POSITIVE_INFINITY,
   1429                 Float.NaN };
   1430 
   1431         Arrays.sort(specials1);
   1432         Object[] print1 = new Object[specials1.length];
   1433         for (int i = 0; i < specials1.length; i++)
   1434             print1[i] = new Float(specials1[i]);
   1435         assertTrue("specials sort incorrectly 1: " + Arrays.asList(print1),
   1436                 Arrays.equals(specials1, answer));
   1437 
   1438         Arrays.sort(specials2);
   1439         Object[] print2 = new Object[specials2.length];
   1440         for (int i = 0; i < specials2.length; i++)
   1441             print2[i] = new Float(specials2[i]);
   1442         assertTrue("specials sort incorrectly 2: " + Arrays.asList(print2),
   1443                 Arrays.equals(specials2, answer));
   1444     }
   1445 
   1446     /**
   1447      * @tests java.util.Arrays#sort(float[], int, int)
   1448      */
   1449     @TestTargetNew(
   1450         level = TestLevel.COMPLETE,
   1451         notes = "",
   1452         method = "sort",
   1453         args = {float[].class, int.class, int.class}
   1454     )
   1455     public void test_sort$FII() {
   1456         // Test for method void java.util.Arrays.sort(float [], int, int)
   1457         int startIndex = arraySize / 4;
   1458         int endIndex = 3 * arraySize / 4;
   1459         float[] reversedArray = new float[arraySize];
   1460         float[] originalReversedArray = new float[arraySize];
   1461         for (int counter = 0; counter < arraySize; counter++) {
   1462             reversedArray[counter] = (float) (arraySize - counter - 1);
   1463             originalReversedArray[counter] = reversedArray[counter];
   1464         }
   1465         Arrays.sort(reversedArray, startIndex, endIndex);
   1466         for (int counter = 0; counter < startIndex; counter++)
   1467             assertTrue("Array modified outside of bounds",
   1468                     reversedArray[counter] == originalReversedArray[counter]);
   1469         for (int counter = startIndex; counter < endIndex - 1; counter++)
   1470             assertTrue("Array not sorted within bounds",
   1471                     reversedArray[counter] <= reversedArray[counter + 1]);
   1472         for (int counter = endIndex; counter < arraySize; counter++)
   1473             assertTrue("Array modified outside of bounds",
   1474                     reversedArray[counter] == originalReversedArray[counter]);
   1475 
   1476         //exception testing
   1477         try {
   1478             Arrays.sort(reversedArray, startIndex + 1, startIndex);
   1479             fail("IllegalArgumentException expected");
   1480         } catch (IllegalArgumentException ignore) {
   1481         }
   1482 
   1483         try {
   1484             Arrays.sort(reversedArray, -1, startIndex);
   1485             fail("ArrayIndexOutOfBoundsException expected (1)");
   1486         } catch (ArrayIndexOutOfBoundsException ignore) {
   1487         }
   1488 
   1489         try {
   1490             Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
   1491             fail("ArrayIndexOutOfBoundsException expected (2)");
   1492         } catch (ArrayIndexOutOfBoundsException ignore) {
   1493         }
   1494 
   1495         //exception order testing
   1496         try {
   1497             Arrays.sort(new float[1], startIndex + 1, startIndex);
   1498             fail("IllegalArgumentException expected");
   1499         } catch (IllegalArgumentException ignore) {
   1500         }
   1501     }
   1502 
   1503     /**
   1504      * @tests java.util.Arrays#sort(int[])
   1505      */
   1506     @TestTargetNew(
   1507         level = TestLevel.COMPLETE,
   1508         notes = "",
   1509         method = "sort",
   1510         args = {int[].class}
   1511     )
   1512     public void test_sort$I() {
   1513         // Test for method void java.util.Arrays.sort(int [])
   1514         int[] reversedArray = new int[arraySize];
   1515         for (int counter = 0; counter < arraySize; counter++)
   1516             reversedArray[counter] = arraySize - counter - 1;
   1517         Arrays.sort(reversedArray);
   1518         for (int counter = 0; counter < arraySize; counter++)
   1519             assertTrue("Resulting array not sorted",
   1520                     reversedArray[counter] == counter);
   1521     }
   1522 
   1523     /**
   1524      * @tests java.util.Arrays#sort(int[], int, int)
   1525      */
   1526     @TestTargetNew(
   1527         level = TestLevel.COMPLETE,
   1528         notes = "",
   1529         method = "sort",
   1530         args = {int[].class, int.class, int.class}
   1531     )
   1532     public void test_sort$III() {
   1533         // Test for method void java.util.Arrays.sort(int [], int, int)
   1534         int startIndex = arraySize / 4;
   1535         int endIndex = 3 * arraySize / 4;
   1536         int[] reversedArray = new int[arraySize];
   1537         int[] originalReversedArray = new int[arraySize];
   1538         for (int counter = 0; counter < arraySize; counter++) {
   1539             reversedArray[counter] = arraySize - counter - 1;
   1540             originalReversedArray[counter] = reversedArray[counter];
   1541         }
   1542         Arrays.sort(reversedArray, startIndex, endIndex);
   1543         for (int counter = 0; counter < startIndex; counter++)
   1544             assertTrue("Array modified outside of bounds",
   1545                     reversedArray[counter] == originalReversedArray[counter]);
   1546         for (int counter = startIndex; counter < endIndex - 1; counter++)
   1547             assertTrue("Array not sorted within bounds",
   1548                     reversedArray[counter] <= reversedArray[counter + 1]);
   1549         for (int counter = endIndex; counter < arraySize; counter++)
   1550             assertTrue("Array modified outside of bounds",
   1551                     reversedArray[counter] == originalReversedArray[counter]);
   1552 
   1553         //exception testing
   1554         try {
   1555             Arrays.sort(reversedArray, startIndex + 1, startIndex);
   1556             fail("IllegalArgumentException expected");
   1557         } catch (IllegalArgumentException ignore) {
   1558         }
   1559 
   1560         try {
   1561             Arrays.sort(reversedArray, -1, startIndex);
   1562             fail("ArrayIndexOutOfBoundsException expected (1)");
   1563         } catch (ArrayIndexOutOfBoundsException ignore) {
   1564         }
   1565 
   1566         try {
   1567             Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
   1568             fail("ArrayIndexOutOfBoundsException expected (2)");
   1569         } catch (ArrayIndexOutOfBoundsException ignore) {
   1570         }
   1571 
   1572         //exception order testing
   1573         try {
   1574             Arrays.sort(new int[1], startIndex + 1, startIndex);
   1575             fail("IllegalArgumentException expected");
   1576         } catch (IllegalArgumentException ignore) {
   1577         }
   1578     }
   1579 
   1580     /**
   1581      * @tests java.util.Arrays#sort(long[])
   1582      */
   1583     @TestTargetNew(
   1584         level = TestLevel.COMPLETE,
   1585         notes = "",
   1586         method = "sort",
   1587         args = {long[].class}
   1588     )
   1589     public void test_sort$J() {
   1590         // Test for method void java.util.Arrays.sort(long [])
   1591         long[] reversedArray = new long[arraySize];
   1592         for (int counter = 0; counter < arraySize; counter++)
   1593             reversedArray[counter] = (long) (arraySize - counter - 1);
   1594         Arrays.sort(reversedArray);
   1595         for (int counter = 0; counter < arraySize; counter++)
   1596             assertTrue("Resulting array not sorted",
   1597                     reversedArray[counter] == (long) counter);
   1598 
   1599     }
   1600 
   1601     /**
   1602      * @tests java.util.Arrays#sort(long[], int, int)
   1603      */
   1604     @TestTargetNew(
   1605         level = TestLevel.COMPLETE,
   1606         notes = "",
   1607         method = "sort",
   1608         args = {long[].class, int.class, int.class}
   1609     )
   1610     public void test_sort$JII() {
   1611         // Test for method void java.util.Arrays.sort(long [], int, int)
   1612         int startIndex = arraySize / 4;
   1613         int endIndex = 3 * arraySize / 4;
   1614         long[] reversedArray = new long[arraySize];
   1615         long[] originalReversedArray = new long[arraySize];
   1616         for (int counter = 0; counter < arraySize; counter++) {
   1617             reversedArray[counter] = (long) (arraySize - counter - 1);
   1618             originalReversedArray[counter] = reversedArray[counter];
   1619         }
   1620         Arrays.sort(reversedArray, startIndex, endIndex);
   1621         for (int counter = 0; counter < startIndex; counter++)
   1622             assertTrue("Array modified outside of bounds",
   1623                     reversedArray[counter] == originalReversedArray[counter]);
   1624         for (int counter = startIndex; counter < endIndex - 1; counter++)
   1625             assertTrue("Array not sorted within bounds",
   1626                     reversedArray[counter] <= reversedArray[counter + 1]);
   1627         for (int counter = endIndex; counter < arraySize; counter++)
   1628             assertTrue("Array modified outside of bounds",
   1629                     reversedArray[counter] == originalReversedArray[counter]);
   1630 
   1631         //exception testing
   1632         try {
   1633             Arrays.sort(reversedArray, startIndex + 1, startIndex);
   1634             fail("IllegalArgumentException expected");
   1635         } catch (IllegalArgumentException ignore) {
   1636         }
   1637 
   1638         try {
   1639             Arrays.sort(reversedArray, -1, startIndex);
   1640             fail("ArrayIndexOutOfBoundsException expected (1)");
   1641         } catch (ArrayIndexOutOfBoundsException ignore) {
   1642         }
   1643 
   1644         try {
   1645             Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
   1646             fail("ArrayIndexOutOfBoundsException expected (2)");
   1647         } catch (ArrayIndexOutOfBoundsException ignore) {
   1648         }
   1649 
   1650         //exception order testing
   1651         try {
   1652             Arrays.sort(new long[1], startIndex + 1, startIndex);
   1653             fail("IllegalArgumentException expected");
   1654         } catch (IllegalArgumentException ignore) {
   1655         }
   1656     }
   1657 
   1658     /**
   1659      * @tests java.util.Arrays#sort(java.lang.Object[])
   1660      */
   1661     @TestTargetNew(
   1662         level = TestLevel.COMPLETE,
   1663         notes = "",
   1664         method = "sort",
   1665         args = {java.lang.Object[].class}
   1666     )
   1667     public void test_sort$Ljava_lang_Object() {
   1668         // Test for method void java.util.Arrays.sort(java.lang.Object [])
   1669         Object[] reversedArray = new Object[arraySize];
   1670         for (int counter = 0; counter < arraySize; counter++)
   1671             reversedArray[counter] = objectArray[arraySize - counter - 1];
   1672         Arrays.sort(reversedArray);
   1673         for (int counter = 0; counter < arraySize; counter++)
   1674             assertTrue("Resulting array not sorted",
   1675                     reversedArray[counter] == objectArray[counter]);
   1676 
   1677         Arrays.fill(reversedArray, 0, reversedArray.length/2, "String");
   1678         Arrays.fill(reversedArray, reversedArray.length/2, reversedArray.length, new Integer(1));
   1679 
   1680         try {
   1681             Arrays.sort(reversedArray);
   1682             fail("ClassCastException expected");
   1683         } catch (ClassCastException e) {
   1684             //expected
   1685         }
   1686     }
   1687 
   1688     /**
   1689      * @tests java.util.Arrays#sort(java.lang.Object[], int, int)
   1690      */
   1691     @TestTargetNew(
   1692         level = TestLevel.COMPLETE,
   1693         notes = "",
   1694         method = "sort",
   1695         args = {java.lang.Object[].class, int.class, int.class}
   1696     )
   1697     public void test_sort$Ljava_lang_ObjectII() {
   1698         // Test for method void java.util.Arrays.sort(java.lang.Object [], int,
   1699         // int)
   1700         int startIndex = arraySize / 4;
   1701         int endIndex = 3 * arraySize / 4;
   1702         Object[] reversedArray = new Object[arraySize];
   1703         Object[] originalReversedArray = new Object[arraySize];
   1704         for (int counter = 0; counter < arraySize; counter++) {
   1705             reversedArray[counter] = objectArray[arraySize - counter - 1];
   1706             originalReversedArray[counter] = reversedArray[counter];
   1707         }
   1708         Arrays.sort(reversedArray, startIndex, endIndex);
   1709         for (int counter = 0; counter < startIndex; counter++)
   1710             assertTrue("Array modified outside of bounds",
   1711                     reversedArray[counter] == originalReversedArray[counter]);
   1712         for (int counter = startIndex; counter < endIndex - 1; counter++)
   1713             assertTrue("Array not sorted within bounds",
   1714                     ((Comparable) reversedArray[counter])
   1715                             .compareTo(reversedArray[counter + 1]) <= 0);
   1716         for (int counter = endIndex; counter < arraySize; counter++)
   1717             assertTrue("Array modified outside of bounds",
   1718                     reversedArray[counter] == originalReversedArray[counter]);
   1719 
   1720         //exception testing
   1721         try {
   1722             Arrays.sort(reversedArray, startIndex + 1, startIndex);
   1723             fail("IllegalArgumentException expected");
   1724         } catch (IllegalArgumentException ignore) {
   1725         }
   1726 
   1727         try {
   1728             Arrays.sort(reversedArray, -1, startIndex);
   1729             fail("ArrayIndexOutOfBoundsException expected (1)");
   1730         } catch (ArrayIndexOutOfBoundsException ignore) {
   1731         }
   1732 
   1733         try {
   1734             Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
   1735             fail("ArrayIndexOutOfBoundsException expected (2)");
   1736         } catch (ArrayIndexOutOfBoundsException ignore) {
   1737         }
   1738 
   1739         //exception order testing
   1740         try {
   1741             Arrays.sort(new Object[1], startIndex + 1, startIndex);
   1742             fail("IllegalArgumentException expected");
   1743         } catch (IllegalArgumentException ignore) {
   1744         }
   1745 
   1746         Arrays.fill(reversedArray, 0, reversedArray.length/2, "String");
   1747         Arrays.fill(reversedArray, reversedArray.length/2, reversedArray.length, new Integer(1));
   1748 
   1749         try {
   1750             Arrays.sort(reversedArray, reversedArray.length/4, 3*reversedArray.length/4);
   1751             fail("ClassCastException expected");
   1752         } catch (ClassCastException e) {
   1753             //expected
   1754         }
   1755 
   1756         Arrays.sort(reversedArray, 0, reversedArray.length/4);
   1757         Arrays.sort(reversedArray, 3*reversedArray.length/4, reversedArray.length);
   1758     }
   1759 
   1760     /**
   1761      * @tests java.util.Arrays#sort(java.lang.Object[], int, int,
   1762      *        java.util.Comparator)
   1763      */
   1764     @TestTargetNew(
   1765         level = TestLevel.COMPLETE,
   1766         notes = "",
   1767         method = "sort",
   1768         args = {java.lang.Object[].class, int.class, int.class, java.util.Comparator.class}
   1769     )
   1770     public void test_sort$Ljava_lang_ObjectIILjava_util_Comparator() {
   1771         // Test for method void java.util.Arrays.sort(java.lang.Object [], int,
   1772         // int, java.util.Comparator)
   1773         int startIndex = arraySize / 4;
   1774         int endIndex = 3 * arraySize / 4;
   1775         ReversedIntegerComparator comp = new ReversedIntegerComparator();
   1776         Object[] originalArray = new Object[arraySize];
   1777         for (int counter = 0; counter < arraySize; counter++)
   1778             originalArray[counter] = objectArray[counter];
   1779         Arrays.sort(objectArray, startIndex, endIndex, comp);
   1780         for (int counter = 0; counter < startIndex; counter++)
   1781             assertTrue("Array modified outside of bounds",
   1782                     objectArray[counter] == originalArray[counter]);
   1783         for (int counter = startIndex; counter < endIndex - 1; counter++)
   1784             assertTrue("Array not sorted within bounds", comp.compare(
   1785                     objectArray[counter], objectArray[counter + 1]) <= 0);
   1786         for (int counter = endIndex; counter < arraySize; counter++)
   1787             assertTrue("Array modified outside of bounds",
   1788                     objectArray[counter] == originalArray[counter]);
   1789 
   1790         Arrays.fill(originalArray, 0, originalArray.length/2, "String");
   1791         Arrays.fill(originalArray, originalArray.length/2, originalArray.length, new Integer(1));
   1792 
   1793         try {
   1794             Arrays.sort(originalArray, startIndex, endIndex, comp);
   1795             fail("ClassCastException expected");
   1796         } catch (ClassCastException e) {
   1797             //expected
   1798         }
   1799 
   1800         Arrays.sort(originalArray, endIndex, originalArray.length, comp);
   1801 
   1802         try {
   1803             Arrays.sort(originalArray, endIndex, originalArray.length + 1, comp);
   1804             fail("ArrayIndexOutOfBoundsException expected");
   1805         } catch(ArrayIndexOutOfBoundsException e) {
   1806             //expected
   1807         }
   1808 
   1809         try {
   1810             Arrays.sort(originalArray, -1, startIndex, comp);
   1811             fail("ArrayIndexOutOfBoundsException expected");
   1812         } catch(ArrayIndexOutOfBoundsException e) {
   1813             //expected
   1814         }
   1815 
   1816         try {
   1817             Arrays.sort(originalArray, originalArray.length, endIndex, comp);
   1818             fail("IllegalArgumentException expected");
   1819         } catch(IllegalArgumentException e) {
   1820             //expected
   1821         }
   1822     }
   1823 
   1824     /**
   1825      * @tests java.util.Arrays#sort(java.lang.Object[], java.util.Comparator)
   1826      */
   1827     @TestTargetNew(
   1828         level = TestLevel.COMPLETE,
   1829         notes = "",
   1830         method = "sort",
   1831         args = {java.lang.Object[].class, java.util.Comparator.class}
   1832     )
   1833     public void test_sort$Ljava_lang_ObjectLjava_util_Comparator() {
   1834         // Test for method void java.util.Arrays.sort(java.lang.Object [],
   1835         // java.util.Comparator)
   1836         ReversedIntegerComparator comp = new ReversedIntegerComparator();
   1837         Arrays.sort(objectArray, comp);
   1838         for (int counter = 0; counter < arraySize - 1; counter++)
   1839             assertTrue("Array not sorted correctly with custom comparator",
   1840                     comp
   1841                             .compare(objectArray[counter],
   1842                                     objectArray[counter + 1]) <= 0);
   1843 
   1844         Arrays.fill(objectArray, 0, objectArray.length/2, "String");
   1845         Arrays.fill(objectArray, objectArray.length/2, objectArray.length, new Integer(1));
   1846 
   1847         try {
   1848             Arrays.sort(objectArray, comp);
   1849             fail("ClassCastException expected");
   1850         } catch (ClassCastException e) {
   1851             //expected
   1852         }
   1853     }
   1854 
   1855     /**
   1856      * @tests java.util.Arrays#sort(short[])
   1857      */
   1858     @TestTargetNew(
   1859         level = TestLevel.COMPLETE,
   1860         notes = "",
   1861         method = "sort",
   1862         args = {short[].class}
   1863     )
   1864     public void test_sort$S() {
   1865         // Test for method void java.util.Arrays.sort(short [])
   1866         short[] reversedArray = new short[arraySize];
   1867         for (int counter = 0; counter < arraySize; counter++)
   1868             reversedArray[counter] = (short) (arraySize - counter - 1);
   1869         Arrays.sort(reversedArray);
   1870         for (int counter = 0; counter < arraySize; counter++)
   1871             assertTrue("Resulting array not sorted",
   1872                     reversedArray[counter] == (short) counter);
   1873     }
   1874 
   1875     /**
   1876      * @tests java.util.Arrays#sort(short[], int, int)
   1877      */
   1878     @TestTargetNew(
   1879         level = TestLevel.COMPLETE,
   1880         notes = "",
   1881         method = "sort",
   1882         args = {short[].class, int.class, int.class}
   1883     )
   1884     public void test_sort$SII() {
   1885         // Test for method void java.util.Arrays.sort(short [], int, int)
   1886         int startIndex = arraySize / 4;
   1887         int endIndex = 3 * arraySize / 4;
   1888         short[] reversedArray = new short[arraySize];
   1889         short[] originalReversedArray = new short[arraySize];
   1890         for (int counter = 0; counter < arraySize; counter++) {
   1891             reversedArray[counter] = (short) (arraySize - counter - 1);
   1892             originalReversedArray[counter] = reversedArray[counter];
   1893         }
   1894         Arrays.sort(reversedArray, startIndex, endIndex);
   1895         for (int counter = 0; counter < startIndex; counter++)
   1896             assertTrue("Array modified outside of bounds",
   1897                     reversedArray[counter] == originalReversedArray[counter]);
   1898         for (int counter = startIndex; counter < endIndex - 1; counter++)
   1899             assertTrue("Array not sorted within bounds",
   1900                     reversedArray[counter] <= reversedArray[counter + 1]);
   1901         for (int counter = endIndex; counter < arraySize; counter++)
   1902             assertTrue("Array modified outside of bounds",
   1903                     reversedArray[counter] == originalReversedArray[counter]);
   1904 
   1905         //exception testing
   1906         try {
   1907             Arrays.sort(reversedArray, startIndex + 1, startIndex);
   1908             fail("IllegalArgumentException expected");
   1909         } catch (IllegalArgumentException ignore) {
   1910         }
   1911 
   1912         try {
   1913             Arrays.sort(reversedArray, -1, startIndex);
   1914             fail("ArrayIndexOutOfBoundsException expected (1)");
   1915         } catch (ArrayIndexOutOfBoundsException ignore) {
   1916         }
   1917 
   1918         try {
   1919             Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
   1920             fail("ArrayIndexOutOfBoundsException expected (2)");
   1921         } catch (ArrayIndexOutOfBoundsException ignore) {
   1922         }
   1923 
   1924         //exception order testing
   1925         try {
   1926             Arrays.sort(new short[1], startIndex + 1, startIndex);
   1927             fail("IllegalArgumentException expected");
   1928         } catch (IllegalArgumentException ignore) {
   1929         }
   1930     }
   1931 
   1932     /**
   1933      * @tests java.util.Arrays#sort(byte[], int, int)
   1934      */
   1935     @TestTargetNew(
   1936         level = TestLevel.PARTIAL_COMPLETE,
   1937         notes = "Verifies NullPointerException.",
   1938         method = "sort",
   1939         args = {byte[].class, int.class, int.class}
   1940     )
   1941     public void test_java_util_Arrays_sort_byte_array_NPE() {
   1942         byte[] byte_array_null = null;
   1943         try {
   1944             java.util.Arrays.sort(byte_array_null);
   1945             fail("Should throw java.lang.NullPointerException");
   1946         } catch (NullPointerException e) {
   1947             // Expected
   1948         }
   1949         try {
   1950             // Regression for HARMONY-378
   1951             java.util.Arrays.sort(byte_array_null, (int) -1, (int) 1);
   1952             fail("Should throw java.lang.NullPointerException");
   1953         } catch (NullPointerException e) {
   1954             // Expected
   1955         }
   1956     }
   1957 
   1958     /**
   1959      * @tests java.util.Arrays#sort(char[], int, int)
   1960      */
   1961     @TestTargetNew(
   1962         level = TestLevel.PARTIAL_COMPLETE,
   1963         notes = "Verifies NullPointerException.",
   1964         method = "sort",
   1965         args = {char[].class, int.class, int.class}
   1966     )
   1967     public void test_java_util_Arrays_sort_char_array_NPE() {
   1968         char[] char_array_null = null;
   1969         try {
   1970             java.util.Arrays.sort(char_array_null);
   1971             fail("Should throw java.lang.NullPointerException");
   1972         } catch (NullPointerException e) {
   1973             // Expected
   1974         }
   1975         try {
   1976             // Regression for HARMONY-378
   1977             java.util.Arrays.sort(char_array_null, (int) -1, (int) 1);
   1978             fail("Should throw java.lang.NullPointerException");
   1979         } catch (NullPointerException e) {
   1980             // Expected
   1981         }
   1982     }
   1983 
   1984     /**
   1985      * @tests java.util.Arrays#sort(double[], int, int)
   1986      */
   1987     @TestTargetNew(
   1988         level = TestLevel.PARTIAL_COMPLETE,
   1989         notes = "Verifies NullPointerException.",
   1990         method = "sort",
   1991         args = {double[].class, int.class, int.class}
   1992     )
   1993     public void test_java_util_Arrays_sort_double_array_NPE() {
   1994         double[] double_array_null = null;
   1995         try {
   1996             java.util.Arrays.sort(double_array_null);
   1997             fail("Should throw java.lang.NullPointerException");
   1998         } catch (NullPointerException e) {
   1999             // Expected
   2000         }
   2001         try {
   2002             // Regression for HARMONY-378
   2003             java.util.Arrays.sort(double_array_null, (int) -1, (int) 1);
   2004             fail("Should throw java.lang.NullPointerException");
   2005         } catch (NullPointerException e) {
   2006             // Expected
   2007         }
   2008     }
   2009 
   2010     /**
   2011      * @tests java.util.Arrays#sort(float[], int, int)
   2012      */
   2013     @TestTargetNew(
   2014         level = TestLevel.PARTIAL_COMPLETE,
   2015         notes = "Verifies NullPointerException.",
   2016         method = "sort",
   2017         args = {float[].class, int.class, int.class}
   2018     )
   2019     public void test_java_util_Arrays_sort_float_array_NPE() {
   2020         float[] float_array_null = null;
   2021         try {
   2022             java.util.Arrays.sort(float_array_null);
   2023             fail("Should throw java.lang.NullPointerException");
   2024         } catch (NullPointerException e) {
   2025             // Expected
   2026         }
   2027         try {
   2028             // Regression for HARMONY-378
   2029             java.util.Arrays.sort(float_array_null, (int) -1, (int) 1);
   2030             fail("Should throw java.lang.NullPointerException");
   2031         } catch (NullPointerException e) {
   2032             // Expected
   2033         }
   2034     }
   2035 
   2036     /**
   2037      * @tests java.util.Arrays#sort(int[], int, int)
   2038      */
   2039     @TestTargetNew(
   2040         level = TestLevel.PARTIAL_COMPLETE,
   2041         notes = "Verifies NullPointerException.",
   2042         method = "sort",
   2043         args = {int[].class, int.class, int.class}
   2044     )
   2045     public void test_java_util_Arrays_sort_int_array_NPE() {
   2046         int[] int_array_null = null;
   2047         try {
   2048             java.util.Arrays.sort(int_array_null);
   2049             fail("Should throw java.lang.NullPointerException");
   2050         } catch (NullPointerException e) {
   2051             // Expected
   2052         }
   2053         try {
   2054             // Regression for HARMONY-378
   2055             java.util.Arrays.sort(int_array_null, (int) -1, (int) 1);
   2056             fail("Should throw java.lang.NullPointerException");
   2057         } catch (NullPointerException e) {
   2058             // Expected
   2059         }
   2060     }
   2061 
   2062     /**
   2063      * @tests java.util.Arrays#sort(Object[], int, int)
   2064      */
   2065     @TestTargetNew(
   2066         level = TestLevel.PARTIAL_COMPLETE,
   2067         notes = "Verifies NullPointerException.",
   2068         method = "sort",
   2069         args = {java.lang.Object[].class, int.class, int.class}
   2070     )
   2071     public void test_java_util_Arrays_sort_object_array_NPE() {
   2072         Object[] object_array_null = null;
   2073         try {
   2074             java.util.Arrays.sort(object_array_null);
   2075             fail("Should throw java.lang.NullPointerException");
   2076         } catch (NullPointerException e) {
   2077             // Expected
   2078         }
   2079         try {
   2080             // Regression for HARMONY-378
   2081             java.util.Arrays.sort(object_array_null, (int) -1, (int) 1);
   2082             fail("Should throw java.lang.NullPointerException");
   2083         } catch (NullPointerException e) {
   2084             // Expected
   2085         }
   2086         try {
   2087             // Regression for HARMONY-378
   2088             java.util.Arrays.sort(object_array_null, (int) -1, (int) 1, null);
   2089             fail("Should throw java.lang.NullPointerException");
   2090         } catch (NullPointerException e) {
   2091             // Expected
   2092         }
   2093     }
   2094 
   2095     /**
   2096      * @tests java.util.Arrays#sort(long[], int, int)
   2097      */
   2098     @TestTargetNew(
   2099         level = TestLevel.PARTIAL_COMPLETE,
   2100         notes = "Verifies NullPointerException.",
   2101         method = "sort",
   2102         args = {long[].class, int.class, int.class}
   2103     )
   2104     public void test_java_util_Arrays_sort_long_array_NPE() {
   2105         long[] long_array_null = null;
   2106         try {
   2107             java.util.Arrays.sort(long_array_null);
   2108             fail("Should throw java.lang.NullPointerException");
   2109         } catch (NullPointerException e) {
   2110             // Expected
   2111         }
   2112         try {
   2113             // Regression for HARMONY-378
   2114             java.util.Arrays.sort(long_array_null, (int) -1, (int) 1);
   2115             fail("Should throw java.lang.NullPointerException");
   2116         } catch (NullPointerException e) {
   2117             // Expected
   2118         }
   2119     }
   2120 
   2121     /**
   2122      * @tests java.util.Arrays#sort(short[], int, int)
   2123      */
   2124     @TestTargetNew(
   2125         level = TestLevel.PARTIAL_COMPLETE,
   2126         notes = "Verifies NullPointerException.",
   2127         method = "sort",
   2128         args = {short[].class, int.class, int.class}
   2129     )
   2130     public void test_java_util_Arrays_sort_short_array_NPE() {
   2131         short[] short_array_null = null;
   2132         try {
   2133             java.util.Arrays.sort(short_array_null);
   2134             fail("Should throw java.lang.NullPointerException");
   2135         } catch (NullPointerException e) {
   2136             // Expected
   2137         }
   2138         try {
   2139             // Regression for HARMONY-378
   2140             java.util.Arrays.sort(short_array_null, (int) -1, (int) 1);
   2141             fail("Should throw java.lang.NullPointerException");
   2142         } catch (NullPointerException e) {
   2143             // Expected
   2144         }
   2145     }
   2146 
   2147     // Lenghts of arrays to test in test_sort;
   2148     private static final int[] LENGTHS = { 0, 1, 2, 3, 5, 8, 13, 21, 34, 55, 100, 1000, 10000 };
   2149 
   2150     /**
   2151      * @tests java.util.Arrays#sort()
   2152      */
   2153     @TestTargetNew(
   2154         level = TestLevel.PARTIAL_COMPLETE,
   2155         notes = "Agressive test of the sort methods for *all* primitive array types",
   2156         method = "sort"
   2157     )
   2158     public void test_sort() {
   2159         for (int len : LENGTHS) {
   2160             PrimitiveTypeArrayBuilder.reset();
   2161             int[] golden = new int[len];
   2162             for (int m = 1; m < 2 * len; m *= 2) {
   2163                 for (PrimitiveTypeArrayBuilder builder : PrimitiveTypeArrayBuilder.values()) {
   2164                     builder.build(golden, m);
   2165                     int[] test = golden.clone();
   2166 
   2167                     for (PrimitiveTypeConverter converter : PrimitiveTypeConverter.values()) {
   2168                         Object convertedGolden = converter.convert(golden);
   2169                         Object convertedTest = converter.convert(test);
   2170                         sort(convertedTest);
   2171                         checkSorted(convertedTest);
   2172                         assertEquals(checkSum(convertedGolden), checkSum(convertedTest));
   2173                     }
   2174                 }
   2175             }
   2176         }
   2177     }
   2178 
   2179     private void sort(Object array) {
   2180         if (array instanceof int[]) {
   2181             Arrays.sort((int[]) array);
   2182         }
   2183         else if (array instanceof long[]) {
   2184             Arrays.sort((long[]) array);
   2185         } else if (array instanceof short[]) {
   2186             Arrays.sort((short[]) array);
   2187         } else if (array instanceof byte[]) {
   2188             Arrays.sort((byte[]) array);
   2189         } else if (array instanceof char[]) {
   2190             Arrays.sort((char[]) array);
   2191         } else if (array instanceof float[]) {
   2192             Arrays.sort((float[]) array);
   2193         } else if (array instanceof double[]) {
   2194             Arrays.sort((double[]) array);
   2195         } else {
   2196             fail("Unknow type of array: " + array.getClass());
   2197         }
   2198     }
   2199 
   2200     private void checkSorted(Object array) {
   2201         if (array instanceof int[]) {
   2202             checkSorted((int[]) array);
   2203         } else if (array instanceof long[]) {
   2204             checkSorted((long[]) array);
   2205         } else if (array instanceof short[]) {
   2206             checkSorted((short[]) array);
   2207         } else if (array instanceof byte[]) {
   2208             checkSorted((byte[]) array);
   2209         } else if (array instanceof char[]) {
   2210             checkSorted((char[]) array);
   2211         } else if (array instanceof float[]) {
   2212             checkSorted((float[]) array);
   2213         } else if (array instanceof double[]) {
   2214             checkSorted((double[]) array);
   2215         } else {
   2216             fail("Unknow type of array: " + array.getClass());
   2217         }
   2218     }
   2219 
   2220     private void checkSorted(int[] a) {
   2221         for (int i = 0; i < a.length - 1; i++) {
   2222             if (a[i] > a[i + 1]) {
   2223                 orderFail(i, "" + a[i], "" + a[i + 1]);
   2224             }
   2225         }
   2226     }
   2227 
   2228     private void checkSorted(long[] a) {
   2229         for (int i = 0; i < a.length - 1; i++) {
   2230             if (a[i] > a[i + 1]) {
   2231                 orderFail(i, "" + a[i], "" + a[i + 1]);
   2232             }
   2233         }
   2234     }
   2235 
   2236     private void checkSorted(short[] a) {
   2237         for (int i = 0; i < a.length - 1; i++) {
   2238             if (a[i] > a[i + 1]) {
   2239                 orderFail(i, "" + a[i], "" + a[i + 1]);
   2240             }
   2241         }
   2242     }
   2243 
   2244     private void checkSorted(byte[] a) {
   2245         for (int i = 0; i < a.length - 1; i++) {
   2246             if (a[i] > a[i + 1]) {
   2247                 orderFail(i, "" + a[i], "" + a[i + 1]);
   2248             }
   2249         }
   2250     }
   2251 
   2252     private void checkSorted(char[] a) {
   2253         for (int i = 0; i < a.length - 1; i++) {
   2254             if (a[i] > a[i + 1]) {
   2255                 orderFail(i, "" + a[i], "" + a[i + 1]);
   2256             }
   2257         }
   2258     }
   2259 
   2260     private void checkSorted(float[] a) {
   2261         for (int i = 0; i < a.length - 1; i++) {
   2262             if (a[i] > a[i + 1]) {
   2263                 orderFail(i, "" + a[i], "" + a[i + 1]);
   2264             }
   2265         }
   2266     }
   2267 
   2268     private void checkSorted(double[] a) {
   2269         for (int i = 0; i < a.length - 1; i++) {
   2270             if (a[i] > a[i + 1]) {
   2271                 orderFail(i, "" + a[i], "" + a[i + 1]);
   2272             }
   2273         }
   2274     }
   2275 
   2276 
   2277     private void orderFail(int index, String value1, String value2) {
   2278         fail("Array is not sorted at " + index + "-th position: " + value1 + " and " + value2);
   2279     }
   2280 
   2281     private int checkSum(Object array) {
   2282         if (array instanceof int[]) {
   2283             return checkSum((int[]) array);
   2284         } else if (array instanceof long[]) {
   2285             return checkSum((long[]) array);
   2286         } else if (array instanceof short[]) {
   2287             return checkSum((short[]) array);
   2288         } else if (array instanceof byte[]) {
   2289             return checkSum((byte[]) array);
   2290         } else if (array instanceof char[]) {
   2291             return checkSum((char[]) array);
   2292         } else if (array instanceof float[]) {
   2293             return checkSum((float[]) array);
   2294         } else if (array instanceof double[]) {
   2295             return checkSum((double[]) array);
   2296         } else {
   2297             fail("Unknow type of array: " + array.getClass());
   2298         }
   2299         throw new AssertionError(); // Needed to shut up compiler
   2300     }
   2301 
   2302     private int checkSum(int[] a) {
   2303         int checkSum = 0;
   2304 
   2305         for (int e : a) {
   2306             checkSum ^= e; // xor
   2307         }
   2308         return checkSum;
   2309     }
   2310 
   2311     private int checkSum(long[] a) {
   2312         long checkSum = 0;
   2313 
   2314         for (long e : a) {
   2315             checkSum ^= e; // xor
   2316         }
   2317         return (int) checkSum;
   2318     }
   2319 
   2320     private int checkSum(short[] a) {
   2321         short checkSum = 0;
   2322 
   2323         for (short e : a) {
   2324             checkSum ^= e; // xor
   2325         }
   2326         return (int) checkSum;
   2327     }
   2328 
   2329     private int checkSum(byte[] a) {
   2330         byte checkSum = 0;
   2331 
   2332         for (byte e : a) {
   2333             checkSum ^= e; // xor
   2334         }
   2335         return (int) checkSum;
   2336     }
   2337 
   2338     private int checkSum(char[] a) {
   2339         char checkSum = 0;
   2340 
   2341         for (char e : a) {
   2342             checkSum ^= e; // xor
   2343         }
   2344         return (int) checkSum;
   2345     }
   2346 
   2347     private int checkSum(float[] a) {
   2348         int checkSum = 0;
   2349 
   2350         for (float e : a) {
   2351             checkSum ^= (int) e; // xor
   2352         }
   2353         return checkSum;
   2354     }
   2355 
   2356     private int checkSum(double[] a) {
   2357         int checkSum = 0;
   2358 
   2359         for (double e : a) {
   2360             checkSum ^= (int) e; // xor
   2361         }
   2362         return checkSum;
   2363     }
   2364 
   2365     private enum PrimitiveTypeArrayBuilder {
   2366 
   2367         RANDOM {
   2368             void build(int[] a, int m) {
   2369                 for (int i = 0; i < a.length; i++) {
   2370                     a[i] = ourRandom.nextInt();
   2371                 }
   2372             }
   2373         },
   2374 
   2375         ASCENDING {
   2376             void build(int[] a, int m) {
   2377                 for (int i = 0; i < a.length; i++) {
   2378                     a[i] = m + i;
   2379                 }
   2380             }
   2381         },
   2382 
   2383         DESCENDING {
   2384             void build(int[] a, int m) {
   2385                 for (int i = 0; i < a.length; i++) {
   2386                     a[i] = a.length - m - i;
   2387                 }
   2388             }
   2389         },
   2390 
   2391         ALL_EQUAL {
   2392             void build(int[] a, int m) {
   2393                 for (int i = 0; i < a.length; i++) {
   2394                     a[i] = m;
   2395                 }
   2396             }
   2397         },
   2398 
   2399         SAW {
   2400             void build(int[] a, int m) {
   2401                 int incCount = 1;
   2402                 int decCount = a.length;
   2403                 int i = 0;
   2404                 int period = m;
   2405                 m--;
   2406 
   2407                 while (true) {
   2408                     for (int k = 1; k <= period; k++) {
   2409                         if (i >= a.length) {
   2410                             return;
   2411                         }
   2412                         a[i++] = incCount++;
   2413                     }
   2414                     period += m;
   2415 
   2416                     for (int k = 1; k <= period; k++) {
   2417                         if (i >= a.length) {
   2418                             return;
   2419                         }
   2420                         a[i++] = decCount--;
   2421                     }
   2422                     period += m;
   2423                 }
   2424             }
   2425         },
   2426 
   2427         REPEATED {
   2428             void build(int[] a, int m) {
   2429                 for (int i = 0; i < a.length; i++) {
   2430                     a[i] = i % m;
   2431                 }
   2432             }
   2433         },
   2434 
   2435         DUPLICATED {
   2436             void build(int[] a, int m) {
   2437                 for (int i = 0; i < a.length; i++) {
   2438                     a[i] = ourRandom.nextInt(m);
   2439                 }
   2440             }
   2441         },
   2442 
   2443         ORGAN_PIPES {
   2444             void build(int[] a, int m) {
   2445                 int middle = a.length / (m + 1);
   2446 
   2447                 for (int i = 0; i < middle; i++) {
   2448                     a[i] = i;
   2449                 }
   2450                 for (int i = middle; i < a.length ; i++) {
   2451                     a[i] = a.length - i - 1;
   2452                 }
   2453             }
   2454         },
   2455 
   2456         STAGGER {
   2457             void build(int[] a, int m) {
   2458                 for (int i = 0; i < a.length; i++) {
   2459                     a[i] = (i * m + i) % a.length;
   2460                 }
   2461             }
   2462         },
   2463 
   2464         PLATEAU {
   2465             void build(int[] a, int m) {
   2466                 for (int i = 0; i < a.length; i++) {
   2467                     a[i] =  Math.min(i, m);
   2468                 }
   2469             }
   2470         },
   2471 
   2472         SHUFFLE {
   2473             void build(int[] a, int m) {
   2474                 for (int i = 0; i < a.length; i++) {
   2475                     a[i] = ourRandom.nextBoolean() ? (ourFirst += 2) : (ourSecond += 2);
   2476                 }
   2477             }
   2478         };
   2479 
   2480         abstract void build(int[] a, int m);
   2481 
   2482         static void reset() {
   2483             ourRandom = new Random(666);
   2484             ourFirst = 0;
   2485             ourSecond = 0;
   2486         }
   2487 
   2488         @Override
   2489         public String toString() {
   2490             String name = name();
   2491 
   2492             for (int i = name.length(); i < 12; i++) {
   2493                 name += " " ;
   2494             }
   2495             return name;
   2496         }
   2497 
   2498         private static int ourFirst;
   2499         private static int ourSecond;
   2500         private static Random ourRandom = new Random(666);
   2501     }
   2502 
   2503     private enum PrimitiveTypeConverter {
   2504 
   2505         INT {
   2506             Object convert(int[] a) {
   2507                 return a;
   2508             }
   2509         },
   2510 
   2511         LONG {
   2512             Object convert(int[] a) {
   2513                 long[] b = new long[a.length];
   2514 
   2515                 for (int i = 0; i < a.length; i++) {
   2516                     b[i] = (int) a[i];
   2517                 }
   2518                 return b;
   2519             }
   2520         },
   2521 
   2522         BYTE {
   2523             Object convert(int[] a) {
   2524                 byte[] b = new byte[a.length];
   2525 
   2526                 for (int i = 0; i < a.length; i++) {
   2527                     b[i] = (byte) a[i];
   2528                 }
   2529                 return b;
   2530             }
   2531         },
   2532 
   2533         SHORT {
   2534             Object convert(int[] a) {
   2535                 short[] b = new short[a.length];
   2536 
   2537                 for (int i = 0; i < a.length; i++) {
   2538                     b[i] = (short) a[i];
   2539                 }
   2540                 return b;
   2541             }
   2542         },
   2543 
   2544         CHAR {
   2545             Object convert(int[] a) {
   2546                 char[] b = new char[a.length];
   2547 
   2548                 for (int i = 0; i < a.length; i++) {
   2549                     b[i] = (char) a[i];
   2550                 }
   2551                 return b;
   2552             }
   2553         },
   2554 
   2555         FLOAT {
   2556             Object convert(int[] a) {
   2557                 float[] b = new float[a.length];
   2558 
   2559                 for (int i = 0; i < a.length; i++) {
   2560                     b[i] = (float) a[i];
   2561                 }
   2562                 return b;
   2563             }
   2564         },
   2565 
   2566         DOUBLE {
   2567             Object convert(int[] a) {
   2568                 double[] b = new double[a.length];
   2569 
   2570                 for (int i = 0; i < a.length; i++) {
   2571                     b[i] = (double) a[i];
   2572                 }
   2573                 return b;
   2574             }
   2575         };
   2576 
   2577         abstract Object convert(int[] a);
   2578 
   2579         public String toString() {
   2580             String name = name();
   2581 
   2582             for (int i = name.length(); i < 9; i++) {
   2583                 name += " " ;
   2584             }
   2585             return name;
   2586         }
   2587     }
   2588 
   2589 
   2590     /**
   2591      * @tests java.util.Arrays#deepEquals(Object[], Object[])
   2592      */
   2593     @TestTargetNew(
   2594         level = TestLevel.COMPLETE,
   2595         notes = "",
   2596         method = "deepEquals",
   2597         args = {java.lang.Object[].class, java.lang.Object[].class}
   2598     )
   2599     public void test_deepEquals$Ljava_lang_ObjectLjava_lang_Object() {
   2600        int [] a1 = {1, 2, 3};
   2601        short [] a2 = {0, 1};
   2602        Object [] a3 = {new Integer(1), a2};
   2603        int [] a4 = {6, 5, 4};
   2604 
   2605        int [] b1 = {1, 2, 3};
   2606        short [] b2 = {0, 1};
   2607        Object [] b3 = {new Integer(1), b2};
   2608 
   2609        Object a [] = {a1, a2, a3};
   2610        Object b [] = {b1, b2, b3};
   2611 
   2612        assertFalse(Arrays.equals(a, b));
   2613        assertTrue(Arrays.deepEquals(a,b));
   2614 
   2615        a[2] = a4;
   2616 
   2617        assertFalse(Arrays.deepEquals(a, b));
   2618     }
   2619 
   2620     /**
   2621      * @tests java.util.Arrays#deepHashCode(Object[])
   2622      */
   2623     @TestTargetNew(
   2624         level = TestLevel.COMPLETE,
   2625         notes = "",
   2626         method = "deepHashCode",
   2627         args = {java.lang.Object[].class}
   2628     )
   2629     public void test_deepHashCode$Ljava_lang_Object() {
   2630         int [] a1 = {1, 2, 3};
   2631         short [] a2 = {0, 1};
   2632         Object [] a3 = {new Integer(1), a2};
   2633 
   2634         int [] b1 = {1, 2, 3};
   2635         short [] b2 = {0, 1};
   2636         Object [] b3 = {new Integer(1), b2};
   2637 
   2638         Object a [] = {a1, a2, a3};
   2639         Object b [] = {b1, b2, b3};
   2640 
   2641         int deep_hash_a = Arrays.deepHashCode(a);
   2642         int deep_hash_b = Arrays.deepHashCode(b);
   2643 
   2644         assertEquals(deep_hash_a, deep_hash_b);
   2645      }
   2646 
   2647     /**
   2648      * @tests java.util.Arrays#hashCode(boolean[] a)
   2649      */
   2650     @TestTargetNew(
   2651         level = TestLevel.COMPLETE,
   2652         notes = "",
   2653         method = "hashCode",
   2654         args = {boolean[].class}
   2655     )
   2656     public void test_hashCode$LZ() {
   2657         int listHashCode;
   2658         int arrayHashCode;
   2659 
   2660         boolean [] boolArr = {true, false, false, true, false};
   2661         List listOfBoolean = new LinkedList();
   2662         for (int i = 0; i < boolArr.length; i++) {
   2663             listOfBoolean.add(new Boolean(boolArr[i]));
   2664         }
   2665         listHashCode = listOfBoolean.hashCode();
   2666         arrayHashCode = Arrays.hashCode(boolArr);
   2667         assertEquals(listHashCode, arrayHashCode);
   2668     }
   2669 
   2670     /**
   2671      * @tests java.util.Arrays#hashCode(int[] a)
   2672      */
   2673     @TestTargetNew(
   2674         level = TestLevel.COMPLETE,
   2675         notes = "",
   2676         method = "hashCode",
   2677         args = {int[].class}
   2678     )
   2679     public void test_hashCode$LI() {
   2680         int listHashCode;
   2681         int arrayHashCode;
   2682 
   2683         int [] intArr = {10, 5, 134, 7, 19};
   2684         List listOfInteger = new LinkedList();
   2685 
   2686         for (int i = 0; i < intArr.length; i++) {
   2687             listOfInteger.add(new Integer(intArr[i]));
   2688         }
   2689         listHashCode = listOfInteger.hashCode();
   2690         arrayHashCode = Arrays.hashCode(intArr);
   2691         assertEquals(listHashCode, arrayHashCode);
   2692 
   2693         int [] intArr2 = {10, 5, 134, 7, 19};
   2694         assertEquals(Arrays.hashCode(intArr2), Arrays.hashCode(intArr));
   2695     }
   2696 
   2697     /**
   2698      * @tests java.util.Arrays#hashCode(char[] a)
   2699      */
   2700     @TestTargetNew(
   2701         level = TestLevel.COMPLETE,
   2702         notes = "",
   2703         method = "hashCode",
   2704         args = {char[].class}
   2705     )
   2706     public void test_hashCode$LC() {
   2707         int listHashCode;
   2708         int arrayHashCode;
   2709 
   2710         char [] charArr = {'a', 'g', 'x', 'c', 'm'};
   2711         List listOfCharacter = new LinkedList();
   2712         for (int i = 0; i < charArr.length; i++) {
   2713             listOfCharacter.add(new Character(charArr[i]));
   2714         }
   2715         listHashCode = listOfCharacter.hashCode();
   2716         arrayHashCode = Arrays.hashCode(charArr);
   2717         assertEquals(listHashCode, arrayHashCode);
   2718     }
   2719 
   2720     /**
   2721      * @tests java.util.Arrays#hashCode(byte[] a)
   2722      */
   2723     @TestTargetNew(
   2724         level = TestLevel.COMPLETE,
   2725         notes = "",
   2726         method = "hashCode",
   2727         args = {byte[].class}
   2728     )
   2729     public void test_hashCode$LB() {
   2730         int listHashCode;
   2731         int arrayHashCode;
   2732 
   2733         byte [] byteArr = {5, 9, 7, 6, 17};
   2734         List listOfByte = new LinkedList();
   2735         for (int i = 0; i < byteArr.length; i++) {
   2736             listOfByte.add(new Byte(byteArr[i]));
   2737         }
   2738         listHashCode = listOfByte.hashCode();
   2739         arrayHashCode = Arrays.hashCode(byteArr);
   2740         assertEquals(listHashCode, arrayHashCode);
   2741     }
   2742 
   2743     /**
   2744      * @tests java.util.Arrays#hashCode(long[] a)
   2745      */
   2746     @TestTargetNew(
   2747         level = TestLevel.COMPLETE,
   2748         notes = "",
   2749         method = "hashCode",
   2750         args = {long[].class}
   2751     )
   2752     public void test_hashCode$LJ() {
   2753         int listHashCode;
   2754         int arrayHashCode;
   2755 
   2756         long [] longArr = {67890234512l, 97587236923425l, 257421912912l,
   2757                 6754268100l, 5};
   2758         List listOfLong = new LinkedList();
   2759         for (int i = 0; i < longArr.length; i++) {
   2760             listOfLong.add(new Long(longArr[i]));
   2761         }
   2762         listHashCode = listOfLong.hashCode();
   2763         arrayHashCode = Arrays.hashCode(longArr);
   2764         assertEquals(listHashCode, arrayHashCode);
   2765     }
   2766 
   2767     /**
   2768      * @tests java.util.Arrays#hashCode(float[] a)
   2769      */
   2770     @TestTargetNew(
   2771         level = TestLevel.COMPLETE,
   2772         notes = "",
   2773         method = "hashCode",
   2774         args = {float[].class}
   2775     )
   2776     public void test_hashCode$LF() {
   2777         int listHashCode;
   2778         int arrayHashCode;
   2779 
   2780         float [] floatArr = {0.13497f, 0.268934f, 12e-5f, -3e+2f, 10e-4f};
   2781         List listOfFloat = new LinkedList();
   2782         for (int i = 0; i < floatArr.length; i++) {
   2783             listOfFloat.add(new Float(floatArr[i]));
   2784         }
   2785         listHashCode = listOfFloat.hashCode();
   2786         arrayHashCode = Arrays.hashCode(floatArr);
   2787         assertEquals(listHashCode, arrayHashCode);
   2788 
   2789         float [] floatArr2 = {0.13497f, 0.268934f, 12e-5f, -3e+2f, 10e-4f};
   2790         assertEquals(Arrays.hashCode(floatArr2), Arrays.hashCode(floatArr));
   2791     }
   2792 
   2793     /**
   2794      * @tests java.util.Arrays#hashCode(double[] a)
   2795      */
   2796     @TestTargetNew(
   2797         level = TestLevel.COMPLETE,
   2798         notes = "",
   2799         method = "hashCode",
   2800         args = {double[].class}
   2801     )
   2802     public void test_hashCode$LD() {
   2803         int listHashCode;
   2804         int arrayHashCode;
   2805 
   2806         double [] doubleArr = {0.134945657, 0.0038754, 11e-150, -30e-300, 10e-4};
   2807         List listOfDouble = new LinkedList();
   2808         for (int i = 0; i < doubleArr.length; i++) {
   2809             listOfDouble.add(new Double(doubleArr[i]));
   2810         }
   2811         listHashCode = listOfDouble.hashCode();
   2812         arrayHashCode = Arrays.hashCode(doubleArr);
   2813         assertEquals(listHashCode, arrayHashCode);
   2814     }
   2815 
   2816     /**
   2817      * @tests java.util.Arrays#hashCode(short[] a)
   2818      */
   2819     @TestTargetNew(
   2820         level = TestLevel.COMPLETE,
   2821         notes = "",
   2822         method = "hashCode",
   2823         args = {short[].class}
   2824     )
   2825     public void test_hashCode$LS() {
   2826         int listHashCode;
   2827         int arrayHashCode;
   2828 
   2829         short [] shortArr = {35, 13, 45, 2, 91};
   2830         List listOfShort = new LinkedList();
   2831         for (int i = 0; i < shortArr.length; i++) {
   2832             listOfShort.add(new Short(shortArr[i]));
   2833         }
   2834         listHashCode = listOfShort.hashCode();
   2835         arrayHashCode = Arrays.hashCode(shortArr);
   2836         assertEquals(listHashCode, arrayHashCode);
   2837     }
   2838 
   2839     /**
   2840      * @tests java.util.Arrays#hashCode(Object[] a)
   2841      */
   2842     @TestTargetNew(
   2843         level = TestLevel.COMPLETE,
   2844         notes = "",
   2845         method = "hashCode",
   2846         args = {java.lang.Object[].class}
   2847     )
   2848     public void test_hashCode$Ljava_lang_Object() {
   2849         int listHashCode;
   2850         int arrayHashCode;
   2851 
   2852         Object[] objectArr = {new Integer(1), new Float(10e-12f), null};
   2853         List listOfObject= new LinkedList();
   2854         for (int i = 0; i < objectArr.length; i++) {
   2855             listOfObject.add(objectArr[i]);
   2856         }
   2857         listHashCode = listOfObject.hashCode();
   2858         arrayHashCode = Arrays.hashCode(objectArr);
   2859         assertEquals(listHashCode, arrayHashCode);
   2860     }
   2861 
   2862     /**
   2863      * Sets up the fixture, for example, open a network connection. This method
   2864      * is called before a test is executed.
   2865      */
   2866     protected void setUp() {
   2867         objArray = new Object[arraySize];
   2868         for (int i = 0; i < objArray.length; i++)
   2869             objArray[i] = new Integer(i);
   2870 
   2871         booleanArray = new boolean[arraySize];
   2872         byteArray = new byte[arraySize];
   2873         charArray = new char[arraySize];
   2874         doubleArray = new double[arraySize];
   2875         floatArray = new float[arraySize];
   2876         intArray = new int[arraySize];
   2877         longArray = new long[arraySize];
   2878         objectArray = new Object[arraySize];
   2879         shortArray = new short[arraySize];
   2880 
   2881         for (int counter = 0; counter < arraySize; counter++) {
   2882             byteArray[counter] = (byte) counter;
   2883             charArray[counter] = (char) (counter + 1);
   2884             doubleArray[counter] = counter;
   2885             floatArray[counter] = counter;
   2886             intArray[counter] = counter;
   2887             longArray[counter] = counter;
   2888             objectArray[counter] = objArray[counter];
   2889             shortArray[counter] = (short) counter;
   2890         }
   2891         for (int counter = 0; counter < arraySize; counter += 2) {
   2892             booleanArray[counter] = false;
   2893             booleanArray[counter + 1] = true;
   2894         }
   2895     }
   2896 
   2897     /**
   2898      * Tears down the fixture, for example, close a network connection. This
   2899      * method is called after a test is executed.
   2900      */
   2901     protected void tearDown() {
   2902         objArray = null;
   2903         booleanArray = null;
   2904         byteArray = null;
   2905         charArray = null;
   2906         doubleArray = null;
   2907         floatArray = null;
   2908         intArray = null;
   2909         longArray = null;
   2910         objectArray = null;
   2911         shortArray = null;
   2912     }
   2913 }
   2914