KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > util > ArraysUtilTest


1 // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
2

3 package jodd.util;
4
5 import junit.framework.TestCase;
6
7 public class ArraysUtilTest extends TestCase {
8
9     int[] x;
10     int[] y;
11     protected void setUp() throws Exception JavaDoc {
12         super.setUp();
13         x = new int[5];
14         for (int i = 0; i < x.length; i++) x[i] = i + 1;
15         y = new int[3];
16         for (int i = 0; i < y.length; i++) y[i] = 11 + i;
17     }
18
19     protected void assertEquals(int[] expected, int[] provided) {
20         assertEquals(expected.length, provided.length);
21         for (int i = 0; i < expected.length; i++) {
22             assertEquals(expected[i], provided[i]);
23         }
24     }
25
26     public void testJoin() {
27         assertEquals(new int[] {1,2,3,4,5,11,12,13}, ArraysUtil.join(x, y));
28     }
29
30     public void testResize() {
31         assertEquals(new int[] {1,2,3}, ArraysUtil.resize(x, 3));
32         assertEquals(new int[] {1,2,3,4,5,0,0}, ArraysUtil.resize(x, 7));
33         assertEquals(new int[] {}, ArraysUtil.resize(x, 0));
34     }
35
36     public void testSub() {
37         assertEquals(new int[] {2,3,4}, ArraysUtil.subarray(x, 1, 3));
38     }
39
40     public void testInsert() {
41         assertEquals(new int[] {1,2,3,11,12,13,4,5}, ArraysUtil.insert(x, y, 3));
42         assertEquals(new int[] {11,12,13,1,2,3,4,5}, ArraysUtil.insert(x, y, 0));
43         assertEquals(new int[] {1,2,3,4,5,11,12,13}, ArraysUtil.insert(x, y, 5));
44     }
45
46     public void testInsertAt() {
47         assertEquals(new int[] {1,2,3,11,12,13,5}, ArraysUtil.insertAt(x, y, 3));
48         assertEquals(new int[] {11,12,13,2,3,4,5}, ArraysUtil.insertAt(x, y, 0));
49         assertEquals(new int[] {1,2,3,4,11,12,13}, ArraysUtil.insertAt(x, y, 4));
50     }
51
52
53     public void testIndexOf() {
54         assertEquals(0, ArraysUtil.indexOf(x, 1));
55         assertEquals(1, ArraysUtil.indexOf(x, 2));
56         assertEquals(4, ArraysUtil.indexOf(x, 5));
57         assertEquals(-1, ArraysUtil.indexOf(x, 6));
58     }
59
60     public void testIndexOf2() {
61         assertEquals(0, ArraysUtil.indexOf(x, new int[] {}));
62         assertEquals(0, ArraysUtil.indexOf(x, new int[] {1,2,3}));
63         assertEquals(-1, ArraysUtil.indexOf(x, new int[] {1,2,3,7}));
64
65         assertEquals(1, ArraysUtil.indexOf(x, new int[] {2,3}));
66         assertEquals(4, ArraysUtil.indexOf(x, new int[] {5}));
67     }
68
69 }
70
Popular Tags