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 TestArrayUnsignedIntList extends TestLongList { 029 030 // conventional 031 // ------------------------------------------------------------------------ 032 033 public TestArrayUnsignedIntList(String testName) { 034 super(testName); 035 } 036 037 public static Test suite() { 038 TestSuite suite = BulkTest.makeSuite(TestArrayUnsignedIntList.class); 039 return suite; 040 } 041 042 // collections testing framework 043 // ------------------------------------------------------------------------ 044 045 protected LongList makeEmptyLongList() { 046 return new ArrayUnsignedIntList(); 047 } 048 049 public String[] ignoredTests() { 050 // sublists are not serializable 051 return new String[] { 052 "TestArrayUnsignedLongList.bulkTestSubList.testFullListSerialization", 053 "TestArrayUnsignedLongList.bulkTestSubList.testEmptyListSerialization", 054 "TestArrayUnsignedLongList.bulkTestSubList.testCanonicalEmptyCollectionExists", 055 "TestArrayUnsignedLongList.bulkTestSubList.testCanonicalFullCollectionExists", 056 "TestArrayUnsignedLongList.bulkTestSubList.testEmptyListCompatibility", 057 "TestArrayUnsignedLongList.bulkTestSubList.testFullListCompatibility", 058 "TestArrayUnsignedLongList.bulkTestSubList.testSerializeDeserializeThenCompare", 059 "TestArrayUnsignedLongList.bulkTestSubList.testSimpleSerialization" 060 }; 061 } 062 063 protected long[] getFullLongs() { 064 long[] result = new long[19]; 065 for(int i = 0; i < result.length; i++) { 066 result[i] = ((long)Integer.MAX_VALUE - 1L - (long)i); 067 } 068 return result; 069 } 070 071 // tests 072 // ------------------------------------------------------------------------ 073 074 public void testArrayConstructor() { 075 long[] data = new long[] { 1, 2, 3 }; 076 LongList list = new ArrayUnsignedIntList(data); 077 for(int i=0;i<data.length;i++) { 078 assertEquals(data[i],list.get(i)); 079 } 080 data[0] = 17; 081 assertEquals(1,list.get(0)); 082 } 083 084 // @TODO need to add serialized form to cvs 085 public void testCanonicalEmptyCollectionExists() { 086 // XXX FIX ME XXX 087 // need to add a serialized form to cvs 088 } 089 090 public void testCanonicalFullCollectionExists() { 091 // XXX FIX ME XXX 092 // need to add a serialized form to cvs 093 } 094 095 public void testEmptyListCompatibility() { 096 // XXX FIX ME XXX 097 // need to add a serialized form to cvs 098 } 099 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 ArrayUnsignedIntList(0)); 107 } 108 109 public void testIllegalArgumentExceptionWhenElementOutOfRange() { 110 ArrayUnsignedIntList list = new ArrayUnsignedIntList(); 111 list.add(ArrayUnsignedIntList.MIN_VALUE); 112 list.add(ArrayUnsignedIntList.MAX_VALUE); 113 try { 114 list.add(-1); 115 fail("Expected IllegalArgumentException"); 116 } catch(IllegalArgumentException e) { 117 // expected 118 } 119 try { 120 list.add(ArrayUnsignedIntList.MAX_VALUE+1); 121 fail("Expected IllegalArgumentException"); 122 } catch(IllegalArgumentException e) { 123 // expected 124 } 125 } 126 127 public void testNegativeInitialCapacityIsInvalid() { 128 try { 129 new ArrayUnsignedIntList(-1); 130 fail("Expected IllegalArgumentException"); 131 } catch(IllegalArgumentException e) { 132 // expected 133 } 134 } 135 136 public void testCopyConstructor() { 137 ArrayUnsignedIntList expected = new ArrayUnsignedIntList(); 138 for(int i=0;i<10;i++) { 139 expected.add(i); 140 } 141 ArrayUnsignedIntList list = new ArrayUnsignedIntList(expected); 142 assertEquals(10,list.size()); 143 assertEquals(expected,list); 144 } 145 146 public void testCopyConstructorWithNull() { 147 try { 148 new ArrayUnsignedIntList((LongList)null); 149 fail("Expected NullPointerException"); 150 } catch(NullPointerException e) { 151 // expected 152 } 153 } 154 155 156 public void testTrimToSize() { 157 ArrayUnsignedIntList list = new ArrayUnsignedIntList(); 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(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(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}