public void ForceLockRecursionException() { var cache = new LRUCache<int, int>(1); cache.Get(0, k => k); // write during a read foreach (var item in cache) Assert.Throws<LockRecursionException>(() => cache.Get(1, k => k)); }
static void Main(string[] args) { LRUCache lRUCache = new LRUCache(2); lRUCache.Put(1, 1); lRUCache.Put(2, 2); lRUCache.Get(1); lRUCache.Put(3, 3); lRUCache.Get(2); lRUCache.Put(4, 4); lRUCache.Get(1); lRUCache.Get(3); lRUCache.Get(4); }
public static void Init(string[] args) { LRUCache obj = new LRUCache(5); obj.Set(1, 1); Console.WriteLine(obj.Get(1)); obj.Set(2, 2); obj.Set(3, 3); obj.Set(4, 4); obj.Set(5, 5); obj.Set(6, 6); Console.WriteLine(obj.Get(1)); Console.WriteLine(obj.Get(3)); Console.WriteLine(obj.Get(6)); }
public void Descriptiontests() { LRUCache cache = new LRUCache(2 /* capacity */); cache.Put(1, 1); cache.Put(2, 2); Assert.Equal(1, cache.Get(1)); // returns 1 cache.Put(3, 3); // evicts key 2 Assert.Equal(-1, cache.Get(2)); // returns -1 (not found) cache.Put(4, 4); // evicts key 1 Assert.Equal(-1, cache.Get(1)); // returns -1 (not found) Assert.Equal(3, cache.Get(3)); // returns 3 Assert.Equal(4, cache.Get(4)); // returns 4 }
public void Run() { var cache = new LRUCache(2); cache.Put(1, 1); cache.Put(2, 2); Console.WriteLine(cache.Get(1)); cache.Put(3, 3); Console.WriteLine(cache.Get(2)); cache.Put(4, 4); Console.WriteLine(cache.Get(1)); Console.WriteLine(cache.Get(3)); Console.WriteLine(cache.Get(4)); }
public void LruTest2() { var cache = new LRUCache(2); cache.Put(1, 1); cache.Put(2, 2); cache.Get(1); cache.Put(3, 3); cache.Get(2); cache.Put(4, 4); cache.Get(1); cache.Get(3); cache.Get(4); }
public static void DownloadSelfAvatar(GetAvatarResult resultHandler, ErrorHandler errorHandler, bool ignoreCache = false, [CallerMemberName] string caller = null) { try { String address = ChatConnection.Instance.WebHost; int port = ChatConnection.Instance.WebPort; String url = String.Format(GetSelfAvatarURL, address, port); if (avatarCache.Contains("Self") && !ignoreCache) { resultHandler(avatarCache.Get("Self")); } else { new Task(() => { using (WebClient client = new WebClient()) { Console.WriteLine(caller + " downloading self avatar"); client.Headers.Add(ClientSession.HeaderToken, ChatConnection.Instance.Session.SessionID); byte[] data = client.DownloadData(url); BitmapImage bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.StreamSource = new MemoryStream(data); bitmap.EndInit(); if (resultHandler != null) { bitmap.Freeze(); Application.Current.Dispatcher.Invoke(() => { avatarCache.AddReplace("Self", bitmap); resultHandler(bitmap); }); } } }).Start(); } } catch (Exception e) { Console.WriteLine(e); if (errorHandler != null) { errorHandler(e); } } }
public static void Init(string[] args) { LRUCache obj = new LRUCache(5); obj.Set(1, 1); Console.WriteLine(obj.Get(1)); obj.Set(2, 2); obj.Set(3, 3); obj.Set(4, 4); obj.Set(5, 5); obj.Set(6, 6); Console.WriteLine(obj.Get(1)); Console.WriteLine(obj.Get(3)); Console.WriteLine(obj.Get(6)); }
public void LRUExpirationTime() { int cacheCapacity = 3; int expirationInSeconds = 5; LRUCache <int?> cache = new LRUCache <int?>(cacheCapacity, expirationInSeconds); cache.Add(1, 1); Thread.Sleep(5000); Assert.Null(cache.Get(1)); //expired cache.Add(1, 1); Thread.Sleep(3000); cache.Get(1); //updated expiration time Thread.Sleep(3000); Assert.Equal(1, cache.Get(1)); //not yet expired }
public static void Test() { int ret = 0; var vi = new LRUCache(2); vi.Put(1, 1); vi.Put(2, 2); ret = vi.Get(1); // return 1; vi.Put(3, 3); // evicts 2; ret = vi.Get(2); // return -1; vi.Put(4, 4); //evicts 1; ret = vi.Get(1); // return -1; ret = vi.Get(3); ret = vi.Get(4); }
public void Test() { LRUCache cache = new LRUCache(2 /* 缓存容量 */); cache.Put(1, 1); cache.Put(2, 2); Console.WriteLine(cache.Get(1)); // 返回 1 cache.Put(3, 3); // 该操作会使得密钥 2 作废 Console.WriteLine(cache.Get(2)); // 返回 -1 (未找到) cache.Put(4, 4); // 该操作会使得密钥 1 作废 Console.WriteLine(cache.Get(1)); // 返回 -1 (未找到) Console.WriteLine(cache.Get(3)); // 返回 3 Console.WriteLine(cache.Get(4)); // 返回 4 Console.ReadLine(); }
public void Eviction_WhenGettingItems_Test() { var cache = new LRUCache <string, string>(3); cache.Set("one", "1"); cache.Set("two", "2"); cache.Set("three", "3"); cache.Get("one"); cache.Set("four", "4"); Assert.AreEqual("1", cache.Get("one")); Assert.IsNull(cache.Get("two")); Assert.AreEqual("3", cache.Get("three")); Assert.AreEqual("4", cache.Get("four")); }
public void TestMethod1() { LRUCache <String, String> c = new LRUCache <String, String>(3); c.Put("1", "one"); // 1 c.Put("2", "two"); // 2 1 c.Put("3", "three"); // 3 2 1 c.Put("4", "four"); // 4 3 2 c.Get("2"); // 2 4 3 c.Remove("1"); c.Put("5", "five"); // 5 2 4 c.Put("4", "second four"); // 4 5 2 c.Get("2"); c.Get("3"); }
public void LRUCache_Test() { var sut = new LRUCache <int, int>(); for (int i = 1; i < 12; i++) { sut.Add(i, i + 1); } var val = sut.Get(1); var val2 = sut.Get(11); Assert.AreEqual(val, 0); Assert.AreEqual(val2, 12); }
public void Test3() { var lru = new LRUCache(2); lru.Put(1, 1); lru.Put(2, 2); lru.Get(1); lru.Put(3, 3); lru.Get(2); lru.Put(4, 4); Assert.That(lru.Get(1), Is.EqualTo(-1)); Assert.That(lru.Get(3), Is.EqualTo(3)); Assert.That(lru.Get(4), Is.EqualTo(4)); }
public void TestPutGet() { ICache<string, string> cache = new LRUCache<string, string>(4); cache.Put("a", "b"); cache.Put("c", "d"); cache.Put("e", "f"); cache.Put("g", "h"); Assert.Equal(4, cache.Size); Assert.Equal("b", cache.Get("a")); Assert.Equal("d", cache.Get("c")); Assert.Equal("f", cache.Get("e")); Assert.Equal("h", cache.Get("g")); }
public void LRUCache_Smoke_Test() { var cache = new LRUCache <int, int>(2); cache.Put(1, 1); cache.Put(2, 2); Assert.AreEqual(1, cache.Get(1)); cache.Put(3, 3); Assert.AreEqual(0, cache.Get(2)); cache.Put(4, 4); Assert.AreEqual(0, cache.Get(1)); Assert.AreEqual(3, cache.Get(3)); Assert.AreEqual(4, cache.Get(4)); }
private static int LeetCode_LRU_Cache() { LRUCache cache = new LRUCache(2); int iReturn = 0; cache.Put(1, 1); cache.Put(2, 2); iReturn = cache.Get(1); // returns 1 cache.Put(3, 3); // evicts key 2 iReturn = cache.Get(2); // returns -1 (not found) cache.Put(4, 4); // evicts key 1 iReturn = cache.Get(1); // returns -1 (not found) iReturn = cache.Get(3); // returns 3 iReturn = cache.Get(4); // returns 4 return(0); }
public void Basic() { var cache = new LRUCache(2); cache.Put(1, 1); cache.Put(2, 2); Assert.Equal(1, cache.Get(1)); cache.Put(3, 3); // evicts key 2 Assert.Equal(-1, cache.Get(2)); // returns -1 (not found) cache.Put(4, 4); // evicts key 1. Assert.Equal(-1, cache.Get(1)); // returns -1 (not found) Assert.Equal(3, cache.Get(3)); // returns 3 Assert.Equal(4, cache.Get(4)); // returns 4 }
public static AnimSheet GetSpellSheet(SpellAnimType animType, int num) { AnimSheet cacheSheet = spellCache.Get(animType.ToString() + num); if (cacheSheet != null) { return(cacheSheet); } if (File.Exists(Paths.EffectsPath + animType.ToString() + "-" + num + ".png")) { AnimSheet sheet = new AnimSheet(); sheet.LoadPixelsFromFile32(Paths.EffectsPath + animType.ToString() + "-" + num + ".png"); sheet.LoadTextureFromPixels32(); switch (animType) { case SpellAnimType.Spell: sheet.GenerateDataBuffer(1, 1); break; case SpellAnimType.Arrow: sheet.GenerateDataBuffer(8, 1); break; case SpellAnimType.Beam: sheet.GenerateDataBuffer(8, 4); break; } spellCache.Add(animType.ToString() + num, sheet); return(sheet); } spellCache.Add(animType.ToString() + num, ErrorTexture); return(ErrorTexture); }
public override float GetProbability(WordSequence wordSequence) { int numberWords = wordSequence.Size; if (numberWords > MaxDepth) { throw new Error("Unsupported NGram: " + wordSequence.Size); } if (numberWords == MaxDepth) { Float probabilityA = ngramProbCache.Get(wordSequence); if (probabilityA != null) { NGramHits++; return(probabilityA); } NGramMisses++; } float probability = ApplyWeights(GetProbabilityRaw(wordSequence)); if (numberWords == MaxDepth) { ngramProbCache.Put(wordSequence, probability); } if (logFile != null) { logFile.WriteLine(wordSequence.ToString().Replace("][", " ") + " : " + Float.ToString(probability)); } return(probability); }
private static void TestLRUCache() { Console.WriteLine($"Testing LRU Cache"); LRUCache cache = new LRUCache(2); cache.Put(1, 1); cache.Put(2, 2); cache.Get(1); // returns 1 cache.Put(3, 3); // evicts key 2 cache.Get(2); // returns -1 (not found) cache.Put(4, 4); // evicts key 1 cache.Get(1); // returns -1 (not found) cache.Get(3); // returns 3 cache.Get(4); // returns 4 Console.WriteLine($""); }
int[] implement_LRU_cache(int capacity, int[] query_type, int[] key, int[] value) { var cache = new LRUCache(capacity); var result = new List <int>(); var max = long.MinValue; var sw = new Stopwatch(); sw.Start(); for (var i = 0; i < query_type.Length; i++) { if (query_type[i] == 0) { result.Add(cache.Get(key[i])); } else { cache.Add(key[i], value[i]); } max = Math.Max(sw.ElapsedMilliseconds, max); } sw.Stop(); Console.WriteLine(max); return(result.ToArray()); }
public void Test(int capacity, string operationsString, string expectedOutputString) { var cache = new LRUCache(capacity); var output = new StringBuilder(); foreach (var operationString in operationsString.Split(';')) { int key; int value; switch (operationString[0]) { case 'g': key = int.Parse(operationString.Substring(1)); if (output.Length > 0) { output.Append(";"); } output.Append(cache.Get(key).ToString(CultureInfo.InvariantCulture)); break; case 's': var indexOfComma = operationString.IndexOf(','); key = int.Parse(operationString.Substring(1, indexOfComma - 1)); value = int.Parse(operationString.Substring(indexOfComma + 1)); cache.Set(key, value); break; default: throw new Exception(string.Format("Unkown operation: {0}", operationString)); } } Assert.AreEqual(expectedOutputString, output.ToString()); }
/// <summary> /// 格式 [bundle/]asset /// </summary> /// <param name="assetPath"></param> /// <returns></returns> public static AssetId Parse(string assetPath) { if (_Cache.Contains(assetPath)) { return(_Cache.Get(assetPath)); } if (string.IsNullOrEmpty(assetPath)) { throw new Exception("素材路径为空"); } var lastDiv = assetPath.LastIndexOf('/'); if (lastDiv == -1) { throw new Exception($"未指定bundle {assetPath}"); } var result = new AssetId( assetPath.Substring(0, lastDiv), assetPath.Substring(lastDiv + 1)); _Cache.Add(assetPath, result); return(result); }
public void ShowImage(String imageURL) { try { LoadingAhihi.Visibility = Visibility.Visible; VideoFull.Close(); VideoFull.Visibility = Visibility.Hidden; ImgFull.Visibility = Visibility.Hidden; if (ImgCache.Contains(imageURL)) { ImgFull.Source = ImgCache.Get(imageURL); ImgFull.MaxHeight = ImgFull.Source.Height; ImgFull.MaxWidth = ImgFull.Source.Width; ImgFull.Visibility = Visibility.Visible; LoadingAhihi.Visibility = Visibility.Hidden; } else { if (imgThread != null && imgThread.IsAlive) { imgThread.Abort(); } imgThread = new Thread(() => { try { WebClient wc = new WebClient(); BitmapFrame bitmap = BitmapFrame.Create(new MemoryStream(wc.DownloadData(imageURL))); wc.Dispose(); Application.Current.Dispatcher.Invoke(() => { ImgCache.AddReplace(imageURL, bitmap); ImgFull.Source = bitmap; ImgFull.MaxHeight = bitmap.PixelHeight; ImgFull.MaxWidth = bitmap.PixelWidth; ImgFull.Visibility = Visibility.Visible; LoadingAhihi.Visibility = Visibility.Hidden; }); } catch (Exception ex) { Console.WriteLine(ex); } }); imgThread.IsBackground = true; imgThread.Start(); } } catch (Exception e) { Console.WriteLine(e); } }
public void RemoveLRU_Test() { var o = new LRUCache<int, string>(5); o.Set(1, "one"); o.Set(2, "two"); o.Set(3, "three"); o.Set(4, "four"); o.Set(5, "five"); var t = o.Get(5); t = o.Get(2); t = o.Get(1); t = o.Get(5); t = o.Get(3); o.Set(6, "six"); //should remove 4 Assert.IsTrue(o.CacheMap.Keys.Any(k => k == 4) == false); }
public void should_prioritize_accessed_records() { LRUCache <int> cache = new LRUCache <int>(3); cache.Set(1, 3); cache.Set(2, 4); cache.Set(3, 5); var value = cache.Get(3); cache.Set(4, 6); Assert.Null(cache.Get(1)); Assert.NotNull(cache.Get(2)); Assert.NotNull(cache.Get(3)); Assert.NotNull(cache.Get(4)); }
static void Main(string[] args) { LRUCache <int, int> cache = new LRUCache <int, int>(2 /* capacity */); cache.Add(1, 1); cache.Add(2, 2); Console.WriteLine(cache.Get(1)); // returns 1 and update 1 to most recently visited at the back end cache.Add(3, 3); // adding 3 should evict key 2 since 2 is least recently visited Console.WriteLine(cache.TryGet(2, out int val)); // returns false (not found) cache[4] = 4; // this should evicts key 1 Console.WriteLine(cache.TryGet(1, out val)); // returns false (not found) Console.WriteLine(cache[3]); // returns 3 Console.WriteLine(cache.Get(4)); // returns 4 Console.WriteLine($"Capacity is {cache.Capacity}"); cache.Capacity = 10; Console.WriteLine($"New Capacity is {cache.Capacity}"); }
public void GetNullItem_Test() { var cache = new LRUCache <string, string>(int.MaxValue); var value = cache.Get("key"); Assert.IsNull(value); }
public void GivenPutOperation_LRUCache_ShouldAdd() { var cache = new LRUCache(2); cache.Put(1, 1); cache.Put(2, 2); Assert.IsTrue(cache.Get(1) == 1); cache.Put(3, 3); Assert.IsTrue(cache.Get(2) == -1); cache.Put(4, 4); Assert.IsTrue(cache.Get(1) == -1); Assert.IsTrue(cache.Get(3) == 3); Assert.IsTrue(cache.Get(4) == 4); }
public void Test1() { var lru = new LRUCache(2); lru.Put(1, 1); lru.Put(2, 2); Assert.That(lru.Get(1), Is.EqualTo(1)); }
public void SetAndGetItem_Test() { var cache = new LRUCache <string, string>(int.MaxValue); cache.Set("key", "1234"); var value = cache.Get("key"); Assert.AreEqual("1234", value); }
public void Get_ExistingItemWithNoValueRecord_Throws() { var lruCache = new LRUCache <ulong, string>(3); lruCache.Put(1, "A"); lruCache.Put(2, "B"); lruCache.values.Remove(2); Assert.ThrowsException <KeyNotFoundException>(() => lruCache.Get(2), string.Empty); }
public void Get_ExistingItem_ReturnsCorrectValue() { var lruCache = new LRUCache <ulong, string>(3); lruCache.Put(1, "A"); lruCache.Put(2, "B"); lruCache.Put(3, "C"); Assert.AreEqual(lruCache.Get(2), "B"); }
public void BasicTest() { var cache = new LRUCache<int, int>(2); var invocationCount = 0; Func<int, int> factory = k => { invocationCount++; // extremely CPU intensive operation return k*2; }; cache.Get(1, factory); // a: factory() cache.Get(2, factory); // b: factory() cache.Get(1, factory); // c: cached (a) cache.Get(2, factory); // d: cached (b) cache.Get(3, factory); // e: factory(); discard [1,2] (c) cache.Get(1, factory); // f: factory(); discard [2,4] (d) // we should have had 2 cached results // and 4 factory invocations Assert.AreEqual(4, invocationCount); // (a,b,e,f) // should only have 2 items in cache Assert.AreEqual(2, cache.Count); // (e,f) // we should have the keys/values enumerated in order of most -> least recently used CollectionAssert.AreEqual(new[] { new KeyValuePair<int, int>(1, 2), // (f) new KeyValuePair<int, int>(3, 6), // (e) }, cache); }
public static void Run() { var st = new LRUCache(2); Console.WriteLine("Start: {0}", DateTime.Now); st.Set(2, 1); st.Set(2, 2); Console.WriteLine(st.Get(2)); st.Set(1, 1); st.Set(4, 1); Console.WriteLine(st.Get(2)); Console.WriteLine("Start: {0}", DateTime.Now); var st2 = new LRUCache(1); st2.Set(2, 1); Console.WriteLine(st2.Get(2)); st2.Set(3, 2); Console.WriteLine(st2.Get(2)); Console.WriteLine(st2.Get(3)); Console.WriteLine("End: {0}", DateTime.Now); }
public void SetGet() { var dico = new LRUCache<string, int>(); dico.Set("the answer", 42); Assert.AreEqual(42, dico.RawGet("the answer")); Assert.AreEqual(1, dico.Count); Assert.AreEqual(1, dico.NbUpdate); Assert.AreEqual(0, dico.NbHit); Assert.AreEqual(1, dico.NbMiss); Assert.AreEqual(0, dico.NbEviction); int fortytwo = dico.Get("the answer"); Assert.AreEqual(42, fortytwo); Assert.AreEqual(1, dico.Count); Assert.AreEqual(1, dico.NbUpdate); Assert.AreEqual(1, dico.NbHit); Assert.AreEqual(1, dico.NbMiss); Assert.AreEqual(0, dico.NbEviction); int fortythree = dico.Get("the wrong answer"); Assert.AreEqual(0, fortythree); Assert.AreEqual(1, dico.Count); Assert.AreEqual(1, dico.NbUpdate); Assert.AreEqual(1, dico.NbHit); Assert.AreEqual(2, dico.NbMiss); Assert.AreEqual(0, dico.NbEviction); dico.Set("the answer", 24); Assert.AreEqual(24, dico.RawGet("the answer")); Assert.AreEqual(1, dico.Count); Assert.AreEqual(2, dico.NbUpdate); Assert.AreEqual(2, dico.NbHit); Assert.AreEqual(2, dico.NbMiss); Assert.AreEqual(0, dico.NbEviction); }
public void TestEviction() { ICache<string, string> cache = new LRUCache<string, string>(2); cache.Put("a", "b"); cache.Put("c", "d"); Assert.Equal(2, cache.Size); cache.Put("e", "f"); Assert.Equal(2, cache.Size); Assert.Null(cache.Get("a")); Assert.Equal("d", cache.Get("c")); Assert.Equal("f", cache.Get("e")); cache.Get("c"); cache.Put("g", "h"); Assert.Equal(2, cache.Size); Assert.Null(cache.Get("e")); Assert.Equal("d", cache.Get("c")); Assert.Equal("h", cache.Get("g")); }
public void TestRemove() { ICache<string, string> cache = new LRUCache<string, string>(4); cache.Put("a", "b"); cache.Put("c", "d"); cache.Put("e", "f"); Assert.Equal(3, cache.Size); Assert.Equal(true, cache.Remove("a")); Assert.Equal(2, cache.Size); Assert.Null(cache.Get("a")); Assert.Equal("d", cache.Get("c")); Assert.Equal("f", cache.Get("e")); Assert.Equal(false, cache.Remove("KeyDoesNotExist")); Assert.Equal(true, cache.Remove("c")); Assert.Equal(1, cache.Size); Assert.Null(cache.Get("c")); Assert.Equal("f", cache.Get("e")); Assert.Equal(true, cache.Remove("e")); Assert.Equal(0, cache.Size); Assert.Null(cache.Get("e")); }
private void Work(LRUCache<int, int> dico, int count) { var rand = new Random(); for (int i = 0; i < 1000000; ++i) { int p = rand.Next(count); if (i % 4 == 0) dico.Set(p, p); else dico.Get(p); } }
public void TestLRUCache() { var cache = new LRUCache<string, int>(3); // make a tiny cache of three elements Assert.IsTrue(cache.Capacity == 3 && cache.Count == 0); // add three elements Assert.IsFalse(cache.ContainsKey("one")); Assert.IsTrue(cache.Get("one") == 0); cache.Add("one", 1); Assert.IsTrue(cache.ContainsKeyAt("one", 0)); Assert.IsTrue(cache.Get("one") == 1); Assert.IsTrue(cache.Count == 1); Assert.IsFalse(cache.ContainsKey("two")); Assert.IsTrue(cache.Get("two") == 0); cache.Add("two", 2); Assert.IsTrue(cache.ContainsKeyAt("two", 1)); Assert.IsTrue(cache.Get("two") == 2); Assert.IsTrue(cache.Count == 2); Assert.IsFalse(cache.ContainsKey("three")); Assert.IsTrue(cache.Get("three") == 0); cache.Add("three", 3); Assert.IsTrue(cache.ContainsKeyAt("three", 2)); Assert.IsTrue(cache.Get("three") == 3); Assert.IsTrue(cache.Count == 3); // we're at capacity. if we add another element, // "one" will get evicted since it's least recently used Assert.IsTrue(cache.Count == cache.Capacity); cache.Add("four", 4); Assert.IsTrue(cache.Get("four") == 4); Assert.IsTrue(cache.Count == 3); Assert.IsTrue(cache.ContainsKeyAt("four", 2)); // from the youngest Assert.IsTrue(cache.ContainsKeyAt("three", 1)); // ... Assert.IsTrue(cache.ContainsKeyAt("two", 0)); // to the oldest Assert.IsFalse(cache.ContainsKey("one")); // now let's touch "two" because that's the least recently used one. // by doing that, we demote "three" to be the least recently used one, // and adding a new entry will then evict it. Assert.IsTrue(cache.Get("two") == 2); // reading the key will touch it Assert.IsTrue(cache.ContainsKeyAt("two", 2)); // now two is the youngest Assert.IsTrue(cache.ContainsKeyAt("four", 1)); // ... Assert.IsTrue(cache.ContainsKeyAt("three", 0)); // and three is the oldest Assert.IsTrue(cache.Count == cache.Capacity); cache.Add("five", 5); Assert.IsTrue(cache.Get("five") == 5); Assert.IsTrue(cache.Count == 3); Assert.IsTrue(cache.ContainsKeyAt("five", 2)); // youngest Assert.IsTrue(cache.ContainsKeyAt("two", 1)); // ... Assert.IsTrue(cache.ContainsKeyAt("four", 0)); // oldest Assert.IsFalse(cache.ContainsKey("three")); // evicted as lru // finally we remove one item, dropping the count. // adding another item will not cause evictions Assert.IsTrue(cache.Remove("four")); Assert.IsFalse(cache.ContainsKey("four")); Assert.IsTrue(cache.Get("four") == 0); Assert.IsTrue(cache.Count == cache.Capacity - 1); cache.Add("six", 6); Assert.IsTrue(cache.Get("six") == 6); Assert.IsTrue(cache.Count == 3); Assert.IsTrue(cache.ContainsKeyAt("six", 2)); // youngest Assert.IsTrue(cache.ContainsKeyAt("five", 1)); // ... Assert.IsTrue(cache.ContainsKeyAt("two", 0)); // oldest Assert.IsFalse(cache.ContainsKey("four")); // removed manually // test clearing cache.Clear(); Assert.IsTrue(cache.Count == 0); }