示例#1
0
        public void OverlappingAdd()
        {
            var tree = new VEBTree <string>(4);

            tree.Add(13, "test1");
            Assert.Throws <ArgumentException>(() => tree.Add(13, "test2"));
        }
示例#2
0
 private static void CorrectnessCheck(VEBTree <string> tree, IEnumerable <uint> checkSet)
 {
     foreach (uint val in checkSet)
     {
         Assert.AreEqual(val.ToString(), tree[val]);
     }
     Assert.AreEqual(checkSet.Count(), tree.Count);
 }
示例#3
0
        public void HighLow()
        {
            var tree = new VEBTree <string>(7);

            Assert.AreEqual(15, tree.HighBits(127));
            Assert.AreEqual(7, tree.LowBits(127));
            Assert.AreEqual(127, tree.Index(15, 7));
        }
示例#4
0
        public void OverlappingItemSet()
        {
            var tree = new VEBTree <string>(4);

            tree[13] = "test1";
            tree[13] = "test2";
            Assert.AreEqual("test2", tree[13]);
        }
示例#5
0
        public void SmallRemove()
        {
            var tree = new VEBTree <string>(4);

            tree.Add(5, "asd");
            Assert.IsTrue(tree.Remove(5));
            Assert.IsFalse(tree.Remove(0));
            Assert.Throws <KeyNotFoundException>(() => Ignore(tree[5]));
        }
示例#6
0
        public void IncorrectAddOrSet()
        {
            var tree = new VEBTree <string>(4);

            tree.Add(15, "t1");
            Assert.Throws <ArgumentOutOfRangeException>(() => tree.Add(16, "test"));
            tree[0] = "t2";
            Assert.Throws <ArgumentOutOfRangeException>(() => tree[20] = "test2");
        }
示例#7
0
        public void EmptyCreation()
        {
            var tree = new VEBTree <string>(8);

            for (uint i = 0; i < Math.Pow(2, 8); i++)
            {
                Assert.Throws <KeyNotFoundException>(() => Ignore(tree[i]));
            }
        }
示例#8
0
        public void AddUnevenPower()
        {
            var tree = new VEBTree <string>(7);

            for (uint i = 0; i < 128; i++)
            {
                tree.Add(i, i.ToString());
            }
        }
示例#9
0
        public void Clear()
        {
            var tree = new VEBTree <string>(8);

            tree.Add(200, "200");
            tree.Add(100, "100");
            tree.Add(1, "1");
            tree.Add(2, "2");
            tree.Add(34, "34");
            tree.Clear();
            Assert.IsFalse(tree.Any());
        }
示例#10
0
        public void SimpleAdd()
        {
            var tree = new VEBTree <string>(4);

            tree.Add(13, "test1");
            tree.Add(8, "test2");
            tree.Add(10, "test3");
            tree.Add(15, "test4");
            Assert.AreEqual("test1", tree[13]);
            Assert.AreEqual("test2", tree[8]);
            Assert.AreEqual("test3", tree[10]);
            Assert.AreEqual("test4", tree[15]);
        }
示例#11
0
        public void Higher()
        {
            var tree = new VEBTree <string>(8);

            tree.Add(44, "44");
            tree.Add(200, "200");
            tree.Add(46, "46");
            tree.Add(216, "216");
            tree.Add(248, "248");
            tree.Add(188, "188");
            Assert.AreEqual(new KeyValuePair <uint, string>(188, "188"), tree.Higher(155));
            Assert.AreEqual(new KeyValuePair <uint, string>(248, "248"), tree.Higher(238));
            Assert.AreEqual(new KeyValuePair <uint, string>(188, "188"), tree.Higher(84));
            Assert.AreEqual(null, tree.Higher(248));
        }
示例#12
0
        public void Lower()
        {
            var tree = new VEBTree <string>(8);

            tree.Add(22, "22");
            tree.Add(69, "69");
            tree.Add(248, "248");
            tree.Add(55, "55");
            tree.Add(26, "26");
            tree.Add(76, "76");
            Assert.AreEqual(null, tree.Lower(5));
            Assert.AreEqual(new KeyValuePair <uint, string>(55, "55"), tree.Lower(61));
            Assert.AreEqual(new KeyValuePair <uint, string>(248, "248"), tree.Lower(255));
            Assert.AreEqual(new KeyValuePair <uint, string>(76, "76"), tree.Lower(248));
            Assert.AreEqual(new KeyValuePair <uint, string>(76, "76"), tree.Lower(115));
            Assert.AreEqual(new KeyValuePair <uint, string>(69, "69"), tree.Lower(73));
        }
示例#13
0
        public void ContainsKey()
        {
            var tree = new VEBTree <string>(2);

            tree.Add(0, "0");
            tree.Add(1, "1");
            tree.Add(2, "2");
            tree.Add(3, "3");
            Assert.IsTrue(tree.ContainsKey(0));
            Assert.IsTrue(tree.ContainsKey(1));
            Assert.IsTrue(tree.ContainsKey(2));
            Assert.IsTrue(tree.ContainsKey(3));
            tree = new VEBTree <string>(2);
            Assert.IsFalse(tree.ContainsKey(0));
            Assert.IsFalse(tree.ContainsKey(1));
            Assert.IsFalse(tree.ContainsKey(2));
            Assert.IsFalse(tree.ContainsKey(3));
        }
示例#14
0
        public void FirstLast()
        {
            var tree = new VEBTree <string>(8);

            Assert.AreEqual(null, tree.First());
            Assert.AreEqual(null, tree.Last());
            tree.Add(229, "229");
            Assert.AreEqual(new KeyValuePair <uint, string>(229, "229"), tree.First());
            Assert.AreEqual(new KeyValuePair <uint, string>(229, "229"), tree.Last());
            tree.Add(216, "216");
            tree.Add(21, "21");
            tree.Add(162, "162");
            tree.Add(240, "240");
            tree.Add(95, "95");
            tree.Remove(240);
            Assert.AreEqual(new KeyValuePair <uint, string>(21, "21"), tree.First());
            Assert.AreEqual(new KeyValuePair <uint, string>(229, "229"), tree.Last());
        }
示例#15
0
        public void Count()
        {
            var tree = new VEBTree <string>(4);

            tree.Add(1, "1");
            tree.Add(8, "8");
            tree.Add(2, "2");
            Assert.IsTrue(tree.Remove(2));
            tree.Add(0, "0");
            tree.Add(15, "15");
            Assert.IsTrue(tree.Remove(0));
            tree.Add(12, "12");
            tree.Add(7, "7");
            Assert.IsTrue(tree.Remove(8));
            Assert.IsTrue(tree.Remove(12));
            tree.Add(9, "9");
            Assert.AreEqual(4, tree.Count);
        }
示例#16
0
        public void Enumerator()
        {
            var tree = new VEBTree <string>(4);

            tree.Add(8, "8");
            tree.Add(15, "15");
            tree.Add(1, "1");
            tree.Add(2, "2");
            tree.Add(0, "0");
            tree.Add(3, "3");
            Assert.IsTrue(tree.Contains(new KeyValuePair <uint, string>(0, "0"), new KVPComparer()));
            Assert.IsTrue(tree.Contains(new KeyValuePair <uint, string>(1, "1"), new KVPComparer()));
            Assert.IsTrue(tree.Contains(new KeyValuePair <uint, string>(2, "2"), new KVPComparer()));
            Assert.IsTrue(tree.Contains(new KeyValuePair <uint, string>(3, "3"), new KVPComparer()));
            Assert.IsTrue(tree.Contains(new KeyValuePair <uint, string>(8, "8"), new KVPComparer()));
            Assert.IsTrue(tree.Contains(new KeyValuePair <uint, string>(15, "15"), new KVPComparer()));
            Assert.AreEqual(6, tree.Count((kvp) => true));
        }
示例#17
0
        public void LargeRemove()
        {
            var tree = new VEBTree <string>(4);

            tree.Add(1, "1");
            tree.Add(8, "8");
            tree.Add(2, "2");
            Assert.IsTrue(tree.Remove(2));
            CorrectnessCheck(tree, new uint[] { 1, 8 });
            tree.Add(0, "0");
            tree.Add(15, "15");
            tree.Add(12, "12");
            tree.Add(7, "7");
            tree.Add(9, "9");
            tree.Add(10, "10");
            tree.Add(11, "11");
            Assert.IsTrue(tree.Remove(15));
            // start deletion correctness check
            Assert.AreEqual("1", tree[1]);
            CorrectnessCheck(tree, new uint[] { 1, 8, 0, 12, 7, 9, 10, 11 });
            // end deletion correctness check
            Assert.IsTrue(tree.Remove(8));
            CorrectnessCheck(tree, new uint[] { 1, 0, 12, 7, 9, 10, 11 });
            Assert.IsTrue(tree.Remove(0));
            CorrectnessCheck(tree, new uint[] { 1, 12, 7, 9, 10, 11 });
            Assert.IsFalse(tree.Remove(8));
            Assert.IsTrue(tree.Remove(11));
            CorrectnessCheck(tree, new uint[] { 1, 12, 7, 9, 10 });
            Assert.IsTrue(tree.Remove(10));
            CorrectnessCheck(tree, new uint[] { 1, 12, 7, 9 });
            Assert.IsTrue(tree.Remove(9));
            CorrectnessCheck(tree, new uint[] { 1, 12, 7 });
            Assert.IsTrue(tree.Remove(12));
            CorrectnessCheck(tree, new uint[] { 1, 7 });
            Assert.Throws <KeyNotFoundException>(() => Ignore(tree[15]));
        }