public void TestInsertion() { List <int> data = new List <int> { 10, 20, 30, 40, 50, 25 }; BalancedTree tree = new BalancedTree(); foreach (int datum in data) { tree.Insert(datum); } Assert.IsTrue(tree.PreOrder() == "302010254050"); }
public void TestBalance() { List <int> data = new List <int> { 14, 7, 23, 8 }; BalancedTree tree = new BalancedTree(); foreach (int datum in data) { tree.Insert(datum); } Assert.IsTrue(tree.Balance == 1); data = new List <int> { 2, 1 }; tree = new BalancedTree(); foreach (int datum in data) { tree.Insert(datum); } Assert.IsTrue(tree.Balance == 1); //The following tests were for development purposes, after balancing is enacted in tree's they will need to be mocked //data = new List<int> //{ // 7,1,3,4 //}; //tree = new BalancedTree(); //foreach (int datum in data) //{ // tree.Insert(datum); //} //Assert.IsTrue(tree.Balance == 3); //data = new List<int> //{ // 7,9,10 //}; //tree = new BalancedTree(); //foreach (int datum in data) //{ // tree.Insert(datum); //} //Assert.IsTrue(tree.Balance == -2); }
public void TestRemoval() { List <int> data = new List <int> { 9, 5, 10, 0, 6, 11, -1, 1, 2 }; BalancedTree tree = new BalancedTree(); foreach (int datum in data) { tree.Insert(datum); } Assert.IsTrue(tree.PreOrder() == "910-15261011"); tree.Remove(10); string result = tree.PreOrder(); Assert.IsTrue(result == "10-1952611"); }
static void Main(string[] args) { BalancedTree <int> tree = new BalancedTree <int>(); List <int> insertList = new List <int> { 9, 5, 10, 0, 6, 11, -1, 1, 2 }; foreach (var item in insertList) { tree.Root = tree.Insert(tree.Root, item); } tree.PrintSorted(); tree.Root = tree.DeleteNode(tree.Root, -1); tree.PrintSorted(); }