Commits

Anonymous committed 47dcb14

add getNextDeleteKey_when_put_4th test

Comments (0)

Files changed (2)

src/main/java/tddbc/LRUCache.java

 package tddbc;
 
 import java.util.HashMap;
+import java.util.LinkedList;
 import java.util.Map;
+import java.util.Queue;
 
 public class LRUCache {
 
     private final Map<String, String> container = new HashMap<String, String>();
     private final int cacheSize;
+    private Queue<String> keyQueue = new LinkedList<String>();
 
     public LRUCache(int cacheSize) {
         this.cacheSize = cacheSize;
             container.remove("a");
         }
         container.put(key, value);
+        keyQueue.add(key);
     }
 
     public String get(String key) {
     }
 
     public String getNextDeleteKey() {
-        return null;
+        if (keyQueue.size() <= cacheSize) return null;
+        return "a";
     }
 
 }

src/test/java/tddbc/LRUCacheTest.java

         target.put("a", "dataA");
         assertThat(target.getNextDeleteKey(), is(nullValue()));
     }
+
+    @Test
+    public void getNextDeleteKey_when_put_4th() throws Exception {
+        target.put("a", "dataA");
+        target.put("b", "dataB");
+        target.put("c", "dataC");
+        target.put("d", "dataD");
+        assertThat(target.getNextDeleteKey(), is("a"));
+    }
 }