コード例 #1
0
        public void TestQueuedAvlTrees()
        {
            qtree = new QueuedAVLTree <string, string>(1);
            List <string> hashes = new List <string>();
            List <string> values = new List <string>();

            Assert.IsTrue(qtree.Count == 0);
            qtree.Validate();
            qtree.Add("wolo", "123");
            Assert.AreEqual(qtree["wolo"], "123");
            Assert.IsTrue(qtree.Count == 1);
            Assert.IsTrue(qtree.ContainsKey("wolo"));
            Assert.IsTrue(qtree.Contains(new KeyValuePair <string, string>("wolo", "123")));
            Assert.IsFalse(qtree.ContainsKey("wolo1"));
            Assert.IsFalse(qtree.Contains(new KeyValuePair <string, string>("wolo", "1234")));
            Assert.IsFalse(qtree.Contains(new KeyValuePair <string, string>("wolo1", "123")));
            Assert.IsFalse(qtree.Remove(new KeyValuePair <string, string>("wolo", "1234")));
            Assert.IsFalse(qtree.Remove(new KeyValuePair <string, string>("wolo1", "123")));
            Assert.IsTrue(qtree.Count == 1);
            qtree.Validate();
            qtree.Add("yolo", "0123");
            Assert.AreEqual(qtree["yolo"], "0123");
            Assert.IsTrue(qtree.Count == 1);
            Assert.IsTrue(qtree.ContainsKey("yolo"));
            Assert.IsTrue(qtree.Contains(new KeyValuePair <string, string>("yolo", "0123")));
            Assert.IsFalse(qtree.Contains(new KeyValuePair <string, string>("wolo", "123")));
            Assert.IsFalse(qtree.ContainsKey("wolo"));
            qtree.Validate();
            Assert.IsTrue(qtree.Remove(new KeyValuePair <string, string>("yolo", "0123")));
            Assert.IsTrue(qtree.Count == 0);
            Assert.IsFalse(qtree.Contains(new KeyValuePair <string, string>("yolo", "0123")));
            Assert.IsFalse(qtree.ContainsKey("yolo"));
            qtree.Validate();
            qtree["wolo"] = "abc";
            Assert.IsTrue(qtree.Count == 1);
            Assert.IsTrue(qtree.Remove("wolo"));
            qtree.Clear();
            Assert.IsTrue(qtree.Count == 0);
            qtree.Validate();

            qtree = new QueuedAVLTree <string, string>(10);
            ExecuteTestQueuedTree(10);
            qtree.Clear();

            qtree = new QueuedAVLTree <string, string>(1024);
            ExecuteTestQueuedTree(1024);
            qtree.Clear();
        }
コード例 #2
0
        public void TestQueuedAvlTreesError()
        {
            Console.Write("--- THE BUG HAS BEEN: ");

            var qt = new QueuedAVLTree <string, string>(10);

            for (int i = 0; i < 20; i += 2)
            {
                qt.Add(new KeyValuePair <string, string>(i.ToString("00"), i.ToString("00")));
            }

            Assert.IsTrue(qt.Count == 10);

            for (int i = 1; i < 21; i += 2)
            {
                qt.Add(new KeyValuePair <string, string>(i.ToString("00"), i.ToString("00")));
                Assert.IsTrue(qt[i.ToString("00")] == i.ToString("00"));
                qt.Validate();
                Assert.IsTrue(qt.Count == 10);
            }

            Console.WriteLine("FIXED! --- ");
        }