public void FirstCommonAncestorAlgo_NeitherNodesInTheTree() { // Arrange & Act var actual = FirstCommonAncestor <int> .FirstCommonAncestorAlgo(root, new BinaryTreeNode <int>(10), new BinaryTreeNode <int>(11)); // Assert actual.Should().Be(null); }
public void FirstCommonAncestorAlgo_TwoNodesHaveDiffParent_CommonAncestorIsRoot() { // Arrange & Act var actual = FirstCommonAncestor <int> .FirstCommonAncestorAlgo(root, rootLeftLeftLeft, rootRightLeftRight); // Assert actual.Should().Be(root); }
public void FirstCommonAncestorAlgo_OnlyOneNodeInTheTree() { // Arrange & Act var actual = FirstCommonAncestor <int> .FirstCommonAncestorAlgo(root, rootLeftLeftLeft, new BinaryTreeNode <int>(10)); // Assert actual.Should().Be(null); }
public void FirstCommonAncestorTestMoreEfficient(TreeNode <int> root, TreeNode <int> p, TreeNode <int> q, TreeNode <int> expectedResult) { TreeNode <int> result = FirstCommonAncestor <int> .commonAncestor(root, p, q); Assert.Equal(expectedResult, result); }