public void CacheCopyToWithIndex() { var cache = new LruCache <int, int>(10); for (int index = 0; index < 10; ++index) { cache.Add(new KeyValuePair <int, int>(index, index)); } KeyValuePair <int, int>[] array = new KeyValuePair <int, int> [20]; cache.CopyTo(array, 10); for (int index = 0; index < cache.Count; ++index) { Assert.AreEqual(9 - index, array[index + 10].Key, "Keys don't match"); Assert.AreEqual(9 - index, array[index + 10].Value, "Values don't match"); } }
public void CacheCopyToTooSmall() { var cache = new LruCache <int, int>(10); for (int index = 0; index < 10; ++index) { cache.Add(new KeyValuePair <int, int>(index, index)); } KeyValuePair <int, int>[] array = new KeyValuePair <int, int> [5]; bool thrown = false; try { cache.CopyTo(array, 0); } catch (IndexOutOfRangeException) { thrown = true; } Assert.IsTrue(thrown, "Exception should have been thrown"); }