public void PerformAddAndGet()
 {
     try
     {
         Console.WriteLine(string.Format("Starting thread #{0} ", this.taskIndex));
         foreach (String line in userAgents)
         {
             try
             {
                 cache.PutEntry(line, new Object());
                 cache.GetEntry(line);
                 readLines++;
             }
             catch (Exception e)
             {
                 Assert.Fail("Test failed with exceptions " + e.StackTrace);
             }
         }
         this.success = true;
     }
     finally
     {
         Console.WriteLine(string.Format("{0} user agents read", readLines));
         Console.WriteLine(string.Format("Thread #{0} finished execution", this.taskIndex));
     }
 }
        public void LRUCache_RemoveOnMaxSizeTest()
        {
            LRUCache <string, TestNode> cache = new LRUCache <string, TestNode>(5);

            for (int i = 0; i < 6; i++)
            {
                cache.PutEntry(i.ToString(), new TestNode(i.ToString(), i));
            }
            Assert.AreEqual(cache.Size(), 5);
            // "0" entry has been removed when inserting "6"
            Assert.Null(cache.GetEntry("0"));
        }
        public void LRUCache_ReplaceExistingItemTest()
        {
            LRUCache <string, TestNode> cache = new LRUCache <string, TestNode>(5);

            for (int i = 0; i < 5; i++)
            {
                cache.PutEntry(i.ToString(), new TestNode(i.ToString(), i));
            }
            Assert.AreEqual(cache.Size(), 5);
            // Now put an element with the same key and a different value
            cache.PutEntry("2", new TestNode("2", 159));
            // previous value has been overwritten
            Assert.AreEqual(159, cache.GetEntry("2").Value);
        }
        public void LRUCache_ReplaceOnMultiAddTest()
        {
            LRUCache <string, Int32> cache = new LRUCache <string, Int32>(5);

            for (int i = 0; i < 6; i++)
            {
                cache.PutEntry(i.ToString(), i);
            }

            // re-add element with different value
            cache.PutEntry("3", 7);
            Assert.AreEqual(cache.Size(), 5);
            // "0" entry has been removed when inserting "6"
            Assert.AreEqual(cache.GetEntry("3"), 7);
        }