01: package gnu.trove;
02:
03: import junit.framework.TestCase;
04:
05: import java.util.Arrays;
06:
07: public class TArrayListTest extends TestCase {
08: private TIntArrayList list;
09:
10: public void setUp() throws Exception {
11: super .setUp();
12:
13: list = new TIntArrayList();
14: list.add(1);
15: list.add(2);
16: list.add(3);
17: list.add(4);
18: list.add(5);
19: }
20:
21: public void tearDown() throws Exception {
22: super .tearDown();
23: }
24:
25: public void testToNativeArray() {
26: assertTrue(Arrays.equals(new int[] { 1, 2, 3, 4, 5 }, list
27: .toNativeArray()));
28: assertTrue(Arrays.equals(new int[] { 1, 2, 3, 4 }, list
29: .toNativeArray(0, 4)));
30: assertTrue(Arrays.equals(new int[] { 2, 3, 4, 5 }, list
31: .toNativeArray(1, 4)));
32: assertTrue(Arrays.equals(new int[] { 2, 3, 4 }, list
33: .toNativeArray(1, 3)));
34: }
35:
36: public void testSubList() throws Exception {
37: TIntArrayList subList = list.subList(1, 4);
38: assertEquals(3, subList.size());
39: assertEquals(2, subList.get(0));
40: assertEquals(4, subList.get(2));
41: }
42:
43: public void testSublist_Exceptions() {
44: try {
45: list.subList(1, 0);
46: fail("expected IllegalArgumentException when end < begin");
47: } catch (IllegalArgumentException expected) {
48: }
49:
50: try {
51: list.subList(-1, 3);
52: fail("expected IndexOutOfBoundsException when begin < 0");
53: } catch (IndexOutOfBoundsException expected) {
54: }
55:
56: try {
57: list.subList(1, 42);
58: fail("expected IndexOutOfBoundsException when end > length");
59: } catch (IndexOutOfBoundsException expected) {
60: }
61: }
62:
63: public void testMax() {
64: assertEquals(5, list.max());
65: assertEquals(1, list.min());
66:
67: TIntArrayList list2 = new TIntArrayList();
68: list2.add(3);
69: list2.add(1);
70: list2.add(2);
71: list2.add(5);
72: list2.add(4);
73: assertEquals(5, list2.max());
74: assertEquals(1, list2.min());
75: }
76: }
|