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)); }
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); }
public void AddTest() { var dict = new LRUCacheDictionary <string, string>(); dict.Add("key1", "value1"); Assert.That(dict.innerDict.Count, Is.EqualTo(1)); Assert.That(dict.innerDict.ContainsKey("key1"), Is.True); var internalNode = dict.innerDict["key1"]; Assert.That(internalNode.Value.Key, Is.EqualTo("key1")); Assert.That(internalNode.Value.Value, Is.EqualTo("value1")); dict.Add("key2", "value2"); Assert.That(dict.innerDict.Count, Is.EqualTo(2)); Assert.That(dict.innerDict.ContainsKey("key2"), Is.True); internalNode = dict.innerDict["key2"]; Assert.That(internalNode.Value.Key, Is.EqualTo("key2")); Assert.That(internalNode.Value.Value, Is.EqualTo("value2")); }
public void AddTest() { var dict = new LRUCacheDictionary <string, string>(); dict.Add("key1", "value1"); Assert.Single(dict.innerDict); Assert.True(dict.innerDict.ContainsKey("key1")); var internalNode = dict.innerDict["key1"]; Assert.Equal("key1", internalNode.Value.Key); Assert.Equal("value1", internalNode.Value.Value); dict.Add("key2", "value2"); Assert.Equal(2, dict.innerDict.Count); Assert.True(dict.innerDict.ContainsKey("key2")); internalNode = dict.innerDict["key2"]; Assert.Equal("key2", internalNode.Value.Key); Assert.Equal("value2", internalNode.Value.Value); }
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); }
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); }
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); }
public void AutoTrimTest() { var dict = new LRUCacheDictionary <string, string>(); dict.AutoTrimCount = 4; // 4アクセス毎に dict.TrimLimit = 3; // 3個を越えるアイテムを削除する dict["key1"] = "value1"; // 1アクセス目 dict["key2"] = "value2"; // 2アクセス目 dict["key3"] = "value3"; // 3アクセス目 dict["key4"] = "value4"; // 4アクセス目 (この直後にTrim) // 1 -> 2 -> 3 -> 4 の順にアクセスしたため、直近 3 件の 2, 3, 4 だけが残る Assert.Equal(new[] { "key2", "key3", "key4" }, dict.innerDict.Keys, collComparer); dict["key5"] = "value5"; // 5アクセス目 dict.Add("key6", "value6"); // 6アクセス目 _ = dict["key2"]; // 7アクセス目 dict.TryGetValue("key4", out _); // 8アクセス目 (この直後にTrim) // 5 -> 6 -> 2 -> 4 の順でアクセスしたため、直近 3 件の 6, 2, 4 だけが残る Assert.Equal(new[] { "key6", "key2", "key4" }, dict.innerDict.Keys, collComparer); }