[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jakarta-commons-dev
Subject:    cvs commit: jakarta-commons/collections/src/test/org/apache/commons/collections AbstractTestSortedMa
From:       scolebourne () apache ! org
Date:       2003-10-31 1:25:45
[Download RAW message or body]

scolebourne    2003/10/30 17:25:45

  Modified:    collections/src/test/org/apache/commons/collections
                        AbstractTestSortedMap.java
  Log:
  Add a lot of tests
  
  Revision  Changes    Path
  1.4       +216 -4    \
jakarta-commons/collections/src/test/org/apache/commons/collections/AbstractTestSortedMap.java
  
  Index: AbstractTestSortedMap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/AbstractTestSortedMap.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AbstractTestSortedMap.java	7 Oct 2003 22:20:57 -0000	1.3
  +++ AbstractTestSortedMap.java	31 Oct 2003 01:25:45 -0000	1.4
  @@ -57,8 +57,13 @@
    */
   package org.apache.commons.collections;
   
  +import java.util.ArrayList;
  +import java.util.Arrays;
   import java.util.Iterator;
  +import java.util.List;
  +import java.util.Map;
   import java.util.SortedMap;
  +import java.util.TreeMap;
   
   /**
    * Abstract test class for {@link java.util.SortedMap} methods and contracts.
  @@ -88,8 +93,15 @@
           return false;
       }
   
  -    // TODO: Add the SortedMap tests!
  -    
  +    /**
  +     * SortedMap uses TreeMap as its known comparison.
  +     * 
  +     * @return a map that is known to be valid
  +     */
  +    protected Map makeConfirmedMap() {
  +        return new TreeMap();
  +    }
  +
       //-----------------------------------------------------------------------
       public void testComparator() {
           SortedMap sm = (SortedMap) makeFullMap();
  @@ -108,6 +120,206 @@
               obj = (Object) it.next();
           }
           assertSame(obj, sm.lastKey());
  +    }
  +    
  +    //-----------------------------------------------------------------------    
  +    public BulkTest bulkTestHeadMap() {
  +        return new TestHeadMap(this);
  +    }
  +
  +    public BulkTest bulkTestTailMap() {
  +        return new TestTailMap(this);
  +    }
  +
  +    public BulkTest bulkTestSubMap() {
  +        return new TestSubMap(this);
  +    }
  +
  +    public static abstract class TestViewMap extends AbstractTestSortedMap {
  +        protected final AbstractTestMap main;
  +        protected final List subSortedKeys = new ArrayList();
  +        protected final List subSortedValues = new ArrayList();
  +        protected final List subSortedNewValues = new ArrayList();
  +        
  +        public TestViewMap(String name, AbstractTestMap main) {
  +            super(name);
  +            this.main = main;
  +        }
  +        protected void resetEmpty() {
  +            // needed to init verify correctly
  +            main.resetEmpty();
  +            super.resetEmpty();
  +        }
  +        protected void resetFull() {
  +            // needed to init verify correctly
  +            main.resetFull();
  +            super.resetFull();
  +        }
  +        protected void verify() {
  +            // cross verify changes on view with changes on main map
  +            super.verify();
  +            main.verify();
  +        }
  +        public BulkTest bulkTestHeadMap() {
  +            return null;  // block infinite recursion
  +        }
  +        public BulkTest bulkTestTailMap() {
  +            return null;  // block infinite recursion
  +        }
  +        public BulkTest bulkTestSubMap() {
  +            return null;  // block infinite recursion
  +        }
  +        
  +        protected Object[] getSampleKeys() {
  +            return subSortedKeys.toArray();
  +        }
  +        protected Object[] getSampleValues() {
  +            return subSortedValues.toArray();
  +        }
  +        protected Object[] getNewSampleValues() {
  +            return subSortedNewValues.toArray();
  +        }
  +        
  +        protected String getCompatibilityVersion() {
  +            return main.getCompatibilityVersion();
  +        }
  +        protected boolean isAllowNullKey() {
  +            return main.isAllowNullKey();
  +        }
  +        protected boolean isAllowNullValue() {
  +            return main.isAllowNullValue();
  +        }
  +        protected boolean isPutAddSupported() {
  +            return main.isPutAddSupported();
  +        }
  +        protected boolean isPutChangeSupported() {
  +            return main.isPutChangeSupported();
  +        }
  +        protected boolean isRemoveSupported() {
  +            return main.isRemoveSupported();
  +        }
  +        protected boolean supportsEmptyCollections() {
  +            return false;
  +        }
  +        protected boolean supportsFullCollections() {
  +            return false;
  +        }
  +    }
  +    
  +    public static class TestHeadMap extends TestViewMap {
  +        static final int SUBSIZE = 6;
  +        final Object toKey;
  +        
  +        public TestHeadMap(AbstractTestMap main) {
  +            super("SortedMap.HeadMap", main);
  +            SortedMap sm = (SortedMap) main.makeFullMap();
  +            for (Iterator it = sm.entrySet().iterator(); it.hasNext();) {
  +                Map.Entry entry = (Map.Entry) it.next();
  +                this.subSortedKeys.add(entry.getKey());
  +                this.subSortedValues.add(entry.getValue());
  +            }
  +            this.toKey = this.subSortedKeys.get(SUBSIZE);
  +            this.subSortedKeys.subList(SUBSIZE, \
this.subSortedKeys.size()).clear();  +            \
this.subSortedValues.subList(SUBSIZE, this.subSortedValues.size()).clear();  +        \
this.subSortedNewValues.addAll(Arrays.asList(main.getNewSampleValues()).subList(0, \
SUBSIZE));  +        }
  +        protected Map makeEmptyMap() {
  +            // done this way so toKey is correctly set in the returned map
  +            return ((SortedMap) main.makeEmptyMap()).headMap(toKey);
  +        }
  +        protected Map makeFullMap() {
  +            return ((SortedMap) main.makeFullMap()).headMap(toKey);
  +        }
  +        public void testHeadMapOutOfRange() {
  +            if (isPutAddSupported() == false) return;
  +            resetEmpty();
  +            try {
  +                ((SortedMap) map).put(toKey, subSortedValues.get(0));
  +                fail();
  +            } catch (IllegalArgumentException ex) {}
  +            verify();
  +        }
  +    }
  +    
  +    public static class TestTailMap extends TestViewMap {
  +        static final int SUBSIZE = 6;
  +        final Object fromKey;
  +        final Object invalidKey;
  +        
  +        public TestTailMap(AbstractTestMap main) {
  +            super("SortedMap.TailMap", main);
  +            SortedMap sm = (SortedMap) main.makeFullMap();
  +            for (Iterator it = sm.entrySet().iterator(); it.hasNext();) {
  +                Map.Entry entry = (Map.Entry) it.next();
  +                this.subSortedKeys.add(entry.getKey());
  +                this.subSortedValues.add(entry.getValue());
  +            }
  +            this.fromKey = this.subSortedKeys.get(this.subSortedKeys.size() - \
SUBSIZE);  +            this.invalidKey = \
this.subSortedKeys.get(this.subSortedKeys.size() - SUBSIZE - 1);  +            \
this.subSortedKeys.subList(0, this.subSortedKeys.size() - SUBSIZE).clear();  +        \
this.subSortedValues.subList(0, this.subSortedValues.size() - SUBSIZE).clear();  +    \
this.subSortedNewValues.addAll(Arrays.asList(main.getNewSampleValues()).subList(0, \
SUBSIZE));  +        }
  +        protected Map makeEmptyMap() {
  +            // done this way so toKey is correctly set in the returned map
  +            return ((SortedMap) main.makeEmptyMap()).tailMap(fromKey);
  +        }
  +        protected Map makeFullMap() {
  +            return ((SortedMap) main.makeFullMap()).tailMap(fromKey);
  +        }
  +        public void testTailMapOutOfRange() {
  +            if (isPutAddSupported() == false) return;
  +            resetEmpty();
  +            try {
  +                ((SortedMap) map).put(invalidKey, subSortedValues.get(0));
  +                fail();
  +            } catch (IllegalArgumentException ex) {}
  +            verify();
  +        }
  +    }
  +    
  +    public static class TestSubMap extends TestViewMap {
  +        static final int SUBSIZE = 3;
  +        final Object fromKey;
  +        final Object toKey;
  +        
  +        public TestSubMap(AbstractTestMap main) {
  +            super("SortedMap.SubMap", main);
  +            SortedMap sm = (SortedMap) main.makeFullMap();
  +            for (Iterator it = sm.entrySet().iterator(); it.hasNext();) {
  +                Map.Entry entry = (Map.Entry) it.next();
  +                this.subSortedKeys.add(entry.getKey());
  +                this.subSortedValues.add(entry.getValue());
  +            }
  +            this.fromKey = this.subSortedKeys.get(SUBSIZE);
  +            this.toKey = this.subSortedKeys.get(this.subSortedKeys.size() - \
SUBSIZE);  +            
  +            this.subSortedKeys.subList(0, SUBSIZE).clear();
  +            this.subSortedKeys.subList(this.subSortedKeys.size() - SUBSIZE, \
this.subSortedKeys.size()).clear();  +            
  +            this.subSortedValues.subList(0, SUBSIZE).clear();
  +            this.subSortedValues.subList(this.subSortedValues.size() - SUBSIZE, \
this.subSortedValues.size()).clear();  +            
  +            this.subSortedNewValues.addAll(Arrays.asList(main.getNewSampleValues()).subList(
  +                SUBSIZE, this.main.getNewSampleValues().length - SUBSIZE));
  +        }
  +        
  +        protected Map makeEmptyMap() {
  +            // done this way so toKey is correctly set in the returned map
  +            return ((SortedMap) main.makeEmptyMap()).subMap(fromKey, toKey);
  +        }
  +        protected Map makeFullMap() {
  +            return ((SortedMap) main.makeFullMap()).subMap(fromKey, toKey);
  +        }
  +        public void testSubMapOutOfRange() {
  +            if (isPutAddSupported() == false) return;
  +            resetEmpty();
  +            try {
  +                ((SortedMap) map).put(toKey, subSortedValues.get(0));
  +                fail();
  +            } catch (IllegalArgumentException ex) {}
  +            verify();
  +        }
       }
       
   }
  
  
  

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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic