Ejemplo n.º 1
0
        public void TimedLRUCache_GetHitStats()
        {
            TimedLRUCache <string, string> cache = new TimedLRUCache <string, string>();
            int    cHits, cMisses;
            string found;

            cache.Add("a", "a");
            cache.Add("b", "b");
            cache.Add("c", "c");

            cache.GetHitStats(out cHits, out cMisses);
            Assert.AreEqual(0, cHits);
            Assert.AreEqual(0, cMisses);

            cache.TryGetValue("a", out found);
            cache.TryGetValue("b", out found);
            cache.TryGetValue("c", out found);
            cache.TryGetValue("d", out found);

            cache.GetHitStats(out cHits, out cMisses);
            Assert.AreEqual(3, cHits);
            Assert.AreEqual(1, cMisses);

            cache.GetHitStats(out cHits, out cMisses);
            Assert.AreEqual(0, cHits);
            Assert.AreEqual(0, cMisses);

            found = cache["a"];
            found = cache["b"];

            try
            {
                found = cache["d"];
            }
            catch
            {
                // Ignore
            }

            cache.GetHitStats(out cHits, out cMisses);
            Assert.AreEqual(2, cHits);
            Assert.AreEqual(1, cMisses);
        }