Exemple #1
0
        public void SearchForIndexTest()
        {
            RedBlackTreeWithIndexAccess tree = new RedBlackTreeWithIndexAccess();
            ArrayList list = new ArrayList();

            Assert.AreEqual(list.BinarySearch(3), tree.SearchForIndex(3));
            tree.RB_Insert(3);
            list.Add(3);
            Assert.AreEqual(list.BinarySearch(3), tree.SearchForIndex(3));
            Assert.AreEqual(list.BinarySearch(4), tree.SearchForIndex(4));
            Assert.AreEqual(list.BinarySearch(2), tree.SearchForIndex(2));
            Assert.AreEqual(1, tree.Count);
        }
Exemple #2
0
        public void InsertingAfterDeletingTest1()
        {
            RedBlackTreeWithIndexAccess tree = new RedBlackTreeWithIndexAccess();
            int NUMBER = 6;
            int HALF   = NUMBER / 2;

            for (int i = 0; i < NUMBER; i++)
            {
                tree.RB_Insert(i);
            }
            for (int i = HALF; i < NUMBER; i++)
            {
                tree.RB_Delete(i);
            }

            int test = tree.SearchForIndex(4);

            if (test.Equals(4))
            {
                Assert.Fail("test.Key == 4");
            }
            for (int i = HALF; i < NUMBER; i++)
            {
                tree.RB_Insert(i);
            }

            //RBNode testNode = tree.GetMinimum();
            //Assert.AreEqual( 0, testNode.Key );
            for (int i = 0; i < NUMBER; i++)
            {
                Assert.AreEqual(i, tree.OS_Rank(i));
                //testNode = tree.GetSuccessor( testNode );
            }
        }
Exemple #3
0
        public void CountTest()
        {
            RedBlackTreeWithIndexAccess tree = new RedBlackTreeWithIndexAccess();

            tree.RB_Insert(3);
            Assert.AreEqual(0, tree.SearchForIndex(3));
            Assert.AreEqual(1, tree.Count);
            tree.RB_Delete(3);
            Assert.AreEqual(0, tree.Count);
            Assert.AreEqual(-1, tree.SearchForIndex(3));

            tree.RB_Insert(2);
            tree.RB_Insert(4);
            tree.RB_Insert(5);
            tree.RB_Insert(6);
            tree.RB_Insert(7);
            tree.RB_Insert(8);
            tree.RB_Insert(9);
            tree.RB_Insert(10);
            tree.RB_Insert(11);
            tree.RB_Insert(12);
            Assert.AreEqual(10, tree.Count);
            tree.RB_Delete(8);
            Assert.AreEqual(9, tree.Count);
            tree.RB_Delete(4);
            Assert.AreEqual(8, tree.Count);
            tree.RB_Delete(2);
            Assert.AreEqual(7, tree.Count);
            tree.RB_Delete(10);
            Assert.AreEqual(6, tree.Count);
            tree.RB_Delete(12);
            Assert.AreEqual(5, tree.Count);
            tree.RB_Delete(6);
            Assert.AreEqual(4, tree.Count);
            tree.RB_Delete(7);
            Assert.AreEqual(3, tree.Count);
            tree.RB_Delete(5);
            Assert.AreEqual(2, tree.Count);
            tree.RB_Delete(11);
            Assert.AreEqual(1, tree.Count);
            tree.RB_Delete(9);
            Assert.AreEqual(0, tree.Count);
        }
Exemple #4
0
        public void SearchForIndexTest4()
        {
            RedBlackTreeWithIndexAccess tree = new RedBlackTreeWithIndexAccess();

            tree.RB_Insert("zhu0");
            tree.RB_Insert("zhu1");
            tree.RB_Insert("zhu2");
            tree.RB_Delete("zhu1");
            int i = ~tree.SearchForIndex("zhu1");

            Assert.AreEqual(1, i);
        }
Exemple #5
0
        public void SearchTest()
        {
            RedBlackTreeWithIndexAccess tree = new RedBlackTreeWithIndexAccess();

            for (int i = 0; i < 1000; i++)
            {
                tree.RB_Insert(i);
            }
            for (int i = 0; i < 1000; i++)
            {
                int found = tree.SearchForIndex(i);
                Assert.AreEqual(i, found);
            }
        }
Exemple #6
0
        public void SearchForIndexTest2()
        {
            RedBlackTreeWithIndexAccess tree = new RedBlackTreeWithIndexAccess();
            ArrayList list = new ArrayList();

            Assert.AreEqual(list.BinarySearch(3), tree.SearchForIndex(3));
            tree.RB_Insert(3);
            list.Add(3);
            tree.RB_Insert(4);
            list.Add(4);
            tree.RB_Insert(6);
            list.Add(6);
            tree.RB_Insert(7);
            list.Add(7);
            Assert.AreEqual(list.BinarySearch(1), tree.SearchForIndex(1));
            Assert.AreEqual(list.BinarySearch(2), tree.SearchForIndex(2));
            Assert.AreEqual(list.BinarySearch(3), tree.SearchForIndex(3));
            Assert.AreEqual(list.BinarySearch(4), tree.SearchForIndex(4));
            Assert.AreEqual(list.BinarySearch(5), tree.SearchForIndex(5));
            Assert.AreEqual(list.BinarySearch(6), tree.SearchForIndex(6));
            Assert.AreEqual(list.BinarySearch(7), tree.SearchForIndex(7));
            Assert.AreEqual(list.BinarySearch(8), tree.SearchForIndex(8));
            Assert.AreEqual(4, tree.Count);
        }
Exemple #7
0
        public void SearchForIndexTest3()
        {
            RedBlackTreeWithIndexAccess tree = new RedBlackTreeWithIndexAccess();

            tree.RB_Insert("zhu0");
            tree.RB_Insert("zhu1");
            tree.RB_Insert("zhu2");
            tree.RB_Insert("zhu3");
            tree.RB_Insert("zhu4");
            tree.RB_Insert("zhu5");
            tree.RB_Insert("zhu6");
            tree.RB_Insert("zhu7");
            tree.RB_Insert("zhu8");
            tree.RB_Insert("zhu9");
            tree.RB_Delete("zhu4");
            tree.RB_Delete("zhu0");
            tree.RB_Delete("zhu1");
            tree.RB_Delete("zhu2");
            tree.RB_Delete("zhu3");
            tree.SearchForIndex("zhu4");
        }