예제 #1
0
파일: T_LRUCache.cs 프로젝트: cjuniet/pads
        public void Remove()
        {
            var dico = new LRUCache<string, int>();

            dico.Set("the answer", 42);
            Assert.AreEqual(42, dico.RawGet("the answer"));
            Assert.AreEqual(1, dico.Count);
            Assert.AreEqual(1, dico.NbUpdate);

            dico.Remove("the answer");
            Assert.AreEqual(0, dico.RawGet("the answer"));
            Assert.AreEqual(0, dico.Count);
            Assert.AreEqual(1, dico.NbUpdate);
        }
예제 #2
0
파일: T_LRUCache.cs 프로젝트: cjuniet/pads
        public void SetGet()
        {
            var dico = new LRUCache<string, int>();

            dico.Set("the answer", 42);
            Assert.AreEqual(42, dico.RawGet("the answer"));
            Assert.AreEqual(1, dico.Count);
            Assert.AreEqual(1, dico.NbUpdate);
            Assert.AreEqual(0, dico.NbHit);
            Assert.AreEqual(1, dico.NbMiss);
            Assert.AreEqual(0, dico.NbEviction);

            int fortytwo = dico.Get("the answer");
            Assert.AreEqual(42, fortytwo);
            Assert.AreEqual(1, dico.Count);
            Assert.AreEqual(1, dico.NbUpdate);
            Assert.AreEqual(1, dico.NbHit);
            Assert.AreEqual(1, dico.NbMiss);
            Assert.AreEqual(0, dico.NbEviction);

            int fortythree = dico.Get("the wrong answer");
            Assert.AreEqual(0, fortythree);
            Assert.AreEqual(1, dico.Count);
            Assert.AreEqual(1, dico.NbUpdate);
            Assert.AreEqual(1, dico.NbHit);
            Assert.AreEqual(2, dico.NbMiss);
            Assert.AreEqual(0, dico.NbEviction);

            dico.Set("the answer", 24);
            Assert.AreEqual(24, dico.RawGet("the answer"));
            Assert.AreEqual(1, dico.Count);
            Assert.AreEqual(2, dico.NbUpdate);
            Assert.AreEqual(2, dico.NbHit);
            Assert.AreEqual(2, dico.NbMiss);
            Assert.AreEqual(0, dico.NbEviction);
        }
예제 #3
0
파일: T_LRUCache.cs 프로젝트: cjuniet/pads
        public void Clear()
        {
            var dico = new LRUCache<string, int>();

            dico.Set("one", 1);
            dico.Set("two", 2);
            dico.Set("three", 3);
            Assert.AreEqual(1, dico.RawGet("one"));
            Assert.AreEqual(2, dico.RawGet("two"));
            Assert.AreEqual(3, dico.RawGet("three"));
            Assert.AreEqual(3, dico.Count);
            Assert.AreEqual(3, dico.NbUpdate);

            dico.Clear();
            Assert.AreEqual(0, dico.RawGet("one"));
            Assert.AreEqual(0, dico.RawGet("two"));
            Assert.AreEqual(0, dico.RawGet("three"));
            Assert.AreEqual(0, dico.Count);
        }
예제 #4
0
파일: T_LRUCache.cs 프로젝트: cjuniet/pads
        public void TestLru()
        {
            var dico = new LRUCache<string, int>(2);

            dico.Set("one", 1);
            Assert.AreEqual(1, dico.RawGet("one"));
            Assert.AreEqual(1, dico.NbUpdate);
            Assert.AreEqual(0, dico.NbEviction);

            dico.Set("two", 2);
            Assert.AreEqual(1, dico.RawGet("one"));
            Assert.AreEqual(2, dico.RawGet("two"));
            Assert.AreEqual(2, dico.NbUpdate);
            Assert.AreEqual(0, dico.NbEviction);

            var u = dico.NbUpdate;
            var e = dico.NbEviction;
            for (int i = 0; i < 1000; ++i)
            {
                dico.Set("three", 3);
                Assert.AreEqual(0, dico.RawGet("one"));
                Assert.AreEqual(2, dico.RawGet("two"));
                Assert.AreEqual(3, dico.RawGet("three"));
                Assert.AreEqual(++u, dico.NbUpdate);
                Assert.AreEqual(++e, dico.NbEviction);

                dico.Set("one", 1);
                Assert.AreEqual(1, dico.RawGet("one"));
                Assert.AreEqual(0, dico.RawGet("two"));
                Assert.AreEqual(3, dico.RawGet("three"));
                Assert.AreEqual(++u, dico.NbUpdate);
                Assert.AreEqual(++e, dico.NbEviction);

                dico.Set("two", 2);
                Assert.AreEqual(1, dico.RawGet("one"));
                Assert.AreEqual(2, dico.RawGet("two"));
                Assert.AreEqual(0, dico.RawGet("three"));
                Assert.AreEqual(++u, dico.NbUpdate);
                Assert.AreEqual(++e, dico.NbEviction);
            }
        }