001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: TestArrayUtils.java 3714 2007-04-08 02:57:38Z gbevin $
007: */
008: package com.uwyn.rife.tools;
009:
010: import com.uwyn.rife.config.RifeConfig;
011: import com.uwyn.rife.site.ConstrainedProperty;
012: import com.uwyn.rife.tools.ArrayUtils;
013: import java.text.NumberFormat;
014: import java.text.SimpleDateFormat;
015: import java.util.Calendar;
016: import java.util.Date;
017: import java.util.Locale;
018: import junit.framework.TestCase;
019:
020: public class TestArrayUtils extends TestCase {
021: public TestArrayUtils(String name) {
022: super (name);
023: }
024:
025: public void testGetArrayType() {
026: assertEquals(ArrayUtils.ArrayType.NO_ARRAY, ArrayUtils
027: .getArrayType(new Object()));
028:
029: assertEquals(ArrayUtils.ArrayType.BOOLEAN_ARRAY, ArrayUtils
030: .getArrayType(new boolean[1]));
031: assertEquals(ArrayUtils.ArrayType.BYTE_ARRAY, ArrayUtils
032: .getArrayType(new byte[1]));
033: assertEquals(ArrayUtils.ArrayType.SHORT_ARRAY, ArrayUtils
034: .getArrayType(new short[1]));
035: assertEquals(ArrayUtils.ArrayType.CHAR_ARRAY, ArrayUtils
036: .getArrayType(new char[1]));
037: assertEquals(ArrayUtils.ArrayType.INT_ARRAY, ArrayUtils
038: .getArrayType(new int[1]));
039: assertEquals(ArrayUtils.ArrayType.LONG_ARRAY, ArrayUtils
040: .getArrayType(new long[1]));
041: assertEquals(ArrayUtils.ArrayType.FLOAT_ARRAY, ArrayUtils
042: .getArrayType(new float[1]));
043: assertEquals(ArrayUtils.ArrayType.DOUBLE_ARRAY, ArrayUtils
044: .getArrayType(new double[1]));
045: assertEquals(ArrayUtils.ArrayType.OBJECT_ARRAY, ArrayUtils
046: .getArrayType(new Object[1]));
047:
048: assertEquals(ArrayUtils.ArrayType.BOOLEAN_ARRAY, ArrayUtils
049: .getArrayType(new boolean[1][1]));
050: assertEquals(ArrayUtils.ArrayType.BYTE_ARRAY, ArrayUtils
051: .getArrayType(new byte[1][1]));
052: assertEquals(ArrayUtils.ArrayType.SHORT_ARRAY, ArrayUtils
053: .getArrayType(new short[1][1]));
054: assertEquals(ArrayUtils.ArrayType.CHAR_ARRAY, ArrayUtils
055: .getArrayType(new char[1][1]));
056: assertEquals(ArrayUtils.ArrayType.INT_ARRAY, ArrayUtils
057: .getArrayType(new int[1][1]));
058: assertEquals(ArrayUtils.ArrayType.LONG_ARRAY, ArrayUtils
059: .getArrayType(new long[1][1]));
060: assertEquals(ArrayUtils.ArrayType.FLOAT_ARRAY, ArrayUtils
061: .getArrayType(new float[1][1]));
062: assertEquals(ArrayUtils.ArrayType.DOUBLE_ARRAY, ArrayUtils
063: .getArrayType(new double[1][1]));
064: assertEquals(ArrayUtils.ArrayType.OBJECT_ARRAY, ArrayUtils
065: .getArrayType(new Object[1][1]));
066: }
067:
068: public void testCreateStringArray() {
069: assertNull(ArrayUtils.createStringArray((Object) null, null));
070: String[] converted = null;
071:
072: converted = ArrayUtils.createStringArray("just a test", null);
073: assertEquals(1, converted.length);
074: assertEquals("just a test", converted[0]);
075:
076: String[] source_string = new String[] { "9", "kojk", "4", "3",
077: "ok", "6.0", "8" };
078: converted = ArrayUtils.createStringArray(
079: (Object) source_string, null);
080: assertEquals(source_string.length, converted.length);
081: assertEquals(source_string[0], converted[0]);
082: assertEquals(source_string[1], converted[1]);
083: assertEquals(source_string[2], converted[2]);
084: assertEquals(source_string[3], converted[3]);
085: assertEquals(source_string[4], converted[4]);
086: assertEquals(source_string[5], converted[5]);
087: assertEquals(source_string[6], converted[6]);
088:
089: boolean[] source_boolean = new boolean[] { false, false, true,
090: false, true };
091: converted = ArrayUtils.createStringArray(
092: (Object) source_boolean, null);
093: assertEquals(source_boolean.length, converted.length);
094: assertEquals(String.valueOf(source_boolean[0]), converted[0]);
095: assertEquals(String.valueOf(source_boolean[1]), converted[1]);
096: assertEquals(String.valueOf(source_boolean[2]), converted[2]);
097: assertEquals(String.valueOf(source_boolean[3]), converted[3]);
098: assertEquals(String.valueOf(source_boolean[4]), converted[4]);
099:
100: byte[] source_byte = new byte[] { 9, 4, 3, 6, 8 };
101: converted = ArrayUtils.createStringArray((Object) source_byte,
102: null);
103: assertNull(converted);
104:
105: char[] source_char = new char[] { 'w', 'o', 'r', 'k', 's' };
106: converted = ArrayUtils.createStringArray((Object) source_char,
107: null);
108: assertEquals(source_char.length, converted.length);
109: assertEquals(String.valueOf(source_char[0]), converted[0]);
110: assertEquals(String.valueOf(source_char[1]), converted[1]);
111: assertEquals(String.valueOf(source_char[2]), converted[2]);
112: assertEquals(String.valueOf(source_char[3]), converted[3]);
113: assertEquals(String.valueOf(source_char[4]), converted[4]);
114:
115: short[] source_short = new short[] { 84, 23, 43, 12, 5 };
116: converted = ArrayUtils.createStringArray((Object) source_short,
117: null);
118: assertEquals(source_short.length, converted.length);
119: assertEquals(String.valueOf(source_short[0]), converted[0]);
120: assertEquals(String.valueOf(source_short[1]), converted[1]);
121: assertEquals(String.valueOf(source_short[2]), converted[2]);
122: assertEquals(String.valueOf(source_short[3]), converted[3]);
123: assertEquals(String.valueOf(source_short[4]), converted[4]);
124:
125: int[] source_int = new int[] { 9834, 454, 2355, 2398, 4834 };
126: converted = ArrayUtils.createStringArray((Object) source_int,
127: null);
128: assertEquals(source_int.length, converted.length);
129: assertEquals(String.valueOf(source_int[0]), converted[0]);
130: assertEquals(String.valueOf(source_int[1]), converted[1]);
131: assertEquals(String.valueOf(source_int[2]), converted[2]);
132: assertEquals(String.valueOf(source_int[3]), converted[3]);
133: assertEquals(String.valueOf(source_int[4]), converted[4]);
134:
135: long[] source_long = new long[] { 59035, 90465, 723479, 47543,
136: 987543 };
137: converted = ArrayUtils.createStringArray((Object) source_long,
138: null);
139: assertEquals(source_long.length, converted.length);
140: assertEquals(String.valueOf(source_long[0]), converted[0]);
141: assertEquals(String.valueOf(source_long[1]), converted[1]);
142: assertEquals(String.valueOf(source_long[2]), converted[2]);
143: assertEquals(String.valueOf(source_long[3]), converted[3]);
144: assertEquals(String.valueOf(source_long[4]), converted[4]);
145:
146: float[] source_float = new float[] { 228.02f, 8734.3f, 8634.2f,
147: 34321.9f, 3478.2f };
148: converted = ArrayUtils.createStringArray((Object) source_float,
149: null);
150: assertEquals(source_float.length, converted.length);
151: assertEquals(String.valueOf(source_float[0]), converted[0]);
152: assertEquals(String.valueOf(source_float[1]), converted[1]);
153: assertEquals(String.valueOf(source_float[2]), converted[2]);
154: assertEquals(String.valueOf(source_float[3]), converted[3]);
155: assertEquals(String.valueOf(source_float[4]), converted[4]);
156:
157: double[] source_double = new double[] { 987634.3434d,
158: 653928.434d, 394374.34387d, 3847764332.3434d, 3434d };
159: converted = ArrayUtils.createStringArray(
160: (Object) source_double, null);
161: assertEquals(source_double.length, converted.length);
162: assertEquals(String.valueOf(source_double[0]), converted[0]);
163: assertEquals(String.valueOf(source_double[1]), converted[1]);
164: assertEquals(String.valueOf(source_double[2]), converted[2]);
165: assertEquals(String.valueOf(source_double[3]), converted[3]);
166: assertEquals(String.valueOf(source_double[4]), converted[4]);
167: }
168:
169: public void testCreateStringArrayObject() {
170: assertNull(ArrayUtils.createStringArray((Object[]) null));
171:
172: String[] source = new String[] { "9", "kojk", "4", "3", "ok",
173: "6.0", "8" };
174: String[] converted = ArrayUtils.createStringArray(source);
175: assertEquals(source.length, converted.length);
176: assertEquals(source[0], converted[0]);
177: assertEquals(source[1], converted[1]);
178: assertEquals(source[2], converted[2]);
179: assertEquals(source[3], converted[3]);
180: assertEquals(source[4], converted[4]);
181: assertEquals(source[5], converted[5]);
182: assertEquals(source[6], converted[6]);
183: }
184:
185: public void testCreateStringArrayDate() {
186: assertNull(ArrayUtils.createStringArray((Date) null, null));
187:
188: Calendar cal = Calendar.getInstance();
189: cal.setTimeZone(RifeConfig.Tools.getDefaultTimeZone());
190: cal.set(2005, 7, 18, 9, 27, 13);
191: cal.set(Calendar.MILLISECOND, 552);
192: String[] converted = ArrayUtils.createStringArray(
193: cal.getTime(), null);
194: assertEquals(1, converted.length);
195: assertEquals("20050818092713552+0200", converted[0]);
196:
197: SimpleDateFormat sf = new SimpleDateFormat(
198: "yyyy.MM.dd G 'at' HH:mm:ss", Locale.ENGLISH);
199: sf.setTimeZone(RifeConfig.Tools.getDefaultTimeZone());
200: converted = ArrayUtils.createStringArray(cal.getTime(),
201: new ConstrainedProperty("someProperty").format(sf));
202: assertEquals(1, converted.length);
203: assertEquals("2005.08.18 AD at 09:27:13", converted[0]);
204: }
205:
206: public void testCreateStringArrayDoubleFormat() {
207: assertNull(ArrayUtils.createStringArray((Double) null, null));
208:
209: String[] converted = ArrayUtils.createStringArray(
210: 6782.349876675, new ConstrainedProperty("someProperty")
211: .format(NumberFormat
212: .getCurrencyInstance(Locale.US)));
213: assertEquals(1, converted.length);
214: assertEquals("$6,782.35", converted[0]);
215: }
216:
217: public void testCreateStringArrayBoolean() {
218: assertNull(ArrayUtils.createStringArray((boolean[]) null));
219:
220: boolean[] source = new boolean[] { false, false, true, false,
221: true };
222: String[] converted = ArrayUtils.createStringArray(source);
223: assertEquals(source.length, converted.length);
224: assertEquals(source.length, converted.length);
225: assertEquals(String.valueOf(source[0]), converted[0]);
226: assertEquals(String.valueOf(source[1]), converted[1]);
227: assertEquals(String.valueOf(source[2]), converted[2]);
228: assertEquals(String.valueOf(source[3]), converted[3]);
229: assertEquals(String.valueOf(source[4]), converted[4]);
230: }
231:
232: public void testCreateStringArrayByte() {
233: assertNull(ArrayUtils.createStringArray((byte[]) null));
234:
235: byte[] source = new byte[] { 9, 4, 3, 6, 8 };
236: String[] converted = ArrayUtils.createStringArray(source);
237: assertEquals(source.length, converted.length);
238: assertEquals(String.valueOf(source[0]), converted[0]);
239: assertEquals(String.valueOf(source[1]), converted[1]);
240: assertEquals(String.valueOf(source[2]), converted[2]);
241: assertEquals(String.valueOf(source[3]), converted[3]);
242: assertEquals(String.valueOf(source[4]), converted[4]);
243: }
244:
245: public void testCreateStringArrayChar() {
246: assertNull(ArrayUtils.createStringArray((char[]) null));
247:
248: char[] source = new char[] { 'w', 'o', 'r', 'k', 's' };
249: String[] converted = ArrayUtils.createStringArray(source);
250: assertEquals(source.length, converted.length);
251: assertEquals(String.valueOf(source[0]), converted[0]);
252: assertEquals(String.valueOf(source[1]), converted[1]);
253: assertEquals(String.valueOf(source[2]), converted[2]);
254: assertEquals(String.valueOf(source[3]), converted[3]);
255: assertEquals(String.valueOf(source[4]), converted[4]);
256: }
257:
258: public void testCreateStringArrayShort() {
259: assertNull(ArrayUtils.createStringArray((short[]) null));
260:
261: short[] source = new short[] { 84, 23, 43, 12, 5 };
262: String[] converted = ArrayUtils.createStringArray(source);
263: assertEquals(source.length, converted.length);
264: assertEquals(String.valueOf(source[0]), converted[0]);
265: assertEquals(String.valueOf(source[1]), converted[1]);
266: assertEquals(String.valueOf(source[2]), converted[2]);
267: assertEquals(String.valueOf(source[3]), converted[3]);
268: assertEquals(String.valueOf(source[4]), converted[4]);
269: }
270:
271: public void testCreateStringArrayInt() {
272: assertNull(ArrayUtils.createStringArray((int[]) null));
273:
274: int[] source = new int[] { 9834, 454, 2355, 2398, 4834 };
275: String[] converted = ArrayUtils.createStringArray(source);
276: assertEquals(source.length, converted.length);
277: assertEquals(String.valueOf(source[0]), converted[0]);
278: assertEquals(String.valueOf(source[1]), converted[1]);
279: assertEquals(String.valueOf(source[2]), converted[2]);
280: assertEquals(String.valueOf(source[3]), converted[3]);
281: assertEquals(String.valueOf(source[4]), converted[4]);
282: }
283:
284: public void testCreateStringArrayLong() {
285: assertNull(ArrayUtils.createStringArray((long[]) null));
286:
287: long[] source = new long[] { 59035, 90465, 723479, 47543,
288: 987543 };
289: String[] converted = ArrayUtils.createStringArray(source);
290: assertEquals(source.length, converted.length);
291: assertEquals(String.valueOf(source[0]), converted[0]);
292: assertEquals(String.valueOf(source[1]), converted[1]);
293: assertEquals(String.valueOf(source[2]), converted[2]);
294: assertEquals(String.valueOf(source[3]), converted[3]);
295: assertEquals(String.valueOf(source[4]), converted[4]);
296: }
297:
298: public void testCreateStringArrayFloat() {
299: assertNull(ArrayUtils.createStringArray((float[]) null));
300:
301: float[] source = new float[] { 228.02f, 8734.3f, 8634.2f,
302: 34321.9f, 3478.2f };
303: String[] converted = ArrayUtils.createStringArray(source);
304: assertEquals(source.length, converted.length);
305: assertEquals(String.valueOf(source[0]), converted[0]);
306: assertEquals(String.valueOf(source[1]), converted[1]);
307: assertEquals(String.valueOf(source[2]), converted[2]);
308: assertEquals(String.valueOf(source[3]), converted[3]);
309: assertEquals(String.valueOf(source[4]), converted[4]);
310: }
311:
312: public void testCreateStringArrayDouble() {
313: assertNull(ArrayUtils.createStringArray((double[]) null));
314:
315: double[] source = new double[] { 987634.3434d, 653928.434d,
316: 394374.34387d, 3847764332.3434d, 3434d };
317: String[] converted = ArrayUtils.createStringArray(source);
318: assertEquals(source.length, converted.length);
319: assertEquals(String.valueOf(source[0]), converted[0]);
320: assertEquals(String.valueOf(source[1]), converted[1]);
321: assertEquals(String.valueOf(source[2]), converted[2]);
322: assertEquals(String.valueOf(source[3]), converted[3]);
323: assertEquals(String.valueOf(source[4]), converted[4]);
324: }
325:
326: public void testCreateBooleanArray() {
327: assertNull(ArrayUtils.createBooleanArray(null));
328:
329: String[] source = new String[] { "false", "false", null,
330: "true", "false", "true" };
331: boolean[] target = new boolean[] { false, false, true, false,
332: true };
333: boolean[] converted = ArrayUtils.createBooleanArray(source);
334: assertEquals(target.length, converted.length);
335: assertEquals(target[0], converted[0]);
336: assertEquals(target[1], converted[1]);
337: assertEquals(target[2], converted[2]);
338: assertEquals(target[3], converted[3]);
339: assertEquals(target[4], converted[4]);
340: }
341:
342: public void testCreateByteArray() {
343: assertNull(ArrayUtils.createByteArray(null));
344:
345: Object[] source = new Object[] { new Integer(9), "ko", "4",
346: null, new Long(3), "ok", "6", "8" };
347: byte[] target = new byte[] { 9, 4, 3, 6, 8 };
348: byte[] converted = ArrayUtils.createByteArray(source);
349: assertEquals(target.length, converted.length);
350: assertEquals(target[0], converted[0]);
351: assertEquals(target[1], converted[1]);
352: assertEquals(target[2], converted[2]);
353: assertEquals(target[3], converted[3]);
354: assertEquals(target[4], converted[4]);
355: }
356:
357: public void testCreateCharArray() {
358: assertNull(ArrayUtils.createCharArray(null));
359:
360: Object[] source = new Object[] { new Character('w'), "loo",
361: null, "ko", "o", "r", "k", "s",
362: new StringBuffer("oook") };
363: char[] target = new char[] { 'w', 'o', 'r', 'k', 's' };
364: char[] converted = ArrayUtils.createCharArray(source);
365: assertEquals(target.length, converted.length);
366: assertEquals(target[0], converted[0]);
367: assertEquals(target[1], converted[1]);
368: assertEquals(target[2], converted[2]);
369: assertEquals(target[3], converted[3]);
370: assertEquals(target[4], converted[4]);
371: }
372:
373: public void testCreateShortArray() {
374: assertNull(ArrayUtils.createShortArray(null));
375:
376: Object[] source = new Object[] { "84", "ko",
377: new Byte((byte) 23), "43", "ok", null,
378: new Short((short) 12), "5" };
379: short[] target = new short[] { 84, 23, 43, 12, 5 };
380: short[] converted = ArrayUtils.createShortArray(source);
381: assertEquals(target.length, converted.length);
382: assertEquals(target[0], converted[0]);
383: assertEquals(target[1], converted[1]);
384: assertEquals(target[2], converted[2]);
385: assertEquals(target[3], converted[3]);
386: assertEquals(target[4], converted[4]);
387: }
388:
389: public void testCreateIntArray() {
390: assertNull(ArrayUtils.createIntArray(null));
391:
392: Object[] source = new Object[] { "ok", new Integer(9834), null,
393: "454", new StringBuffer("2355"), "ko", "2398",
394: new Long(4834L), "koko" };
395: int[] target = new int[] { 9834, 454, 2355, 2398, 4834 };
396: int[] converted = ArrayUtils.createIntArray(source);
397: assertEquals(target.length, converted.length);
398: assertEquals(target[0], converted[0]);
399: assertEquals(target[1], converted[1]);
400: assertEquals(target[2], converted[2]);
401: assertEquals(target[3], converted[3]);
402: assertEquals(target[4], converted[4]);
403: }
404:
405: public void testCreateLongArray() {
406: assertNull(ArrayUtils.createLongArray(null));
407:
408: Object[] source = new Object[] { new Integer(59035), "90465",
409: "ok", "723479", null, "47543", "ko",
410: new Integer(987543) };
411: long[] target = new long[] { 59035, 90465, 723479, 47543,
412: 987543 };
413: long[] converted = ArrayUtils.createLongArray(source);
414: assertEquals(target.length, converted.length);
415: assertEquals(target[0], converted[0]);
416: assertEquals(target[1], converted[1]);
417: assertEquals(target[2], converted[2]);
418: assertEquals(target[3], converted[3]);
419: assertEquals(target[4], converted[4]);
420: }
421:
422: public void testCreateFloatArray() {
423: assertNull(ArrayUtils.createFloatArray(null));
424:
425: Object[] source = new Object[] { "228.02", new Float(8734.3f),
426: "lokoko", "8634.2", null, "kokiro",
427: new Double(34321.9d), "3478.2" };
428: float[] target = new float[] { 228.02f, 8734.3f, 8634.2f,
429: 34321.9f, 3478.2f };
430: float[] converted = ArrayUtils.createFloatArray(source);
431: assertEquals(target.length, converted.length);
432: assertEquals(target[0], converted[0], 0);
433: assertEquals(target[1], converted[1], 0);
434: assertEquals(target[2], converted[2], 0);
435: assertEquals(target[3], converted[3], 0);
436: assertEquals(target[4], converted[4], 0);
437: }
438:
439: public void testCreateDoubleArray() {
440: assertNull(ArrayUtils.createDoubleArray(null));
441:
442: Object[] source = new Object[] { new Double(987634.3434d),
443: null, "653928.434", "oooook",
444: new Double(394374.34387d), "3847764332.3434", "koooko",
445: new Integer(3434) };
446: double[] target = new double[] { 987634.3434d, 653928.434d,
447: 394374.34387d, 3847764332.3434d, 3434d };
448: double[] converted = ArrayUtils.createDoubleArray(source);
449: assertEquals(target.length, converted.length);
450: assertEquals(target[0], converted[0], 0);
451: assertEquals(target[1], converted[1], 0);
452: assertEquals(target[2], converted[2], 0);
453: assertEquals(target[3], converted[3], 0);
454: assertEquals(target[4], converted[4], 0);
455: }
456:
457: public void testJoinString() {
458: String[] first = new String[] { "lkjhkjh", "uhggh", "kgyugioh",
459: "kjhgkhjh", "phhgg" };
460: String[] second = new String[] { "ihhjf", "hhjgvgjfc",
461: "oighiufhuf", "uiguhgi", "iuggiug" };
462:
463: assertNull(ArrayUtils.join((String[]) null, (String[]) null));
464: assertSame(first, ArrayUtils.join(first, (String[]) null));
465: assertSame(second, ArrayUtils.join((String[]) null, second));
466:
467: String[] join = ArrayUtils.join(first, second);
468: assertEquals(join[0], first[0]);
469: assertEquals(join[1], first[1]);
470: assertEquals(join[2], first[2]);
471: assertEquals(join[3], first[3]);
472: assertEquals(join[4], first[4]);
473: assertEquals(join[5], second[0]);
474: assertEquals(join[6], second[1]);
475: assertEquals(join[7], second[2]);
476: assertEquals(join[8], second[3]);
477: assertEquals(join[9], second[4]);
478: }
479:
480: public void testJoinStringSingle() {
481: String[] first = new String[] { "lkjhkjh", "uhggh", "kgyugioh",
482: "kjhgkhjh", "phhgg" };
483: String second = "ihhjf";
484:
485: assertNull(ArrayUtils.join((String[]) null, (String) null));
486: assertSame(first, ArrayUtils.join(first, (String) null));
487: assertEquals(1, ArrayUtils.join((String[]) null, second).length);
488: assertEquals(second,
489: ArrayUtils.join((String[]) null, second)[0]);
490:
491: String[] join = ArrayUtils.join(first, second);
492: assertEquals(join[0], first[0]);
493: assertEquals(join[1], first[1]);
494: assertEquals(join[2], first[2]);
495: assertEquals(join[3], first[3]);
496: assertEquals(join[4], first[4]);
497: assertEquals(join[5], second);
498: }
499:
500: public void testJoinByte() {
501: byte[] first = new byte[] { 2, 5, 5, 4, 6 };
502: byte[] second = new byte[] { 9, 4, 3, 6, 8 };
503:
504: assertNull(ArrayUtils.join((byte[]) null, (byte[]) null));
505: assertSame(first, ArrayUtils.join(first, (byte[]) null));
506: assertSame(second, ArrayUtils.join((byte[]) null, second));
507:
508: byte[] join = ArrayUtils.join(first, second);
509: assertEquals(join[0], first[0]);
510: assertEquals(join[1], first[1]);
511: assertEquals(join[2], first[2]);
512: assertEquals(join[3], first[3]);
513: assertEquals(join[4], first[4]);
514: assertEquals(join[5], second[0]);
515: assertEquals(join[6], second[1]);
516: assertEquals(join[7], second[2]);
517: assertEquals(join[8], second[3]);
518: assertEquals(join[9], second[4]);
519: }
520:
521: public void testJoinByteSingle() {
522: byte[] first = new byte[] { 2, 5, 5, 4, 6 };
523: byte second = 9;
524:
525: assertEquals(1, ArrayUtils.join((byte[]) null, second).length);
526: assertEquals(second, ArrayUtils.join((byte[]) null, second)[0]);
527:
528: byte[] join = ArrayUtils.join(first, second);
529: assertEquals(join[0], first[0]);
530: assertEquals(join[1], first[1]);
531: assertEquals(join[2], first[2]);
532: assertEquals(join[3], first[3]);
533: assertEquals(join[4], first[4]);
534: assertEquals(join[5], second);
535: }
536:
537: public void testJoinChar() {
538: char[] first = new char[] { 't', 'h', 'i', 's', ' ' };
539: char[] second = new char[] { 'w', 'o', 'r', 'k', 's' };
540:
541: assertNull(ArrayUtils.join((char[]) null, (char[]) null));
542: assertSame(first, ArrayUtils.join(first, (char[]) null));
543: assertSame(second, ArrayUtils.join((char[]) null, second));
544:
545: char[] join = ArrayUtils.join(first, second);
546: assertEquals(join[0], first[0]);
547: assertEquals(join[1], first[1]);
548: assertEquals(join[2], first[2]);
549: assertEquals(join[3], first[3]);
550: assertEquals(join[4], first[4]);
551: assertEquals(join[5], second[0]);
552: assertEquals(join[6], second[1]);
553: assertEquals(join[7], second[2]);
554: assertEquals(join[8], second[3]);
555: assertEquals(join[9], second[4]);
556: }
557:
558: public void testJoinCharSingle() {
559: char[] first = new char[] { 't', 'h', 'i', 's', ' ' };
560: char second = 'w';
561:
562: assertEquals(1, ArrayUtils.join((char[]) null, second).length);
563: assertEquals(second, ArrayUtils.join((char[]) null, second)[0]);
564:
565: char[] join = ArrayUtils.join(first, second);
566: assertEquals(join[0], first[0]);
567: assertEquals(join[1], first[1]);
568: assertEquals(join[2], first[2]);
569: assertEquals(join[3], first[3]);
570: assertEquals(join[4], first[4]);
571: assertEquals(join[5], second);
572: }
573:
574: public void testJoinShort() {
575: short[] first = new short[] { 8, 3, 54, 23, 54 };
576: short[] second = new short[] { 84, 23, 43, 12, 5 };
577:
578: assertNull(ArrayUtils.join((short[]) null, (short[]) null));
579: assertSame(first, ArrayUtils.join(first, (short[]) null));
580: assertSame(second, ArrayUtils.join((short[]) null, second));
581:
582: short[] join = ArrayUtils.join(first, second);
583: assertEquals(join[0], first[0]);
584: assertEquals(join[1], first[1]);
585: assertEquals(join[2], first[2]);
586: assertEquals(join[3], first[3]);
587: assertEquals(join[4], first[4]);
588: assertEquals(join[5], second[0]);
589: assertEquals(join[6], second[1]);
590: assertEquals(join[7], second[2]);
591: assertEquals(join[8], second[3]);
592: assertEquals(join[9], second[4]);
593: }
594:
595: public void testJoinShortSingle() {
596: short[] first = new short[] { 8, 3, 54, 23, 54 };
597: short second = 84;
598:
599: assertEquals(1, ArrayUtils.join((short[]) null, second).length);
600: assertEquals(second, ArrayUtils.join((short[]) null, second)[0]);
601:
602: short[] join = ArrayUtils.join(first, second);
603: assertEquals(join[0], first[0]);
604: assertEquals(join[1], first[1]);
605: assertEquals(join[2], first[2]);
606: assertEquals(join[3], first[3]);
607: assertEquals(join[4], first[4]);
608: assertEquals(join[5], second);
609: }
610:
611: public void testJoinInt() {
612: int[] first = new int[] { 834, 3476, 343, 234, 545 };
613: int[] second = new int[] { 9834, 454, 2355, 2398, 4834 };
614:
615: assertNull(ArrayUtils.join((int[]) null, (int[]) null));
616: assertSame(first, ArrayUtils.join(first, (int[]) null));
617: assertSame(second, ArrayUtils.join((int[]) null, second));
618:
619: int[] join = ArrayUtils.join(first, second);
620: assertEquals(join[0], first[0]);
621: assertEquals(join[1], first[1]);
622: assertEquals(join[2], first[2]);
623: assertEquals(join[3], first[3]);
624: assertEquals(join[4], first[4]);
625: assertEquals(join[5], second[0]);
626: assertEquals(join[6], second[1]);
627: assertEquals(join[7], second[2]);
628: assertEquals(join[8], second[3]);
629: assertEquals(join[9], second[4]);
630: }
631:
632: public void testJoinIntSingle() {
633: int[] first = new int[] { 834, 3476, 343, 234, 545 };
634: int second = 9834;
635:
636: assertEquals(1, ArrayUtils.join((int[]) null, second).length);
637: assertEquals(second, ArrayUtils.join((int[]) null, second)[0]);
638:
639: int[] join = ArrayUtils.join(first, second);
640: assertEquals(join[0], first[0]);
641: assertEquals(join[1], first[1]);
642: assertEquals(join[2], first[2]);
643: assertEquals(join[3], first[3]);
644: assertEquals(join[4], first[4]);
645: assertEquals(join[5], second);
646: }
647:
648: public void testJoinLong() {
649: long[] first = new long[] { 987634, 98785, 54654, 9864, 4697932 };
650: long[] second = new long[] { 59035, 90465, 723479, 47543,
651: 987543 };
652:
653: assertNull(ArrayUtils.join((long[]) null, (long[]) null));
654: assertSame(first, ArrayUtils.join(first, (long[]) null));
655: assertSame(second, ArrayUtils.join((long[]) null, second));
656:
657: long[] join = ArrayUtils.join(first, second);
658: assertEquals(join[0], first[0]);
659: assertEquals(join[1], first[1]);
660: assertEquals(join[2], first[2]);
661: assertEquals(join[3], first[3]);
662: assertEquals(join[4], first[4]);
663: assertEquals(join[5], second[0]);
664: assertEquals(join[6], second[1]);
665: assertEquals(join[7], second[2]);
666: assertEquals(join[8], second[3]);
667: assertEquals(join[9], second[4]);
668: }
669:
670: public void testJoinLongSingle() {
671: long[] first = new long[] { 987634, 98785, 54654, 9864, 4697932 };
672: long second = 59035;
673:
674: assertEquals(1, ArrayUtils.join((long[]) null, second).length);
675: assertEquals(second, ArrayUtils.join((long[]) null, second)[0]);
676:
677: long[] join = ArrayUtils.join(first, second);
678: assertEquals(join[0], first[0]);
679: assertEquals(join[1], first[1]);
680: assertEquals(join[2], first[2]);
681: assertEquals(join[3], first[3]);
682: assertEquals(join[4], first[4]);
683: assertEquals(join[5], second);
684: }
685:
686: public void testJoinFloat() {
687: float[] first = new float[] { 43.3f, 7489.2f, 7634.98f, 343.8f,
688: 736.9f };
689: float[] second = new float[] { 228.02f, 8734.3f, 8634.2f,
690: 34321.9f, 3478.2f };
691:
692: assertNull(ArrayUtils.join((float[]) null, (float[]) null));
693: assertSame(first, ArrayUtils.join(first, (float[]) null));
694: assertSame(second, ArrayUtils.join((float[]) null, second));
695:
696: float[] join = ArrayUtils.join(first, second);
697: assertEquals(join[0], first[0], 0);
698: assertEquals(join[1], first[1], 0);
699: assertEquals(join[2], first[2], 0);
700: assertEquals(join[3], first[3], 0);
701: assertEquals(join[4], first[4], 0);
702: assertEquals(join[5], second[0], 0);
703: assertEquals(join[6], second[1], 0);
704: assertEquals(join[7], second[2], 0);
705: assertEquals(join[8], second[3], 0);
706: assertEquals(join[9], second[4], 0);
707: }
708:
709: public void testJoinFloatSingle() {
710: float[] first = new float[] { 43.3f, 7489.2f, 7634.98f, 343.8f,
711: 736.9f };
712: float second = 228.02f;
713:
714: assertEquals(1, ArrayUtils.join((float[]) null, second).length);
715: assertEquals(second, ArrayUtils.join((float[]) null, second)[0]);
716:
717: float[] join = ArrayUtils.join(first, second);
718: assertEquals(join[0], first[0], 0);
719: assertEquals(join[1], first[1], 0);
720: assertEquals(join[2], first[2], 0);
721: assertEquals(join[3], first[3], 0);
722: assertEquals(join[4], first[4], 0);
723: assertEquals(join[5], second, 0);
724: }
725:
726: public void testJoinDouble() {
727: double[] first = new double[] { 973284.678943d,
728: 8936498736.232d, 78634.9834d, 37467.334d,
729: 986347.234243d };
730: double[] second = new double[] { 987634.3434d, 653928.434d,
731: 394374.34387d, 3847764332.3434d, 3434d };
732:
733: assertNull(ArrayUtils.join((double[]) null, (double[]) null));
734: assertSame(first, ArrayUtils.join(first, (double[]) null));
735: assertSame(second, ArrayUtils.join((double[]) null, second));
736:
737: double[] join = ArrayUtils.join(first, second);
738: assertEquals(join[0], first[0], 0);
739: assertEquals(join[1], first[1], 0);
740: assertEquals(join[2], first[2], 0);
741: assertEquals(join[3], first[3], 0);
742: assertEquals(join[4], first[4], 0);
743: assertEquals(join[5], second[0], 0);
744: assertEquals(join[6], second[1], 0);
745: assertEquals(join[7], second[2], 0);
746: assertEquals(join[8], second[3], 0);
747: assertEquals(join[9], second[4], 0);
748: }
749:
750: public void testJoinDoubleSingle() {
751: double[] first = new double[] { 973284.678943d,
752: 8936498736.232d, 78634.9834d, 37467.334d,
753: 986347.234243d };
754: double second = 987634.3434d;
755:
756: assertEquals(1, ArrayUtils.join((double[]) null, second).length);
757: assertEquals(second,
758: ArrayUtils.join((double[]) null, second)[0]);
759:
760: double[] join = ArrayUtils.join(first, second);
761: assertEquals(join[0], first[0], 0);
762: assertEquals(join[1], first[1], 0);
763: assertEquals(join[2], first[2], 0);
764: assertEquals(join[3], first[3], 0);
765: assertEquals(join[4], first[4], 0);
766: assertEquals(join[5], second, 0);
767: }
768:
769: public void testJoinBoolean() {
770: boolean[] first = new boolean[] { true, false, false, true,
771: true };
772: boolean[] second = new boolean[] { false, false, true, false,
773: true };
774:
775: assertNull(ArrayUtils.join((boolean[]) null, (boolean[]) null));
776: assertSame(first, ArrayUtils.join(first, (boolean[]) null));
777: assertSame(second, ArrayUtils.join((boolean[]) null, second));
778:
779: boolean[] join = ArrayUtils.join(first, second);
780: assertEquals(join[0], first[0]);
781: assertEquals(join[1], first[1]);
782: assertEquals(join[2], first[2]);
783: assertEquals(join[3], first[3]);
784: assertEquals(join[4], first[4]);
785: assertEquals(join[5], second[0]);
786: assertEquals(join[6], second[1]);
787: assertEquals(join[7], second[2]);
788: assertEquals(join[8], second[3]);
789: assertEquals(join[9], second[4]);
790: }
791:
792: public void testJoinBooleanSingle() {
793: boolean[] first = new boolean[] { true, false, false, true,
794: true };
795: boolean second = false;
796:
797: assertEquals(1,
798: ArrayUtils.join((boolean[]) null, second).length);
799: assertEquals(second,
800: ArrayUtils.join((boolean[]) null, second)[0]);
801:
802: boolean[] join = ArrayUtils.join(first, second);
803: assertEquals(join[0], first[0]);
804: assertEquals(join[1], first[1]);
805: assertEquals(join[2], first[2]);
806: assertEquals(join[3], first[3]);
807: assertEquals(join[4], first[4]);
808: assertEquals(join[5], second);
809: }
810: }
|