public void CountFullNodes_ShouldReturnCorrectNumber() { var tree = BinaryTreeTestData.SetupTestTree(); var result = tree.CountFullNodes; Assert.Equal(2, result); }
public void GetAbsolutePathToNode_ShouldThrowArgumentException_WhenTargetNodeDoesNotExist() { var tree = BinaryTreeTestData.SetupTestTree(); Assert.Throws <ArgumentException>(() => { tree.GetAbsolutePathToNode(100); }); }
public void Clear_ShouldDeleteAllNodesFromTree() { var tree = BinaryTreeTestData.SetupTestTree(); tree.Clear(); Assert.Null(tree.Root); Assert.Equal(0, tree.CountNodes); }
public void Delete_ShouldThrowArgumentException_WhenTryingToDeleteNotExistingNode(int valueToDelete) { var tree = BinaryTreeTestData.SetupTestTree(); Assert.Throws <ArgumentException>(() => { tree.Delete(valueToDelete); }); }
public void Delete_ShouldDeleteNodeWithTwoChildren() { var tree = BinaryTreeTestData.SetupTestTree(); tree.Delete(20); Assert.Equal(50, tree.Root.Value); Assert.Equal(70, tree.Root.Right.Value); Assert.Equal(60, tree.Root.Right.Left.Value); Assert.Equal(15, tree.Root.Left.Value); Assert.Equal(10, tree.Root.Left.Left.Value); Assert.Equal(30, tree.Root.Left.Right.Value); }
public void Delete_ShouldDeleteNodeWithLeftChild() { var tree = BinaryTreeTestData.SetupTestTree(); tree.Delete(70); Assert.Equal(50, tree.Root.Value); Assert.Equal(20, tree.Root.Left.Value); Assert.Equal(10, tree.Root.Left.Left.Value); Assert.Equal(30, tree.Root.Left.Right.Value); Assert.Equal(60, tree.Root.Right.Value); Assert.Equal(15, tree.Root.Left.Left.Right.Value); Assert.Null(tree.Root.Right.Left); Assert.Null(tree.Root.Right.Right); }
public void TraversalInOrder_ShouldPassTreeFromMinToMaxNode() { var tree = BinaryTreeTestData.SetupTestTree(); var nodesInOrderList = new List <BinaryTreeNode <int> >(); tree.TraversalInOrder(node => { nodesInOrderList.Add(node); }); Assert.Equal(nodesInOrderList[0], tree.Root.Left.Left); Assert.Equal(nodesInOrderList[1], tree.Root.Left.Left.Right); Assert.Equal(nodesInOrderList[2], tree.Root.Left); Assert.Equal(nodesInOrderList[3], tree.Root.Left.Right); Assert.Equal(nodesInOrderList[4], tree.Root); Assert.Equal(nodesInOrderList[5], tree.Root.Right.Left); Assert.Equal(nodesInOrderList[6], tree.Root.Right); }