Exemple #1
0
        private void NullNodesTest(ICommonAncestorFinder commonAncestorFinder)
        {
            BinaryTreeNode <int> root     = new BinaryTreeNode <int>(9);
            BinaryTreeNode <int> node1    = null;
            BinaryTreeNode <int> node2    = new BinaryTreeNode <int>(10);
            BinaryTreeNode <int> result1  = commonAncestorFinder.FindCommonAncestor(root, node1, node2);
            BinaryTreeNode <int> result2  = commonAncestorFinder.FindCommonAncestor(root, node2, node1);
            BinaryTreeNode <int> expected = null;

            Assert.AreEqual(expected, result1);
            Assert.AreEqual(expected, result2);
        }
Exemple #2
0
        private void AncestorFoundTest(ICommonAncestorFinder commonAncestorFinder)
        {
            BinaryTreeNode <int> root     = BuildBinaryTree();
            BinaryTreeNode <int> node1    = root.Left.Right;
            BinaryTreeNode <int> node2    = root.Left.Left.Right;
            BinaryTreeNode <int> expected = root.Left;
            BinaryTreeNode <int> result   = commonAncestorFinder.FindCommonAncestor(root, node1, node2);

            Assert.AreEqual(expected, result);
        }