private static void GetAddTestAssert(int index, Element ele, LRUElementCache cache)
        {
            cache.AddToCache(ele, index);

            Element actual = cache.Get(index);

            Assert.AreEqual(ele, actual);
        }
        public void GetTest()
        {
            LRUElementCache cache = new LRUElementCache(9);

            int     index = 0;
            Element ele   = new Element(new byte[0]);

            GetAddTestAssert(index, ele, cache);

            int     index1 = 1;
            Element ele1   = new Element(new byte[0]);

            GetAddTestAssert(index1, ele1, cache);

            int     index2 = 2;
            Element ele2   = new Element(new byte[0]);

            GetAddTestAssert(index2, ele2, cache);

            int     index3 = 2;
            Element ele3   = new Element(new byte[0]);

            GetAddTestAssert(index3, ele3, cache);

            Element ele4 = cache.Get(4);

            Assert.IsNull(ele4);

            LRUElementCache emptyCache = new LRUElementCache(0);

            emptyCache.AddToCache(new Element(new byte[0]), 0);
            Assert.IsNull(emptyCache.Get(0));

            LRUElementCache smallCache = new LRUElementCache(1);

            smallCache.AddToCache(new Element(new byte[0]), 0);
            smallCache.AddToCache(new Element(new byte[0]), 7);
            Assert.IsNotNull(smallCache.Get(7));
            Assert.IsNull(smallCache.Get(0));
        }
Пример #3
0
        public byte[] Get(int index)
        {
            Element element = _cache.Get(index);

            byte[] result;
            if (element == null)
            {
                result = _simpleCollectionNextSpace.Get(index);
            }
            else
            {
                result = element.Data;
            }

            return(result);
        }