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); }
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); }
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); }
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")); }
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)); }
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); }
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)); }
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"); }
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); }
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); } }
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); } }
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); } }
public void TestSetOptimizer() { LRUReplacementPolicy <int, int> lruReplacement = new LRUReplacementPolicy <int, int>(); Tuple <int, int, NWaySetAssociativeCache <int, int> .CacheOperation>[] tuples = new Tuple <int, int, NWaySetAssociativeCache <int, int> .CacheOperation> [1000]; for (int i = 0; i < 1000; i++) { if ((new Random()).Next(0, 2) > 0) { tuples[i] = Tuple.Create(Math.Max(1, (i + 1) % 50), Math.Max(1, (i + 1) % 50), NWaySetAssociativeCache <int, int> .CacheOperation.Put); } else { tuples[i] = Tuple.Create(Math.Max(1, (i + 1) % 50), Math.Max(1, (i + 1) % 50), NWaySetAssociativeCache <int, int> .CacheOperation.Get); } } Console.WriteLine(SetOptimizer <int, int> .GetLowestMissN(10, tuples, lruReplacement)); }
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)); } }
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); } }