commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From morg...@apache.org
Subject cvs commit: jakarta-commons/collections/src/test/org/apache/commons/collections TestLRUMap.java
Date Wed, 08 May 2002 16:07:06 GMT
morgand     02/05/08 09:07:06

  Modified:    collections/src/test/org/apache/commons/collections
                        TestLRUMap.java
  Log:
  test to make sure that gets promote keys to the Most Recently Used
  position
  
  Revision  Changes    Path
  1.18      +31 -4     jakarta-commons/collections/src/test/org/apache/commons/collections/TestLRUMap.java
  
  Index: TestLRUMap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestLRUMap.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- TestLRUMap.java	22 Feb 2002 22:26:01 -0000	1.17
  +++ TestLRUMap.java	8 May 2002 16:07:05 -0000	1.18
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestLRUMap.java,v
1.17 2002/02/22 22:26:01 morgand Exp $
  - * $Revision: 1.17 $
  - * $Date: 2002/02/22 22:26:01 $
  + * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestLRUMap.java,v
1.18 2002/05/08 16:07:05 morgand Exp $
  + * $Revision: 1.18 $
  + * $Date: 2002/05/08 16:07:05 $
    *
    * ====================================================================
    *
  @@ -65,6 +65,7 @@
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
   import java.util.ArrayList;
  +import java.util.Iterator;
   import java.util.Map;
   import java.util.HashMap;
   
  @@ -72,7 +73,7 @@
    * 
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @author <a href="mailto:morgand@apache.org">Morgan Delagrange</a>
  - * @version $Id: TestLRUMap.java,v 1.17 2002/02/22 22:26:01 morgand Exp $
  + * @version $Id: TestLRUMap.java,v 1.18 2002/05/08 16:07:05 morgand Exp $
    */
   public class TestLRUMap extends TestSequencedHashMap
   {
  @@ -154,6 +155,32 @@
   
           assertTrue("map should have size = 3, but actually = " + map.size(), 
                      map.size() == 3);
  +    }
  +
  +    public void testGetPromotion() {
  +        LRUMap map = new LRUMap(3);
  +        map.put("1","1");
  +        map.put("2","2");
  +        map.put("3","3");
  +        // LRU is now 1 (then 2 then 3)
  +
  +        // promote 1 to top
  +        // eviction order is now 2,3,1
  +        map.get("1");
  +
  +        // add another value, forcing a remove
  +        // 2 should be evicted (then 3,1,4)
  +        map.put("4","4");
  +
  +        Iterator keyIterator = map.keySet().iterator();
  +        Object[] keys = new Object[3];
  +        for (int i = 0; keyIterator.hasNext() ; ++i) {
  +            keys[i] = keyIterator.next();
  +        }
  +
  +        assertTrue("first evicted should be 3, was " + keys[0], keys[0].equals("3"));
  +        assertTrue("second evicted should be 1, was " + keys[1], keys[1].equals("1"));
  +        assertTrue("third evicted should be 4, was " + keys[2], keys[2].equals("4"));
       }
   
       /**
  
  
  

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


Mime
View raw message