public void Test_Delete_On_Single_Node_Tree() { // Arrange BinaryTree bt = new BinaryTree(); Data data = new Data(17, "Data17"); bt.Insert(17, data); // Act bool removed = bt.Remove(17); // Should find the single node (17 == 17)... // Assert Assert.IsTrue(removed); Assert.IsTrue(bt.TreeDepth() == 0); }
public void Test_Tree_Depth_For_Single_Node_Tree() { // Arrange BinaryTree b = new BinaryTree(); Data data = new Data(); b.Insert(1, data); // Act int depth = b.TreeDepth(); // Assert Assert.IsTrue(depth == 1); }
public void Test_Tree_Depth_For_Seven_Node_Tree() { // Arrange BinaryTree b = new BinaryTree(); BuildSevenNodeBalancedTree(b); // Act int depth = b.TreeDepth(); // Assert Assert.IsTrue(depth == 4); }
public void Test_Tree_Depth_For_Null_Tree() { // Arrange BinaryTree b = new BinaryTree(); // Act int depth = b.TreeDepth(); // Assert Assert.IsTrue(depth == 0); }
public void Test_Remove_On_Node_With_Only_A_Right_Subtree() { // Arrange BinaryTree bt = new BinaryTree(); Node n1 = new Node(17); Node n2 = new Node(23); // This is the node we will delete. Node n3 = new Node(29); // This order of insertion should create a right-only subtree. bt.Insert(n1); bt.Insert(n2); bt.Insert(n3); // Act bool removed = bt.Remove(23); // Assert Assert.IsTrue(removed); Assert.IsTrue(bt.TreeDepth() == 2); }
public void Test_Remove_On_Node_With_Only_A_Left_Subtree() { // Arrange BinaryTree bt = new BinaryTree(); Node n1 = new Node(17); Node n2 = new Node(14); // This is the one we will remove. Node n3 = new Node(9); // This order of insertion should create a left-only subtree. bt.Insert(n1); bt.Insert(n2); bt.Insert(n3); // Act bool removed = bt.Remove(14); // Assert Assert.IsTrue(removed); Assert.IsTrue(bt.TreeDepth() == 2); Queue<Node> queue = bt.TreeToQueue(); Assert.IsTrue(queue.Dequeue() == n3); Assert.IsTrue(queue.Dequeue() == n1); }