示例#1
0
        public void AddEntryViaCacheShouldBeSuccess()
        {
            //Arrange
            int    cacheSize      = 16;
            int    nSet           = 3;
            string key1           = "key1";
            string expectedValue1 = "value1";
            string key2           = "key2";
            string expectedValue2 = "value2";
            string key3           = "key3";
            string expectedValue3 = "value3";

            var algorithm = new LRUAlgorithm <string, string>();

            var cache = new Cache <string, string>(cacheSize, nSet, algorithm);

            cache.Put(key1, expectedValue1);
            cache.Put(key2, expectedValue2);
            cache.Put(key3, expectedValue3);

            //Actual
            var actualValue1 = algorithm.GetValue(key1);
            var actualValue2 = algorithm.GetValue(key2);
            var actualValue3 = algorithm.GetValue(key3);

            //Assert
            Assert.AreEqual(expectedValue1, actualValue1);
            Assert.AreEqual(expectedValue2, actualValue2);
            Assert.AreEqual(expectedValue3, actualValue3);
        }
示例#2
0
        public void TryGetFromNullCacheShouldBeErrorTest()
        {
            //Arrange
            string key = "134";

            var algorithm = new LRUAlgorithm <string, string>();

            //Actual
            //Assert
            Assert.Throws <InvalidOperationException>(() => algorithm.GetValue(key));
        }
示例#3
0
        public void AddEntryToHashMapShouldBeSuccess()
        {
            //Arrange
            string key           = "55";
            int    expectedValue = 4;
            var    algorithm     = new LRUAlgorithm <string, double>();

            algorithm.Add(key, expectedValue);

            //Actual
            var actualValue = algorithm.GetValue(key);

            //Assert
            Assert.AreEqual(expectedValue, actualValue);
        }
示例#4
0
        public void TryRemovePairFromAlgorithmShouldBerRemovedFromCacheTest()
        {
            //Arrange
            int    cacheSize = 10;
            int    nSet      = 5;
            int    key       = 134;
            string value     = "2221";

            var algorithm = new LRUAlgorithm <int, string>();
            var cache     = new Cache <int, string>(cacheSize, nSet, algorithm);

            cache.Put(key, value);

            algorithm.Remove();

            //Actual
            //Assert
            Assert.Throws <InvalidOperationException>(() => cache.Get(key));
            Assert.Throws <InvalidOperationException>(() => algorithm.GetValue(key));
        }
示例#5
0
        public void RemoveEntryViaAlgorithmShouldBeSuccess()
        {
            //Arrange
            int    cacheSize = 255;
            int    nSet      = 1;
            double key       = 6.4;
            double value     = 2.2;

            var algorithm = new LRUAlgorithm <double, double>();

            var cache = new Cache <double, double>(cacheSize, nSet, algorithm);

            cache.Put(key, value);

            algorithm.Remove();

            //Actual
            //Assert
            Assert.Throws <InvalidOperationException>(() => algorithm.GetValue(key));
            Assert.Throws <InvalidOperationException>(() => cache.Get(key));
        }