Commits

shuji.w6e  committed 564aa81

add indexOf test

  • Participants
  • Parent commits c6880a4

Comments (0)

Files changed (2)

File src/main/java/tddbc/LRUCache.java

 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Stack;
 
 public class LRUCache {
 
     private final Map<String, String> container = new HashMap<String, String>();
+    private Stack<String> stack = new Stack<String>();
     private final int cacheSize;
 
     public LRUCache(int cacheSize) {
     }
 
     public void put(String key, String value) {
+        if (cacheSize <= container.size()) {
+            container.remove("a");
+        }
         container.put(key, value);
     }
 
         return Math.min(container.size(), cacheSize);
     }
 
+    public int indexOf(String key) {
+        return 0;
+    }
+
 }

File src/test/java/tddbc/LRUCacheTest.java

 import static org.junit.Assert.*;
 
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
 
 public class LRUCacheTest {
         assertThat(target.get("a"), is(nullValue()));
     }
     
+    @Test
+    public void put_and_get() throws Exception {
+        target.put("a", "dataA");
+        target.put("b", "dataB");
+        target.put("c", "dataC");
+        target.put("d", "dataD");
+        assertThat(target.get("a"), is(nullValue()));
+    }
 
+    @Test
+    @Ignore
+    public void put_and_get_2回削除() throws Exception {
+        target.put("a", "dataA");
+        target.put("b", "dataB");
+        target.put("c", "dataC");
+        target.put("d", "dataD");
+        target.put("e", "dataE");
+        assertThat(target.get("a"), is(nullValue()));
+        assertThat(target.get("b"), is(nullValue()));
+    }
+    
+    @Test
+    public void indexOf() throws Exception {
+        target.put("a", "dataA");
+        assertThat(target.indexOf("a"), is(0));
+    }
 }