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)); }
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)); } }
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 ); } }
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 ); } }
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); }
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"); }
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); } }
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; } }
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); } }
public void StressTestForGetMinimum() { RedBlackTreeWithIndexAccess tree = new RedBlackTreeWithIndexAccess(); for (int i = 0; i < 1000000; i++) { tree.RB_Insert(new TestObject(4)); } tree.RB_Insert(new TestObject(1)); RBNodeIndexAccess node = null; int key = 0; while (key != 1) { node = tree.GetMinimumNode(); key = ((TestObject)node.Key)._value; tree.RB_Delete(node); } }
public void GetEqualOrMoreTest4() { RedBlackTreeWithIndexAccess tree = new RedBlackTreeWithIndexAccess(); for (int i = 0; i < 100000; i++) { tree.RB_Insert(i); } for (int i = 10000; i < 10010; i++) { tree.RB_Delete(i); RBNodeIndexAccess node = tree.GetEqualOrMore(i, null); Assert.AreEqual(i + 1, (int)node.Key); for (int j = i + 2; j < 100000; j++) { node = tree.GetNext(node); Assert.AreEqual(j, (int)node.Key); } } }
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); }