Пример #1
0
        public void CountTest()
        {
            var dict = new LRUCacheDictionary <string, string>();

            Assert.That(dict.Count, Is.EqualTo(0));

            dict.Add("key1", "value1");
            Assert.That(dict.Count, Is.EqualTo(1));

            dict.Add("key2", "value2");
            Assert.That(dict.Count, Is.EqualTo(2));

            dict.Remove("key1");
            Assert.That(dict.Count, Is.EqualTo(1));

            dict.Clear();
            Assert.That(dict.Count, Is.EqualTo(0));
        }
Пример #2
0
        public void CountTest()
        {
            var dict = new LRUCacheDictionary <string, string>();

            Assert.Empty(dict);

            dict.Add("key1", "value1");
            Assert.Single(dict);

            dict.Add("key2", "value2");
            Assert.Equal(2, dict.Count);

            dict.Remove("key1");
            Assert.Single(dict);

            dict.Clear();
            Assert.Empty(dict);
        }
Пример #3
0
        public void ValuesTest()
        {
            var dict = new LRUCacheDictionary <string, string>
            {
                { "key1", "value1" },
                { "key2", "value2" },
                { "key3", "value3" },
            };

            Assert.That(dict.Values, Is.EquivalentTo(new[] { "value1", "value2", "value3" }));

            dict.Add("foo", "bar");
            Assert.That(dict.Values, Is.EquivalentTo(new[] { "value1", "value2", "value3", "bar" }));

            dict.Remove("key2");
            Assert.That(dict.Values, Is.EquivalentTo(new[] { "value1", "value3", "bar" }));

            dict.Clear();
            Assert.That(dict.Values, Is.Empty);
        }
Пример #4
0
        public void ValuesTest()
        {
            var dict = new LRUCacheDictionary <string, string>
            {
                ["key1"] = "value1",
                ["key2"] = "value2",
                ["key3"] = "value3",
            };

            Assert.Equal(new[] { "value1", "value2", "value3" }, dict.Values, collComparer);

            dict.Add("foo", "bar");
            Assert.Equal(new[] { "value1", "value2", "value3", "bar" }, dict.Values, collComparer);

            dict.Remove("key2");
            Assert.Equal(new[] { "value1", "value3", "bar" }, dict.Values, collComparer);

            dict.Clear();
            Assert.Empty(dict.Values);
        }
Пример #5
0
        public void KeysTest()
        {
            var dict = new LRUCacheDictionary <string, string>
            {
                { "key1", "value1" },
                { "key2", "value2" },
                { "key3", "value3" },
            };

            Assert.Equal(new[] { "key1", "key2", "key3" }, dict.Keys, collComparer);

            dict.Add("foo", "bar");
            Assert.Equal(new[] { "key1", "key2", "key3", "foo" }, dict.Keys, collComparer);

            dict.Remove("key2");
            Assert.Equal(new[] { "key1", "key3", "foo" }, dict.Keys, collComparer);

            dict.Clear();
            Assert.Empty(dict.Keys);
        }