scolebourne 2003/07/12 08:11:26
Modified: collections/src/test/org/apache/commons/collections
TestList.java TestCollection.java
TestBoundedFifoBuffer.java
TestCircularFifoBuffer.java
TestUnboundedFifoBuffer.java TestSet.java
TestBinaryHeap.java
collections/src/test/org/apache/commons/collections/decorators
TestTransformedCollection.java
Log:
Added more controlling if methods into Collection test hierarchy
- isNullSupported
- isFailFastSupported
Revision Changes Path
1.18 +74 -75
jakarta-commons/collections/src/test/org/apache/commons/collections/TestList.java
Index: TestList.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestList.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- TestList.java 26 Apr 2003 10:27:59 -0000 1.17
+++ TestList.java 12 Jul 2003 15:11:25 -0000 1.18
@@ -91,11 +91,77 @@
*/
public abstract class TestList extends TestCollection {
-
+ /**
+ * Constructor.
+ * @param testName
+ */
public TestList(String testName) {
super(testName);
}
+ //-----------------------------------------------------------------------
+ /**
+ * Returns true if the collections produced by
+ * [EMAIL PROTECTED] #makeCollection()} and [EMAIL PROTECTED]
#makeFullCollection()}
+ * support the <code>set</code> operation.<p>
+ * Default implementation returns true. Override if your collection
+ * class does not support set.
+ */
+ protected boolean isSetSupported() {
+ return true;
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Verifies that the test list implementation matches the confirmed list
+ * implementation.
+ */
+ protected void verify() {
+ super.verify();
+
+ List list1 = getList();
+ List list2 = getConfirmedList();
+
+ assertEquals("List should equal confirmed", list1, list2);
+ assertEquals("Confirmed should equal list", list2, list1);
+
+ assertEquals("Hash codes should be equal",
+ list1.hashCode(), list2.hashCode());
+
+ int i = 0;
+ Iterator iterator1 = list1.iterator();
+ Iterator iterator2 = list2.iterator();
+ Object[] array = list1.toArray();
+ while (iterator2.hasNext()) {
+ assertTrue("List iterator should have next", iterator1.hasNext());
+ Object o1 = iterator1.next();
+ Object o2 = iterator2.next();
+ assertEquals("Iterator elements should be equal", o1, o2);
+ o2 = list1.get(i);
+ assertEquals("get should return correct element", o1, o2);
+ o2 = array[i];
+ assertEquals("toArray should have correct element", o1, o2);
+ i++;
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Returns an empty [EMAIL PROTECTED] ArrayList}.
+ */
+ protected Collection makeConfirmedCollection() {
+ ArrayList list = new ArrayList();
+ return list;
+ }
+
+ /**
+ * Returns a full [EMAIL PROTECTED] ArrayList}.
+ */
+ protected Collection makeConfirmedFullCollection() {
+ ArrayList list = new ArrayList();
+ list.addAll(Arrays.asList(getFullElements()));
+ return list;
+ }
/**
* Return a new, empty [EMAIL PROTECTED] List} to be used for testing.
@@ -104,7 +170,6 @@
*/
protected abstract List makeEmptyList();
-
/**
* Return a new, full [EMAIL PROTECTED] List} to be used for testing.
*
@@ -117,7 +182,6 @@
return list;
}
-
/**
* Returns [EMAIL PROTECTED] makeEmptyList()}.
*
@@ -127,7 +191,6 @@
return makeEmptyList();
}
-
/**
* Returns [EMAIL PROTECTED] makeFullList()}.
*
@@ -137,19 +200,7 @@
return makeFullList();
}
-
- /**
- * Returns true if the collections produced by
- * [EMAIL PROTECTED] #makeCollection()} and [EMAIL PROTECTED]
#makeFullCollection()}
- * support the <code>set</code> operation.<p>
- * Default implementation returns true. Override if your collection
- * class does not support set.
- */
- protected boolean isSetSupported() {
- return true;
- }
-
-
+ //-----------------------------------------------------------------------
/**
* Returns the [EMAIL PROTECTED] collection} field cast to a [EMAIL PROTECTED]
List}.
*
@@ -159,7 +210,6 @@
return (List)collection;
}
-
/**
* Returns the [EMAIL PROTECTED] confirmed} field cast to a [EMAIL PROTECTED]
List}.
*
@@ -169,7 +219,7 @@
return (List)confirmed;
}
-
+ //-----------------------------------------------------------------------
/**
* Tests bounds checking for [EMAIL PROTECTED] List#add(int, Object)} on an
* empty list.
@@ -952,60 +1002,7 @@
}
}
-
- /**
- * Returns an empty [EMAIL PROTECTED] ArrayList}.
- */
- protected Collection makeConfirmedCollection() {
- ArrayList list = new ArrayList();
- return list;
- }
-
-
- /**
- * Returns a full [EMAIL PROTECTED] ArrayList}.
- */
- protected Collection makeConfirmedFullCollection() {
- ArrayList list = new ArrayList();
- list.addAll(Arrays.asList(getFullElements()));
- return list;
- }
-
-
- /**
- * Verifies that the test list implementation matches the confirmed list
- * implementation.
- */
- protected void verify() {
- super.verify();
-
- List list1 = getList();
- List list2 = getConfirmedList();
-
- assertEquals("List should equal confirmed", list1, list2);
- assertEquals("Confirmed should equal list", list2, list1);
-
- assertEquals("Hash codes should be equal",
- list1.hashCode(), list2.hashCode());
-
- int i = 0;
- Iterator iterator1 = list1.iterator();
- Iterator iterator2 = list2.iterator();
- Object[] array = list1.toArray();
- while (iterator2.hasNext()) {
- assertTrue("List iterator should have next", iterator1.hasNext());
- Object o1 = iterator1.next();
- Object o2 = iterator2.next();
- assertEquals("Iterator elements should be equal", o1, o2);
- o2 = list1.get(i);
- assertEquals("get should return correct element", o1, o2);
- o2 = array[i];
- assertEquals("toArray should have correct element", o1, o2);
- i++;
- }
- }
-
-
+ //-----------------------------------------------------------------------
/**
* Returns a [EMAIL PROTECTED] BulkTest} for testing [EMAIL PROTECTED]
List#subList(int,int)}.
* The returned bulk test will run through every <Code>TestList</Code>
@@ -1095,6 +1092,7 @@
* if elements are added to the original list.
*/
public void testListSubListFailFastOnAdd() {
+ if (!isFailFastSupported()) return;
if (!isAddSupported()) return;
resetFull();
@@ -1126,6 +1124,7 @@
* if elements are removed from the original list.
*/
public void testListSubListFailFastOnRemove() {
+ if (!isFailFastSupported()) return;
if (!isRemoveSupported()) return;
resetFull();
1.12 +128 -109
jakarta-commons/collections/src/test/org/apache/commons/collections/TestCollection.java
Index: TestCollection.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestCollection.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- TestCollection.java 9 May 2003 18:34:19 -0000 1.11
+++ TestCollection.java 12 Jul 2003 15:11:25 -0000 1.12
@@ -58,7 +58,6 @@
* <http://www.apache.org/>.
*
*/
-
package org.apache.commons.collections;
import java.lang.reflect.Array;
@@ -73,35 +72,35 @@
import java.util.Map;
import java.util.NoSuchElementException;
-
/**
* Tests base [EMAIL PROTECTED] java.util.Collection} methods and contracts.
* <p>
* You should create a concrete subclass of this class to test any custom
* [EMAIL PROTECTED] Collection} implementation. At minimum, you'll have to
* implement the [EMAIL PROTECTED] #makeCollection()} method. You might want to
- * override some of the additional protected methods as well:<P>
- *
- * <B>Element Population Methods</B><P>
- *
+ * override some of the additional protected methods as well:
+ * <p>
+ * <B>Element Population Methods</B>
+ * <p>
* Override these if your collection restricts what kind of elements are
* allowed (for instance, if <Code>null</Code> is not permitted):
* <UL>
* <Li>[EMAIL PROTECTED] #getFullElements()}
* <Li>[EMAIL PROTECTED] #getOtherElements()}
* </UL>
- *
- * <B>Supported Operation Methods</B><P>
- *
+ * <p>
+ * <B>Supported Operation Methods</B>
+ * <p>
* Override these if your collection doesn't support certain operations:
* <UL>
* <LI>[EMAIL PROTECTED] #isAddSuppoted()}
* <LI>[EMAIL PROTECTED] #isRemoveSupported()}
* <li>[EMAIL PROTECTED] #areEqualElementsDistinguishable()}
+ * <LI>[EMAIL PROTECTED] #isNullSupported()}
* </UL>
- *
- * <B>Fixture Methods</B><P>
- *
+ * <p>
+ * <B>Fixture Methods</B>
+ * <p>
* Fixtures are used to verify that the the operation results in correct state
* for the collection. Basically, the operation is performed against your
* collection implementation, and an identical operation is performed against a
@@ -113,50 +112,51 @@
* if their state is identical. The comparison is usually much more involved
* than a simple <Code>equals</Code> test. This verification is used to ensure
* proper modifications are made along with ensuring that the collection does
- * not change when read-only modifications are made.<P>
- *
+ * not change when read-only modifications are made.
+ * <p>
* The [EMAIL PROTECTED] #collection} field holds an instance of your collection
* implementation; the [EMAIL PROTECTED] #confirmed} field holds an instance of the
* confirmed collection implementation. The [EMAIL PROTECTED] #resetEmpty()} and
* [EMAIL PROTECTED] #resetFull()} methods set these fields to empty or full
collections,
- * so that tests can proceed from a known state.<P>
- *
+ * so that tests can proceed from a known state.
+ * <p>
* After a modification operation to both [EMAIL PROTECTED] #collection} and
* [EMAIL PROTECTED] #confirmed}, the [EMAIL PROTECTED] #verify()} method is
invoked to compare
* the results. You may want to override [EMAIL PROTECTED] #verify()} to perform
* additional verifications. For instance, when testing the collection
* views of a map, [EMAIL PROTECTED] TestMap} would override [EMAIL PROTECTED]
#verify()} to make
* sure the map is changed after the collection view is changed.
- *
+ * <p>
* If you're extending this class directly, you will have to provide
* implementations for the following:
* <UL>
* <LI>[EMAIL PROTECTED] #makeConfirmedCollection()}
* <LI>[EMAIL PROTECTED] #makeConfirmedFullCollection()}
* </UL>
- *
+ * <p>
* Those methods should provide a confirmed collection implementation
- * that's compatible with your collection implementation.<P>
- *
+ * that's compatible with your collection implementation.
+ * <p>
* If you're extending [EMAIL PROTECTED] TestList}, [EMAIL PROTECTED] TestSet},
* or [EMAIL PROTECTED] TestBag}, you probably don't have to worry about the
* above methods, because those three classes already override the methods
* to provide standard JDK confirmed collections.<P>
- *
- * <B>Other notes</B><P>
- *
+ * <p>
+ * <B>Other notes</B>
+ * <p>
* If your [EMAIL PROTECTED] Collection} fails one of these tests by design,
* you may still use this base set of cases. Simply override the
* test case (method) your [EMAIL PROTECTED] Collection} fails. For instance, the
* [EMAIL PROTECTED] #testIteratorFailFast()} method is provided since most
collections
* have fail-fast iterators; however, that's not strictly required by the
* collection contract, so you may want to override that method to do
- * nothing.<P>
+ * nothing.
*
* @author Rodney Waldhoff
* @author Paul Jack
* @author <a href="mailto:[EMAIL PROTECTED]">Michael A. Smith</a>
* @author Neil O'Toole
+ * @author Stephen Colebourne
* @version $Id$
*/
public abstract class TestCollection extends TestObject {
@@ -190,33 +190,16 @@
*/
protected Collection confirmed;
-
- public TestCollection(String testName) {
- super(testName);
- }
-
-
- /**
- * Resets the [EMAIL PROTECTED] #collection} and [EMAIL PROTECTED] #confirmed}
fields to empty
- * collections. Invoke this method before performing a modification
- * test.
- */
- protected void resetEmpty() {
- this.collection = makeCollection();
- this.confirmed = makeConfirmedCollection();
- }
-
-
/**
- * Resets the [EMAIL PROTECTED] #collection} and [EMAIL PROTECTED] #confirmed}
fields to full
- * collections. Invoke this method before performing a modification
- * test.
+ * Constructor.
+ *
+ * @param testName the test name
*/
- protected void resetFull() {
- this.collection = makeFullCollection();
- this.confirmed = makeConfirmedFullCollection();
+ public TestCollection(String testName) {
+ super(testName);
}
+ //-----------------------------------------------------------------------
/**
* Specifies whether equal elements in the collection are, in fact,
* distinguishable with information not readily available. That is, if a
@@ -244,6 +227,48 @@
}
/**
+ * Returns true if the collections produced by
+ * [EMAIL PROTECTED] #makeCollection()} and [EMAIL PROTECTED]
#makeFullCollection()}
+ * support the <Code>add</Code> and <Code>addAll</Code>
+ * operations.<P>
+ * Default implementation returns true. Override if your collection
+ * class does not support add or addAll.
+ */
+ protected boolean isAddSupported() {
+ return true;
+ }
+
+ /**
+ * Returns true if the collections produced by
+ * [EMAIL PROTECTED] #makeCollection()} and [EMAIL PROTECTED]
#makeFullCollection()}
+ * support the <Code>remove</Code>, <Code>removeAll</Code>,
+ * <Code>retainAll</Code>, <Code>clear</Code> and
+ * <Code>iterator().remove()</Code> methods.
+ * Default implementation returns true. Override if your collection
+ * class does not support removal operations.
+ */
+ protected boolean isRemoveSupported() {
+ return true;
+ }
+
+ /**
+ * Returns true to indicate that the collection supports holding null.
+ * The default implementation returns true;
+ */
+ protected boolean isNullSupported() {
+ return true;
+ }
+
+ /**
+ * Returns true to indicate that the collection supports fail fast iterators.
+ * The default implementation returns true;
+ */
+ protected boolean isFailFastSupported() {
+ return false;
+ }
+
+ //-----------------------------------------------------------------------
+ /**
* Verifies that [EMAIL PROTECTED] #collection} and [EMAIL PROTECTED]
#confirmed} have
* identical state.
*/
@@ -315,7 +340,28 @@
}
}
-
+ //-----------------------------------------------------------------------
+ /**
+ * Resets the [EMAIL PROTECTED] #collection} and [EMAIL PROTECTED] #confirmed}
fields to empty
+ * collections. Invoke this method before performing a modification
+ * test.
+ */
+ protected void resetEmpty() {
+ this.collection = makeCollection();
+ this.confirmed = makeConfirmedCollection();
+ }
+
+ /**
+ * Resets the [EMAIL PROTECTED] #collection} and [EMAIL PROTECTED] #confirmed}
fields to full
+ * collections. Invoke this method before performing a modification
+ * test.
+ */
+ protected void resetFull() {
+ this.collection = makeFullCollection();
+ this.confirmed = makeConfirmedFullCollection();
+ }
+
+ //-----------------------------------------------------------------------
/**
* Returns a confirmed empty collection.
* For instance, an [EMAIL PROTECTED] java.util.ArrayList} for lists or a
@@ -325,8 +371,6 @@
*/
protected abstract Collection makeConfirmedCollection();
-
-
/**
* Returns a confirmed full collection.
* For instance, an [EMAIL PROTECTED] java.util.ArrayList} for lists or a
@@ -337,52 +381,54 @@
*/
protected abstract Collection makeConfirmedFullCollection();
+ /**
+ * Return a new, empty [EMAIL PROTECTED] Collection} to be used for testing.
+ */
+ protected abstract Collection makeCollection();
/**
- * Returns true if the collections produced by
- * [EMAIL PROTECTED] #makeCollection()} and [EMAIL PROTECTED]
#makeFullCollection()}
- * support the <Code>add</Code> and <Code>addAll</Code>
- * operations.<P>
- * Default implementation returns true. Override if your collection
- * class does not support add or addAll.
+ * Returns a full collection to be used for testing. The collection
+ * returned by this method should contain every element returned by
+ * [EMAIL PROTECTED] #getFullElements()}. The default implementation, in fact,
+ * simply invokes <Code>addAll</Code> on an empty collection with
+ * the results of [EMAIL PROTECTED] #getFullElements()}. Override this default
+ * if your collection doesn't support addAll.
*/
- protected boolean isAddSupported() {
- return true;
+ protected Collection makeFullCollection() {
+ Collection c = makeCollection();
+ c.addAll(Arrays.asList(getFullElements()));
+ return c;
}
-
/**
- * Returns true if the collections produced by
- * [EMAIL PROTECTED] #makeCollection()} and [EMAIL PROTECTED]
#makeFullCollection()}
- * support the <Code>remove</Code>, <Code>removeAll</Code>,
- * <Code>retainAll</Code>, <Code>clear</Code> and
- * <Code>iterator().remove()</Code> methods.
- * Default implementation returns true. Override if your collection
- * class does not support removal operations.
+ * Returns an empty collection for Object tests.
*/
- protected boolean isRemoveSupported() {
- return true;
+ protected Object makeObject() {
+ return makeCollection();
}
-
+ //-----------------------------------------------------------------------
/**
* Returns an array of objects that are contained in a collection
* produced by [EMAIL PROTECTED] #makeFullCollection()}. Every element in the
* returned array <I>must</I> be an element in a full collection.<P>
* The default implementation returns a heterogenous array of
- * objects with some duplicates and with the null element.
+ * objects with some duplicates. null is added if allowed.
* Override if you require specific testing elements. Note that if you
* override [EMAIL PROTECTED] #makeFullCollection()}, you <I>must</I> override
* this method to reflect the contents of a full collection.
*/
protected Object[] getFullElements() {
- ArrayList list = new ArrayList();
- list.addAll(Arrays.asList(getFullNonNullElements()));
- list.add(4, null);
- return list.toArray();
+ if (isNullSupported()) {
+ ArrayList list = new ArrayList();
+ list.addAll(Arrays.asList(getFullNonNullElements()));
+ list.add(4, null);
+ return list.toArray();
+ } else {
+ return (Object[]) getFullNonNullElements().clone();
+ }
}
-
/**
* Returns an array of elements that are <I>not</I> contained in a
* full collection. Every element in the returned array must
@@ -396,36 +442,7 @@
return getOtherNonNullElements();
}
-
- /**
- * Return a new, empty [EMAIL PROTECTED] Collection} to be used for testing.
- */
- protected abstract Collection makeCollection();
-
-
- /**
- * Returns a full collection to be used for testing. The collection
- * returned by this method should contain every element returned by
- * [EMAIL PROTECTED] #getFullElements()}. The default implementation, in fact,
- * simply invokes <Code>addAll</Code> on an empty collection with
- * the results of [EMAIL PROTECTED] #getFullElements()}. Override this default
- * if your collection doesn't support addAll.
- */
- protected Collection makeFullCollection() {
- Collection c = makeCollection();
- c.addAll(Arrays.asList(getFullElements()));
- return c;
- }
-
-
- /**
- * Returns an empty collection for Object tests.
- */
- public Object makeObject() {
- return makeCollection();
- }
-
-
+ //-----------------------------------------------------------------------
/**
* Tests [EMAIL PROTECTED] Collection#add(Object)}.
*/
@@ -1137,6 +1154,8 @@
* Tests that the collection's iterator is fail-fast.
*/
public void testCollectionIteratorFailFast() {
+ if (!isFailFastSupported()) return;
+
if (isAddSupported()) {
resetFull();
try {
1.6 +41 -36
jakarta-commons/collections/src/test/org/apache/commons/collections/TestBoundedFifoBuffer.java
Index: TestBoundedFifoBuffer.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestBoundedFifoBuffer.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TestBoundedFifoBuffer.java 26 Apr 2003 15:12:28 -0000 1.5
+++ TestBoundedFifoBuffer.java 12 Jul 2003 15:11:25 -0000 1.6
@@ -78,21 +78,48 @@
return BulkTest.makeSuite(TestBoundedFifoBuffer.class);
}
+ //-----------------------------------------------------------------------
/**
- * Returns an empty BoundedFifoBuffer that won't overflow.
- *
- * @return an empty BoundedFifoBuffer
+ * Runs through the regular verifications, but also verifies that
+ * the buffer contains the same elements in the same sequence as the
+ * list.
*/
- public Collection makeCollection() {
- return new BoundedFifoBuffer(100);
+ protected void verify() {
+ super.verify();
+ Iterator iterator1 = collection.iterator();
+ Iterator iterator2 = confirmed.iterator();
+ while (iterator2.hasNext()) {
+ assertTrue(iterator1.hasNext());
+ Object o1 = iterator1.next();
+ Object o2 = iterator2.next();
+ assertEquals(o1, o2);
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Overridden because UnboundedFifoBuffer doesn't allow null elements.
+ * @return false
+ */
+ protected boolean isNullSupported() {
+ return false;
+ }
+
+ /**
+ * Overridden because UnboundedFifoBuffer isn't fail fast.
+ * @return false
+ */
+ protected boolean isFailFastSupported() {
+ return false;
}
+ //-----------------------------------------------------------------------
/**
* Returns an empty ArrayList.
*
* @return an empty ArrayList
*/
- public Collection makeConfirmedCollection() {
+ protected Collection makeConfirmedCollection() {
return new ArrayList();
}
@@ -101,44 +128,22 @@
*
* @return a full ArrayList
*/
- public Collection makeConfirmedFullCollection() {
+ protected Collection makeConfirmedFullCollection() {
Collection c = makeConfirmedCollection();
c.addAll(java.util.Arrays.asList(getFullElements()));
return c;
}
/**
- * Overridden because BoundedFifoBuffer doesn't support null elements.
- *
- * @return an array of random objects without a null element
- */
- public Object[] getFullElements() {
- return getFullNonNullElements();
- }
-
- /**
- * Overridden, because BoundedFifoBuffer's iterators aren't fail-fast.
- */
- public void testCollectionIteratorFailFast() {
- }
-
- /**
- * Runs through the regular verifications, but also verifies that
- * the buffer contains the same elements in the same sequence as the
- * list.
+ * Returns an empty BoundedFifoBuffer that won't overflow.
+ *
+ * @return an empty BoundedFifoBuffer
*/
- public void verify() {
- super.verify();
- Iterator iterator1 = collection.iterator();
- Iterator iterator2 = confirmed.iterator();
- while (iterator2.hasNext()) {
- assertTrue(iterator1.hasNext());
- Object o1 = iterator1.next();
- Object o2 = iterator2.next();
- assertEquals(o1, o2);
- }
+ protected Collection makeCollection() {
+ return new BoundedFifoBuffer(100);
}
+ //-----------------------------------------------------------------------
/**
* Tests that the removal operation actually removes the first element.
*/
1.2 +42 -37
jakarta-commons/collections/src/test/org/apache/commons/collections/TestCircularFifoBuffer.java
Index: TestCircularFifoBuffer.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestCircularFifoBuffer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestCircularFifoBuffer.java 26 Apr 2003 15:13:22 -0000 1.1
+++ TestCircularFifoBuffer.java 12 Jul 2003 15:11:25 -0000 1.2
@@ -81,21 +81,48 @@
return BulkTest.makeSuite(TestCircularFifoBuffer.class);
}
+ //-----------------------------------------------------------------------
/**
- * Returns an empty BoundedFifoBuffer that won't overflow.
- *
- * @return an empty BoundedFifoBuffer
+ * Runs through the regular verifications, but also verifies that
+ * the buffer contains the same elements in the same sequence as the
+ * list.
*/
- public Collection makeCollection() {
- return new CircularFifoBuffer(100);
+ protected void verify() {
+ super.verify();
+ Iterator iterator1 = collection.iterator();
+ Iterator iterator2 = confirmed.iterator();
+ while (iterator2.hasNext()) {
+ assertTrue(iterator1.hasNext());
+ Object o1 = iterator1.next();
+ Object o2 = iterator2.next();
+ assertEquals(o1, o2);
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Overridden because UnboundedFifoBuffer doesn't allow null elements.
+ * @return false
+ */
+ protected boolean isNullSupported() {
+ return false;
+ }
+
+ /**
+ * Overridden because UnboundedFifoBuffer isn't fail fast.
+ * @return false
+ */
+ protected boolean isFailFastSupported() {
+ return false;
}
+ //-----------------------------------------------------------------------
/**
* Returns an empty ArrayList.
*
* @return an empty ArrayList
*/
- public Collection makeConfirmedCollection() {
+ protected Collection makeConfirmedCollection() {
return new ArrayList();
}
@@ -104,44 +131,22 @@
*
* @return a full ArrayList
*/
- public Collection makeConfirmedFullCollection() {
+ protected Collection makeConfirmedFullCollection() {
Collection c = makeConfirmedCollection();
c.addAll(java.util.Arrays.asList(getFullElements()));
return c;
}
/**
- * Overridden because CircularFifoBuffer doesn't support null elements.
- *
- * @return an array of random objects without a null element
- */
- public Object[] getFullElements() {
- return getFullNonNullElements();
- }
-
- /**
- * Overridden, because CircularFifoBuffer's iterators aren't fail-fast.
- */
- public void testCollectionIteratorFailFast() {
- }
-
- /**
- * Runs through the regular verifications, but also verifies that
- * the buffer contains the same elements in the same sequence as the
- * list.
+ * Returns an empty BoundedFifoBuffer that won't overflow.
+ *
+ * @return an empty BoundedFifoBuffer
*/
- public void verify() {
- super.verify();
- Iterator iterator1 = collection.iterator();
- Iterator iterator2 = confirmed.iterator();
- while (iterator2.hasNext()) {
- assertTrue(iterator1.hasNext());
- Object o1 = iterator1.next();
- Object o2 = iterator2.next();
- assertEquals(o1, o2);
- }
+ protected Collection makeCollection() {
+ return new CircularFifoBuffer(100);
}
+ //-----------------------------------------------------------------------
/**
* Tests that the removal operation actually removes the first element.
*/
1.5 +40 -41
jakarta-commons/collections/src/test/org/apache/commons/collections/TestUnboundedFifoBuffer.java
Index: TestUnboundedFifoBuffer.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestUnboundedFifoBuffer.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TestUnboundedFifoBuffer.java 19 Feb 2003 20:33:11 -0000 1.4
+++ TestUnboundedFifoBuffer.java 12 Jul 2003 15:11:25 -0000 1.5
@@ -78,72 +78,71 @@
return BulkTest.makeSuite(TestUnboundedFifoBuffer.class);
}
+ //-----------------------------------------------------------------------
/**
- * Returns an empty UnboundedFifoBuffer with a small capacity.
- *
- * @return an empty UnboundedFifoBuffer
+ * Verifies that the ArrayList has the same elements in the same
+ * sequence as the UnboundedFifoBuffer.
*/
- public Collection makeCollection() {
- return new UnboundedFifoBuffer(5);
+ protected void verify() {
+ super.verify();
+ Iterator iterator1 = collection.iterator();
+ Iterator iterator2 = confirmed.iterator();
+ while (iterator2.hasNext()) {
+ assertTrue(iterator1.hasNext());
+ Object o1 = iterator1.next();
+ Object o2 = iterator2.next();
+ assertEquals(o1, o2);
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Overridden because UnboundedFifoBuffer doesn't allow null elements.
+ * @return false
+ */
+ protected boolean isNullSupported() {
+ return false;
}
+ /**
+ * Overridden because UnboundedFifoBuffer isn't fail fast.
+ * @return false
+ */
+ protected boolean isFailFastSupported() {
+ return false;
+ }
+ //-----------------------------------------------------------------------
/**
* Returns an empty ArrayList.
*
* @return an empty ArrayList
*/
- public Collection makeConfirmedCollection() {
+ protected Collection makeConfirmedCollection() {
return new ArrayList();
}
-
/**
* Returns a full ArrayList.
*
* @return a full ArrayList
*/
- public Collection makeConfirmedFullCollection() {
+ protected Collection makeConfirmedFullCollection() {
Collection c = makeConfirmedCollection();
c.addAll(java.util.Arrays.asList(getFullElements()));
return c;
}
-
/**
- * Overridden because UnboundedFifoBuffer doesn't allow null elements.
+ * Returns an empty UnboundedFifoBuffer with a small capacity.
*
- * @return an array of random elements without the null element
- */
- public Object[] getFullElements() {
- return getFullNonNullElements();
- }
-
-
- /**
- * Overridden because UnboundedFifoBuffer's iterators aren't fail-fast.
- */
- public void testCollectionIteratorFailFast() {
- }
-
-
- /**
- * Verifies that the ArrayList has the same elements in the same
- * sequence as the UnboundedFifoBuffer.
+ * @return an empty UnboundedFifoBuffer
*/
- public void verify() {
- super.verify();
- Iterator iterator1 = collection.iterator();
- Iterator iterator2 = confirmed.iterator();
- while (iterator2.hasNext()) {
- assertTrue(iterator1.hasNext());
- Object o1 = iterator1.next();
- Object o2 = iterator2.next();
- assertEquals(o1, o2);
- }
+ protected Collection makeCollection() {
+ return new UnboundedFifoBuffer(5);
}
-
+ //-----------------------------------------------------------------------
/**
* Tests that UnboundedFifoBuffer removes elements in the right order.
*/
1.3 +53 -55
jakarta-commons/collections/src/test/org/apache/commons/collections/TestSet.java
Index: TestSet.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestSet.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestSet.java 18 Jun 2002 03:06:45 -0000 1.2
+++ TestSet.java 12 Jul 2003 15:11:25 -0000 1.3
@@ -85,7 +85,6 @@
*/
public abstract class TestSet extends TestCollection {
-
/**
* Constructor.
*
@@ -95,34 +94,24 @@
super(name);
}
-
- /**
- * Makes an empty collection by invoking [EMAIL PROTECTED] #makeEmptySet()}.
- *
- * @return an empty collection
- */
- protected final Collection makeCollection() {
- return makeEmptySet();
- }
-
-
- /**
- * Makes a full collection by invoking [EMAIL PROTECTED] #makeFullSet()}.
- *
- * @return a full collection
- */
- protected final Collection makeFullCollection() {
- return makeFullSet();
- }
-
+ //-----------------------------------------------------------------------
/**
- * Return the [EMAIL PROTECTED] TestCollection#collection} fixture, but cast
as a
- * Set.
+ * Provides additional verifications for sets.
*/
- protected Set getSet() {
- return (Set)collection;
+ protected void verify() {
+ super.verify();
+ assertEquals("Sets should be equal", confirmed, collection);
+ assertEquals("Sets should have equal hashCodes",
+ confirmed.hashCode(), collection.hashCode());
+ HashSet set = new HashSet();
+ Iterator iterator = collection.iterator();
+ while (iterator.hasNext()) {
+ assertTrue("Set.iterator should only return unique elements",
+ set.add(iterator.next()));
+ }
}
+ //-----------------------------------------------------------------------
/**
* Returns an empty [EMAIL PROTECTED] HashSet} for use in modification testing.
*
@@ -132,7 +121,6 @@
return new HashSet();
}
-
/**
* Returns a full [EMAIL PROTECTED] HashSet} for use in modification testing.
*
@@ -145,21 +133,12 @@
}
/**
- * Return the [EMAIL PROTECTED] TestCollection#confirmed} fixture, but cast as
a
- * Set.
- **/
- protected Set getConfirmedSet() {
- return (Set)confirmed;
- }
-
- /**
* Makes an empty set. The returned set should have no elements.
*
* @return an empty set
*/
protected abstract Set makeEmptySet();
-
/**
* Makes a full set by first creating an empty set and then adding
* all the elements returned by [EMAIL PROTECTED] #getFullElements()}.
@@ -174,7 +153,42 @@
return set;
}
+ /**
+ * Makes an empty collection by invoking [EMAIL PROTECTED] #makeEmptySet()}.
+ *
+ * @return an empty collection
+ */
+ protected final Collection makeCollection() {
+ return makeEmptySet();
+ }
+
+ /**
+ * Makes a full collection by invoking [EMAIL PROTECTED] #makeFullSet()}.
+ *
+ * @return a full collection
+ */
+ protected final Collection makeFullCollection() {
+ return makeFullSet();
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Return the [EMAIL PROTECTED] TestCollection#collection} fixture, but cast
as a
+ * Set.
+ */
+ protected Set getSet() {
+ return (Set)collection;
+ }
+
+ /**
+ * Return the [EMAIL PROTECTED] TestCollection#confirmed} fixture, but cast as
a
+ * Set.
+ **/
+ protected Set getConfirmedSet() {
+ return (Set)confirmed;
+ }
+ //-----------------------------------------------------------------------
/**
* Tests [EMAIL PROTECTED] Set#equals(Object)}.
*/
@@ -213,21 +227,5 @@
getSet().hashCode(), getConfirmedSet().hashCode());
}
-
- /**
- * Provides additional verifications for sets.
- */
- protected void verify() {
- super.verify();
- assertEquals("Sets should be equal", confirmed, collection);
- assertEquals("Sets should have equal hashCodes",
- confirmed.hashCode(), collection.hashCode());
- HashSet set = new HashSet();
- Iterator iterator = collection.iterator();
- while (iterator.hasNext()) {
- assertTrue("Set.iterator should only return unique elements",
- set.add(iterator.next()));
- }
- }
}
1.8 +215 -217
jakarta-commons/collections/src/test/org/apache/commons/collections/TestBinaryHeap.java
Index: TestBinaryHeap.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestBinaryHeap.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- TestBinaryHeap.java 13 Oct 2002 12:59:52 -0000 1.7
+++ TestBinaryHeap.java 12 Jul 2003 15:11:25 -0000 1.8
@@ -58,7 +58,6 @@
* <http://www.apache.org/>.
*
*/
-
package org.apache.commons.collections;
import java.util.ArrayList;
@@ -80,216 +79,215 @@
* @version $Id$
*/
public class TestBinaryHeap extends TestCollection {
-
- public static Test suite() {
- return new TestSuite(TestBinaryHeap.class);
- }
-
- public TestBinaryHeap(String testName) {
- super(testName);
- }
-
- /**
- * Return a new, empty [EMAIL PROTECTED] Object} to used for testing.
- */
- public Collection makeCollection() {
- return new BinaryHeap();
- }
-
-
- public Collection makeConfirmedCollection() {
- return new ArrayList();
- }
-
- public Collection makeConfirmedFullCollection() {
- ArrayList list = new ArrayList();
- list.addAll(Arrays.asList(getFullElements()));
- return list;
- }
-
- public Object[] getFullElements() {
- return getFullNonNullStringElements();
- }
-
- public Object[] getOtherElements() {
- return getOtherNonNullStringElements();
- }
-
- public void testCollectionIteratorFailFast() {
- }
-
- public void testBasicOps() {
- BinaryHeap heap = new BinaryHeap();
-
- assertTrue("heap should be empty after create", heap.isEmpty());
-
- try {
- heap.peek();
- fail("NoSuchElementException should be thrown if peek is called " +
- "before any elements are inserted");
- } catch (NoSuchElementException e) {
- // expected
- }
-
- try {
- heap.pop();
- fail("NoSuchElementException should be thrown if pop is called " +
- "before any elements are inserted");
- } catch (NoSuchElementException e) {
- // expected
- }
-
- heap.insert("a");
- heap.insert("c");
- heap.insert("e");
- heap.insert("b");
- heap.insert("d");
- heap.insert("n");
- heap.insert("m");
- heap.insert("l");
- heap.insert("k");
- heap.insert("j");
- heap.insert("i");
- heap.insert("h");
- heap.insert("g");
- heap.insert("f");
-
- assertTrue("heap should not be empty after inserts", !heap.isEmpty());
-
- for(int i = 0; i < 14; i++) {
- assertEquals("peek using default constructor should return " +
- "minimum value in the binary heap",
- String.valueOf((char)('a' + i)), heap.peek());
-
- assertEquals("pop using default constructor should return minimum " +
- "value in the binary heap",
- String.valueOf((char)('a' + i)), heap.pop());
-
- if(i + 1 < 14) {
- assertTrue("heap should not be empty before all elements are popped",
- !heap.isEmpty());
- } else {
- assertTrue("heap should be empty after all elements are popped",
- heap.isEmpty());
- }
- }
-
- try {
- heap.peek();
- fail("NoSuchElementException should be thrown if peek is called " +
- "after all elements are popped");
- } catch (NoSuchElementException e) {
- // expected
- }
-
- try {
- heap.pop();
- fail("NoSuchElementException should be thrown if pop is called " +
- "after all elements are popped");
- } catch (NoSuchElementException e) {
- // expected
- }
- }
-
- public void testBasicComparatorOps() {
- BinaryHeap heap =
- new BinaryHeap(new ReverseComparator(new ComparableComparator()));
-
- assertTrue("heap should be empty after create", heap.isEmpty());
-
- try {
- heap.peek();
- fail("NoSuchElementException should be thrown if peek is called " +
- "before any elements are inserted");
- } catch (NoSuchElementException e) {
- // expected
- }
-
- try {
- heap.pop();
- fail("NoSuchElementException should be thrown if pop is called " +
- "before any elements are inserted");
- } catch (NoSuchElementException e) {
- // expected
- }
-
- heap.insert("a");
- heap.insert("c");
- heap.insert("e");
- heap.insert("b");
- heap.insert("d");
- heap.insert("n");
- heap.insert("m");
- heap.insert("l");
- heap.insert("k");
- heap.insert("j");
- heap.insert("i");
- heap.insert("h");
- heap.insert("g");
- heap.insert("f");
-
- assertTrue("heap should not be empty after inserts", !heap.isEmpty());
-
- for(int i = 0; i < 14; i++) {
-
- // note: since we're using a comparator that reverses items, the
- // "minimum" item is "n", and the "maximum" item is "a".
-
- assertEquals("peek using default constructor should return " +
- "minimum value in the binary heap",
- String.valueOf((char)('n' - i)), heap.peek());
-
- assertEquals("pop using default constructor should return minimum " +
- "value in the binary heap",
- String.valueOf((char)('n' - i)), heap.pop());
-
- if(i + 1 < 14) {
- assertTrue("heap should not be empty before all elements are popped",
- !heap.isEmpty());
- } else {
- assertTrue("heap should be empty after all elements are popped",
- heap.isEmpty());
- }
- }
-
- try {
- heap.peek();
- fail("NoSuchElementException should be thrown if peek is called " +
- "after all elements are popped");
- } catch (NoSuchElementException e) {
- // expected
- }
-
- try {
- heap.pop();
- fail("NoSuchElementException should be thrown if pop is called " +
- "after all elements are popped");
- } catch (NoSuchElementException e) {
- // expected
- }
- }
-
-
- public void verify() {
- super.verify();
- BinaryHeap heap = (BinaryHeap)collection;
-
- Comparator c = heap.m_comparator;
- if (c == null) c = ComparatorUtils.naturalComparator();
- if (!heap.m_isMinHeap) c = ComparatorUtils.reversedComparator(c);
-
- Object[] tree = heap.m_elements;
- for (int i = 1; i <= heap.m_size; i++) {
- Object parent = tree[i];
- if (i * 2 <= heap.m_size) {
- assertTrue("Parent is less than or equal to its left child",
- c.compare(parent, tree[i * 2]) <= 0);
- }
- if (i * 2 + 1 < heap.m_size) {
- assertTrue("Parent is less than or equal to its right child",
- c.compare(parent, tree[i * 2 + 1]) <= 0);
- }
- }
- }
-}
+ public static Test suite() {
+ return new TestSuite(TestBinaryHeap.class);
+ }
+
+ public TestBinaryHeap(String testName) {
+ super(testName);
+ }
+
+ //-----------------------------------------------------------------------
+ protected void verify() {
+ super.verify();
+ BinaryHeap heap = (BinaryHeap) collection;
+
+ Comparator c = heap.m_comparator;
+ if (c == null)
+ c = ComparatorUtils.naturalComparator();
+ if (!heap.m_isMinHeap)
+ c = ComparatorUtils.reversedComparator(c);
+
+ Object[] tree = heap.m_elements;
+ for (int i = 1; i <= heap.m_size; i++) {
+ Object parent = tree[i];
+ if (i * 2 <= heap.m_size) {
+ assertTrue("Parent is less than or equal to its left child",
c.compare(parent, tree[i * 2]) <= 0);
+ }
+ if (i * 2 + 1 < heap.m_size) {
+ assertTrue("Parent is less than or equal to its right child",
c.compare(parent, tree[i * 2 + 1]) <= 0);
+ }
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Overridden because UnboundedFifoBuffer isn't fail fast.
+ * @return false
+ */
+ protected boolean isFailFastSupported() {
+ return false;
+ }
+
+ //-----------------------------------------------------------------------
+ protected Collection makeConfirmedCollection() {
+ return new ArrayList();
+ }
+
+ protected Collection makeConfirmedFullCollection() {
+ ArrayList list = new ArrayList();
+ list.addAll(Arrays.asList(getFullElements()));
+ return list;
+ }
+
+ /**
+ * Return a new, empty [EMAIL PROTECTED] Object} to used for testing.
+ */
+ protected Collection makeCollection() {
+ return new BinaryHeap();
+ }
+
+ //-----------------------------------------------------------------------
+ protected Object[] getFullElements() {
+ return getFullNonNullStringElements();
+ }
+
+ protected Object[] getOtherElements() {
+ return getOtherNonNullStringElements();
+ }
+
+ //-----------------------------------------------------------------------
+ public void testBasicOps() {
+ BinaryHeap heap = new BinaryHeap();
+
+ assertTrue("heap should be empty after create", heap.isEmpty());
+
+ try {
+ heap.peek();
+ fail("NoSuchElementException should be thrown if peek is called before
any elements are inserted");
+ } catch (NoSuchElementException e) {
+ // expected
+ }
+
+ try {
+ heap.pop();
+ fail("NoSuchElementException should be thrown if pop is called before
any elements are inserted");
+ } catch (NoSuchElementException e) {
+ // expected
+ }
+
+ heap.insert("a");
+ heap.insert("c");
+ heap.insert("e");
+ heap.insert("b");
+ heap.insert("d");
+ heap.insert("n");
+ heap.insert("m");
+ heap.insert("l");
+ heap.insert("k");
+ heap.insert("j");
+ heap.insert("i");
+ heap.insert("h");
+ heap.insert("g");
+ heap.insert("f");
+
+ assertTrue("heap should not be empty after inserts", !heap.isEmpty());
+
+ for (int i = 0; i < 14; i++) {
+ assertEquals(
+ "peek using default constructor should return minimum value in the
binary heap",
+ String.valueOf((char) ('a' + i)),
+ heap.peek());
+
+ assertEquals(
+ "pop using default constructor should return minimum value in the
binary heap",
+ String.valueOf((char) ('a' + i)),
+ heap.pop());
+
+ if (i + 1 < 14) {
+ assertTrue("heap should not be empty before all elements are
popped", !heap.isEmpty());
+ } else {
+ assertTrue("heap should be empty after all elements are popped",
heap.isEmpty());
+ }
+ }
+
+ try {
+ heap.peek();
+ fail("NoSuchElementException should be thrown if peek is called after
all elements are popped");
+ } catch (NoSuchElementException e) {
+ // expected
+ }
+
+ try {
+ heap.pop();
+ fail("NoSuchElementException should be thrown if pop is called after
all elements are popped");
+ } catch (NoSuchElementException e) {
+ // expected
+ }
+ }
+
+ public void testBasicComparatorOps() {
+ BinaryHeap heap = new BinaryHeap(new ReverseComparator(new
ComparableComparator()));
+
+ assertTrue("heap should be empty after create", heap.isEmpty());
+
+ try {
+ heap.peek();
+ fail("NoSuchElementException should be thrown if peek is called before
any elements are inserted");
+ } catch (NoSuchElementException e) {
+ // expected
+ }
+
+ try {
+ heap.pop();
+ fail("NoSuchElementException should be thrown if pop is called before
any elements are inserted");
+ } catch (NoSuchElementException e) {
+ // expected
+ }
+
+ heap.insert("a");
+ heap.insert("c");
+ heap.insert("e");
+ heap.insert("b");
+ heap.insert("d");
+ heap.insert("n");
+ heap.insert("m");
+ heap.insert("l");
+ heap.insert("k");
+ heap.insert("j");
+ heap.insert("i");
+ heap.insert("h");
+ heap.insert("g");
+ heap.insert("f");
+
+ assertTrue("heap should not be empty after inserts", !heap.isEmpty());
+
+ for (int i = 0; i < 14; i++) {
+
+ // note: since we're using a comparator that reverses items, the
+ // "minimum" item is "n", and the "maximum" item is "a".
+
+ assertEquals(
+ "peek using default constructor should return minimum value in the
binary heap",
+ String.valueOf((char) ('n' - i)),
+ heap.peek());
+
+ assertEquals(
+ "pop using default constructor should return minimum value in the
binary heap",
+ String.valueOf((char) ('n' - i)),
+ heap.pop());
+
+ if (i + 1 < 14) {
+ assertTrue("heap should not be empty before all elements are
popped", !heap.isEmpty());
+ } else {
+ assertTrue("heap should be empty after all elements are popped",
heap.isEmpty());
+ }
+ }
+
+ try {
+ heap.peek();
+ fail("NoSuchElementException should be thrown if peek is called after
all elements are popped");
+ } catch (NoSuchElementException e) {
+ // expected
+ }
+
+ try {
+ heap.pop();
+ fail("NoSuchElementException should be thrown if pop is called after
all elements are popped");
+ } catch (NoSuchElementException e) {
+ // expected
+ }
+ }
+
+}
1.2 +5 -2
jakarta-commons/collections/src/test/org/apache/commons/collections/decorators/TestTransformedCollection.java
Index: TestTransformedCollection.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/decorators/TestTransformedCollection.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestTransformedCollection.java 11 May 2003 13:18:27 -0000 1.1
+++ TestTransformedCollection.java 12 Jul 2003 15:11:26 -0000 1.2
@@ -108,6 +108,7 @@
junit.textui.TestRunner.main(testCaseName);
}
+ //-----------------------------------------------------------------------
public Collection makeConfirmedCollection() {
return new ArrayList();
}
@@ -128,6 +129,7 @@
return TransformedCollection.decorate(list, NOOP_TRANSFORMER);
}
+ //-----------------------------------------------------------------------
protected Object[] getFullElements() {
return new Object[] {"1", "3", "5", "7", "2", "4", "6"};
}
@@ -136,6 +138,7 @@
return new Object[] {"9", "88", "678", "87", "98", "78", "99"};
}
+ //-----------------------------------------------------------------------
public void testTransformedCollection() {
Collection coll = TransformedCollection.decorate(new ArrayList(),
STRING_TO_INTEGER_TRANSFORMER);
assertEquals(0, coll.size());
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]