commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject cvs commit: jakarta-commons/collections/src/test/org/apache/commons/collections AbstractTestMap.java AbstractTestBag.java
Date Sun, 05 Oct 2003 12:34:46 GMT
scolebourne    2003/10/05 05:34:46

  Modified:    collections/src/test/org/apache/commons/collections
                        AbstractTestMap.java AbstractTestBag.java
  Log:
  Make testframework jar independent of collections jar
  (Except Bag interface)
  
  Revision  Changes    Path
  1.2       +16 -7     jakarta-commons/collections/src/test/org/apache/commons/collections/AbstractTestMap.java
  
  Index: AbstractTestMap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/AbstractTestMap.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractTestMap.java	2 Oct 2003 23:01:09 -0000	1.1
  +++ AbstractTestMap.java	5 Oct 2003 12:34:46 -0000	1.2
  @@ -59,9 +59,11 @@
   
   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,6 +150,7 @@
    * @author Michael Smith
    * @author Rodney Waldhoff
    * @author Paul Jack
  + * @author Stephen Colebourne
    * @version $Revision$ $Date$
    */
   public abstract class AbstractTestMap extends AbstractTestObject {
  @@ -868,7 +871,9 @@
       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 @@
       }
   
       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 @@
                        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());
       }
   
   
  
  
  
  1.2       +73 -23    jakarta-commons/collections/src/test/org/apache/commons/collections/AbstractTestBag.java
  
  Index: AbstractTestBag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/AbstractTestBag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractTestBag.java	2 Oct 2003 22:35:31 -0000	1.1
  +++ AbstractTestBag.java	5 Oct 2003 12:34:46 -0000	1.2
  @@ -72,8 +72,10 @@
    * you may still use this base set of cases.  Simply override the
    * test case (method) your {@link Bag} fails.
    *
  + * @version $Revision$ $Date$
  + * 
    * @author Chuck Burdick
  - * @version $Id$
  + * @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 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);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message