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