public void PostorderTraversal_Empty_ReturnEmpty() { var helper = new TreeTraversalSolution(); TreeNode root = null; var result = helper.PostorderTraversal(root); Assert.That(result, Is.EqualTo(new List <int> { })); }
public void PostorderTraversal_SingleItem_ReturnExpected() { var helper = new TreeTraversalSolution(); var root = new TreeNode { val = 1 }; var result = helper.PostorderTraversal(root); Assert.That(result, Is.EqualTo(new List <int> { 1 })); }
public void PostorderTraversal_NullFixed_ReturnExpected() { var helper = new TreeTraversalSolution(); var root = new TreeNode { val = 1, left = new TreeNode { val = 2, right = new TreeNode { val = 3, left = new TreeNode { val = 4, } } }, right = new TreeNode { val = 5, right = new TreeNode { val = 6, left = new TreeNode { val = 7, }, right = new TreeNode { val = 8, } } } }; var result = helper.PostorderTraversal(root); Assert.That(result, Is.EqualTo(new List <int> { 4, 3, 2, 7, 8, 6, 5, 1 })); }
public void PostorderTraversal_WhenRightNull_ReturnExpected() { var helper = new TreeTraversalSolution(); var root = new TreeNode { val = 1, left = new TreeNode { val = 2 }, right = null }; var result = helper.PostorderTraversal(root); Assert.That(result, Is.EqualTo(new List <int> { 2, 1 })); }
public void PostorderTraversal_CompleteBTree_ReturnExpected() { var helper = new TreeTraversalSolution(); var root = new TreeNode { val = 1, left = new TreeNode { val = 2, }, right = new TreeNode { val = 3, } }; var result = helper.PostorderTraversal(root); Assert.That(result, Is.EqualTo(new List <int> { 2, 3, 1 })); }