Esempio n. 1
0
        public void OS_Select_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, (int)tree.OS_Select(i));
            }

            for (int i = HALF; i < NUMBER; i++)
            {
                tree.RB_Insert(i);
            }
            for (int i = 0; i < NUMBER; i++)
            {
                Assert.AreEqual(i, (int)tree.OS_Select(i));
            }
        }
Esempio n. 2
0
        public void SearchForIndexTest5()
        {
            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");
            //Trace.WriteLine("_______before deleting of zhu0______");
            //tree.InorderPrint();
            //Trace.WriteLine("_______deleting of zhu0___");
            tree.RB_Delete("zhu0");
            //tree.InorderPrint();
            //Trace.WriteLine("____________________________________");
            //Trace.WriteLine("_______inserting of SergZ___");
            tree.RB_Insert("SergZ");
            //tree.InorderPrint();
            //Trace.WriteLine("____________________________________");
            //Trace.WriteLine("_______deleting of zhu1___");
            tree.RB_Delete("zhu1");
            //tree.InorderPrint();

            Assert.AreEqual("zhu2", tree.OS_Select(1));
        }
Esempio n. 3
0
        public void OS_Select_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, (int)tree.OS_Select(i));
            }
        }
Esempio n. 4
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;
            }
        }
Esempio n. 5
0
        public void SearchAfterDeletingTest()
        {
            RedBlackTreeWithIndexAccess tree = new RedBlackTreeWithIndexAccess();

            for (int i = 0; i < 1000; i++)
            {
                tree.RB_Insert(i);
            }
            for (int i = 0; i < 1000; i = i + 2)
            {
                tree.RB_Delete(i);
            }
            for (int i = 0; i < 499; i++)
            {
                int found = (int)tree.OS_Select(i);
                Assert.AreEqual(i * 2 + 1, found);
            }
        }