Make testframework jar independent of collections jar

(Except Bag interface)


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131234 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2003-10-05 12:34:46 +00:00
parent f8acd98e11
commit 03f4174238
2 changed files with 89 additions and 30 deletions

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/AbstractTestBag.java,v 1.1 2003/10/02 22:35:31 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/AbstractTestBag.java,v 1.2 2003/10/05 12:34:46 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -72,8 +72,10 @@ import java.util.List;
* you may still use this base set of cases. Simply override the
* test case (method) your {@link Bag} fails.
*
* @version $Revision: 1.2 $ $Date: 2003/10/05 12:34:46 $
*
* @author Chuck Burdick
* @version $Id: AbstractTestBag.java,v 1.1 2003/10/02 22:35:31 scolebourne Exp $
* @author Stephen Colebourne
*/
public abstract class AbstractTestBag extends AbstractTestObject {
// TODO: this class should really extend from TestCollection, but the bag
@ -170,35 +172,83 @@ public abstract class AbstractTestBag extends AbstractTestObject {
public void testContains() {
Bag bag = makeBag();
bag.add("A");
bag.add("A");
bag.add("A");
bag.add("B");
bag.add("B");
List compare = new ArrayList();
compare.add("A");
compare.add("B");
assertEquals("Other list has 1 'B'", 1, (new HashBag(compare)).getCount("B"));
assertTrue("Bag has at least 1 'B'", 1 <= bag.getCount("B"));
assertTrue("Bag contains items in the list", bag.containsAll(compare));
compare.add("A");
compare.add("B");
assertEquals("Other list has 2 'B'", 2, (new HashBag(compare)).getCount("B"));
assertTrue("Bag has at least 2 'B'", 2 <= bag.getCount("B"));
assertTrue("Bag contains items in the list", bag.containsAll(compare));
compare.add("A");
compare.add("B");
assertEquals("Other list has 3 'B'", 3, (new HashBag(compare)).getCount("B"));
assertTrue("Bag does not have 3 'B'", 3 > bag.getCount("B"));
assertTrue("Bag contains items in the list", !bag.containsAll(compare));
assertEquals("Bag does not have at least 1 'A'", false, bag.contains("A"));
assertEquals("Bag does not have at least 1 'B'", false, bag.contains("B"));
bag.add("A"); // bag 1A
assertEquals("Bag has at least 1 'A'", true, bag.contains("A"));
assertEquals("Bag does not have at least 1 'B'", false, bag.contains("B"));
bag.add("A"); // bag 2A
assertEquals("Bag has at least 1 'A'", true, bag.contains("A"));
assertEquals("Bag does not have at least 1 'B'", false, bag.contains("B"));
bag.add("B"); // bag 2A,1B
assertEquals("Bag has at least 1 'A'", true, bag.contains("A"));
assertEquals("Bag has at least 1 'B'", true, bag.contains("B"));
}
public void testContainsAll() {
Bag bag = makeBag();
List known = new ArrayList();
List known1A = new ArrayList();
known1A.add("A");
List known2A = new ArrayList();
known2A.add("A");
known2A.add("A");
List known1B = new ArrayList();
known1B.add("B");
List known1A1B = new ArrayList();
known1A1B.add("A");
known1A1B.add("B");
assertEquals("Bag containsAll of empty", true, bag.containsAll(known));
assertEquals("Bag does not containsAll of 1 'A'", false, bag.containsAll(known1A));
assertEquals("Bag does not containsAll of 2 'A'", false, bag.containsAll(known2A));
assertEquals("Bag does not containsAll of 1 'B'", false, bag.containsAll(known1B));
assertEquals("Bag does not containsAll of 1 'A' 1 'B'", false, bag.containsAll(known1A1B));
bag.add("A"); // bag 1A
assertEquals("Bag containsAll of empty", true, bag.containsAll(known));
assertEquals("Bag containsAll of 1 'A'", true, bag.containsAll(known1A));
assertEquals("Bag does not containsAll of 2 'A'", false, bag.containsAll(known2A));
assertEquals("Bag does not containsAll of 1 'B'", false, bag.containsAll(known1B));
assertEquals("Bag does not containsAll of 1 'A' 1 'B'", false, bag.containsAll(known1A1B));
bag.add("A"); // bag 2A
assertEquals("Bag containsAll of empty", true, bag.containsAll(known));
assertEquals("Bag containsAll of 1 'A'", true, bag.containsAll(known1A));
assertEquals("Bag containsAll of 2 'A'", true, bag.containsAll(known2A));
assertEquals("Bag does not containsAll of 1 'B'", false, bag.containsAll(known1B));
assertEquals("Bag does not containsAll of 1 'A' 1 'B'", false, bag.containsAll(known1A1B));
bag.add("A"); // bag 3A
assertEquals("Bag containsAll of empty", true, bag.containsAll(known));
assertEquals("Bag containsAll of 1 'A'", true, bag.containsAll(known1A));
assertEquals("Bag containsAll of 2 'A'", true, bag.containsAll(known2A));
assertEquals("Bag does not containsAll of 1 'B'", false, bag.containsAll(known1B));
assertEquals("Bag does not containsAll of 1 'A' 1 'B'", false, bag.containsAll(known1A1B));
bag.add("B"); // bag 3A1B
assertEquals("Bag containsAll of empty", true, bag.containsAll(known));
assertEquals("Bag containsAll of 1 'A'", true, bag.containsAll(known1A));
assertEquals("Bag containsAll of 2 'A'", true, bag.containsAll(known2A));
assertEquals("Bag containsAll of 1 'B'", true, bag.containsAll(known1B));
assertEquals("Bag containsAll of 1 'A' 1 'B'", true, bag.containsAll(known1A1B));
}
public void testSize() {
Bag bag = makeBag();
assertEquals("Should have 0 total items", 0, bag.size());
bag.add("A");
assertEquals("Should have 1 total items", 1, bag.size());
bag.add("A");
assertEquals("Should have 2 total items", 2, bag.size());
bag.add("A");
assertEquals("Should have 3 total items", 3, bag.size());
bag.add("B");
assertEquals("Should have 4 total items", 4, bag.size());
bag.add("B");
assertEquals("Should have 5 total items", 5, bag.size());
bag.remove("A", 2);

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/AbstractTestMap.java,v 1.1 2003/10/02 23:01:09 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/AbstractTestMap.java,v 1.2 2003/10/05 12:34:46 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -59,9 +59,11 @@ package org.apache.commons.collections;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -148,7 +150,8 @@ import java.util.Set;
* @author Michael Smith
* @author Rodney Waldhoff
* @author Paul Jack
* @version $Revision: 1.1 $ $Date: 2003/10/02 23:01:09 $
* @author Stephen Colebourne
* @version $Revision: 1.2 $ $Date: 2003/10/05 12:34:46 $
*/
public abstract class AbstractTestMap extends AbstractTestObject {
@ -868,7 +871,9 @@ public abstract class AbstractTestMap extends AbstractTestObject {
private Map.Entry[] makeEntryArray(Object[] keys, Object[] values) {
Map.Entry[] result = new Map.Entry[keys.length];
for (int i = 0; i < keys.length; i++) {
result[i] = new DefaultMapEntry(keys[i], values[i]);
Map map = new HashMap();
map.put(keys[i], values[i]);
result[i] = (Map.Entry) map.entrySet().iterator().next();
}
return result;
}
@ -1187,8 +1192,8 @@ public abstract class AbstractTestMap extends AbstractTestObject {
}
protected void verifyValues() {
Bag bag1 = new HashBag(confirmed.values());
Bag bag2 = new HashBag(values);
List known = new ArrayList(confirmed.values());
List test = new ArrayList(values);
int size = confirmed.size();
boolean empty = confirmed.isEmpty();
@ -1198,8 +1203,12 @@ public abstract class AbstractTestMap extends AbstractTestObject {
empty, values.isEmpty());
assertTrue("values should contain all HashMap's elements",
values.containsAll(confirmed.values()));
assertEquals("Map's values should still equal HashMap's",
bag1, bag2);
// originally coded to use a HashBag, but now separate jar so...
for (Iterator it = known.iterator(); it.hasNext();) {
boolean removed = test.remove(it.next());
assertTrue("Map's values should still equal HashMap's", removed);
}
assertTrue("Map's values should still equal HashMap's", test.isEmpty());
}