Exemplo n.º 1
0
        public void CanGetEntry()
        {
            var sut = new Lru(1);

            sut.Add(1, "Test");

            Assert.Equal("Test", sut.Get(1));
        }
Exemplo n.º 2
0
        public void LeastRecentlyUsedEntryRemoved()
        {
            var sut = new Lru(1);

            sut.Add(1, "Test");
            sut.Add(2, "Test1");

            Assert.Null(sut.Get(1));
            Assert.Equal("Test1", sut.Get(2));
        }
Exemplo n.º 3
0
        public static void Test()
        {
            var cache = new Lru <string, int?>(3);

            cache.Set("a", 1);
            cache.Set("a", 2);
            cache.Set("b", 3);
            cache.Set("c", 4);

            Console.WriteLine("a={0}, b={1}, c={2}", cache.Get("a"), cache.Get("b"), cache.Get("c"));
            cache.Set("d", 5);
            Console.WriteLine("a={0}, b={1}, c={2}, d={3}", cache.Get("a"), cache.Get("b"), cache.Get("c"), cache.Get("d"));
        }
Exemplo n.º 4
0
        public void Fuzzy()
        {
            const int testCaseSize = 1000;
            var       sut          = new Lru(testCaseSize);

            for (var i = 0; i < testCaseSize; i++)
            {
                sut.Add(i, i.ToString(CultureInfo.InvariantCulture));
            }

            for (var i = testCaseSize; i < testCaseSize * 2; i++)
            {
                sut.Add(i, i.ToString(CultureInfo.InvariantCulture));
                Assert.Null(sut.Get(i - testCaseSize));
            }
        }
Exemplo n.º 5
0
        public void CanInsertEntry()
        {
            var sut = new Lru(1);

            sut.Add(1, "Test");
        }
Exemplo n.º 6
0
 protected CachedUsers()
 {
     _cache = new Lru<string, User>(CacheLength);
 }