001: /***
002: * Retrotranslator: a Java bytecode transformer that translates Java classes
003: * compiled with JDK 5.0 into classes that can be run on JVM 1.4.
004: *
005: * Copyright (c) 2005 - 2008 Taras Puchko
006: * All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in the
015: * documentation and/or other materials provided with the distribution.
016: * 3. Neither the name of the copyright holders nor the names of its
017: * contributors may be used to endorse or promote products derived from
018: * this software without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
021: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
022: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
023: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
024: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
025: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
026: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
027: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
028: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
029: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
030: * THE POSSIBILITY OF SUCH DAMAGE.
031: */package net.sf.retrotranslator.runtime.java.util;
032:
033: import java.util.Arrays;
034: import junit.framework.TestCase;
035:
036: /**
037: * @author Taras Puchko
038: */
039: public class _ArraysTestCase extends TestCase {
040:
041: public void testDeepEqualsTrue() {
042: Object[] a = { "a", "b", new Object[] { "c", null } };
043: Object[] b = { "a", "b", new Object[] { "c", null } };
044: assertTrue(Arrays.deepEquals(a, b));
045: assertTrue(Arrays.deepEquals(null, null));
046: }
047:
048: public void testDeepEqualsFalse() {
049: Object[] a = { "a", "b", new Object[] { "c", null } };
050: Object[] b = { "a", "b", new Object[] { "x", null } };
051: assertFalse(Arrays.deepEquals(a, b));
052: assertFalse(Arrays.deepEquals(null, new Object[0]));
053: assertFalse(Arrays.deepEquals(new Object[0], null));
054: }
055:
056: public void testDeepHashCode() throws Exception {
057: Object[] a = { "a", "b", new Object[] { "c", null } };
058: assertEquals(130076, Arrays.deepHashCode(a));
059: }
060:
061: public void testDeepToString() {
062: Object[] a = { "a", "b", new Object[] { "c", null } };
063: assertEquals("[a, b, [c, null]]", Arrays.deepToString(a));
064: assertEquals("null", Arrays.deepToString(null));
065: assertEquals("[]", Arrays.deepToString(new Object[0]));
066: }
067:
068: public void testToStringBoolean() {
069: boolean[] a = { true, false, true };
070: assertEquals("[true, false, true]", Arrays.toString(a));
071: assertEquals("null", Arrays.toString((boolean[]) null));
072: assertEquals("[]", Arrays.toString(new boolean[0]));
073: }
074:
075: public void testToStringByte() {
076: byte[] a = { 1, -1, 10 };
077: assertEquals("[1, -1, 10]", Arrays.toString(a));
078: assertEquals("null", Arrays.toString((byte[]) null));
079: assertEquals("[]", Arrays.toString(new byte[0]));
080: }
081:
082: public void testToStringChar() {
083: char[] a = { 'a', 'b', 'c' };
084: assertEquals("[a, b, c]", Arrays.toString(a));
085: assertEquals("null", Arrays.toString((char[]) null));
086: assertEquals("[]", Arrays.toString(new char[0]));
087: }
088:
089: public void testToStringDouble() {
090: double[] a = { 1.1, -0.5, 0.8 };
091: assertEquals("[1.1, -0.5, 0.8]", Arrays.toString(a));
092: assertEquals("null", Arrays.toString((double[]) null));
093: assertEquals("[]", Arrays.toString(new double[0]));
094: }
095:
096: public void testToStringFloat() {
097: float[] a = { 1.17f, -0.51f, 0.87f };
098: assertEquals("[1.17, -0.51, 0.87]", Arrays.toString(a));
099: assertEquals("null", Arrays.toString((float[]) null));
100: assertEquals("[]", Arrays.toString(new float[0]));
101: }
102:
103: public void testToStringInt() {
104: int[] a = { 0, -10, 54 };
105: assertEquals("[0, -10, 54]", Arrays.toString(a));
106: assertEquals("null", Arrays.toString((int[]) null));
107: assertEquals("[]", Arrays.toString(new int[0]));
108: }
109:
110: public void testToStringLong() {
111: long[] a = { 0, -1000, 657 };
112: assertEquals("[0, -1000, 657]", Arrays.toString(a));
113: assertEquals("null", Arrays.toString((long[]) null));
114: assertEquals("[]", Arrays.toString(new long[0]));
115: }
116:
117: public void testToStringObject() {
118: Object[] nested = new Object[] { "c", null };
119: Object[] a = { "a", "b", null, nested };
120: assertEquals("[a, b, null, " + nested.toString() + "]", Arrays
121: .toString(a));
122: assertEquals("null", Arrays.toString((Object[]) null));
123: assertEquals("[]", Arrays.toString(new Object[0]));
124: }
125:
126: public void testHashCodeBoolean() throws Exception {
127: boolean[] a = { true, false, true };
128: assertEquals(1252360, Arrays.hashCode(a));
129: }
130:
131: public void testHashCodeByte() throws Exception {
132: byte[] a = { 1, -1, 10 };
133: assertEquals(30731, Arrays.hashCode(a));
134: }
135:
136: public void testHashCodeChar() throws Exception {
137: char[] a = { 'a', 'b', 'c' };
138: assertEquals(126145, Arrays.hashCode(a));
139: }
140:
141: public void testHashCodeDouble() throws Exception {
142: double[] a = { 1.1, -0.5, 0.8 };
143: assertEquals(-1896317019, Arrays.hashCode(a));
144: }
145:
146: public void testHashCodeFloat() throws Exception {
147: float[] a = { 1.17f, -0.51f, 0.87f };
148: assertEquals(299754404, Arrays.hashCode(a));
149: }
150:
151: public void testHashCodeInt() throws Exception {
152: int[] a = { 0, -10, 54 };
153: assertEquals(29535, Arrays.hashCode(a));
154: }
155:
156: public void testHashCodeLong() throws Exception {
157: long[] a = { 0, -1000, 657 };
158: assertEquals(61417, Arrays.hashCode(a));
159: }
160:
161: public void testHashCodeObject() throws Exception {
162: Object[] a = { "a", "b", null, Integer.valueOf("1") };
163: assertEquals(3907427, Arrays.hashCode(a));
164: }
165:
166: }
|