Commits

Shuji Watanabe committed 35bf27c

registerでa_3000を与えるとbaが格納される

  • Participants
  • Parent commits 7f89752

Comments (0)

Files changed (2)

File src/main/java/tddbc/lrucache/WeightContainer.java

     }
 
     public void register(String element, long weight) {
+        if (list.contains(element)) {
+            list.remove(element);
+        }
         list.add(element);
         Set<String> set = map.get(weight);
         if (set == null) {

File src/test/java/tddbc/lrucache/WeightContainerTest.java

 
     }
 
+    public static class abが追加された場合 {
+
+        private WeightContainer sut;
+
+        @Before
+        public void setUp() throws Exception {
+            sut = new WeightContainer();
+            sut.register("a", 1000);
+            sut.register("b", 2000);
+        }
+        
+        @Test
+        public void registerでa_3000を与えるとbaが格納される() throws Exception {
+            // Exercise
+            sut.register("a", 3000);
+            // Verify
+            assertThat(sut.size(), is(2));
+            assertThat(sut.get(0), is("b"));
+            assertThat(sut.get(1), is("a"));
+        }
+    }
+
     public static class abcが追加された場合 {
 
         private WeightContainer sut;