public void TestCreateBinaryTree() { int?[] nums = new int?[] { 1, 2, 3, 4, null, null, 5, 6 }; var binaryTree = BinaryTreeNode.CreateBinaryTree(nums); Assert.NotNull(binaryTree); }
public void TestCountNodes(int[] nums, int expectedCount) { int?[] arr = nums.Cast <int?>().ToArray(); var treeProblems = new TreeProblems(); var root = BinaryTreeNode.CreateBinaryTree(arr); var actualCount = treeProblems.CountNodes(root); Assert.Equal <int>(expectedCount, actualCount); }
public void TestDelNodesParentAndChild() { var root = BinaryTreeNode.CreateBinaryTree(new int?[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }); var to_delete = new int[] { 2, 5 }; var expectedForest = BinaryTreeNode.CreateBinaryTreeForest(new int?[2][] { new int?[3] { 4, 8, 9 }, new int?[5] { 1, null, 3, 6, 7 } }); var treeProblems = new TreeProblems(); var actualForest = treeProblems.DelNodes(root, to_delete); Assert.Equal <int>(expectedForest.Count, actualForest.Count); }
public void TestDelNodesEasy() { var root = BinaryTreeNode.CreateBinaryTree(new int?[] { 1, 2, 3, 4, 5, 6, 7 }); var to_delete = new int[] { 3, 5 }; var expectedForest = BinaryTreeNode.CreateBinaryTreeForest(new int?[3][] { new int?[1] { 6 }, new int?[1] { 7 }, new int?[4] { 1, 2, null, 4 } }); var treeProblems = new TreeProblems(); var actualForest = treeProblems.DelNodes(root, to_delete); Assert.Equal <int>(expectedForest.Count, actualForest.Count); }