コード例 #1
0
        public void OS_Rank_AfterDeletingTest()
        {
            RedBlackTreeWithIndexAccess tree = new RedBlackTreeWithIndexAccess();
            int NUMBER = 1000;
            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);
            }

            for (int i = 0; i < HALF; i++)
            {
                Assert.AreEqual(i, tree.OS_Rank(i));
            }

            for (int i = HALF; i < NUMBER; i++)
            {
                tree.RB_Insert(i);
            }
            for (int i = 0; i < NUMBER; i++)
            {
                Assert.AreEqual(i, tree.OS_Rank(i));
            }
        }
コード例 #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 );
            }
        }
コード例 #3
0
        public void InsertingAfterDeletingTest1000()
        {
            RedBlackTreeWithIndexAccess tree = new RedBlackTreeWithIndexAccess();
            int NUMBER = 1000;
            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);
            }
            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 );
            }
        }
コード例 #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);
        }
コード例 #5
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);
        }
コード例 #6
0
        public void DeletingTest()
        {
            RedBlackTreeWithIndexAccess tree = new RedBlackTreeWithIndexAccess();

            for (int i = 0; i < 1000; i++)
            {
                tree.RB_Insert(i);
            }
            for (int i = 0; i < 1000; i++)
            {
                tree.RB_Delete(i);
            }
        }
コード例 #7
0
        public void OS_Rank_Test()
        {
            RedBlackTreeWithIndexAccess tree = new RedBlackTreeWithIndexAccess();

            for (int i = 0; i < 1000; i++)
            {
                tree.RB_Insert(i);
            }
            for (int i = 0; i < 1000; i++)
            {
                Assert.AreEqual(i, tree.OS_Rank(i));
            }
        }
コード例 #8
0
        public void GetMinMaxTest()
        {
            RedBlackTreeWithIndexAccess tree = new RedBlackTreeWithIndexAccess();

            for (int i = 0; i < 1000; i++)
            {
                tree.RB_Insert(i);
            }
            int min = (int)tree.GetMinimum();

            Assert.AreEqual(0, min);
            int max = (int)tree.GetMaximum();

            Assert.AreEqual(999, max);
        }
コード例 #9
0
        public void OS_SelectTest()
        {
            RedBlackTreeWithIndexAccess tree = new RedBlackTreeWithIndexAccess();
            int NUMBER = 40;

            //int TEST_NUM = 8;
            for (int i = 0; i < NUMBER; i++)
            {
                tree.RB_Insert(i);
            }

            Assert.AreEqual(NUMBER, tree.Count);
            //Trace.WriteLine( "______________________________" );

            try
            {
                //Trace.WriteLine( "________delete 8______________________" );
                tree.RB_Delete(8);
                //Trace.WriteLine( "________delete 9______________________" );
                tree.RB_Delete(9);
                //Trace.WriteLine( "________delete 10______________________" );
                tree.RB_Delete(10);
                //Trace.WriteLine( "________delete 11______________________" );
                tree.RB_Delete(11);
                //Trace.WriteLine( "________delete 12______________________" );
                tree.RB_Delete(12);
                //Trace.WriteLine( "________delete 13______________________" );
                tree.RB_Delete(13);
                //Trace.WriteLine( "________delete 14______________________" );
                tree.RB_Delete(14);
                //Trace.WriteLine( "______________________________" );
                //tree.InorderPrint();
                tree.RB_Delete(15);
                for (int j = 0; j < 32; j++)
                {
                    tree.OS_Select(j);
                    //Assert.AreEqual( i, found );
                }
            }
            catch (InvalidCastException ex)
            {
                Trace.WriteLine(ex.Message);
                Trace.WriteLine("______________________________");
                tree.InorderPrint();
                Trace.WriteLine("tree.Count: " + tree.Count);
                throw ex;
            }
        }
コード例 #10
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);
        }
コード例 #11
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");
        }
コード例 #12
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);
        }