Added more controlling if methods into Collection test hierarchy
- isNullSupported - isFailFastSupported git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131108 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ee78317bba
commit
f51f08a1fd
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestBinaryHeap.java,v 1.7 2002/10/13 12:59:52 scolebourne Exp $
|
||||
* $Revision: 1.7 $
|
||||
* $Date: 2002/10/13 12:59:52 $
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestBinaryHeap.java,v 1.8 2003/07/12 15:11:25 scolebourne Exp $
|
||||
* $Revision: 1.8 $
|
||||
* $Date: 2003/07/12 15:11:25 $
|
||||
*
|
||||
* ====================================================================
|
||||
*
|
||||
|
@ -58,7 +58,6 @@
|
|||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.commons.collections;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -77,219 +76,218 @@ import org.apache.commons.collections.comparators.ReverseComparator;
|
|||
* Tests the BinaryHeap.
|
||||
*
|
||||
* @author <a href="mailto:mas@apache.org">Michael A. Smith</a>
|
||||
* @version $Id: TestBinaryHeap.java,v 1.7 2002/10/13 12:59:52 scolebourne Exp $
|
||||
* @version $Id: TestBinaryHeap.java,v 1.8 2003/07/12 15:11:25 scolebourne Exp $
|
||||
*/
|
||||
public class TestBinaryHeap extends TestCollection {
|
||||
|
||||
public static Test suite() {
|
||||
return new TestSuite(TestBinaryHeap.class);
|
||||
}
|
||||
|
||||
public TestBinaryHeap(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a new, empty {@link 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());
|
||||
}
|
||||
public static Test suite() {
|
||||
return new TestSuite(TestBinaryHeap.class);
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
public TestBinaryHeap(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
|
||||
try {
|
||||
heap.peek();
|
||||
fail("NoSuchElementException should be thrown if peek is called " +
|
||||
"after all elements are popped");
|
||||
} catch (NoSuchElementException e) {
|
||||
// expected
|
||||
//-----------------------------------------------------------------------
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
heap.pop();
|
||||
fail("NoSuchElementException should be thrown if pop is called " +
|
||||
"after all elements are popped");
|
||||
} catch (NoSuchElementException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Overridden because UnboundedFifoBuffer isn't fail fast.
|
||||
* @return false
|
||||
*/
|
||||
protected boolean isFailFastSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void verify() {
|
||||
super.verify();
|
||||
BinaryHeap heap = (BinaryHeap)collection;
|
||||
//-----------------------------------------------------------------------
|
||||
protected Collection makeConfirmedCollection() {
|
||||
return new ArrayList();
|
||||
}
|
||||
|
||||
Comparator c = heap.m_comparator;
|
||||
if (c == null) c = ComparatorUtils.naturalComparator();
|
||||
if (!heap.m_isMinHeap) c = ComparatorUtils.reversedComparator(c);
|
||||
protected Collection makeConfirmedFullCollection() {
|
||||
ArrayList list = new ArrayList();
|
||||
list.addAll(Arrays.asList(getFullElements()));
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a new, empty {@link 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
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestBoundedFifoBuffer.java,v 1.5 2003/04/26 15:12:28 scolebourne Exp $
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestBoundedFifoBuffer.java,v 1.6 2003/07/12 15:11:25 scolebourne Exp $
|
||||
* ====================================================================
|
||||
*
|
||||
* The Apache Software License, Version 1.1
|
||||
|
@ -78,56 +78,13 @@ public class TestBoundedFifoBuffer extends TestCollection {
|
|||
return BulkTest.makeSuite(TestBoundedFifoBuffer.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an empty BoundedFifoBuffer that won't overflow.
|
||||
*
|
||||
* @return an empty BoundedFifoBuffer
|
||||
*/
|
||||
public Collection makeCollection() {
|
||||
return new BoundedFifoBuffer(100);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an empty ArrayList.
|
||||
*
|
||||
* @return an empty ArrayList
|
||||
*/
|
||||
public Collection makeConfirmedCollection() {
|
||||
return new ArrayList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a full ArrayList.
|
||||
*
|
||||
* @return a full ArrayList
|
||||
*/
|
||||
public 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.
|
||||
*/
|
||||
public void verify() {
|
||||
protected void verify() {
|
||||
super.verify();
|
||||
Iterator iterator1 = collection.iterator();
|
||||
Iterator iterator2 = confirmed.iterator();
|
||||
|
@ -139,6 +96,54 @@ public class TestBoundedFifoBuffer extends TestCollection {
|
|||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
protected Collection makeConfirmedCollection() {
|
||||
return new ArrayList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a full ArrayList.
|
||||
*
|
||||
* @return a full ArrayList
|
||||
*/
|
||||
protected Collection makeConfirmedFullCollection() {
|
||||
Collection c = makeConfirmedCollection();
|
||||
c.addAll(java.util.Arrays.asList(getFullElements()));
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an empty BoundedFifoBuffer that won't overflow.
|
||||
*
|
||||
* @return an empty BoundedFifoBuffer
|
||||
*/
|
||||
protected Collection makeCollection() {
|
||||
return new BoundedFifoBuffer(100);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Tests that the removal operation actually removes the first element.
|
||||
*/
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestCircularFifoBuffer.java,v 1.1 2003/04/26 15:13:22 scolebourne Exp $
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestCircularFifoBuffer.java,v 1.2 2003/07/12 15:11:25 scolebourne Exp $
|
||||
* ====================================================================
|
||||
*
|
||||
* The Apache Software License, Version 1.1
|
||||
|
@ -67,7 +67,7 @@ import junit.framework.Test;
|
|||
/**
|
||||
* Test cases for CircularFifoBuffer.
|
||||
*
|
||||
* @version $Revision: 1.1 $ $Date: 2003/04/26 15:13:22 $
|
||||
* @version $Revision: 1.2 $ $Date: 2003/07/12 15:11:25 $
|
||||
*
|
||||
* @author Stephen Colebourne
|
||||
*/
|
||||
|
@ -81,56 +81,13 @@ public class TestCircularFifoBuffer extends TestCollection {
|
|||
return BulkTest.makeSuite(TestCircularFifoBuffer.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an empty BoundedFifoBuffer that won't overflow.
|
||||
*
|
||||
* @return an empty BoundedFifoBuffer
|
||||
*/
|
||||
public Collection makeCollection() {
|
||||
return new CircularFifoBuffer(100);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an empty ArrayList.
|
||||
*
|
||||
* @return an empty ArrayList
|
||||
*/
|
||||
public Collection makeConfirmedCollection() {
|
||||
return new ArrayList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a full ArrayList.
|
||||
*
|
||||
* @return a full ArrayList
|
||||
*/
|
||||
public 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.
|
||||
*/
|
||||
public void verify() {
|
||||
protected void verify() {
|
||||
super.verify();
|
||||
Iterator iterator1 = collection.iterator();
|
||||
Iterator iterator2 = confirmed.iterator();
|
||||
|
@ -142,6 +99,54 @@ public class TestCircularFifoBuffer extends TestCollection {
|
|||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
protected Collection makeConfirmedCollection() {
|
||||
return new ArrayList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a full ArrayList.
|
||||
*
|
||||
* @return a full ArrayList
|
||||
*/
|
||||
protected Collection makeConfirmedFullCollection() {
|
||||
Collection c = makeConfirmedCollection();
|
||||
c.addAll(java.util.Arrays.asList(getFullElements()));
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an empty BoundedFifoBuffer that won't overflow.
|
||||
*
|
||||
* @return an empty BoundedFifoBuffer
|
||||
*/
|
||||
protected Collection makeCollection() {
|
||||
return new CircularFifoBuffer(100);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Tests that the removal operation actually removes the first element.
|
||||
*/
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestCollection.java,v 1.11 2003/05/09 18:34:19 scolebourne Exp $
|
||||
* $Revision: 1.11 $
|
||||
* $Date: 2003/05/09 18:34:19 $
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestCollection.java,v 1.12 2003/07/12 15:11:25 scolebourne Exp $
|
||||
* $Revision: 1.12 $
|
||||
* $Date: 2003/07/12 15:11:25 $
|
||||
*
|
||||
* ====================================================================
|
||||
*
|
||||
|
@ -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.List;
|
|||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
|
||||
/**
|
||||
* Tests base {@link java.util.Collection} methods and contracts.
|
||||
* <p>
|
||||
* You should create a concrete subclass of this class to test any custom
|
||||
* {@link Collection} implementation. At minimum, you'll have to
|
||||
* implement the {@link #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>{@link #getFullElements()}
|
||||
* <Li>{@link #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>{@link #isAddSuppoted()}
|
||||
* <LI>{@link #isRemoveSupported()}
|
||||
* <li>{@link #areEqualElementsDistinguishable()}
|
||||
* <LI>{@link #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,51 +112,52 @@ import java.util.NoSuchElementException;
|
|||
* 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 {@link #collection} field holds an instance of your collection
|
||||
* implementation; the {@link #confirmed} field holds an instance of the
|
||||
* confirmed collection implementation. The {@link #resetEmpty()} and
|
||||
* {@link #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 {@link #collection} and
|
||||
* {@link #confirmed}, the {@link #verify()} method is invoked to compare
|
||||
* the results. You may want to override {@link #verify()} to perform
|
||||
* additional verifications. For instance, when testing the collection
|
||||
* views of a map, {@link TestMap} would override {@link #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>{@link #makeConfirmedCollection()}
|
||||
* <LI>{@link #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 {@link TestList}, {@link TestSet},
|
||||
* or {@link 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 {@link Collection} fails one of these tests by design,
|
||||
* you may still use this base set of cases. Simply override the
|
||||
* test case (method) your {@link Collection} fails. For instance, the
|
||||
* {@link #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:mas@apache.org">Michael A. Smith</a>
|
||||
* @author Neil O'Toole
|
||||
* @version $Id: TestCollection.java,v 1.11 2003/05/09 18:34:19 scolebourne Exp $
|
||||
* @author Stephen Colebourne
|
||||
* @version $Id: TestCollection.java,v 1.12 2003/07/12 15:11:25 scolebourne Exp $
|
||||
*/
|
||||
public abstract class TestCollection extends TestObject {
|
||||
|
||||
|
@ -190,33 +190,16 @@ public abstract class TestCollection extends TestObject {
|
|||
*/
|
||||
protected Collection confirmed;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param testName the test name
|
||||
*/
|
||||
public TestCollection(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Resets the {@link #collection} and {@link #confirmed} fields to empty
|
||||
* collections. Invoke this method before performing a modification
|
||||
* test.
|
||||
*/
|
||||
protected void resetEmpty() {
|
||||
this.collection = makeCollection();
|
||||
this.confirmed = makeConfirmedCollection();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Resets the {@link #collection} and {@link #confirmed} fields to full
|
||||
* collections. Invoke this method before performing a modification
|
||||
* test.
|
||||
*/
|
||||
protected void resetFull() {
|
||||
this.collection = makeFullCollection();
|
||||
this.confirmed = makeConfirmedFullCollection();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Specifies whether equal elements in the collection are, in fact,
|
||||
* distinguishable with information not readily available. That is, if a
|
||||
|
@ -243,6 +226,48 @@ public abstract class TestCollection extends TestObject {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the collections produced by
|
||||
* {@link #makeCollection()} and {@link #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
|
||||
* {@link #makeCollection()} and {@link #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 {@link #collection} and {@link #confirmed} have
|
||||
* identical state.
|
||||
|
@ -315,7 +340,28 @@ public abstract class TestCollection extends TestObject {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Resets the {@link #collection} and {@link #confirmed} fields to empty
|
||||
* collections. Invoke this method before performing a modification
|
||||
* test.
|
||||
*/
|
||||
protected void resetEmpty() {
|
||||
this.collection = makeCollection();
|
||||
this.confirmed = makeConfirmedCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the {@link #collection} and {@link #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 {@link java.util.ArrayList} for lists or a
|
||||
|
@ -325,8 +371,6 @@ public abstract class TestCollection extends TestObject {
|
|||
*/
|
||||
protected abstract Collection makeConfirmedCollection();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns a confirmed full collection.
|
||||
* For instance, an {@link java.util.ArrayList} for lists or a
|
||||
|
@ -337,72 +381,11 @@ public abstract class TestCollection extends TestObject {
|
|||
*/
|
||||
protected abstract Collection makeConfirmedFullCollection();
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the collections produced by
|
||||
* {@link #makeCollection()} and {@link #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
|
||||
* {@link #makeCollection()} and {@link #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 an array of objects that are contained in a collection
|
||||
* produced by {@link #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.
|
||||
* Override if you require specific testing elements. Note that if you
|
||||
* override {@link #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();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns an array of elements that are <I>not</I> contained in a
|
||||
* full collection. Every element in the returned array must
|
||||
* not exist in a collection returned by {@link #makeFullCollection()}.
|
||||
* The default implementation returns a heterogenous array of elements
|
||||
* without null. Note that some of the tests add these elements
|
||||
* to an empty or full collection, so if your collection restricts
|
||||
* certain kinds of elements, you should override this method.
|
||||
*/
|
||||
protected Object[] getOtherElements() {
|
||||
return getOtherNonNullElements();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a new, empty {@link 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
|
||||
|
@ -417,15 +400,49 @@ public abstract class TestCollection extends TestObject {
|
|||
return c;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns an empty collection for Object tests.
|
||||
*/
|
||||
public Object makeObject() {
|
||||
protected Object makeObject() {
|
||||
return makeCollection();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Returns an array of objects that are contained in a collection
|
||||
* produced by {@link #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. null is added if allowed.
|
||||
* Override if you require specific testing elements. Note that if you
|
||||
* override {@link #makeFullCollection()}, you <I>must</I> override
|
||||
* this method to reflect the contents of a full collection.
|
||||
*/
|
||||
protected Object[] getFullElements() {
|
||||
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
|
||||
* not exist in a collection returned by {@link #makeFullCollection()}.
|
||||
* The default implementation returns a heterogenous array of elements
|
||||
* without null. Note that some of the tests add these elements
|
||||
* to an empty or full collection, so if your collection restricts
|
||||
* certain kinds of elements, you should override this method.
|
||||
*/
|
||||
protected Object[] getOtherElements() {
|
||||
return getOtherNonNullElements();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Tests {@link Collection#add(Object)}.
|
||||
*/
|
||||
|
@ -1137,6 +1154,8 @@ public abstract class TestCollection extends TestObject {
|
|||
* Tests that the collection's iterator is fail-fast.
|
||||
*/
|
||||
public void testCollectionIteratorFailFast() {
|
||||
if (!isFailFastSupported()) return;
|
||||
|
||||
if (isAddSupported()) {
|
||||
resetFull();
|
||||
try {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestList.java,v 1.17 2003/04/26 10:27:59 scolebourne Exp $
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestList.java,v 1.18 2003/07/12 15:11:25 scolebourne Exp $
|
||||
* ====================================================================
|
||||
*
|
||||
* The Apache Software License, Version 1.1
|
||||
|
@ -82,7 +82,7 @@ import java.util.NoSuchElementException;
|
|||
* you may still use this base set of cases. Simply override the
|
||||
* test case (method) your {@link List} fails.
|
||||
*
|
||||
* @version $Revision: 1.17 $ $Date: 2003/04/26 10:27:59 $
|
||||
* @version $Revision: 1.18 $ $Date: 2003/07/12 15:11:25 $
|
||||
*
|
||||
* @author Rodney Waldhoff
|
||||
* @author Paul Jack
|
||||
|
@ -91,11 +91,77 @@ import java.util.NoSuchElementException;
|
|||
*/
|
||||
public abstract class TestList extends TestCollection {
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param testName
|
||||
*/
|
||||
public TestList(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Returns true if the collections produced by
|
||||
* {@link #makeCollection()} and {@link #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 {@link ArrayList}.
|
||||
*/
|
||||
protected Collection makeConfirmedCollection() {
|
||||
ArrayList list = new ArrayList();
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a full {@link ArrayList}.
|
||||
*/
|
||||
protected Collection makeConfirmedFullCollection() {
|
||||
ArrayList list = new ArrayList();
|
||||
list.addAll(Arrays.asList(getFullElements()));
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a new, empty {@link List} to be used for testing.
|
||||
|
@ -104,7 +170,6 @@ public abstract class TestList extends TestCollection {
|
|||
*/
|
||||
protected abstract List makeEmptyList();
|
||||
|
||||
|
||||
/**
|
||||
* Return a new, full {@link List} to be used for testing.
|
||||
*
|
||||
|
@ -117,7 +182,6 @@ public abstract class TestList extends TestCollection {
|
|||
return list;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns {@link makeEmptyList()}.
|
||||
*
|
||||
|
@ -127,7 +191,6 @@ public abstract class TestList extends TestCollection {
|
|||
return makeEmptyList();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns {@link makeFullList()}.
|
||||
*
|
||||
|
@ -137,19 +200,7 @@ public abstract class TestList extends TestCollection {
|
|||
return makeFullList();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the collections produced by
|
||||
* {@link #makeCollection()} and {@link #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 {@link collection} field cast to a {@link List}.
|
||||
*
|
||||
|
@ -159,7 +210,6 @@ public abstract class TestList extends TestCollection {
|
|||
return (List)collection;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the {@link confirmed} field cast to a {@link List}.
|
||||
*
|
||||
|
@ -169,7 +219,7 @@ public abstract class TestList extends TestCollection {
|
|||
return (List)confirmed;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Tests bounds checking for {@link List#add(int, Object)} on an
|
||||
* empty list.
|
||||
|
@ -952,60 +1002,7 @@ public abstract class TestList extends TestCollection {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns an empty {@link ArrayList}.
|
||||
*/
|
||||
protected Collection makeConfirmedCollection() {
|
||||
ArrayList list = new ArrayList();
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a full {@link 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 {@link BulkTest} for testing {@link List#subList(int,int)}.
|
||||
* The returned bulk test will run through every <Code>TestList</Code>
|
||||
|
@ -1095,6 +1092,7 @@ public abstract class TestList extends TestCollection {
|
|||
* if elements are added to the original list.
|
||||
*/
|
||||
public void testListSubListFailFastOnAdd() {
|
||||
if (!isFailFastSupported()) return;
|
||||
if (!isAddSupported()) return;
|
||||
|
||||
resetFull();
|
||||
|
@ -1126,6 +1124,7 @@ public abstract class TestList extends TestCollection {
|
|||
* if elements are removed from the original list.
|
||||
*/
|
||||
public void testListSubListFailFastOnRemove() {
|
||||
if (!isFailFastSupported()) return;
|
||||
if (!isRemoveSupported()) return;
|
||||
|
||||
resetFull();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestSet.java,v 1.2 2002/06/18 03:06:45 mas Exp $
|
||||
* $Revision: 1.2 $
|
||||
* $Date: 2002/06/18 03:06:45 $
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestSet.java,v 1.3 2003/07/12 15:11:25 scolebourne Exp $
|
||||
* $Revision: 1.3 $
|
||||
* $Date: 2003/07/12 15:11:25 $
|
||||
*
|
||||
* ====================================================================
|
||||
*
|
||||
|
@ -81,11 +81,10 @@ import java.util.Set;
|
|||
* elements may be added; see {@link TestCollection} for more details.<P>
|
||||
*
|
||||
* @author Paul Jack
|
||||
* @version $Id: TestSet.java,v 1.2 2002/06/18 03:06:45 mas Exp $
|
||||
* @version $Id: TestSet.java,v 1.3 2003/07/12 15:11:25 scolebourne Exp $
|
||||
*/
|
||||
public abstract class TestSet extends TestCollection {
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
|
@ -95,34 +94,24 @@ public abstract class TestSet extends TestCollection {
|
|||
super(name);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Makes an empty collection by invoking {@link #makeEmptySet()}.
|
||||
*
|
||||
* @return an empty collection
|
||||
* Provides additional verifications for sets.
|
||||
*/
|
||||
protected final Collection makeCollection() {
|
||||
return makeEmptySet();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Makes a full collection by invoking {@link #makeFullSet()}.
|
||||
*
|
||||
* @return a full collection
|
||||
*/
|
||||
protected final Collection makeFullCollection() {
|
||||
return makeFullSet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@link TestCollection#collection} fixture, but cast as a
|
||||
* Set.
|
||||
*/
|
||||
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 {@link HashSet} for use in modification testing.
|
||||
*
|
||||
|
@ -132,7 +121,6 @@ public abstract class TestSet extends TestCollection {
|
|||
return new HashSet();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a full {@link HashSet} for use in modification testing.
|
||||
*
|
||||
|
@ -144,14 +132,6 @@ public abstract class TestSet extends TestCollection {
|
|||
return set;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@link 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.
|
||||
*
|
||||
|
@ -159,7 +139,6 @@ public abstract class TestSet extends TestCollection {
|
|||
*/
|
||||
protected abstract Set makeEmptySet();
|
||||
|
||||
|
||||
/**
|
||||
* Makes a full set by first creating an empty set and then adding
|
||||
* all the elements returned by {@link #getFullElements()}.
|
||||
|
@ -174,7 +153,42 @@ public abstract class TestSet extends TestCollection {
|
|||
return set;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an empty collection by invoking {@link #makeEmptySet()}.
|
||||
*
|
||||
* @return an empty collection
|
||||
*/
|
||||
protected final Collection makeCollection() {
|
||||
return makeEmptySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a full collection by invoking {@link #makeFullSet()}.
|
||||
*
|
||||
* @return a full collection
|
||||
*/
|
||||
protected final Collection makeFullCollection() {
|
||||
return makeFullSet();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Return the {@link TestCollection#collection} fixture, but cast as a
|
||||
* Set.
|
||||
*/
|
||||
protected Set getSet() {
|
||||
return (Set)collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@link TestCollection#confirmed} fixture, but cast as a
|
||||
* Set.
|
||||
**/
|
||||
protected Set getConfirmedSet() {
|
||||
return (Set)confirmed;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Tests {@link Set#equals(Object)}.
|
||||
*/
|
||||
|
@ -214,20 +228,4 @@ public abstract class TestSet extends TestCollection {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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,7 +1,7 @@
|
|||
/*
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestUnboundedFifoBuffer.java,v 1.4 2003/02/19 20:33:11 scolebourne Exp $
|
||||
* $Revision: 1.4 $
|
||||
* $Date: 2003/02/19 20:33:11 $
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestUnboundedFifoBuffer.java,v 1.5 2003/07/12 15:11:25 scolebourne Exp $
|
||||
* $Revision: 1.5 $
|
||||
* $Date: 2003/07/12 15:11:25 $
|
||||
*
|
||||
* ====================================================================
|
||||
*
|
||||
|
@ -78,60 +78,12 @@ public class TestUnboundedFifoBuffer extends TestCollection {
|
|||
return BulkTest.makeSuite(TestUnboundedFifoBuffer.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an empty UnboundedFifoBuffer with a small capacity.
|
||||
*
|
||||
* @return an empty UnboundedFifoBuffer
|
||||
*/
|
||||
public Collection makeCollection() {
|
||||
return new UnboundedFifoBuffer(5);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns an empty ArrayList.
|
||||
*
|
||||
* @return an empty ArrayList
|
||||
*/
|
||||
public Collection makeConfirmedCollection() {
|
||||
return new ArrayList();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a full ArrayList.
|
||||
*
|
||||
* @return a full ArrayList
|
||||
*/
|
||||
public Collection makeConfirmedFullCollection() {
|
||||
Collection c = makeConfirmedCollection();
|
||||
c.addAll(java.util.Arrays.asList(getFullElements()));
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Overridden because UnboundedFifoBuffer doesn't allow null elements.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
public void verify() {
|
||||
protected void verify() {
|
||||
super.verify();
|
||||
Iterator iterator1 = collection.iterator();
|
||||
Iterator iterator2 = confirmed.iterator();
|
||||
|
@ -143,7 +95,54 @@ public class TestUnboundedFifoBuffer extends TestCollection {
|
|||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
protected Collection makeConfirmedCollection() {
|
||||
return new ArrayList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a full ArrayList.
|
||||
*
|
||||
* @return a full ArrayList
|
||||
*/
|
||||
protected Collection makeConfirmedFullCollection() {
|
||||
Collection c = makeConfirmedCollection();
|
||||
c.addAll(java.util.Arrays.asList(getFullElements()));
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an empty UnboundedFifoBuffer with a small capacity.
|
||||
*
|
||||
* @return an empty UnboundedFifoBuffer
|
||||
*/
|
||||
protected Collection makeCollection() {
|
||||
return new UnboundedFifoBuffer(5);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Tests that UnboundedFifoBuffer removes elements in the right order.
|
||||
*/
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/decorators/Attic/TestTransformedCollection.java,v 1.1 2003/05/11 13:18:27 scolebourne Exp $
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/decorators/Attic/TestTransformedCollection.java,v 1.2 2003/07/12 15:11:26 scolebourne Exp $
|
||||
* ====================================================================
|
||||
*
|
||||
* The Apache Software License, Version 1.1
|
||||
|
@ -74,7 +74,7 @@ import org.apache.commons.collections.Transformer;
|
|||
* implementation.
|
||||
*
|
||||
* @since Commons Collections 3.0
|
||||
* @version $Revision: 1.1 $ $Date: 2003/05/11 13:18:27 $
|
||||
* @version $Revision: 1.2 $ $Date: 2003/07/12 15:11:26 $
|
||||
*
|
||||
* @author Stephen Colebourne
|
||||
*/
|
||||
|
@ -108,6 +108,7 @@ public class TestTransformedCollection extends TestCollection {
|
|||
junit.textui.TestRunner.main(testCaseName);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
public Collection makeConfirmedCollection() {
|
||||
return new ArrayList();
|
||||
}
|
||||
|
@ -128,6 +129,7 @@ public class TestTransformedCollection extends TestCollection {
|
|||
return TransformedCollection.decorate(list, NOOP_TRANSFORMER);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
protected Object[] getFullElements() {
|
||||
return new Object[] {"1", "3", "5", "7", "2", "4", "6"};
|
||||
}
|
||||
|
@ -136,6 +138,7 @@ public class TestTransformedCollection extends TestCollection {
|
|||
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());
|
||||
|
|
Loading…
Reference in New Issue