Exemplo n.º 1
0
        public void TestNoWriteThrough()
        {
            LRUReplacementPolicy <int, int>    lruReplacement = new LRUReplacementPolicy <int, int>();
            MyMemory <int, int>                memoryAccess   = new MyMemory <int, int>();
            NWaySetAssociativeCache <int, int> cache;

            cache = new NWaySetAssociativeCache <int, int>(memoryAccess, lruReplacement, 8, 2, false);
            Tuple <int, int>[] tuples = new Tuple <int, int> [100];
            for (int i = 0; i < 100; i++)
            {
                tuples[i] = Tuple.Create(i + 1, i + 1);
                memoryAccess.Put(i + 1, i + 1);
            }

            int[] oldValues = cache.PutAll(tuples);
            for (int i = 0; i < 100; i++)
            {
                if (oldValues[i] != 0)
                {
                    if (memoryAccess.Contains(i + 1))
                    {
                        memoryAccess.Remove(i + 1);
                    }
                    memoryAccess.Put(i + 1, oldValues[i]);
                }
            }
            cache.Get(100);
        }
Exemplo n.º 2
0
        public void TestInitialization()
        {
            LRUReplacementPolicy <string, int>    lruReplacement = new LRUReplacementPolicy <string, int>();
            MyMemory <string, int>                memoryAccess   = new MyMemory <string, int>();
            NWaySetAssociativeCache <string, int> cache;

            cache = new NWaySetAssociativeCache <string, int>(memoryAccess, lruReplacement, 100, 10, true);
        }
Exemplo n.º 3
0
        public void TestAddingEntry()
        {
            LRUReplacementPolicy <string, int>    lruReplacement = new LRUReplacementPolicy <string, int>();
            MyMemory <string, int>                memoryAccess   = new MyMemory <string, int>();
            NWaySetAssociativeCache <string, int> cache;

            cache = new NWaySetAssociativeCache <string, int>(memoryAccess, lruReplacement, 100, 10, true);
            cache.Put("Hello", 5);
        }
Exemplo n.º 4
0
        public void TestContainsKeyString()
        {
            LRUReplacementPolicy <string, string>    lruReplacement = new LRUReplacementPolicy <string, string>();
            MyMemory <string, string>                memoryAccess   = new MyMemory <string, string>();
            NWaySetAssociativeCache <string, string> cache;

            cache = new NWaySetAssociativeCache <string, string>(memoryAccess, lruReplacement, 100, 10, true);
            cache.Put("Hello", 3 + "");
            Assert.IsTrue(cache.ContainsKey("Hello"));
        }
Exemplo n.º 5
0
        public void TestGettingNonExistentEntryString()
        {
            LRUReplacementPolicy <string, string>    lruReplacement = new LRUReplacementPolicy <string, string>();
            MyMemory <string, string>                memoryAccess   = new MyMemory <string, string>();
            NWaySetAssociativeCache <string, string> cache;

            cache = new NWaySetAssociativeCache <string, string>(memoryAccess, lruReplacement, 100, 10, true);
            cache.Put("Hello", 3 + "");
            Assert.AreEqual(cache.Get("Bye"), default(string));
        }
Exemplo n.º 6
0
        public void TestMissingValueRetrievalFromMemory()
        {
            LRUReplacementPolicy <int, int>    lruReplacement = new LRUReplacementPolicy <int, int>();
            MyMemory <int, int>                memoryAccess   = new MyMemory <int, int>();
            NWaySetAssociativeCache <int, int> cache;

            cache = new NWaySetAssociativeCache <int, int>(memoryAccess, lruReplacement, 8, 2, true);
            memoryAccess.Put(5, 6);
            Assert.AreEqual(cache.Get(5), 6);
        }
Exemplo n.º 7
0
        public void TestPutRemoveGet()
        {
            LRUReplacementPolicy <string, string>    lruReplacement = new LRUReplacementPolicy <string, string>();
            MyMemory <string, string>                memoryAccess   = new MyMemory <string, string>();
            NWaySetAssociativeCache <string, string> cache;

            cache = new NWaySetAssociativeCache <string, string>(memoryAccess, lruReplacement, 100, 10, true);
            cache.Put("A", "B");
            cache.Remove("A");
            Assert.AreEqual(cache.Get("A"), default(string));
        }
Exemplo n.º 8
0
        public void TestPutAllString()
        {
            LRUReplacementPolicy <string, string>    lruReplacement = new LRUReplacementPolicy <string, string>();
            MyMemory <string, string>                memoryAccess   = new MyMemory <string, string>();
            NWaySetAssociativeCache <string, string> cache;

            cache = new NWaySetAssociativeCache <string, string>(memoryAccess, lruReplacement, 100, 10, true);
            Tuple <string, string>[] tuples = new Tuple <string, string> [2];
            tuples[0] = Tuple.Create("a", "b");
            tuples[1] = Tuple.Create("c", "d");
            cache.PutAll(tuples);
            Assert.AreEqual(cache.Get("c"), "d");
        }
Exemplo n.º 9
0
        public void TestIncongruentNWay()
        {
            LRUReplacementPolicy <int, int>    lruReplacement = new LRUReplacementPolicy <int, int>();
            MyMemory <int, int>                memoryAccess   = new MyMemory <int, int>();
            NWaySetAssociativeCache <int, int> cache;

            cache = new NWaySetAssociativeCache <int, int>(memoryAccess, lruReplacement, 8, 3, true);
            Tuple <int, int>[] tuples = new Tuple <int, int> [100];
            for (int i = 0; i < 100; i++)
            {
                tuples[i] = Tuple.Create(i + 1, i + 1);
            }
            cache.PutAll(tuples);
            cache.Get(1);
        }
Exemplo n.º 10
0
        public void TestCustomReplacementOverCapacity()
        {
            RandomReplacementPolicy <int, int> ranReplacement = new RandomReplacementPolicy <int, int>();
            MyMemory <int, int> memoryAccess = new MyMemory <int, int>();
            NWaySetAssociativeCache <int, int> cache;

            cache = new NWaySetAssociativeCache <int, int>(memoryAccess, ranReplacement, 8, 2, true);
            Tuple <int, int>[] tuples = new Tuple <int, int> [100];
            for (int i = 0; i < 100; i++)
            {
                tuples[i] = Tuple.Create(i + 1, i + 1);
            }
            cache.PutAll(tuples);
            cache.Get(1);
        }
Exemplo n.º 11
0
        public void TestConstructorError()
        {
            LRUReplacementPolicy <int, int>    lruReplacement = new LRUReplacementPolicy <int, int>();
            MyMemory <int, int>                memoryAccess   = new MyMemory <int, int>();
            NWaySetAssociativeCache <int, int> cache;

            try
            {
                cache = new NWaySetAssociativeCache <int, int>(memoryAccess, lruReplacement, 8, 9, true);
                Assert.Fail();
            }
            catch (ConstructorParameterException e)
            {
                Console.WriteLine(e);
            }
        }
Exemplo n.º 12
0
        public void TestRemoveNonExistent()
        {
            LRUReplacementPolicy <int, int>    lruReplacement = new LRUReplacementPolicy <int, int>();
            MyMemory <int, int>                memoryAccess   = new MyMemory <int, int>();
            NWaySetAssociativeCache <int, int> cache;

            cache = new NWaySetAssociativeCache <int, int>(memoryAccess, lruReplacement, 8, 2, false);
            try
            {
                cache.Remove(5);
                Assert.Fail();
            }
            catch (EntryNotFoundException e)
            {
                Console.WriteLine(e);
            }
        }
Exemplo n.º 13
0
        public void TestKeyError()
        {
            LRUReplacementPolicy <int, int>    lruReplacement = new LRUReplacementPolicy <int, int>();
            MyMemory <int, int>                memoryAccess   = new MyMemory <int, int>();
            NWaySetAssociativeCache <int, int> cache;

            try
            {
                cache = new NWaySetAssociativeCache <int, int>(memoryAccess, lruReplacement, 8, 2, false);
                cache.Put(0, 5);
                Assert.Fail();
            }
            catch (KeyValueUsesDefaultValueException <Int32> e)
            {
                Console.WriteLine(e);
            }
        }
Exemplo n.º 14
0
        public void TestCompletelyAssociative()
        {
            LRUReplacementPolicy <int, int>    lruReplacement = new LRUReplacementPolicy <int, int>();
            MyMemory <int, int>                memoryAccess   = new MyMemory <int, int>();
            NWaySetAssociativeCache <int, int> cache;

            cache = new NWaySetAssociativeCache <int, int>(memoryAccess, lruReplacement, 100, 100, true);
            Tuple <int, int>[] tuples = new Tuple <int, int> [100];
            for (int i = 0; i < 100; i++)
            {
                tuples[i] = Tuple.Create(i + 1, i + 1);
            }
            cache.PutAll(tuples);
            for (int i = 0; i < 100; i++)
            {
                Assert.AreEqual(i + 1, cache.Get(i + 1));
            }
        }
Exemplo n.º 15
0
        public void TestNoWriteBackException()
        {
            LRUReplacementPolicy <int, int>    lruReplacement = new LRUReplacementPolicy <int, int>();
            MyMemory <int, int>                memoryAccess   = new MyMemory <int, int>();
            NWaySetAssociativeCache <int, int> cache;

            cache = new NWaySetAssociativeCache <int, int>(memoryAccess, lruReplacement, 8, 2, false);
            Tuple <int, int>[] tuples = new Tuple <int, int> [100];
            for (int i = 0; i < 100; i++)
            {
                tuples[i] = Tuple.Create(i + 1, i + 1);
                memoryAccess.Put(i + 1, i + 1);
            }

            int[] oldValues = cache.PutAll(tuples);
            for (int i = 0; i < 100; i++)
            {
                if (oldValues[i] != 0)
                {
                    if (memoryAccess.Contains(i + 1))
                    {
                        memoryAccess.Remove(i + 1);
                    }
                    memoryAccess.Put(i + 1, oldValues[i]);
                }
            }
            try
            {
                cache.Get(1);
                Assert.Fail();
            }
            catch (EntryNotFoundException e)
            {
                Console.WriteLine(e);
            }
        }