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 TestArrayDoubleList extends TestDoubleList { 029 030 // conventional 031 // ------------------------------------------------------------------------ 032 033 public TestArrayDoubleList(String testName) { 034 super(testName); 035 } 036 037 public static Test suite() { 038 TestSuite suite = BulkTest.makeSuite(TestArrayDoubleList.class); 039 return suite; 040 } 041 042 // collections testing framework 043 // ------------------------------------------------------------------------ 044 045 protected DoubleList makeEmptyDoubleList() { 046 return new ArrayDoubleList(); 047 } 048 049 public String[] ignoredTests() { 050 // sublists are not serializable 051 return new String[] { 052 "TestArrayDoubleList.bulkTestSubList.testFullListSerialization", 053 "TestArrayDoubleList.bulkTestSubList.testEmptyListSerialization", 054 "TestArrayDoubleList.bulkTestSubList.testCanonicalEmptyCollectionExists", 055 "TestArrayDoubleList.bulkTestSubList.testCanonicalFullCollectionExists", 056 "TestArrayDoubleList.bulkTestSubList.testEmptyListCompatibility", 057 "TestArrayDoubleList.bulkTestSubList.testFullListCompatibility", 058 "TestArrayDoubleList.bulkTestSubList.testSerializeDeserializeThenCompare", 059 "TestArrayDoubleList.bulkTestSubList.testSimpleSerialization" 060 }; 061 } 062 063 // tests 064 // ------------------------------------------------------------------------ 065 066 /** @TODO need to add serialized form to cvs */ 067 public void testCanonicalEmptyCollectionExists() { 068 // XXX FIX ME XXX 069 // need to add a serialized form to cvs 070 } 071 072 public void testCanonicalFullCollectionExists() { 073 // XXX FIX ME XXX 074 // need to add a serialized form to cvs 075 } 076 077 public void testEmptyListCompatibility() { 078 // XXX FIX ME XXX 079 // need to add a serialized form to cvs 080 } 081 082 public void testFullListCompatibility() { 083 // XXX FIX ME XXX 084 // need to add a serialized form to cvs 085 } 086 087 public void testAddGetLargeValues() { 088 DoubleList list = new ArrayDoubleList(); 089 for (int i = 0; i < 1000; i++) { 090 double value = ((double) (Double.MAX_VALUE)); 091 value -= i; 092 list.add(value); 093 } 094 for (int i = 0; i < 1000; i++) { 095 double value = ((double) (Double.MAX_VALUE)); 096 value -= i; 097 assertEquals(value, list.get(i), 0f); 098 } 099 } 100 101 public void testZeroInitialCapacityIsValid() { 102 assertNotNull(new ArrayDoubleList(0)); 103 } 104 105 public void testNegativeInitialCapacityIsInvalid() { 106 try { 107 new ArrayDoubleList(-1); 108 fail("Expected IllegalArgumentException"); 109 } catch(IllegalArgumentException e) { 110 // expected 111 } 112 } 113 114 public void testCopyConstructor() { 115 ArrayDoubleList expected = new ArrayDoubleList(); 116 for(int i=0;i<10;i++) { 117 expected.add((double)i); 118 } 119 ArrayDoubleList list = new ArrayDoubleList(expected); 120 assertEquals(10,list.size()); 121 assertEquals(expected,list); 122 } 123 124 public void testCopyConstructorWithNull() { 125 try { 126 new ArrayDoubleList((DoubleCollection) null); 127 fail("Expected NullPointerException"); 128 } catch(NullPointerException e) { 129 // expected 130 } 131 } 132 133 public void testArrayConstructor() { 134 ArrayDoubleList expected = new ArrayDoubleList(); 135 for (int i = 0; i < 10; i++) { 136 expected.add((double) i); 137 } 138 ArrayDoubleList list = new ArrayDoubleList(expected.toArray()); 139 assertEquals(10, list.size()); 140 assertEquals(expected, list); 141 } 142 143 public void testArrayConstructorWithNull() { 144 try { 145 new ArrayDoubleList((double[]) null); 146 fail("Expected NullPointerException"); 147 } catch (NullPointerException e) { 148 // expected 149 } 150 } 151 152 153 public void testTrimToSize() { 154 ArrayDoubleList list = new ArrayDoubleList(); 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((double)i); 164 } 165 166 for(int i=0;i<10;i++) { 167 assertEquals((double)i,list.get(i), 0f); 168 } 169 170 list.trimToSize(); 171 172 for(int i=0;i<10;i++) { 173 assertEquals((double)i,list.get(i), 0f); 174 } 175 176 for(int i=0;i<10;i+=2) { 177 list.removeElement((double)i); 178 } 179 180 for(int i=0;i<5;i++) { 181 assertEquals((double)(2*i)+1,list.get(i), 0f); 182 } 183 184 list.trimToSize(); 185 186 for(int i=0;i<5;i++) { 187 assertEquals((double)(2*i)+1,list.get(i), 0f); 188 } 189 190 list.trimToSize(); 191 192 for(int i=0;i<5;i++) { 193 assertEquals((double)(2*i)+1,list.get(i), 0f); 194 } 195 196 list.clear(); 197 } 198 } 199 200}