Ejemplo 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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
            }
        }