rename _a/_b to collectionA/collectionB

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131262 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Rodney Waldhoff 2003-10-09 11:03:55 +00:00
parent 7b2af5cff1
commit 96e2ca244e
1 changed files with 108 additions and 108 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/TestCollectionUtils.java,v 1.28 2003/10/09 11:00:09 rwaldhoff Exp $ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestCollectionUtils.java,v 1.29 2003/10/09 11:03:55 rwaldhoff Exp $
* ==================================================================== * ====================================================================
* *
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
@ -89,7 +89,7 @@ import org.apache.commons.collections.decorators.UnmodifiableCollection;
* @author Stephen Colebourne * @author Stephen Colebourne
* @author Phil Steitz * @author Phil Steitz
* *
* @version $Revision: 1.28 $ $Date: 2003/10/09 11:00:09 $ * @version $Revision: 1.29 $ $Date: 2003/10/09 11:03:55 $
*/ */
public class TestCollectionUtils extends TestCase { public class TestCollectionUtils extends TestCase {
@ -106,44 +106,44 @@ public class TestCollectionUtils extends TestCase {
junit.textui.TestRunner.main(testCaseName); junit.textui.TestRunner.main(testCaseName);
} }
private Collection _a = null; private Collection collectionA = null;
private Collection _b = null; private Collection collectionB = null;
public void setUp() { public void setUp() {
_a = new ArrayList(); collectionA = new ArrayList();
_a.add("a"); collectionA.add("a");
_a.add("b"); collectionA.add("b");
_a.add("b"); collectionA.add("b");
_a.add("c"); collectionA.add("c");
_a.add("c"); collectionA.add("c");
_a.add("c"); collectionA.add("c");
_a.add("d"); collectionA.add("d");
_a.add("d"); collectionA.add("d");
_a.add("d"); collectionA.add("d");
_a.add("d"); collectionA.add("d");
_b = new LinkedList(); collectionB = new LinkedList();
_b.add("e"); collectionB.add("e");
_b.add("d"); collectionB.add("d");
_b.add("d"); collectionB.add("d");
_b.add("c"); collectionB.add("c");
_b.add("c"); collectionB.add("c");
_b.add("c"); collectionB.add("c");
_b.add("b"); collectionB.add("b");
_b.add("b"); collectionB.add("b");
_b.add("b"); collectionB.add("b");
_b.add("b"); collectionB.add("b");
} }
public void testGetCardinalityMap() { public void testGetCardinalityMap() {
Map freq = CollectionUtils.getCardinalityMap(_a); Map freq = CollectionUtils.getCardinalityMap(collectionA);
assertEquals(new Integer(1),freq.get("a")); assertEquals(new Integer(1),freq.get("a"));
assertEquals(new Integer(2),freq.get("b")); assertEquals(new Integer(2),freq.get("b"));
assertEquals(new Integer(3),freq.get("c")); assertEquals(new Integer(3),freq.get("c"));
assertEquals(new Integer(4),freq.get("d")); assertEquals(new Integer(4),freq.get("d"));
assertNull(freq.get("e")); assertNull(freq.get("e"));
freq = CollectionUtils.getCardinalityMap(_b); freq = CollectionUtils.getCardinalityMap(collectionB);
assertNull(freq.get("a")); assertNull(freq.get("a"));
assertEquals(new Integer(4),freq.get("b")); assertEquals(new Integer(4),freq.get("b"));
assertEquals(new Integer(3),freq.get("c")); assertEquals(new Integer(3),freq.get("c"));
@ -152,17 +152,17 @@ public class TestCollectionUtils extends TestCase {
} }
public void testCardinality() { public void testCardinality() {
assertEquals(1,CollectionUtils.cardinality("a",_a)); assertEquals(1,CollectionUtils.cardinality("a",collectionA));
assertEquals(2,CollectionUtils.cardinality("b",_a)); assertEquals(2,CollectionUtils.cardinality("b",collectionA));
assertEquals(3,CollectionUtils.cardinality("c",_a)); assertEquals(3,CollectionUtils.cardinality("c",collectionA));
assertEquals(4,CollectionUtils.cardinality("d",_a)); assertEquals(4,CollectionUtils.cardinality("d",collectionA));
assertEquals(0,CollectionUtils.cardinality("e",_a)); assertEquals(0,CollectionUtils.cardinality("e",collectionA));
assertEquals(0,CollectionUtils.cardinality("a",_b)); assertEquals(0,CollectionUtils.cardinality("a",collectionB));
assertEquals(4,CollectionUtils.cardinality("b",_b)); assertEquals(4,CollectionUtils.cardinality("b",collectionB));
assertEquals(3,CollectionUtils.cardinality("c",_b)); assertEquals(3,CollectionUtils.cardinality("c",collectionB));
assertEquals(2,CollectionUtils.cardinality("d",_b)); assertEquals(2,CollectionUtils.cardinality("d",collectionB));
assertEquals(1,CollectionUtils.cardinality("e",_b)); assertEquals(1,CollectionUtils.cardinality("e",collectionB));
} }
public void testCardinalityOfNull() { public void testCardinalityOfNull() {
@ -252,7 +252,7 @@ public class TestCollectionUtils extends TestCase {
} }
public void testUnion() { public void testUnion() {
Collection col = CollectionUtils.union(_a,_b); Collection col = CollectionUtils.union(collectionA,collectionB);
Map freq = CollectionUtils.getCardinalityMap(col); Map freq = CollectionUtils.getCardinalityMap(col);
assertEquals(new Integer(1),freq.get("a")); assertEquals(new Integer(1),freq.get("a"));
assertEquals(new Integer(4),freq.get("b")); assertEquals(new Integer(4),freq.get("b"));
@ -260,7 +260,7 @@ public class TestCollectionUtils extends TestCase {
assertEquals(new Integer(4),freq.get("d")); assertEquals(new Integer(4),freq.get("d"));
assertEquals(new Integer(1),freq.get("e")); assertEquals(new Integer(1),freq.get("e"));
Collection col2 = CollectionUtils.union(_b,_a); Collection col2 = CollectionUtils.union(collectionB,collectionA);
Map freq2 = CollectionUtils.getCardinalityMap(col2); Map freq2 = CollectionUtils.getCardinalityMap(col2);
assertEquals(new Integer(1),freq2.get("a")); assertEquals(new Integer(1),freq2.get("a"));
assertEquals(new Integer(4),freq2.get("b")); assertEquals(new Integer(4),freq2.get("b"));
@ -270,7 +270,7 @@ public class TestCollectionUtils extends TestCase {
} }
public void testIntersection() { public void testIntersection() {
Collection col = CollectionUtils.intersection(_a,_b); Collection col = CollectionUtils.intersection(collectionA,collectionB);
Map freq = CollectionUtils.getCardinalityMap(col); Map freq = CollectionUtils.getCardinalityMap(col);
assertNull(freq.get("a")); assertNull(freq.get("a"));
assertEquals(new Integer(2),freq.get("b")); assertEquals(new Integer(2),freq.get("b"));
@ -278,7 +278,7 @@ public class TestCollectionUtils extends TestCase {
assertEquals(new Integer(2),freq.get("d")); assertEquals(new Integer(2),freq.get("d"));
assertNull(freq.get("e")); assertNull(freq.get("e"));
Collection col2 = CollectionUtils.intersection(_b,_a); Collection col2 = CollectionUtils.intersection(collectionB,collectionA);
Map freq2 = CollectionUtils.getCardinalityMap(col2); Map freq2 = CollectionUtils.getCardinalityMap(col2);
assertNull(freq2.get("a")); assertNull(freq2.get("a"));
assertEquals(new Integer(2),freq2.get("b")); assertEquals(new Integer(2),freq2.get("b"));
@ -288,7 +288,7 @@ public class TestCollectionUtils extends TestCase {
} }
public void testDisjunction() { public void testDisjunction() {
Collection col = CollectionUtils.disjunction(_a,_b); Collection col = CollectionUtils.disjunction(collectionA,collectionB);
Map freq = CollectionUtils.getCardinalityMap(col); Map freq = CollectionUtils.getCardinalityMap(col);
assertEquals(new Integer(1),freq.get("a")); assertEquals(new Integer(1),freq.get("a"));
assertEquals(new Integer(2),freq.get("b")); assertEquals(new Integer(2),freq.get("b"));
@ -296,7 +296,7 @@ public class TestCollectionUtils extends TestCase {
assertEquals(new Integer(2),freq.get("d")); assertEquals(new Integer(2),freq.get("d"));
assertEquals(new Integer(1),freq.get("e")); assertEquals(new Integer(1),freq.get("e"));
Collection col2 = CollectionUtils.disjunction(_b,_a); Collection col2 = CollectionUtils.disjunction(collectionB,collectionA);
Map freq2 = CollectionUtils.getCardinalityMap(col2); Map freq2 = CollectionUtils.getCardinalityMap(col2);
assertEquals(new Integer(1),freq2.get("a")); assertEquals(new Integer(1),freq2.get("a"));
assertEquals(new Integer(2),freq2.get("b")); assertEquals(new Integer(2),freq2.get("b"));
@ -306,21 +306,21 @@ public class TestCollectionUtils extends TestCase {
} }
public void testDisjunctionAsUnionMinusIntersection() { public void testDisjunctionAsUnionMinusIntersection() {
Collection dis = CollectionUtils.disjunction(_a,_b); Collection dis = CollectionUtils.disjunction(collectionA,collectionB);
Collection un = CollectionUtils.union(_a,_b); Collection un = CollectionUtils.union(collectionA,collectionB);
Collection inter = CollectionUtils.intersection(_a,_b); Collection inter = CollectionUtils.intersection(collectionA,collectionB);
assertTrue(CollectionUtils.isEqualCollection(dis,CollectionUtils.subtract(un,inter))); assertTrue(CollectionUtils.isEqualCollection(dis,CollectionUtils.subtract(un,inter)));
} }
public void testDisjunctionAsSymmetricDifference() { public void testDisjunctionAsSymmetricDifference() {
Collection dis = CollectionUtils.disjunction(_a,_b); Collection dis = CollectionUtils.disjunction(collectionA,collectionB);
Collection amb = CollectionUtils.subtract(_a,_b); Collection amb = CollectionUtils.subtract(collectionA,collectionB);
Collection bma = CollectionUtils.subtract(_b,_a); Collection bma = CollectionUtils.subtract(collectionB,collectionA);
assertTrue(CollectionUtils.isEqualCollection(dis,CollectionUtils.union(amb,bma))); assertTrue(CollectionUtils.isEqualCollection(dis,CollectionUtils.union(amb,bma)));
} }
public void testSubtract() { public void testSubtract() {
Collection col = CollectionUtils.subtract(_a,_b); Collection col = CollectionUtils.subtract(collectionA,collectionB);
Map freq = CollectionUtils.getCardinalityMap(col); Map freq = CollectionUtils.getCardinalityMap(col);
assertEquals(new Integer(1),freq.get("a")); assertEquals(new Integer(1),freq.get("a"));
assertNull(freq.get("b")); assertNull(freq.get("b"));
@ -328,7 +328,7 @@ public class TestCollectionUtils extends TestCase {
assertEquals(new Integer(2),freq.get("d")); assertEquals(new Integer(2),freq.get("d"));
assertNull(freq.get("e")); assertNull(freq.get("e"));
Collection col2 = CollectionUtils.subtract(_b,_a); Collection col2 = CollectionUtils.subtract(collectionB,collectionA);
Map freq2 = CollectionUtils.getCardinalityMap(col2); Map freq2 = CollectionUtils.getCardinalityMap(col2);
assertEquals(new Integer(1),freq2.get("e")); assertEquals(new Integer(1),freq2.get("e"));
assertNull(freq2.get("d")); assertNull(freq2.get("d"));
@ -338,62 +338,62 @@ public class TestCollectionUtils extends TestCase {
} }
public void testIsSubCollectionOfSelf() { public void testIsSubCollectionOfSelf() {
assertTrue(CollectionUtils.isSubCollection(_a,_a)); assertTrue(CollectionUtils.isSubCollection(collectionA,collectionA));
assertTrue(CollectionUtils.isSubCollection(_b,_b)); assertTrue(CollectionUtils.isSubCollection(collectionB,collectionB));
} }
public void testIsSubCollection() { public void testIsSubCollection() {
assertTrue(!CollectionUtils.isSubCollection(_a,_b)); assertTrue(!CollectionUtils.isSubCollection(collectionA,collectionB));
assertTrue(!CollectionUtils.isSubCollection(_b,_a)); assertTrue(!CollectionUtils.isSubCollection(collectionB,collectionA));
} }
public void testIsSubCollection2() { public void testIsSubCollection2() {
Collection c = new ArrayList(); Collection c = new ArrayList();
assertTrue(CollectionUtils.isSubCollection(c,_a)); assertTrue(CollectionUtils.isSubCollection(c,collectionA));
assertTrue(!CollectionUtils.isSubCollection(_a,c)); assertTrue(!CollectionUtils.isSubCollection(collectionA,c));
c.add("a"); c.add("a");
assertTrue(CollectionUtils.isSubCollection(c,_a)); assertTrue(CollectionUtils.isSubCollection(c,collectionA));
assertTrue(!CollectionUtils.isSubCollection(_a,c)); assertTrue(!CollectionUtils.isSubCollection(collectionA,c));
c.add("b"); c.add("b");
assertTrue(CollectionUtils.isSubCollection(c,_a)); assertTrue(CollectionUtils.isSubCollection(c,collectionA));
assertTrue(!CollectionUtils.isSubCollection(_a,c)); assertTrue(!CollectionUtils.isSubCollection(collectionA,c));
c.add("b"); c.add("b");
assertTrue(CollectionUtils.isSubCollection(c,_a)); assertTrue(CollectionUtils.isSubCollection(c,collectionA));
assertTrue(!CollectionUtils.isSubCollection(_a,c)); assertTrue(!CollectionUtils.isSubCollection(collectionA,c));
c.add("c"); c.add("c");
assertTrue(CollectionUtils.isSubCollection(c,_a)); assertTrue(CollectionUtils.isSubCollection(c,collectionA));
assertTrue(!CollectionUtils.isSubCollection(_a,c)); assertTrue(!CollectionUtils.isSubCollection(collectionA,c));
c.add("c"); c.add("c");
assertTrue(CollectionUtils.isSubCollection(c,_a)); assertTrue(CollectionUtils.isSubCollection(c,collectionA));
assertTrue(!CollectionUtils.isSubCollection(_a,c)); assertTrue(!CollectionUtils.isSubCollection(collectionA,c));
c.add("c"); c.add("c");
assertTrue(CollectionUtils.isSubCollection(c,_a)); assertTrue(CollectionUtils.isSubCollection(c,collectionA));
assertTrue(!CollectionUtils.isSubCollection(_a,c)); assertTrue(!CollectionUtils.isSubCollection(collectionA,c));
c.add("d"); c.add("d");
assertTrue(CollectionUtils.isSubCollection(c,_a)); assertTrue(CollectionUtils.isSubCollection(c,collectionA));
assertTrue(!CollectionUtils.isSubCollection(_a,c)); assertTrue(!CollectionUtils.isSubCollection(collectionA,c));
c.add("d"); c.add("d");
assertTrue(CollectionUtils.isSubCollection(c,_a)); assertTrue(CollectionUtils.isSubCollection(c,collectionA));
assertTrue(!CollectionUtils.isSubCollection(_a,c)); assertTrue(!CollectionUtils.isSubCollection(collectionA,c));
c.add("d"); c.add("d");
assertTrue(CollectionUtils.isSubCollection(c,_a)); assertTrue(CollectionUtils.isSubCollection(c,collectionA));
assertTrue(!CollectionUtils.isSubCollection(_a,c)); assertTrue(!CollectionUtils.isSubCollection(collectionA,c));
c.add("d"); c.add("d");
assertTrue(CollectionUtils.isSubCollection(c,_a)); assertTrue(CollectionUtils.isSubCollection(c,collectionA));
assertTrue(CollectionUtils.isSubCollection(_a,c)); assertTrue(CollectionUtils.isSubCollection(collectionA,c));
c.add("e"); c.add("e");
assertTrue(!CollectionUtils.isSubCollection(c,_a)); assertTrue(!CollectionUtils.isSubCollection(c,collectionA));
assertTrue(CollectionUtils.isSubCollection(_a,c)); assertTrue(CollectionUtils.isSubCollection(collectionA,c));
} }
public void testIsEqualCollectionToSelf() { public void testIsEqualCollectionToSelf() {
assertTrue(CollectionUtils.isEqualCollection(_a,_a)); assertTrue(CollectionUtils.isEqualCollection(collectionA,collectionA));
assertTrue(CollectionUtils.isEqualCollection(_b,_b)); assertTrue(CollectionUtils.isEqualCollection(collectionB,collectionB));
} }
public void testIsEqualCollection() { public void testIsEqualCollection() {
assertTrue(!CollectionUtils.isEqualCollection(_a,_b)); assertTrue(!CollectionUtils.isEqualCollection(collectionA,collectionB));
assertTrue(!CollectionUtils.isEqualCollection(_b,_a)); assertTrue(!CollectionUtils.isEqualCollection(collectionB,collectionA));
} }
public void testIsEqualCollection2() { public void testIsEqualCollection2() {
@ -438,7 +438,7 @@ public class TestCollectionUtils extends TestCase {
a.add("1"); a.add("1");
assertTrue(CollectionUtils.isProperSubCollection(b,a)); assertTrue(CollectionUtils.isProperSubCollection(b,a));
assertTrue(CollectionUtils.isProperSubCollection( assertTrue(CollectionUtils.isProperSubCollection(
CollectionUtils.intersection(_a, _b), _a)); CollectionUtils.intersection(collectionA, collectionB), collectionA));
assertTrue(CollectionUtils.isProperSubCollection( assertTrue(CollectionUtils.isProperSubCollection(
CollectionUtils.subtract(a, b), a)); CollectionUtils.subtract(a, b), a));
assertTrue(!CollectionUtils.isProperSubCollection( assertTrue(!CollectionUtils.isProperSubCollection(
@ -447,24 +447,24 @@ public class TestCollectionUtils extends TestCase {
public void testFind() { public void testFind() {
Predicate testPredicate = PredicateUtils.equalPredicate("d"); Predicate testPredicate = PredicateUtils.equalPredicate("d");
Object test = CollectionUtils.find(_a, testPredicate); Object test = CollectionUtils.find(collectionA, testPredicate);
assertTrue(test.equals("d")); assertTrue(test.equals("d"));
testPredicate = PredicateUtils.equalPredicate("de"); testPredicate = PredicateUtils.equalPredicate("de");
test = CollectionUtils.find(_a, testPredicate); test = CollectionUtils.find(collectionA, testPredicate);
assertTrue(test == null); assertTrue(test == null);
assertEquals(CollectionUtils.find(null,testPredicate), null); assertEquals(CollectionUtils.find(null,testPredicate), null);
assertEquals(CollectionUtils.find(_a, null), null); assertEquals(CollectionUtils.find(collectionA, null), null);
} }
public void testForAllDo() { public void testForAllDo() {
Closure testClosure = ClosureUtils.invokerClosure("clear"); Closure testClosure = ClosureUtils.invokerClosure("clear");
Collection col = new ArrayList(); Collection col = new ArrayList();
col.add(_a); col.add(collectionA);
col.add(_b); col.add(collectionB);
CollectionUtils.forAllDo(col, testClosure); CollectionUtils.forAllDo(col, testClosure);
assertTrue(_a.isEmpty() && _b.isEmpty()); assertTrue(collectionA.isEmpty() && collectionB.isEmpty());
CollectionUtils.forAllDo(col, null); CollectionUtils.forAllDo(col, null);
assertTrue(_a.isEmpty() && _b.isEmpty()); assertTrue(collectionA.isEmpty() && collectionB.isEmpty());
CollectionUtils.forAllDo(null, testClosure); CollectionUtils.forAllDo(null, testClosure);
col.add(null); col.add(null);
// null should be OK // null should be OK
@ -815,39 +815,39 @@ public class TestCollectionUtils extends TestCase {
public void testCollect() { public void testCollect() {
Transformer transformer = TransformerUtils.constantTransformer("z"); Transformer transformer = TransformerUtils.constantTransformer("z");
Collection collection = CollectionUtils.collect(_a, transformer); Collection collection = CollectionUtils.collect(collectionA, transformer);
assertTrue(collection.size() == _a.size()); assertTrue(collection.size() == collectionA.size());
assertTrue(_a.contains("a") && ! _a.contains("z")); assertTrue(collectionA.contains("a") && ! collectionA.contains("z"));
assertTrue(collection.contains("z") && !collection.contains("a")); assertTrue(collection.contains("z") && !collection.contains("a"));
collection = new ArrayList(); collection = new ArrayList();
CollectionUtils.collect(_a, transformer, collection); CollectionUtils.collect(collectionA, transformer, collection);
assertTrue(collection.size() == _a.size()); assertTrue(collection.size() == collectionA.size());
assertTrue(_a.contains("a") && ! _a.contains("z")); assertTrue(collectionA.contains("a") && ! collectionA.contains("z"));
assertTrue(collection.contains("z") && !collection.contains("a")); assertTrue(collection.contains("z") && !collection.contains("a"));
Iterator iterator = null; Iterator iterator = null;
collection = new ArrayList(); collection = new ArrayList();
CollectionUtils.collect(iterator, transformer, collection); CollectionUtils.collect(iterator, transformer, collection);
iterator = _a.iterator(); iterator = collectionA.iterator();
CollectionUtils.collect(iterator, transformer, collection); CollectionUtils.collect(iterator, transformer, collection);
assertTrue(collection.size() == _a.size()); assertTrue(collection.size() == collectionA.size());
assertTrue(_a.contains("a") && ! _a.contains("z")); assertTrue(collectionA.contains("a") && ! collectionA.contains("z"));
assertTrue(collection.contains("z") && !collection.contains("a")); assertTrue(collection.contains("z") && !collection.contains("a"));
iterator = _a.iterator(); iterator = collectionA.iterator();
collection = CollectionUtils.collect(iterator, transformer); collection = CollectionUtils.collect(iterator, transformer);
assertTrue(collection.size() == _a.size()); assertTrue(collection.size() == collectionA.size());
assertTrue(collection.contains("z") && !collection.contains("a")); assertTrue(collection.contains("z") && !collection.contains("a"));
collection = CollectionUtils.collect((Iterator) null, (Transformer) null); collection = CollectionUtils.collect((Iterator) null, (Transformer) null);
assertTrue(collection.size() == 0); assertTrue(collection.size() == 0);
int size = _a.size(); int size = collectionA.size();
CollectionUtils.collect((Collection) null, transformer, _a); CollectionUtils.collect((Collection) null, transformer, collectionA);
assertTrue(_a.size() == size && _a.contains("a")); assertTrue(collectionA.size() == size && collectionA.contains("a"));
CollectionUtils.collect(_b, null, _a); CollectionUtils.collect(collectionB, null, collectionA);
assertTrue(_a.size() == size && _a.contains("a")); assertTrue(collectionA.size() == size && collectionA.contains("a"));
} }