예제 #1
0
        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);
        }
예제 #2
0
        public void FirstCommonAncestorAlgo_TwoNodesHaveDiffParent_CommonAncestorIsRoot()
        {
            // Arrange & Act
            var actual = FirstCommonAncestor <int> .FirstCommonAncestorAlgo(root, rootLeftLeftLeft, rootRightLeftRight);

            // Assert
            actual.Should().Be(root);
        }
예제 #3
0
        public void FirstCommonAncestorAlgo_OnlyOneNodeInTheTree()
        {
            // Arrange & Act
            var actual = FirstCommonAncestor <int> .FirstCommonAncestorAlgo(root, rootLeftLeftLeft, new BinaryTreeNode <int>(10));

            // Assert
            actual.Should().Be(null);
        }
예제 #4
0
        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);
        }