private void AssertAddedFirst(LRUMap map, Object key, Object value) { map.Add(key, value); Assert.AreEqual(key, ((ArrayList)map.Keys)[0]); Assert.AreEqual(value, ((ArrayList)map.Values)[0]); Assert.IsTrue(map.Count <= map.MaxSize); }
public void PutAndRemove() { int size = 10; IDictionary cache = new LRUMap(size); cache.Add("key:" + 1, "data:" + 1); cache.Remove("key:" + 1); Assert.IsNull(cache["key:" + 1]); }
public void PutWithSizeLimitOfZero() { IDictionary cache = new LRUMap(0); cache.Add("key", "data"); string data = (string)cache["key"]; Assert.IsNull(data, "Data is wrong."); }
public void AddDoesBoundsChecking() { var map = new LRUMap(128); for (int i = 0; i < 200; i++) { map.Add("str" + i, i); } Assert.That(map.Count, Is.EqualTo(128)); }
public void PutWithNoSizeLimit() { int size = 10; IDictionary cache = new LRUMap(); for (int i = 0; i < size; i++) { cache.Add("key:" + i, "data:" + i); } for (int i = 0; i < size; i++) { string data = (string)cache["key:" + i]; Assert.AreEqual("data:" + i, data, "Data is wrong."); } }
public void GetEntrySet() { int size = 10; IDictionary cache = new LRUMap(size); for (int i = 0; i < size; i++) { cache.Add("key:" + i, "data:" + i); } Assert.AreEqual(size, cache.Keys.Count, "Set contains the wrong number of items."); // check minimal correctness foreach (DictionaryEntry entry in cache) { Assert.AreNotEqual(-1, entry.Value.ToString().IndexOf("data:")); } }
public void Test() { LRUMap map = new LRUMap(5); AssertAddedFirst(map, "One", 1); AssertAddedFirst(map, "Two", 2); AssertAddedFirst(map, "Three", 3); AssertAddedFirst(map, "Four", 4); AssertAddedFirst(map, "Five", 5); AssertAddedFirst(map, "Six", 6); Assert.IsTrue(!map.Contains("One")); AssertAddedFirst(map, "Seven", 7); Assert.IsTrue(!map.Contains("Two")); AssertAddedFirst(map, "Eight", 8); Assert.IsTrue(!map.Contains("Three")); AssertAddedFirst(map, "Nine", 9); Assert.IsTrue(!map.Contains("Four")); AssertAddedFirst(map, "Ten", 10); Assert.IsTrue(!map.Contains("Five")); map.Remove("Eight"); Assert.AreEqual(4, map.Count); map.Add("One", 1); Assert.AreEqual(5, map.Count); Assert.IsTrue(map.Contains("One")); Assert.IsTrue(map.Contains("Six")); Assert.IsTrue(map.Contains("Seven")); Assert.IsTrue(map.Contains("Nine")); Assert.IsTrue(map.Contains("Ten")); Assert.AreEqual("Six", ((ArrayList)map.Keys)[map.Count - 1]); Assert.AreEqual("One", ((ArrayList)map.Keys)[0]); AssertGetIsMostRecent(map, "Six", 6); AssertGetIsMostRecent(map, "Nine", 9); AssertGetIsMostRecent(map, "Seven", 7); AssertGetIsMostRecent(map, "Ten", 10); AssertGetIsMostRecent(map, "One", 1); Assert.AreEqual("Six", ((ArrayList)map.Keys)[map.Count - 1]); AssertSetIsMostRecent(map, "One", "Uno"); AssertSetIsMostRecent(map, "Two", "Dos"); Assert.AreEqual(5, map.Count); }