public void TestFindRange() { myDataCache.Add(new MyKey("key1"), new MyValue("value1")); myDataCache.Add(new MyKey("key2"), new MyValue("value2")); myDataCache.InnerDict.Add(new MyKey("key3"), new MyValue("value3")); myDataCache.InnerDict.Add(new MyKey("key4"), new MyValue("value4")); var items = myDataCache.FindRange(new MyKey("key3").ToArray(), new MyKey("key5").ToArray()).ToArray(); new MyKey("key3").Should().Be(items[0].Key); new MyValue("value3").Should().Be(items[0].Value); new MyKey("key4").Should().Be(items[1].Key); new MyValue("value4").Should().Be(items[1].Value); items.Length.Should().Be(2); // case 2 Need to sort the cache of myDataCache myDataCache = new MyDataCache(); myDataCache.Add(new MyKey("key1"), new MyValue("value1")); myDataCache.Add(new MyKey("key2"), new MyValue("value2")); myDataCache.InnerDict.Add(new MyKey("key4"), new MyValue("value4")); myDataCache.InnerDict.Add(new MyKey("key3"), new MyValue("value3")); items = myDataCache.FindRange(new MyKey("key3").ToArray(), new MyKey("key5").ToArray()).ToArray(); new MyKey("key3").Should().Be(items[0].Key); new MyValue("value3").Should().Be(items[0].Value); new MyKey("key4").Should().Be(items[1].Key); new MyValue("value4").Should().Be(items[1].Value); items.Length.Should().Be(2); // case 3 FindRange by Backward myDataCache = new MyDataCache(); myDataCache.Add(new MyKey("key1"), new MyValue("value1")); myDataCache.Add(new MyKey("key2"), new MyValue("value2")); myDataCache.InnerDict.Add(new MyKey("key4"), new MyValue("value4")); myDataCache.InnerDict.Add(new MyKey("key3"), new MyValue("value3")); myDataCache.InnerDict.Add(new MyKey("key5"), new MyValue("value5")); items = myDataCache.FindRange(new MyKey("key5").ToArray(), new MyKey("key3").ToArray(), SeekDirection.Backward).ToArray(); new MyKey("key5").Should().Be(items[0].Key); new MyValue("value5").Should().Be(items[0].Value); new MyKey("key4").Should().Be(items[1].Key); new MyValue("value4").Should().Be(items[1].Value); items.Length.Should().Be(2); }
public void TestFindInvalid() { var myDataCache = new MyDataCache <MyKey, MyValue>(); myDataCache.Add(new MyKey("key1"), new MyValue("value1")); myDataCache.InnerDict.Add(new MyKey("key2"), new MyValue("value2")); myDataCache.InnerDict.Add(new MyKey("key3"), new MyValue("value3")); myDataCache.InnerDict.Add(new MyKey("key4"), new MyValue("value3")); var items = myDataCache.Find().GetEnumerator(); items.MoveNext().Should().Be(true); items.Current.Key.Should().Be(new MyKey("key1")); myDataCache.TryGet(new MyKey("key3")); // GETLINE items.MoveNext().Should().Be(true); items.Current.Key.Should().Be(new MyKey("key2")); items.MoveNext().Should().Be(true); items.Current.Key.Should().Be(new MyKey("key3")); items.MoveNext().Should().Be(true); items.Current.Key.Should().Be(new MyKey("key4")); items.MoveNext().Should().Be(false); }
public void TestAccessByKey() { myDataCache.Add(new MyKey("key1"), new MyValue("value1")); myDataCache.Add(new MyKey("key2"), new MyValue("value2")); myDataCache[new MyKey("key1")].Should().Be(new MyValue("value1")); // case 2 read from inner myDataCache.InnerDict.Add(new MyKey("key3"), new MyValue("value3")); myDataCache[new MyKey("key3")].Should().Be(new MyValue("value3")); }