1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.collections.primitives;
18
19 import junit.framework.Test;
20 import junit.framework.TestSuite;
21
22 import org.apache.commons.collections.BulkTest;
23
24
25
26
27
28 public class TestArrayUnsignedShortList extends TestIntList {
29
30
31
32
33 public TestArrayUnsignedShortList(String testName) {
34 super(testName);
35 }
36
37 public static Test suite() {
38 TestSuite suite = BulkTest.makeSuite(TestArrayUnsignedShortList.class);
39 return suite;
40 }
41
42
43
44
45 protected IntList makeEmptyIntList() {
46 return new ArrayUnsignedShortList();
47 }
48
49 public String[] ignoredTests() {
50
51 return new String[] {
52 "TestArrayUnsignedShortList.bulkTestSubList.testFullListSerialization",
53 "TestArrayUnsignedShortList.bulkTestSubList.testEmptyListSerialization",
54 "TestArrayUnsignedShortList.bulkTestSubList.testCanonicalEmptyCollectionExists",
55 "TestArrayUnsignedShortList.bulkTestSubList.testCanonicalFullCollectionExists",
56 "TestArrayUnsignedShortList.bulkTestSubList.testEmptyListCompatibility",
57 "TestArrayUnsignedShortList.bulkTestSubList.testFullListCompatibility",
58 "TestArrayUnsignedShortList.bulkTestSubList.testSerializeDeserializeThenCompare",
59 "TestArrayUnsignedShortList.bulkTestSubList.testSimpleSerialization"
60 };
61 }
62
63
64
65
66 public void testArrayConstructor() {
67 int[] data = new int[] { 1, 2, 3 };
68 IntList list = new ArrayUnsignedShortList(data);
69 for(int i=0;i<data.length;i++) {
70 assertEquals(data[i],list.get(i));
71 }
72 data[0] = 17;
73 assertEquals(1,list.get(0));
74 }
75
76
77 public void testCanonicalEmptyCollectionExists() {
78
79
80 }
81
82 public void testCanonicalFullCollectionExists() {
83
84
85 }
86
87 public void testEmptyListCompatibility() {
88
89
90 }
91
92 public void testFullListCompatibility() {
93
94
95 }
96
97 public void testZeroInitialCapacityIsValid() {
98 assertNotNull(new ArrayUnsignedShortList(0));
99 }
100
101 public void testIllegalArgumentExceptionWhenElementOutOfRange() {
102 ArrayUnsignedShortList list = new ArrayUnsignedShortList();
103 list.add(ArrayUnsignedShortList.MIN_VALUE);
104 list.add(ArrayUnsignedShortList.MAX_VALUE);
105 try {
106 list.add(-1);
107 fail("Expected IllegalArgumentException");
108 } catch(IllegalArgumentException e) {
109
110 }
111 try {
112 list.add(ArrayUnsignedShortList.MAX_VALUE+1);
113 fail("Expected IllegalArgumentException");
114 } catch(IllegalArgumentException e) {
115
116 }
117 }
118
119 public void testNegativeInitialCapacityIsInvalid() {
120 try {
121 new ArrayUnsignedShortList(-1);
122 fail("Expected IllegalArgumentException");
123 } catch(IllegalArgumentException e) {
124
125 }
126 }
127
128 public void testCopyConstructor() {
129 ArrayUnsignedShortList expected = new ArrayUnsignedShortList();
130 for(int i=0;i<10;i++) {
131 expected.add(i);
132 }
133 ArrayUnsignedShortList list = new ArrayUnsignedShortList(expected);
134 assertEquals(10,list.size());
135 assertEquals(expected,list);
136 }
137
138 public void testCopyConstructorWithNull() {
139 try {
140 new ArrayUnsignedShortList((IntList)null);
141 fail("Expected NullPointerException");
142 } catch(NullPointerException e) {
143
144 }
145 }
146
147
148 public void testTrimToSize() {
149 ArrayUnsignedShortList list = new ArrayUnsignedShortList();
150 for(int j=0;j<3;j++) {
151 assertTrue(list.isEmpty());
152
153 list.trimToSize();
154
155 assertTrue(list.isEmpty());
156
157 for(int i=0;i<10;i++) {
158 list.add(i);
159 }
160
161 for(int i=0;i<10;i++) {
162 assertEquals(i,list.get(i));
163 }
164
165 list.trimToSize();
166
167 for(int i=0;i<10;i++) {
168 assertEquals(i,list.get(i));
169 }
170
171 for(int i=0;i<10;i+=2) {
172 list.removeElement(i);
173 }
174
175 for(int i=0;i<5;i++) {
176 assertEquals((2*i)+1,list.get(i));
177 }
178
179 list.trimToSize();
180
181 for(int i=0;i<5;i++) {
182 assertEquals((2*i)+1,list.get(i));
183 }
184
185 list.trimToSize();
186
187 for(int i=0;i<5;i++) {
188 assertEquals((2*i)+1,list.get(i));
189 }
190
191 list.clear();
192 }
193 }
194
195 }