001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.collections.primitives;
018
019import junit.framework.Test;
020import junit.framework.TestSuite;
021
022import org.apache.commons.collections.BulkTest;
023
024/**
025 * @version $Revision: 480451 $ $Date: 2006-11-29 02:45:08 -0500 (Wed, 29 Nov 2006) $
026 * @author Rodney Waldhoff
027 */
028public class TestArrayBooleanList extends TestBooleanList {
029
030    // conventional
031    // ------------------------------------------------------------------------
032
033    public TestArrayBooleanList(String testName) {
034        super(testName);
035    }
036
037    public static Test suite() {
038        TestSuite suite = BulkTest.makeSuite(TestArrayBooleanList.class);
039        return suite;
040    }
041
042    // collections testing framework
043    // ------------------------------------------------------------------------
044
045    protected BooleanList makeEmptyBooleanList() {
046        return new ArrayBooleanList();
047    }
048
049    public String[] ignoredTests() {
050        return new String[] { 
051
052                // having only two unique values breaks these:
053                "TestArrayBooleanList.bulkTestSubList.testListEquals",
054                "TestArrayBooleanList.bulkTestSubList.testCollectionRemoveAll",
055                "TestArrayBooleanList.bulkTestSubList.testCollectionRetainAll",
056
057                // sublists are not serializable                
058            "TestArrayBooleanList.bulkTestSubList.testFullListSerialization",
059            "TestArrayBooleanList.bulkTestSubList.testEmptyListSerialization",
060            "TestArrayBooleanList.bulkTestSubList.testCanonicalEmptyCollectionExists",
061            "TestArrayBooleanList.bulkTestSubList.testCanonicalFullCollectionExists",
062            "TestArrayBooleanList.bulkTestSubList.testEmptyListCompatibility",
063            "TestArrayBooleanList.bulkTestSubList.testFullListCompatibility",
064            "TestArrayBooleanList.bulkTestSubList.testSerializeDeserializeThenCompare",
065            "TestArrayBooleanList.bulkTestSubList.testSimpleSerialization"
066        };
067    }
068
069    // tests
070    // ------------------------------------------------------------------------
071
072    /** @TODO need to add serialized form to cvs */
073    public void testCanonicalEmptyCollectionExists() {
074        // XXX FIX ME XXX
075        // need to add a serialized form to cvs
076    }
077
078    public void testCanonicalFullCollectionExists() {
079        // XXX FIX ME XXX
080        // need to add a serialized form to cvs
081    }
082
083    public void testEmptyListCompatibility() {
084        // XXX FIX ME XXX
085        // need to add a serialized form to cvs
086    }
087
088    public void testFullListCompatibility() {
089        // XXX FIX ME XXX
090        // need to add a serialized form to cvs
091    }
092
093    public void testZeroInitialCapacityIsValid() {
094        assertNotNull(new ArrayBooleanList(0));
095    }
096
097    public void testNegativeInitialCapacityIsInvalid() {
098        try {
099            new ArrayBooleanList(-1);
100            fail("Expected IllegalArgumentException");
101        } catch(IllegalArgumentException e) {
102            // expected
103        }
104    }
105
106    public void testCopyConstructor() {
107        ArrayBooleanList expected = new ArrayBooleanList();
108        for(int i=0;i<10;i++) {
109            expected.add(i%2==0);
110        }
111        ArrayBooleanList list = new ArrayBooleanList(expected);
112        assertEquals(10,list.size());
113        assertEquals(expected,list);
114    }
115
116    public void testCopyConstructorWithNull() {
117        try {
118            new ArrayBooleanList((BooleanCollection) null);
119            fail("Expected NullPointerException");
120        } catch(NullPointerException e) {
121            // expected
122        }
123    }
124
125    public void testArrayConstructor() {
126        ArrayBooleanList expected = new ArrayBooleanList();
127        for (int i = 0; i < 10; i++) {
128            expected.add(i % 2 == 0);
129        }
130        ArrayBooleanList list = new ArrayBooleanList(expected.toArray());
131        assertEquals(10, list.size());
132        assertEquals(expected, list);
133    }
134
135    public void testArrayConstructorWithNull() {
136        try {
137            new ArrayBooleanList((boolean[]) null);
138            fail("Expected NullPointerException");
139        } catch (NullPointerException e) {
140            // expected
141        }
142    }
143
144
145    public void testTrimToSize() {
146        ArrayBooleanList list = new ArrayBooleanList();
147        for(int j=0;j<3;j++) {
148            assertTrue(list.isEmpty());
149    
150            list.trimToSize();
151    
152            assertTrue(list.isEmpty());
153            
154            for(int i=0;i<10;i++) {
155                list.add(i%2==0);
156            }
157            
158            for(int i=0;i<10;i++) {
159                assertEquals(i%2==0,list.get(i));
160            }
161            
162            list.trimToSize();
163    
164            for(int i=0;i<10;i++) {
165                assertEquals(i%2==0,list.get(i));
166            }
167    
168            for(int i=0;i<5;i++) {
169                list.removeElement(true);
170            }
171            
172            for(int i=0;i<5;i++) {
173                assertEquals(false,list.get(i));
174            }
175    
176            list.trimToSize();
177                    
178            for(int i=0;i<5;i++) {
179                assertEquals(false,list.get(i));
180            }
181
182            list.trimToSize();
183                    
184            for(int i=0;i<5;i++) {
185                assertEquals(false,list.get(i));
186            }
187    
188            list.clear();
189        }
190    }
191
192}