KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

45     protected ShortList makeEmptyShortList() {
46         return new ArrayUnsignedByteList();
47     }
48
49     public String JavaDoc[] ignoredTests() {
50         // sublists are not serializable
51
return new String JavaDoc[] {
52             "TestArrayUnsignedByteList.bulkTestSubList.testFullListSerialization",
53             "TestArrayUnsignedByteList.bulkTestSubList.testEmptyListSerialization",
54             "TestArrayUnsignedByteList.bulkTestSubList.testCanonicalEmptyCollectionExists",
55             "TestArrayUnsignedByteList.bulkTestSubList.testCanonicalFullCollectionExists",
56             "TestArrayUnsignedByteList.bulkTestSubList.testEmptyListCompatibility",
57             "TestArrayUnsignedByteList.bulkTestSubList.testFullListCompatibility",
58             "TestArrayUnsignedByteList.bulkTestSubList.testSerializeDeserializeThenCompare",
59             "TestArrayUnsignedByteList.bulkTestSubList.testSimpleSerialization"
60         };
61     }
62
63     protected short[] getFullShorts() {
64         short[] result = new short[19];
65         for(int i = 0; i < result.length; i++) {
66             result[i] = (short)(ArrayUnsignedByteList.MAX_VALUE - i);
67         }
68         return result;
69     }
70
71     // tests
72
// ------------------------------------------------------------------------
73

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