예제 #1
0
        public void adding_duplicate_keys_should_replace_value()
        {
            LRUCache cache = new LRUCache(10);

            string key = "key1";
            string value = "value1";

            cache.Add(key, value);
            cache.Exists(key).ShouldBeTrue();
            cache.Get(key).ShouldEqual(value);

            value = "some new value";
            cache.Add(key,value);
            cache.Get(key).ShouldEqual(value);
        }
예제 #2
0
        public void get_should_reset_timestamp()
        {
            LRUCache cache = new LRUCache(3);

            cache.Add("key1", "value1");
            cache.Add("key2", "value2");
            cache.Add("key3", "value3");

            // if we call Get using key1, it becomes youngest
            cache.Get("key1");

            // now when we add one more, the oldest should be removed. Oldest is now key2
            cache.Add("key4", "value4");

            cache.Exists("key1").ShouldBeTrue("key1 should be in cache");
            cache.Exists("key2").ShouldBeFalse("key2 should NOT be in cache");
            cache.Exists("key3").ShouldBeTrue("key3 should be in cache");
            cache.Exists("key4").ShouldBeTrue("key4 should be in cache");
        }