KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > lang > ArrayUtilsAddTest


1 /*
2  * Copyright 2002-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.commons.lang;
18
19 import java.util.Arrays JavaDoc;
20
21 import junit.framework.Test;
22 import junit.framework.TestCase;
23 import junit.framework.TestSuite;
24 import junit.textui.TestRunner;
25
26 /**
27  * Tests ArrayUtils add methods.
28  *
29  * @author Gary D. Gregory
30  * @version $Id: ArrayUtilsAddTest.java 161244 2005-04-14 06:16:36Z ggregory $
31  */

32 public class ArrayUtilsAddTest extends TestCase {
33     public static void main(String JavaDoc[] args) {
34         TestRunner.run(suite());
35     }
36
37     public static Test suite() {
38         TestSuite suite = new TestSuite(ArrayUtilsAddTest.class);
39         suite.setName("ArrayUtils add Tests");
40         return suite;
41     }
42
43     public void testAddObjectArrayBoolean() {
44         boolean[] newArray;
45         newArray = ArrayUtils.add((boolean[])null, false);
46         assertTrue(Arrays.equals(new boolean[]{false}, newArray));
47         assertEquals(Boolean.TYPE, newArray.getClass().getComponentType());
48         newArray = ArrayUtils.add((boolean[])null, true);
49         assertTrue(Arrays.equals(new boolean[]{true}, newArray));
50         assertEquals(Boolean.TYPE, newArray.getClass().getComponentType());
51         boolean[] array1 = new boolean[]{true, false, true};
52         newArray = ArrayUtils.add(array1, false);
53         assertTrue(Arrays.equals(new boolean[]{true, false, true, false}, newArray));
54         assertEquals(Boolean.TYPE, newArray.getClass().getComponentType());
55     }
56     
57     public void testAddObjectArrayByte() {
58         byte[] newArray;
59         newArray = ArrayUtils.add((byte[])null, (byte)0);
60         assertTrue(Arrays.equals(new byte[]{0}, newArray));
61         assertEquals(Byte.TYPE, newArray.getClass().getComponentType());
62         newArray = ArrayUtils.add((byte[])null, (byte)1);
63         assertTrue(Arrays.equals(new byte[]{1}, newArray));
64         assertEquals(Byte.TYPE, newArray.getClass().getComponentType());
65         byte[] array1 = new byte[]{1, 2, 3};
66         newArray = ArrayUtils.add(array1, (byte)0);
67         assertTrue(Arrays.equals(new byte[]{1, 2, 3, 0}, newArray));
68         assertEquals(Byte.TYPE, newArray.getClass().getComponentType());
69         newArray = ArrayUtils.add(array1, (byte)4);
70         assertTrue(Arrays.equals(new byte[]{1, 2, 3, 4}, newArray));
71         assertEquals(Byte.TYPE, newArray.getClass().getComponentType());
72     }
73     
74     public void testAddObjectArrayChar() {
75         char[] newArray;
76         newArray = ArrayUtils.add((char[])null, (char)0);
77         assertTrue(Arrays.equals(new char[]{0}, newArray));
78         assertEquals(Character.TYPE, newArray.getClass().getComponentType());
79         newArray = ArrayUtils.add((char[])null, (char)1);
80         assertTrue(Arrays.equals(new char[]{1}, newArray));
81         assertEquals(Character.TYPE, newArray.getClass().getComponentType());
82         char[] array1 = new char[]{1, 2, 3};
83         newArray = ArrayUtils.add(array1, (char)0);
84         assertTrue(Arrays.equals(new char[]{1, 2, 3, 0}, newArray));
85         assertEquals(Character.TYPE, newArray.getClass().getComponentType());
86         newArray = ArrayUtils.add(array1, (char)4);
87         assertTrue(Arrays.equals(new char[]{1, 2, 3, 4}, newArray));
88         assertEquals(Character.TYPE, newArray.getClass().getComponentType());
89     }
90     
91     public void testAddObjectArrayDouble() {
92         double[] newArray;
93         newArray = ArrayUtils.add((double[])null, 0);
94         assertTrue(Arrays.equals(new double[]{0}, newArray));
95         assertEquals(Double.TYPE, newArray.getClass().getComponentType());
96         newArray = ArrayUtils.add((double[])null, 1);
97         assertTrue(Arrays.equals(new double[]{1}, newArray));
98         assertEquals(Double.TYPE, newArray.getClass().getComponentType());
99         double[] array1 = new double[]{1, 2, 3};
100         newArray = ArrayUtils.add(array1, 0);
101         assertTrue(Arrays.equals(new double[]{1, 2, 3, 0}, newArray));
102         assertEquals(Double.TYPE, newArray.getClass().getComponentType());
103         newArray = ArrayUtils.add(array1, 4);
104         assertTrue(Arrays.equals(new double[]{1, 2, 3, 4}, newArray));
105         assertEquals(Double.TYPE, newArray.getClass().getComponentType());
106     }
107     
108     public void testAddObjectArrayFloat() {
109         float[] newArray;
110         newArray = ArrayUtils.add((float[])null, 0);
111         assertTrue(Arrays.equals(new float[]{0}, newArray));
112         assertEquals(Float.TYPE, newArray.getClass().getComponentType());
113         newArray = ArrayUtils.add((float[])null, 1);
114         assertTrue(Arrays.equals(new float[]{1}, newArray));
115         assertEquals(Float.TYPE, newArray.getClass().getComponentType());
116         float[] array1 = new float[]{1, 2, 3};
117         newArray = ArrayUtils.add(array1, 0);
118         assertTrue(Arrays.equals(new float[]{1, 2, 3, 0}, newArray));
119         assertEquals(Float.TYPE, newArray.getClass().getComponentType());
120         newArray = ArrayUtils.add(array1, 4);
121         assertTrue(Arrays.equals(new float[]{1, 2, 3, 4}, newArray));
122         assertEquals(Float.TYPE, newArray.getClass().getComponentType());
123     }
124     
125     public void testAddObjectArrayInt() {
126         int[] newArray;
127         newArray = ArrayUtils.add((int[])null, 0);
128         assertTrue(Arrays.equals(new int[]{0}, newArray));
129         assertEquals(Integer.TYPE, newArray.getClass().getComponentType());
130         newArray = ArrayUtils.add((int[])null, 1);
131         assertTrue(Arrays.equals(new int[]{1}, newArray));
132         assertEquals(Integer.TYPE, newArray.getClass().getComponentType());
133         int[] array1 = new int[]{1, 2, 3};
134         newArray = ArrayUtils.add(array1, 0);
135         assertTrue(Arrays.equals(new int[]{1, 2, 3, 0}, newArray));
136         assertEquals(Integer.TYPE, newArray.getClass().getComponentType());
137         newArray = ArrayUtils.add(array1, 4);
138         assertTrue(Arrays.equals(new int[]{1, 2, 3, 4}, newArray));
139         assertEquals(Integer.TYPE, newArray.getClass().getComponentType());
140     }
141     
142     public void testAddObjectArrayLong() {
143         long[] newArray;
144         newArray = ArrayUtils.add((long[])null, 0);
145         assertTrue(Arrays.equals(new long[]{0}, newArray));
146         assertEquals(Long.TYPE, newArray.getClass().getComponentType());
147         newArray = ArrayUtils.add((long[])null, 1);
148         assertTrue(Arrays.equals(new long[]{1}, newArray));
149         assertEquals(Long.TYPE, newArray.getClass().getComponentType());
150         long[] array1 = new long[]{1, 2, 3};
151         newArray = ArrayUtils.add(array1, 0);
152         assertTrue(Arrays.equals(new long[]{1, 2, 3, 0}, newArray));
153         assertEquals(Long.TYPE, newArray.getClass().getComponentType());
154         newArray = ArrayUtils.add(array1, 4);
155         assertTrue(Arrays.equals(new long[]{1, 2, 3, 4}, newArray));
156         assertEquals(Long.TYPE, newArray.getClass().getComponentType());
157     }
158     
159     public void testAddObjectArrayShort() {
160         short[] newArray;
161         newArray = ArrayUtils.add((short[])null, (short)0);
162         assertTrue(Arrays.equals(new short[]{0}, newArray));
163         assertEquals(Short.TYPE, newArray.getClass().getComponentType());
164         newArray = ArrayUtils.add((short[])null, (short)1);
165         assertTrue(Arrays.equals(new short[]{1}, newArray));
166         assertEquals(Short.TYPE, newArray.getClass().getComponentType());
167         short[] array1 = new short[]{1, 2, 3};
168         newArray = ArrayUtils.add(array1, (short)0);
169         assertTrue(Arrays.equals(new short[]{1, 2, 3, 0}, newArray));
170         assertEquals(Short.TYPE, newArray.getClass().getComponentType());
171         newArray = ArrayUtils.add(array1, (short)4);
172         assertTrue(Arrays.equals(new short[]{1, 2, 3, 4}, newArray));
173         assertEquals(Short.TYPE, newArray.getClass().getComponentType());
174     }
175     
176     public void testAddObjectArrayObject() {
177         Object JavaDoc[] newArray;
178         newArray = ArrayUtils.add((Object JavaDoc[])null, null);
179         assertTrue(Arrays.equals((new Object JavaDoc[]{null}), newArray));
180         assertEquals(Object JavaDoc.class, newArray.getClass().getComponentType());
181         
182         newArray = ArrayUtils.add((Object JavaDoc[])null, "a");
183         assertTrue(Arrays.equals((new String JavaDoc[]{"a"}), newArray));
184         assertTrue(Arrays.equals((new Object JavaDoc[]{"a"}), newArray));
185         assertEquals(String JavaDoc.class, newArray.getClass().getComponentType());
186         
187         String JavaDoc[] stringArray1 = new String JavaDoc[]{"a", "b", "c"};
188         newArray = ArrayUtils.add(stringArray1, null);
189         assertTrue(Arrays.equals((new String JavaDoc[]{"a", "b", "c", null}), newArray));
190         assertEquals(String JavaDoc.class, newArray.getClass().getComponentType());
191         
192         newArray = ArrayUtils.add(stringArray1, "d");
193         assertTrue(Arrays.equals((new String JavaDoc[]{"a", "b", "c", "d"}), newArray));
194         assertEquals(String JavaDoc.class, newArray.getClass().getComponentType());
195         
196         Number JavaDoc[] numberArray1 = new Number JavaDoc[]{new Integer JavaDoc(1), new Double JavaDoc(2)};
197         newArray = ArrayUtils.add(numberArray1, new Float JavaDoc(3));
198         assertTrue(Arrays.equals((new Number JavaDoc[]{new Integer JavaDoc(1), new Double JavaDoc(2), new Float JavaDoc(3)}), newArray));
199         assertEquals(Number JavaDoc.class, newArray.getClass().getComponentType());
200         
201         numberArray1 = null;
202         newArray = ArrayUtils.add(numberArray1, new Float JavaDoc(3));
203         assertTrue(Arrays.equals((new Float JavaDoc[]{new Float JavaDoc(3)}), newArray));
204         assertEquals(Float JavaDoc.class, newArray.getClass().getComponentType());
205         
206         numberArray1 = null;
207         newArray = ArrayUtils.add(numberArray1, null);
208         assertTrue(Arrays.equals((new Object JavaDoc[]{null}), newArray));
209         assertEquals(Object JavaDoc.class, newArray.getClass().getComponentType());
210     }
211     
212     public void testAddObjectArrayToObjectArray() {
213         assertNull(ArrayUtils.addAll((Object JavaDoc[]) null, (Object JavaDoc[]) null));
214         Object JavaDoc[] newArray;
215         String JavaDoc[] stringArray1 = new String JavaDoc[]{"a", "b", "c"};
216         String JavaDoc[] stringArray2 = new String JavaDoc[]{"1", "2", "3"};
217         newArray = ArrayUtils.addAll(stringArray1, null);
218         assertNotSame(stringArray1, newArray);
219         assertTrue(Arrays.equals(stringArray1, newArray));
220         assertTrue(Arrays.equals((new String JavaDoc[]{"a", "b", "c"}), newArray));
221         assertEquals(String JavaDoc.class, newArray.getClass().getComponentType());
222         newArray = ArrayUtils.addAll(null, stringArray2);
223         assertNotSame(stringArray2, newArray);
224         assertTrue(Arrays.equals(stringArray2, newArray));
225         assertTrue(Arrays.equals((new String JavaDoc[]{"1", "2", "3"}), newArray));
226         assertEquals(String JavaDoc.class, newArray.getClass().getComponentType());
227         newArray = ArrayUtils.addAll(stringArray1, stringArray2);
228         assertTrue(Arrays.equals((new String JavaDoc[]{"a", "b", "c", "1", "2", "3"}), newArray));
229         assertEquals(String JavaDoc.class, newArray.getClass().getComponentType());
230         newArray = ArrayUtils.addAll(ArrayUtils.EMPTY_STRING_ARRAY, null);
231         assertTrue(Arrays.equals(ArrayUtils.EMPTY_STRING_ARRAY, newArray));
232         assertTrue(Arrays.equals((new String JavaDoc[]{}), newArray));
233         assertEquals(String JavaDoc.class, newArray.getClass().getComponentType());
234         newArray = ArrayUtils.addAll(null, ArrayUtils.EMPTY_STRING_ARRAY);
235         assertTrue(Arrays.equals(ArrayUtils.EMPTY_STRING_ARRAY, newArray));
236         assertTrue(Arrays.equals((new String JavaDoc[]{}), newArray));
237         assertEquals(String JavaDoc.class, newArray.getClass().getComponentType());
238         newArray = ArrayUtils.addAll(ArrayUtils.EMPTY_STRING_ARRAY, ArrayUtils.EMPTY_STRING_ARRAY);
239         assertTrue(Arrays.equals(ArrayUtils.EMPTY_STRING_ARRAY, newArray));
240         assertTrue(Arrays.equals((new String JavaDoc[]{}), newArray));
241         assertEquals(String JavaDoc.class, newArray.getClass().getComponentType());
242         String JavaDoc[] stringArrayNull = new String JavaDoc []{null};
243         newArray = ArrayUtils.addAll(stringArrayNull, stringArrayNull);
244         assertTrue(Arrays.equals((new String JavaDoc[]{null, null}), newArray));
245         assertEquals(String JavaDoc.class, newArray.getClass().getComponentType());
246
247         // boolean
248
assertTrue( Arrays.equals( new boolean[] { true, false, false, true },
249             ArrayUtils.addAll( new boolean[] { true, false }, new boolean[] { false, true } ) ) );
250
251         // char
252
assertTrue( Arrays.equals( new char[] { 'a', 'b', 'c', 'd' },
253             ArrayUtils.addAll( new char[] { 'a', 'b' }, new char[] { 'c', 'd' } ) ) );
254
255         // byte
256
assertTrue( Arrays.equals( new byte[] { (byte) 0, (byte) 1, (byte) 2, (byte) 3 },
257             ArrayUtils.addAll( new byte[] { (byte) 0, (byte) 1 }, new byte[] { (byte) 2, (byte) 3 } ) ) );
258
259         // short
260
assertTrue( Arrays.equals( new short[] { (short) 10, (short) 20, (short) 30, (short) 40 },
261             ArrayUtils.addAll( new short[] { (short) 10, (short) 20 }, new short[] { (short) 30, (short) 40 } ) ) );
262
263         // int
264
assertTrue( Arrays.equals( new int[] { 1, 1000, -1000, -1 },
265             ArrayUtils.addAll( new int[] { 1, 1000 }, new int[] { -1000, -1 } ) ) );
266
267         // long
268
assertTrue( Arrays.equals( new long[] { 1L, -1L, 1000L, -1000L },
269             ArrayUtils.addAll( new long[] { 1L, -1L }, new long[] { 1000L, -1000L } ) ) );
270
271         // float
272
assertTrue( Arrays.equals( new float[] { 10.5f, 10.1f, 1.6f, 0.01f },
273             ArrayUtils.addAll( new float[] { 10.5f, 10.1f }, new float[] { 1.6f, 0.01f } ) ) );
274
275         // double
276
assertTrue( Arrays.equals( new double[] { Math.PI, -Math.PI, 0, 9.99 },
277             ArrayUtils.addAll( new double[] { Math.PI, -Math.PI }, new double[] { 0, 9.99 } ) ) );
278
279     }
280     
281     public void testAddObjectAtIndex() {
282         Object JavaDoc[] newArray;
283         newArray = ArrayUtils.add((Object JavaDoc[])null, 0, null);
284         assertTrue(Arrays.equals((new Object JavaDoc[]{null}), newArray));
285         assertEquals(Object JavaDoc.class, newArray.getClass().getComponentType());
286         newArray = ArrayUtils.add((Object JavaDoc[])null, 0, "a");
287         assertTrue(Arrays.equals((new String JavaDoc[]{"a"}), newArray));
288         assertTrue(Arrays.equals((new Object JavaDoc[]{"a"}), newArray));
289         assertEquals(String JavaDoc.class, newArray.getClass().getComponentType());
290         String JavaDoc[] stringArray1 = new String JavaDoc[]{"a", "b", "c"};
291         newArray = ArrayUtils.add(stringArray1, 0, null);
292         assertTrue(Arrays.equals((new String JavaDoc[]{null, "a", "b", "c"}), newArray));
293         assertEquals(String JavaDoc.class, newArray.getClass().getComponentType());
294         newArray = ArrayUtils.add(stringArray1, 1, null);
295         assertTrue(Arrays.equals((new String JavaDoc[]{"a", null, "b", "c"}), newArray));
296         assertEquals(String JavaDoc.class, newArray.getClass().getComponentType());
297         newArray = ArrayUtils.add(stringArray1, 3, null);
298         assertTrue(Arrays.equals((new String JavaDoc[]{"a", "b", "c", null}), newArray));
299         assertEquals(String JavaDoc.class, newArray.getClass().getComponentType());
300         newArray = ArrayUtils.add(stringArray1, 3, "d");
301         assertTrue(Arrays.equals((new String JavaDoc[]{"a", "b", "c", "d"}), newArray));
302         assertEquals(String JavaDoc.class, newArray.getClass().getComponentType());
303         assertEquals(String JavaDoc.class, newArray.getClass().getComponentType());
304
305         Object JavaDoc[] o = new Object JavaDoc[] {"1", "2", "4"};
306         Object JavaDoc[] result = ArrayUtils.add(o, 2, "3");
307         Object JavaDoc[] result2 = ArrayUtils.add(o, 3, "5");
308         
309         assertNotNull(result);
310         assertEquals(4, result.length);
311         assertEquals("1", result[0]);
312         assertEquals("2", result[1]);
313         assertEquals("3", result[2]);
314         assertEquals("4", result[3]);
315         assertNotNull(result2);
316         assertEquals(4, result2.length);
317         assertEquals("1", result2[0]);
318         assertEquals("2", result2[1]);
319         assertEquals("4", result2[2]);
320         assertEquals("5", result2[3]);
321
322         // boolean tests
323
boolean[] booleanArray = ArrayUtils.add( null, 0, true );
324         assertTrue( Arrays.equals( new boolean[] { true }, booleanArray ) );
325         booleanArray = ArrayUtils.add( new boolean[] { true }, 0, false);
326         assertTrue( Arrays.equals( new boolean[] { false, true }, booleanArray ) );
327         booleanArray = ArrayUtils.add( new boolean[] { false }, 1, true);
328         assertTrue( Arrays.equals( new boolean[] { false, true }, booleanArray ) );
329         booleanArray = ArrayUtils.add( new boolean[] { true, false }, 1, true);
330         assertTrue( Arrays.equals( new boolean[] { true, true, false }, booleanArray ) );
331
332         // char tests
333
char[] charArray = ArrayUtils.add( (char[]) null, 0, 'a' );
334         assertTrue( Arrays.equals( new char[] { 'a' }, charArray ) );
335         charArray = ArrayUtils.add( new char[] { 'a' }, 0, 'b');
336         assertTrue( Arrays.equals( new char[] { 'b', 'a' }, charArray ) );
337         charArray = ArrayUtils.add( new char[] { 'a', 'b' }, 0, 'c');
338         assertTrue( Arrays.equals( new char[] { 'c', 'a', 'b' }, charArray ) );
339         charArray = ArrayUtils.add( new char[] { 'a', 'b' }, 1, 'k');
340         assertTrue( Arrays.equals( new char[] { 'a', 'k', 'b' }, charArray ) );
341         charArray = ArrayUtils.add( new char[] { 'a', 'b', 'c' }, 1, 't');
342         assertTrue( Arrays.equals( new char[] { 'a', 't', 'b', 'c' }, charArray ) );
343
344         // short tests
345
short[] shortArray = ArrayUtils.add( new short[] { 1 }, 0, (short) 2);
346         assertTrue( Arrays.equals( new short[] { 2, 1 }, shortArray ) );
347         shortArray = ArrayUtils.add( new short[] { 2, 6 }, 2, (short) 10);
348         assertTrue( Arrays.equals( new short[] { 2, 6, 10 }, shortArray ) );
349         shortArray = ArrayUtils.add( new short[] { 2, 6 }, 0, (short) -4);
350         assertTrue( Arrays.equals( new short[] { -4, 2, 6 }, shortArray ) );
351         shortArray = ArrayUtils.add( new short[] { 2, 6, 3 }, 2, (short) 1);
352         assertTrue( Arrays.equals( new short[] { 2, 6, 1, 3 }, shortArray ) );
353
354         // byte tests
355
byte[] byteArray = ArrayUtils.add( new byte[] { 1 }, 0, (byte) 2);
356         assertTrue( Arrays.equals( new byte[] { 2, 1 }, byteArray ) );
357         byteArray = ArrayUtils.add( new byte[] { 2, 6 }, 2, (byte) 3);
358         assertTrue( Arrays.equals( new byte[] { 2, 6, 3 }, byteArray ) );
359         byteArray = ArrayUtils.add( new byte[] { 2, 6 }, 0, (byte) 1);
360         assertTrue( Arrays.equals( new byte[] { 1, 2, 6 }, byteArray ) );
361         byteArray = ArrayUtils.add( new byte[] { 2, 6, 3 }, 2, (byte) 1);
362         assertTrue( Arrays.equals( new byte[] { 2, 6, 1, 3 }, byteArray ) );
363
364         // int tests
365
int[] intArray = ArrayUtils.add( new int[] { 1 }, 0, 2);
366         assertTrue( Arrays.equals( new int[] { 2, 1 }, intArray ) );
367         intArray = ArrayUtils.add( new int[] { 2, 6 }, 2, 10);
368         assertTrue( Arrays.equals( new int[] { 2, 6, 10 }, intArray ) );
369         intArray = ArrayUtils.add( new int[] { 2, 6 }, 0, -4);
370         assertTrue( Arrays.equals( new int[] { -4, 2, 6 }, intArray ) );
371         intArray = ArrayUtils.add( new int[] { 2, 6, 3 }, 2, 1);
372         assertTrue( Arrays.equals( new int[] { 2, 6, 1, 3 }, intArray ) );
373
374         // long tests
375
long[] longArray = ArrayUtils.add( new long[] { 1L }, 0, 2L);
376         assertTrue( Arrays.equals( new long[] { 2L, 1L }, longArray ) );
377         longArray = ArrayUtils.add( new long[] { 2L, 6L }, 2, 10L);
378         assertTrue( Arrays.equals( new long[] { 2L, 6L, 10L }, longArray ) );
379         longArray = ArrayUtils.add( new long[] { 2L, 6L }, 0, -4L);
380         assertTrue( Arrays.equals( new long[] { -4L, 2L, 6L }, longArray ) );
381         longArray = ArrayUtils.add( new long[] { 2L, 6L, 3L }, 2, 1L);
382         assertTrue( Arrays.equals( new long[] { 2L, 6L, 1L, 3L }, longArray ) );
383
384         // float tests
385
float[] floatArray = ArrayUtils.add( new float[] { 1.1f }, 0, 2.2f);
386         assertTrue( Arrays.equals( new float[] { 2.2f, 1.1f }, floatArray ) );
387         floatArray = ArrayUtils.add( new float[] { 2.3f, 6.4f }, 2, 10.5f);
388         assertTrue( Arrays.equals( new float[] { 2.3f, 6.4f, 10.5f }, floatArray ) );
389         floatArray = ArrayUtils.add( new float[] { 2.6f, 6.7f }, 0, -4.8f);
390         assertTrue( Arrays.equals( new float[] { -4.8f, 2.6f, 6.7f }, floatArray ) );
391         floatArray = ArrayUtils.add( new float[] { 2.9f, 6.0f, 0.3f }, 2, 1.0f);
392         assertTrue( Arrays.equals( new float[] { 2.9f, 6.0f, 1.0f, 0.3f }, floatArray ) );
393
394         // double tests
395
double[] doubleArray = ArrayUtils.add( new double[] { 1.1 }, 0, 2.2);
396         assertTrue( Arrays.equals( new double[] { 2.2, 1.1 }, doubleArray ) );
397         doubleArray = ArrayUtils.add( new double[] { 2.3, 6.4 }, 2, 10.5);
398         assertTrue( Arrays.equals( new double[] { 2.3, 6.4, 10.5 }, doubleArray ) );
399         doubleArray = ArrayUtils.add( new double[] { 2.6, 6.7 }, 0, -4.8);
400         assertTrue( Arrays.equals( new double[] { -4.8, 2.6, 6.7 }, doubleArray ) );
401         doubleArray = ArrayUtils.add( new double[] { 2.9, 6.0, 0.3 }, 2, 1.0);
402         assertTrue( Arrays.equals( new double[] { 2.9, 6.0, 1.0, 0.3 }, doubleArray ) );
403     }
404     
405 }
406
Popular Tags