KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > retrotranslator > runtime > java > util > _ArraysTestCase


1 /***
2  * Retrotranslator: a Java bytecode transformer that translates Java classes
3  * compiled with JDK 5.0 into classes that can be run on JVM 1.4.
4  *
5  * Copyright (c) 2005 - 2007 Taras Puchko
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of the copyright holders nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30  * THE POSSIBILITY OF SUCH DAMAGE.
31  */

32 package net.sf.retrotranslator.runtime.java.util;
33
34 import java.util.Arrays JavaDoc;
35 import junit.framework.TestCase;
36
37 /**
38  * @author Taras Puchko
39  */

40 public class _ArraysTestCase extends TestCase {
41
42     public void testDeepEqualsTrue() {
43         Object JavaDoc[] a = {"a", "b", new Object JavaDoc[] {"c", null}};
44         Object JavaDoc[] b = {"a", "b", new Object JavaDoc[] {"c", null}};
45         assertTrue(Arrays.deepEquals(a, b));
46         assertTrue(Arrays.deepEquals(null, null));
47     }
48
49     public void testDeepEqualsFalse() {
50         Object JavaDoc[] a = {"a", "b", new Object JavaDoc[] {"c", null}};
51         Object JavaDoc[] b = {"a", "b", new Object JavaDoc[] {"x", null}};
52         assertFalse(Arrays.deepEquals(a, b));
53         assertFalse(Arrays.deepEquals(null, new Object JavaDoc[0]));
54         assertFalse(Arrays.deepEquals(new Object JavaDoc[0], null));
55     }
56
57     public void testDeepHashCode() throws Exception JavaDoc {
58         Object JavaDoc[] a = {"a", "b", new Object JavaDoc[] {"c", null}};
59         assertEquals(130076, Arrays.deepHashCode(a));
60     }
61
62     public void testDeepToString() {
63         Object JavaDoc[] a = {"a", "b", new Object JavaDoc[] {"c", null}};
64         assertEquals("[a, b, [c, null]]", Arrays.deepToString(a));
65         assertEquals("null", Arrays.deepToString(null));
66         assertEquals("[]", Arrays.deepToString(new Object JavaDoc[0]));
67     }
68
69     public void testToStringBoolean() {
70         boolean[] a = {true, false, true};
71         assertEquals("[true, false, true]", Arrays.toString(a));
72         assertEquals("null", Arrays.toString((boolean[]) null));
73         assertEquals("[]", Arrays.toString(new boolean[0]));
74     }
75
76     public void testToStringByte() {
77         byte[] a = {1, -1, 10};
78         assertEquals("[1, -1, 10]", Arrays.toString(a));
79         assertEquals("null", Arrays.toString((byte[]) null));
80         assertEquals("[]", Arrays.toString(new byte[0]));
81     }
82
83     public void testToStringChar() {
84         char[] a = {'a', 'b', 'c'};
85         assertEquals("[a, b, c]", Arrays.toString(a));
86         assertEquals("null", Arrays.toString((char[]) null));
87         assertEquals("[]", Arrays.toString(new char[0]));
88     }
89
90     public void testToStringDouble() {
91         double[] a = {1.1, -0.5, 0.8};
92         assertEquals("[1.1, -0.5, 0.8]", Arrays.toString(a));
93         assertEquals("null", Arrays.toString((double[]) null));
94         assertEquals("[]", Arrays.toString(new double[0]));
95     }
96
97     public void testToStringFloat() {
98         float[] a = {1.17f, -0.51f, 0.87f};
99         assertEquals("[1.17, -0.51, 0.87]", Arrays.toString(a));
100         assertEquals("null", Arrays.toString((float[]) null));
101         assertEquals("[]", Arrays.toString(new float[0]));
102     }
103
104     public void testToStringInt() {
105         int[] a = {0, -10, 54};
106         assertEquals("[0, -10, 54]", Arrays.toString(a));
107         assertEquals("null", Arrays.toString((int[]) null));
108         assertEquals("[]", Arrays.toString(new int[0]));
109     }
110
111     public void testToStringLong() {
112         long[] a = {0, -1000, 657};
113         assertEquals("[0, -1000, 657]", Arrays.toString(a));
114         assertEquals("null", Arrays.toString((long[]) null));
115         assertEquals("[]", Arrays.toString(new long[0]));
116     }
117
118     public void testToStringObject() {
119         Object JavaDoc[] nested = new Object JavaDoc[]{"c", null};
120         Object JavaDoc[] a = {"a", "b", null, nested};
121         assertEquals("[a, b, null, " + nested.toString() + "]", Arrays.toString(a));
122         assertEquals("null", Arrays.toString((Object JavaDoc[]) null));
123         assertEquals("[]", Arrays.toString(new Object JavaDoc[0]));
124     }
125
126     public void testHashCodeBoolean() throws Exception JavaDoc {
127         boolean[] a = {true, false, true};
128         assertEquals(1252360, Arrays.hashCode(a));
129     }
130
131     public void testHashCodeByte() throws Exception JavaDoc {
132         byte[] a = {1, -1, 10};
133         assertEquals(30731, Arrays.hashCode(a));
134     }
135
136     public void testHashCodeChar() throws Exception JavaDoc {
137         char[] a = {'a', 'b', 'c'};
138         assertEquals(126145, Arrays.hashCode(a));
139     }
140
141     public void testHashCodeDouble() throws Exception JavaDoc {
142         double[] a = {1.1, -0.5, 0.8};
143         assertEquals(-1896317019, Arrays.hashCode(a));
144     }
145
146     public void testHashCodeFloat() throws Exception JavaDoc {
147         float[] a = {1.17f, -0.51f, 0.87f};
148         assertEquals(299754404, Arrays.hashCode(a));
149     }
150
151     public void testHashCodeInt() throws Exception JavaDoc {
152         int[] a = {0, -10, 54};
153         assertEquals(29535, Arrays.hashCode(a));
154     }
155
156     public void testHashCodeLong() throws Exception JavaDoc {
157         long[] a = {0, -1000, 657};
158         assertEquals(61417, Arrays.hashCode(a));
159     }
160
161     public void testHashCodeObject() throws Exception JavaDoc {
162         Object JavaDoc[] a = {"a", "b", null, Integer.valueOf("1")};
163         assertEquals(3907427, Arrays.hashCode(a));
164     }
165
166 }
167
Popular Tags