Exemplo n.º 1
0
        public void adding_more_items_than_size_should_remove_oldest_item()
        {
            LRUCache cache = new LRUCache(3);

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

            cache.Add("key4","value4");

            cache.Exists("key1").ShouldBeFalse("key1 should not be in cache");
            cache.Exists("key2").ShouldBeTrue("key2 should be in cache");
            cache.Exists("key3").ShouldBeTrue("key3 should be in cache");
            cache.Exists("key4").ShouldBeTrue("key4 should be in cache");
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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");
        }
Exemplo n.º 4
0
        public void exists_should_reset_timestamp()
        {
            LRUCache cache = new LRUCache(3);

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

            // if we check whether key1 Exists, it becomes youngest
            cache.Exists("key1");

            // now when we add one more, the oldest (which is now key2) should be removed.
            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");
        }
Exemplo n.º 5
0
        public void Should_be_able_to_add_to_a_new_cache()
        {
            LRUCache cache = new LRUCache(10);

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

            cache.Add(key, value);
            cache.Exists(key).ShouldBeTrue();
        }