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

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

            // Assert
            actual.Should().Be(null);
        }
Exemplo n.º 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);
        }