public MainForm()
 {
     InitializeComponent();
     FIFO = new FIFOAlgorithm(workingSetSize, WSFIFODataGrid, labelFIFOTotal, labelFIFOHit, labelFIFOFault, labelFIFOHitRatio);
     LRU  = new LRUAlgorithm(workingSetSize, WSLRUDataGrid, labelLRUTotal, labelLRUHit, labelLRUFault, labelLRUHitRatio, LRUStackDataGrid);
     simulationManager = new SimulationManager();
 }
예제 #2
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);
        }
예제 #3
0
 public MultiLevelFeedbackQueueScheduler(string _name, List <MultiLevelableScheduler> _queues, FIFOAlgorithm _FIFO, LRUAlgorithm _LRU)
 {
     name   = _name;
     queues = _queues;
     FIFO   = _FIFO;
     LRU    = _LRU;
 }
예제 #4
0
        public void TryGetFromNullCacheShouldBeErrorTest()
        {
            //Arrange
            string key = "134";

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

            //Actual
            //Assert
            Assert.Throws <InvalidOperationException>(() => algorithm.GetValue(key));
        }
예제 #5
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);
        }
예제 #6
0
        public void TryUpdateAlreadyFirstEntryTest()
        {
            //Arrange
            int    cacheSize = 10;
            int    nSet      = 5;
            string key       = "134";
            string value     = "2221";

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

            cache.Put(key, value);

            //Actual
            //Assert
            Assert.DoesNotThrow(() => algorithm.Update(key));
        }
예제 #7
0
        public void UpdateEntryViaAlgorithmShouldBeFirst()
        {
            //Arrange
            string key1   = "1";
            int    value1 = 1;
            string key2   = "2";
            int    value2 = 2;

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

            algorithm.Add(key1, value1);
            algorithm.Add(key2, value2);
            algorithm.Update(key1);

            //Actual
            //Assert
            Assert.IsTrue(algorithm.IsKeyValuePairFirst(key1));
        }
예제 #8
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));
        }
예제 #9
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));
        }
예제 #10
0
        public void GetEntryViaCacheShouldBeFirst()
        {
            //Arrange
            int    cacheSize = 256;
            int    nSet      = 5;
            int    key1      = 1;
            string value1    = "1";
            int    key2      = 2;
            string value2    = "2";

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

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

            cache.Put(key1, value1);
            cache.Put(key2, value2);
            cache.Get(key1);

            //Actual
            //Assert
            Assert.IsTrue(algorithm.IsKeyValuePairFirst(key1));
        }