1
2
3
4 package org.melati.poem.util.test;
5
6 import java.util.Vector;
7
8 import org.melati.poem.util.ArrayUtils;
9
10 import junit.framework.TestCase;
11
12
13
14
15
16 public class ArrayUtilsTest extends TestCase {
17
18
19
20
21
22 public ArrayUtilsTest(String arg0) {
23 super(arg0);
24 }
25
26
27
28
29 public void testArrayOfVector() {
30 assertEquals(new Object[]{}.length, ArrayUtils.arrayOf(new Vector<Object>()).length);
31
32 }
33
34
35
36
37 public void testArrayOfEnumeration() {
38 assertEquals(new String[]{}.length,
39 ArrayUtils.arrayOf(new Vector<Object>().elements()).length);
40
41 }
42
43
44
45
46 public void testAdded() {
47 String[] them = {"one", "two", "three"};
48 assertEquals(them.length + 1, ArrayUtils.added(them, "four").length);
49 }
50
51
52
53
54 public void testRemoved() {
55 String[] them = {"one", "two", "three", "four", "five"};
56 Object[] without = ArrayUtils.removed(them, "four");
57 assertEquals(them.length - 1, without.length);
58 assertTrue(without[2] instanceof String);
59 }
60
61
62
63
64 public void testConcatenated() {
65 String[] x = {"one", "two", "three"};
66 String[] y = {"four", "five", "six"};
67 assertEquals(x.length + y.length, ArrayUtils.concatenated(x,y).length);
68 }
69
70
71
72
73 public void testSection() {
74 String[] in = {"one", "two", "three", "four"};
75 assertEquals("three", ArrayUtils.section(in, 2, 3)[0]);
76 }
77
78
79
80
81 public void testIndexOf() {
82 String[] in = {"one", "two", "three", "four"};
83 assertEquals(1, ArrayUtils.indexOf(in, "two"));
84 }
85
86
87
88
89 public void testContains() {
90 String[] in = {"one", "two", "three", "four"};
91 assertTrue(ArrayUtils.contains(in, "two"));
92 assertFalse(ArrayUtils.contains(in, "five"));
93 }
94
95 }