コード例 #1
0
        public void TestRangeEnumerate()
        {
            BTreeDictionary <int, string> data = new BTreeDictionary <int, string>(Comparer);

            for (int i = 0; i < 100; i++)
            {
                Assert.IsTrue(data.TryAdd(i, i.ToString()));
            }

            int ix = 0;

            foreach (KeyValuePair <int, string> kv in data.EnumerateRange(-500, 5000))
            {
                Assert.AreEqual(ix++, kv.Key);
            }
            Assert.AreEqual(100, ix);

            foreach (
                KeyValuePair <int, int> range in
                new Dictionary <int, int> {
                { 6, 25 }, { 7, 25 }, { 8, 25 }, { 9, 25 }, { 22, 25 }, { 28, 28 }
            })
            {
                ix = range.Key;
                foreach (KeyValuePair <int, string> kv in data.EnumerateRange(ix, range.Value))
                {
                    Assert.AreEqual(ix++, kv.Key);
                }
                Assert.AreEqual(range.Value, ix - 1);
            }
        }