001: /*
002: * $Header: /home/cvs/jakarta-commons/primitives/src/test/org/apache/commons/collections/primitives/TestArrayFloatList.java,v 1.1 2003/10/13 22:46:55 scolebourne Exp $
003: * ====================================================================
004: * The Apache Software License, Version 1.1
005: *
006: * Copyright (c) 2002-2003 The Apache Software Foundation. All rights
007: * reserved.
008: *
009: * Redistribution and use in source and binary forms, with or without
010: * modification, are permitted provided that the following conditions
011: * are met:
012: *
013: * 1. Redistributions of source code must retain the above copyright
014: * notice, this list of conditions and the following disclaimer.
015: *
016: * 2. Redistributions in binary form must reproduce the above copyright
017: * notice, this list of conditions and the following disclaimer in
018: * the documentation and/or other materials provided with the
019: * distribution.
020: *
021: * 3. The end-user documentation included with the redistribution, if
022: * any, must include the following acknowledgement:
023: * "This product includes software developed by the
024: * Apache Software Foundation (http://www.apache.org/)."
025: * Alternately, this acknowledgement may appear in the software itself,
026: * if and wherever such third-party acknowledgements normally appear.
027: *
028: * 4. The names "The Jakarta Project", "Commons", and "Apache Software
029: * Foundation" must not be used to endorse or promote products derived
030: * from this software without prior written permission. For written
031: * permission, please contact apache@apache.org.
032: *
033: * 5. Products derived from this software may not be called "Apache"
034: * nor may "Apache" appear in their names without prior written
035: * permission of the Apache Software Foundation.
036: *
037: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
038: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
039: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
040: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
041: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
042: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
043: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
044: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
045: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
046: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
047: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
048: * SUCH DAMAGE.
049: * ====================================================================
050: *
051: * This software consists of voluntary contributions made by many
052: * individuals on behalf of the Apache Software Foundation. For more
053: * information on the Apache Software Foundation, please see
054: * <http://www.apache.org/>.
055: *
056: */
057:
058: package org.apache.commons.collections.primitives;
059:
060: import junit.framework.Test;
061: import junit.framework.TestSuite;
062:
063: import org.apache.commons.collections.BulkTest;
064:
065: /**
066: * @version $Revision: 1.1 $ $Date: 2003/10/13 22:46:55 $
067: * @author Rodney Waldhoff
068: */
069: public class TestArrayFloatList extends TestFloatList {
070:
071: // conventional
072: // ------------------------------------------------------------------------
073:
074: public TestArrayFloatList(String testName) {
075: super (testName);
076: }
077:
078: public static Test suite() {
079: TestSuite suite = BulkTest.makeSuite(TestArrayFloatList.class);
080: return suite;
081: }
082:
083: // collections testing framework
084: // ------------------------------------------------------------------------
085:
086: protected FloatList makeEmptyFloatList() {
087: return new ArrayFloatList();
088: }
089:
090: protected String[] ignoredTests() {
091: // sublists are not serializable
092: return new String[] {
093: "TestArrayFloatList.bulkTestSubList.testFullListSerialization",
094: "TestArrayFloatList.bulkTestSubList.testEmptyListSerialization",
095: "TestArrayFloatList.bulkTestSubList.testCanonicalEmptyCollectionExists",
096: "TestArrayFloatList.bulkTestSubList.testCanonicalFullCollectionExists",
097: "TestArrayFloatList.bulkTestSubList.testEmptyListCompatibility",
098: "TestArrayFloatList.bulkTestSubList.testFullListCompatibility",
099: "TestArrayFloatList.bulkTestSubList.testSerializeDeserializeThenCompare",
100: "TestArrayFloatList.bulkTestSubList.testSimpleSerialization" };
101: }
102:
103: // tests
104: // ------------------------------------------------------------------------
105:
106: /** @TODO need to add serialized form to cvs */
107: public void testCanonicalEmptyCollectionExists() {
108: // XXX FIX ME XXX
109: // need to add a serialized form to cvs
110: }
111:
112: public void testCanonicalFullCollectionExists() {
113: // XXX FIX ME XXX
114: // need to add a serialized form to cvs
115: }
116:
117: public void testEmptyListCompatibility() {
118: // XXX FIX ME XXX
119: // need to add a serialized form to cvs
120: }
121:
122: public void testFullListCompatibility() {
123: // XXX FIX ME XXX
124: // need to add a serialized form to cvs
125: }
126:
127: public void testAddGetLargeValues() {
128: FloatList list = new ArrayFloatList();
129: for (int i = 0; i < 1000; i++) {
130: float value = ((float) (Float.MAX_VALUE));
131: value -= i;
132: list.add(value);
133: }
134: for (int i = 0; i < 1000; i++) {
135: float value = ((float) (Float.MAX_VALUE));
136: value -= i;
137: assertEquals(value, list.get(i), 0f);
138: }
139: }
140:
141: public void testZeroInitialCapacityIsValid() {
142: assertNotNull(new ArrayFloatList(0));
143: }
144:
145: public void testNegativeInitialCapacityIsInvalid() {
146: try {
147: new ArrayFloatList(-1);
148: fail("Expected IllegalArgumentException");
149: } catch (IllegalArgumentException e) {
150: // expected
151: }
152: }
153:
154: public void testCopyConstructor() {
155: ArrayFloatList expected = new ArrayFloatList();
156: for (int i = 0; i < 10; i++) {
157: expected.add((float) i);
158: }
159: ArrayFloatList list = new ArrayFloatList(expected);
160: assertEquals(10, list.size());
161: assertEquals(expected, list);
162: }
163:
164: public void testCopyConstructorWithNull() {
165: try {
166: new ArrayFloatList(null);
167: fail("Expected NullPointerException");
168: } catch (NullPointerException e) {
169: // expected
170: }
171: }
172:
173: public void testTrimToSize() {
174: ArrayFloatList list = new ArrayFloatList();
175: for (int j = 0; j < 3; j++) {
176: assertTrue(list.isEmpty());
177:
178: list.trimToSize();
179:
180: assertTrue(list.isEmpty());
181:
182: for (int i = 0; i < 10; i++) {
183: list.add((float) i);
184: }
185:
186: for (int i = 0; i < 10; i++) {
187: assertEquals((float) i, list.get(i), 0f);
188: }
189:
190: list.trimToSize();
191:
192: for (int i = 0; i < 10; i++) {
193: assertEquals((float) i, list.get(i), 0f);
194: }
195:
196: for (int i = 0; i < 10; i += 2) {
197: list.removeElement((float) i);
198: }
199:
200: for (int i = 0; i < 5; i++) {
201: assertEquals((float) (2 * i) + 1, list.get(i), 0f);
202: }
203:
204: list.trimToSize();
205:
206: for (int i = 0; i < 5; i++) {
207: assertEquals((float) (2 * i) + 1, list.get(i), 0f);
208: }
209:
210: list.trimToSize();
211:
212: for (int i = 0; i < 5; i++) {
213: assertEquals((float) (2 * i) + 1, list.get(i), 0f);
214: }
215:
216: list.clear();
217: }
218: }
219:
220: }
|