KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > primitives > TestArrayUnsignedShortList


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
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  * @version $Revision: 480451 $ $Date: 2006-11-28 23:45:08 -0800 (Tue, 28 Nov 2006) $
26  * @author Rodney Waldhoff
27  */

28 public class TestArrayUnsignedShortList extends TestIntList {
29
30     // conventional
31
// ------------------------------------------------------------------------
32

33     public TestArrayUnsignedShortList(String JavaDoc testName) {
34         super(testName);
35     }
36
37     public static Test suite() {
38         TestSuite suite = BulkTest.makeSuite(TestArrayUnsignedShortList.class);
39         return suite;
40     }
41
42     // collections testing framework
43
// ------------------------------------------------------------------------
44

45     protected IntList makeEmptyIntList() {
46         return new ArrayUnsignedShortList();
47     }
48
49     public String JavaDoc[] ignoredTests() {
50         // sublists are not serializable
51
return new String JavaDoc[] {
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     // tests
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     // @TODO need to add serialized form to cvs
77
public void testCanonicalEmptyCollectionExists() {
78         // XXX FIX ME XXX
79
// need to add a serialized form to cvs
80
}
81
82     public void testCanonicalFullCollectionExists() {
83         // XXX FIX ME XXX
84
// need to add a serialized form to cvs
85
}
86
87     public void testEmptyListCompatibility() {
88         // XXX FIX ME XXX
89
// need to add a serialized form to cvs
90
}
91
92     public void testFullListCompatibility() {
93         // XXX FIX ME XXX
94
// need to add a serialized form to cvs
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 JavaDoc e) {
109             // expected
110
}
111         try {
112             list.add(ArrayUnsignedShortList.MAX_VALUE+1);
113             fail("Expected IllegalArgumentException");
114         } catch(IllegalArgumentException JavaDoc e) {
115             // expected
116
}
117     }
118
119     public void testNegativeInitialCapacityIsInvalid() {
120         try {
121             new ArrayUnsignedShortList(-1);
122             fail("Expected IllegalArgumentException");
123         } catch(IllegalArgumentException JavaDoc e) {
124             // expected
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 JavaDoc e) {
143             // expected
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 }
196
Popular Tags