KickJava   Java API By Example, From Geeks To Geeks.

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


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 TestArrayShortList extends TestShortList {
29
30     // conventional
31
// ------------------------------------------------------------------------
32

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

45     protected ShortList makeEmptyShortList() {
46         return new ArrayShortList();
47     }
48
49     public String JavaDoc[] ignoredTests() {
50         // sublists are not serializable
51
return new String JavaDoc[] {
52             "TestArrayShortList.bulkTestSubList.testFullListSerialization",
53             "TestArrayShortList.bulkTestSubList.testEmptyListSerialization",
54             "TestArrayShortList.bulkTestSubList.testCanonicalEmptyCollectionExists",
55             "TestArrayShortList.bulkTestSubList.testCanonicalFullCollectionExists",
56             "TestArrayShortList.bulkTestSubList.testEmptyListCompatibility",
57             "TestArrayShortList.bulkTestSubList.testFullListCompatibility",
58             "TestArrayShortList.bulkTestSubList.testSerializeDeserializeThenCompare",
59             "TestArrayShortList.bulkTestSubList.testSimpleSerialization"
60         };
61     }
62
63     // tests
64
// ------------------------------------------------------------------------
65

66     /** @TODO need to add serialized form to cvs */
67     public void testCanonicalEmptyCollectionExists() {
68         // XXX FIX ME XXX
69
// need to add a serialized form to cvs
70
}
71
72     public void testCanonicalFullCollectionExists() {
73         // XXX FIX ME XXX
74
// need to add a serialized form to cvs
75
}
76
77     public void testEmptyListCompatibility() {
78         // XXX FIX ME XXX
79
// need to add a serialized form to cvs
80
}
81
82     public void testFullListCompatibility() {
83         // XXX FIX ME XXX
84
// need to add a serialized form to cvs
85
}
86
87     public void testAddGetLargeValues() {
88         ShortList list = new ArrayShortList();
89         for (int i = 0; i < 1000; i++) {
90             short value = ((short) (Integer.MAX_VALUE));
91             value += i;
92             list.add(value);
93         }
94         for (int i = 0; i < 1000; i++) {
95             short value = ((short) (Integer.MAX_VALUE));
96             value += i;
97             assertEquals(value, list.get(i));
98         }
99     }
100
101     public void testZeroInitialCapacityIsValid() {
102         assertNotNull(new ArrayShortList(0));
103     }
104
105     public void testNegativeInitialCapacityIsInvalid() {
106         try {
107             new ArrayShortList(-1);
108             fail("Expected IllegalArgumentException");
109         } catch(IllegalArgumentException JavaDoc e) {
110             // expected
111
}
112     }
113
114     public void testCopyConstructor() {
115         ArrayShortList expected = new ArrayShortList();
116         for(int i=0;i<10;i++) {
117             expected.add((short)i);
118         }
119         ArrayShortList list = new ArrayShortList(expected);
120         assertEquals(10,list.size());
121         assertEquals(expected,list);
122     }
123
124     public void testCopyConstructorWithNull() {
125         try {
126             new ArrayShortList((ShortCollection) null);
127             fail("Expected NullPointerException");
128         } catch(NullPointerException JavaDoc e) {
129             // expected
130
}
131     }
132
133     public void testArrayConstructor() {
134         ArrayShortList expected = new ArrayShortList();
135         for (int i = 0; i < 10; i++) {
136             expected.add((short) i);
137         }
138         ArrayShortList list = new ArrayShortList(expected.toArray());
139         assertEquals(10, list.size());
140         assertEquals(expected, list);
141     }
142
143     public void testArrayConstructorWithNull() {
144         try {
145             new ArrayShortList((short[]) null);
146             fail("Expected NullPointerException");
147         } catch (NullPointerException JavaDoc e) {
148             // expected
149
}
150     }
151
152
153     public void testTrimToSize() {
154         ArrayShortList list = new ArrayShortList();
155         for(int j=0;j<3;j++) {
156             assertTrue(list.isEmpty());
157     
158             list.trimToSize();
159     
160             assertTrue(list.isEmpty());
161             
162             for(int i=0;i<10;i++) {
163                 list.add((short)i);
164             }
165             
166             for(int i=0;i<10;i++) {
167                 assertEquals((short)i,list.get(i));
168             }
169             
170             list.trimToSize();
171     
172             for(int i=0;i<10;i++) {
173                 assertEquals((short)i,list.get(i));
174             }
175     
176             for(int i=0;i<10;i+=2) {
177                 list.removeElement((short)i);
178             }
179             
180             for(int i=0;i<5;i++) {
181                 assertEquals((short)(2*i)+1,list.get(i));
182             }
183     
184             list.trimToSize();
185                     
186             for(int i=0;i<5;i++) {
187                 assertEquals((short)(2*i)+1,list.get(i));
188             }
189
190             list.trimToSize();
191                     
192             for(int i=0;i<5;i++) {
193                 assertEquals((short)(2*i)+1,list.get(i));
194             }
195     
196             list.clear();
197         }
198     }
199
200 }
201
Popular Tags