예제 #1
0
        public void TryRemove_returns_false_for_unknown_entry()
        {
            var cache = new MruCache <int, string>(capacity: 3);

            cache.Add(1, "one");

            Assert.False(cache.TryRemove(2, out var removed));
            Assert.Null(removed);
        }
예제 #2
0
        public void TryRemove_removes_existing_entries()
        {
            var cache = new MruCache <int, string>(capacity: 3);

            cache.Add(1, "one");
            cache.Add(2, "two");
            cache.Add(3, "three");

            Assert.True(cache.TryRemove(1, out var removed));
            Assert.AreEqual("one", removed);
            Assert.False(cache.TryGetValue(1, out _));

            Assert.True(cache.TryGetValue(2, out _));
            Assert.True(cache.TryGetValue(3, out _));
        }