コード例 #1
0
        public void ThrowsRightExceptions()
        {
            var cache = CacheBuilder.LRU_ThreadSafe <string, string>(3);

            Assert.Throws <ArgumentNullException>(() => { cache[null] = ""; });
            Assert.Throws <KeyNotFoundException>(() => { var no = cache["not present"]; });
        }
コード例 #2
0
        public void LruOverCapacity()
        {
            var cache = CacheBuilder.LRU_ThreadSafe <int, int>(3);

            cache[1] = 10;
            cache[2] = 20;
            cache[3] = 30;

            Assert.IsTrue(cache.ContainsKey(1));
            cache[4] = 40;
            Assert.IsFalse(cache.ContainsKey(1));
        }
コード例 #3
0
        public void LruAccess() //New 1.01: missed test coverage
        {
            var cache = CacheBuilder.LRU_ThreadSafe <int, int>(3);

            cache[1] = 10;
            cache[2] = 20;
            cache[3] = 30;

            var v1 = cache[1];
            var v2 = cache[2];

            Assert.IsTrue(cache.ContainsKey(3));
            cache[4] = 40;
            Assert.IsFalse(cache.ContainsKey(3));
        }
コード例 #4
0
        public void LruRollingPuts()
        {
            const int capacity = 3;
            var       cache    = CacheBuilder.LRU_ThreadSafe <int, int>(capacity);

            cache[1] = 10;
            cache[2] = 20;
            cache[3] = 30;

            for (int i = 4; i < 100; i++)
            {
                Assert.IsTrue(cache.ContainsKey(i - capacity));
                cache[i] = 10 * i;
                Assert.IsFalse(cache.ContainsKey(i - capacity));
            }
        }
コード例 #5
0
        private ICache <int, int> GetCache(CacheType cacheType, int capacity)
        {
            switch (cacheType)
            {
            case CacheType.LRU_ThreadSafe:
                return(CacheBuilder.LRU_ThreadSafe <int, int>(capacity));

            case CacheType.LRU_Non_ThreadSafe:
                return(CacheBuilder.LRU_NonThreadSafe <int, int>(capacity));

            case CacheType.MRU_ThreadSafe:
                return(CacheBuilder.MRU_ThreadSafe <int, int>(capacity));

            case CacheType.MRU_Non_ThreadSafe:
                return(CacheBuilder.MRU_NonThreadSafe <int, int>(capacity));

            default:
                throw new NotSupportedException(cacheType.ToString());
            }
        }