add tests, make 'em pass ;)

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130986 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Rodney Waldhoff 2003-03-03 23:23:40 +00:00
parent 2298039999
commit aa7cc64c4f
7 changed files with 329 additions and 46 deletions

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/Attic/AbstractIntCollection.java,v 1.4 2003/01/13 23:07:08 rwaldhoff Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/Attic/AbstractIntCollection.java,v 1.5 2003/03/03 23:23:39 rwaldhoff Exp $
* ====================================================================
* The Apache Software License, Version 1.1
*
@ -69,7 +69,7 @@ package org.apache.commons.collections.primitives;
* these methods to provide a more efficient implementation.
*
* @since Commons Collections 2.2
* @version $Revision: 1.4 $ $Date: 2003/01/13 23:07:08 $
* @version $Revision: 1.5 $ $Date: 2003/03/03 23:23:39 $
*
* @author Rodney Waldhoff
*/
@ -79,21 +79,6 @@ public abstract class AbstractIntCollection implements IntCollection {
protected AbstractIntCollection() { }
/**
* Constructs a collection containing the elements of
* the given collection, added in the order they are
* returned by that collection's iterator.
*
* @see #addAll
* @param that the non-<code>null</code> collection of <code>int</code>s
* to add
* @throws NullPointerException if <i>that</i> is <code>null</code>
* @throws UnsupportedOperationException if {@link #addAll addAll} does
*/
protected AbstractIntCollection(IntCollection that) {
addAll(that);
}
/** Unsupported in this base implementation. */
public boolean add(int element) {
throw new UnsupportedOperationException("add(int) is not supported.");

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/Attic/AbstractRandomAccessIntList.java,v 1.13 2003/03/01 00:47:28 rwaldhoff Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/Attic/AbstractRandomAccessIntList.java,v 1.14 2003/03/03 23:23:39 rwaldhoff Exp $
* ====================================================================
* The Apache Software License, Version 1.1
*
@ -74,7 +74,7 @@ import java.util.NoSuchElementException;
* to provide a more efficient implementation.
*
* @since Commons Collections 2.2
* @version $Revision: 1.13 $ $Date: 2003/03/01 00:47:28 $
* @version $Revision: 1.14 $ $Date: 2003/03/03 23:23:39 $
*
* @author Rodney Waldhoff
*/
@ -87,20 +87,6 @@ public abstract class AbstractRandomAccessIntList extends AbstractIntCollection
protected AbstractRandomAccessIntList() {
}
/**
* Constructs a list containing the elements of the given collection,
* in the order they are returned by that collection's iterator.
*
* @see #addAll
* @param that the non-<code>null</code> collection of <code>int</code>s
* to add
* @throws NullPointerException if <i>that</i> is <code>null</code>
* @throws UnsupportedOperationException if {@link #addAll addAll} does
*/
protected AbstractRandomAccessIntList(IntCollection that) {
super(that);
}
// fully abstract methods
//-------------------------------------------------------------------------
@ -275,14 +261,10 @@ public abstract class AbstractRandomAccessIntList extends AbstractIntCollection
}
protected static class RandomAccessIntListIterator extends ComodChecker implements IntListIterator {
RandomAccessIntListIterator(AbstractRandomAccessIntList list) {
this(list,0);
}
RandomAccessIntListIterator(AbstractRandomAccessIntList list, int index) {
super(list);
if(index < 0 || index > getList().size()) {
throw new IllegalArgumentException("Index " + index + " not in [0," + getList().size() + ")");
throw new IndexOutOfBoundsException("Index " + index + " not in [0," + getList().size() + ")");
} else {
_nextIndex = index;
resyncModCount();

View File

@ -0,0 +1,113 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/Attic/TestAbstractIntCollection.java,v 1.1 2003/03/03 23:23:40 rwaldhoff Exp $
* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.collections.primitives;
import java.util.Collections;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.commons.collections.primitives.adapters.IteratorIntIterator;
/**
* @version $Revision: 1.1 $ $Date: 2003/03/03 23:23:40 $
* @author Rodney Waldhoff
*/
public class TestAbstractIntCollection extends TestCase {
// conventional
// ------------------------------------------------------------------------
public TestAbstractIntCollection(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(TestAbstractIntCollection.class);
}
// tests
// ------------------------------------------------------------------------
public void testAddIsUnsupportedByDefault() {
IntCollection col = new IntCollectionImpl();
try {
col.add(1);
fail("Expected UnsupportedOperationException");
} catch(UnsupportedOperationException e) {
// expected
}
}
// inner classes
// ------------------------------------------------------------------------
static class IntCollectionImpl extends AbstractIntCollection {
public IntCollectionImpl() {
}
public IntIterator iterator() {
return new IteratorIntIterator(Collections.EMPTY_LIST.iterator());
}
public int size() {
return 0;
}
}
}

View File

@ -0,0 +1,155 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/Attic/TestAbstractRandomAccessIntList.java,v 1.1 2003/03/03 23:23:40 rwaldhoff Exp $
* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.collections.primitives;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* @version $Revision: 1.1 $ $Date: 2003/03/03 23:23:40 $
* @author Rodney Waldhoff
*/
public class TestAbstractRandomAccessIntList extends TestCase {
// conventional
// ------------------------------------------------------------------------
public TestAbstractRandomAccessIntList(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(TestAbstractRandomAccessIntList.class);
}
// tests
// ------------------------------------------------------------------------
public void testAddIsUnsupportedByDefault() {
AbstractRandomAccessIntList list = new AbstractRandomAccessIntListImpl();
try {
list.add(1);
fail("Expected UnsupportedOperationException");
} catch(UnsupportedOperationException e) {
// expected
}
try {
list.set(0,1);
fail("Expected UnsupportedOperationException");
} catch(UnsupportedOperationException e) {
// expected
}
}
public void testAddAllIsUnsupportedByDefault() {
AbstractRandomAccessIntList list = new AbstractRandomAccessIntListImpl();
IntList list2 = new ArrayIntList();
list2.add(3);
try {
list.addAll(list2);
fail("Expected UnsupportedOperationException");
} catch(UnsupportedOperationException e) {
// expected
}
}
public void testSetIsUnsupportedByDefault() {
AbstractRandomAccessIntList list = new AbstractRandomAccessIntListImpl();
try {
list.set(0,1);
fail("Expected UnsupportedOperationException");
} catch(UnsupportedOperationException e) {
// expected
}
}
public void testRemoveElementIsUnsupportedByDefault() {
AbstractRandomAccessIntList list = new AbstractRandomAccessIntListImpl();
try {
list.removeElementAt(0);
fail("Expected UnsupportedOperationException");
} catch(UnsupportedOperationException e) {
// expected
}
}
// inner classes
// ------------------------------------------------------------------------
static class AbstractRandomAccessIntListImpl extends AbstractRandomAccessIntList {
public AbstractRandomAccessIntListImpl() {
}
/**
* @see org.apache.commons.collections.primitives.IntList#get(int)
*/
public int get(int index) {
throw new IndexOutOfBoundsException();
}
/**
* @see org.apache.commons.collections.primitives.IntCollection#size()
*/
public int size() {
return 0;
}
}
}

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/Attic/TestAll.java,v 1.8 2003/02/26 19:17:23 rwaldhoff Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/Attic/TestAll.java,v 1.9 2003/03/03 23:23:40 rwaldhoff Exp $
* ====================================================================
* The Apache Software License, Version 1.1
*
@ -62,7 +62,7 @@ import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* @version $Revision: 1.8 $ $Date: 2003/02/26 19:17:23 $
* @version $Revision: 1.9 $ $Date: 2003/03/03 23:23:40 $
* @author Rodney Waldhoff
*/
public class TestAll extends TestCase {
@ -78,6 +78,9 @@ public class TestAll extends TestCase {
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(TestAbstractIntCollection.suite());
suite.addTest(TestAbstractRandomAccessIntList.suite());
suite.addTest(TestArrayIntList.suite());
suite.addTest(TestArrayUnsignedShortList.suite());

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/Attic/TestIntList.java,v 1.7 2003/03/01 00:47:28 rwaldhoff Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/Attic/TestIntList.java,v 1.8 2003/03/03 23:23:40 rwaldhoff Exp $
* ====================================================================
* The Apache Software License, Version 1.1
*
@ -58,6 +58,7 @@
package org.apache.commons.collections.primitives;
import java.io.Serializable;
import java.util.AbstractCollection;
import java.util.ArrayList;
import java.util.List;
@ -66,7 +67,7 @@ import org.apache.commons.collections.primitives.adapters.IntListList;
import org.apache.commons.collections.primitives.adapters.ListIntList;
/**
* @version $Revision: 1.7 $ $Date: 2003/03/01 00:47:28 $
* @version $Revision: 1.8 $ $Date: 2003/03/03 23:23:40 $
* @author Rodney Waldhoff
*/
public abstract class TestIntList extends TestList {
@ -297,7 +298,6 @@ public abstract class TestIntList extends TestList {
assertEquals(50,list.size());
}
public void testAddGet() {
IntList list = makeEmptyIntList();
for (int i = 0; i < 1000; i++) {
@ -378,4 +378,49 @@ public abstract class TestIntList extends TestList {
}
}
public void testListIteratorOutOfBounds() throws Exception {
try {
makeEmptyIntList().listIterator(2);
fail("Expected IndexOutOfBoundsException");
} catch(IndexOutOfBoundsException e) {
// expected
}
try {
makeFullIntList().listIterator(-1);
fail("Expected IndexOutOfBoundsException");
} catch(IndexOutOfBoundsException e) {
// expected
}
try {
makeFullIntList().listIterator(makeFullIntList().size()+2);
fail("Expected IndexOutOfBoundsException");
} catch(IndexOutOfBoundsException e) {
// expected
}
}
public void testListIteratorSetWithoutNext() throws Exception {
IntListIterator iter = makeFullIntList().listIterator();
try {
iter.set(3);
fail("Expected IllegalStateException");
} catch(IllegalStateException e) {
// expected
}
}
public void testListIteratorSetAfterRemove() throws Exception {
IntListIterator iter = makeFullIntList().listIterator();
iter.next();
iter.remove();
try {
iter.set(3);
fail("Expected IllegalStateException");
} catch(IllegalStateException e) {
// expected
}
}
}

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/adapters/Attic/TestIntListIteratorListIterator.java,v 1.1 2003/03/01 00:47:29 rwaldhoff Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/adapters/Attic/TestIntListIteratorListIterator.java,v 1.2 2003/03/03 23:23:40 rwaldhoff Exp $
* ====================================================================
* The Apache Software License, Version 1.1
*
@ -69,7 +69,7 @@ import org.apache.commons.collections.primitives.IntList;
/**
* @todo should extend TestListIterator when there is one
* @version $Revision: 1.1 $ $Date: 2003/03/01 00:47:29 $
* @version $Revision: 1.2 $ $Date: 2003/03/03 23:23:40 $
* @author Rodney Waldhoff
*/
public class TestIntListIteratorListIterator extends TestIterator {
@ -82,7 +82,7 @@ public class TestIntListIteratorListIterator extends TestIterator {
}
public static Test suite() {
return new TestSuite(TestIntIteratorIterator.class);
return new TestSuite(TestIntListIteratorListIterator.class);
}
// collections testing framework