public void PreorderTraversal_Empty_ReturnEmpty() { var helper = new TreeTraversalSolution(); TreeNode root = null; var result = helper.PreorderTraversal(root); Assert.That(result, Is.EqualTo(new List <int> { })); }
public void PreorderTraversal_SingleItem_ReturnExpected() { var helper = new TreeTraversalSolution(); var root = new TreeNode { val = 1 }; var result = helper.PreorderTraversal(root); Assert.That(result, Is.EqualTo(new List <int> { 1 })); }
public void PreorderTraversal_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.PreorderTraversal(root); Assert.That(result, Is.EqualTo(new List <int> { 1, 2, 3, 4, 5, 6, 7, 8 })); }
public void PreorderTraversal_WhenRightNull_ReturnExpected() { var helper = new TreeTraversalSolution(); var root = new TreeNode { val = 1, right = null, left = new TreeNode { val = 2 } }; var result = helper.PreorderTraversal(root); Assert.That(result, Is.EqualTo(new List <int> { 1, 2 })); }
public void PreorderTraversal_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.PreorderTraversal(root); Assert.That(result, Is.EqualTo(new List <int> { 1, 2, 3 })); }