Example #1
0
        public void FindNode()
        {
            BSTNode <int> binaryTree = TestDataForBST.CreateBinaryTree();

            FindAnElementInBST findAnElementInBST = new FindAnElementInBST();

            Assert.AreEqual(findAnElementInBST.FindANode(binaryTree, new BSTNode <int>(5)).Data, new BSTNode <int>(5).Data);

            Assert.AreEqual(findAnElementInBST.FindANodeIteratively(binaryTree, new BSTNode <int>(5)).Data, new BSTNode <int>(5).Data);
        }
Example #2
0
        public void InsertNodeTest()
        {
            var expectedOutput = "Node Inserted Successfully";

            using (StringWriter sw = new StringWriter())
            {
                Console.SetOut(sw);

                BSTNode <int> binaryTree = TestDataForBST.CreateBinaryTree();
                InsertANode   i          = new InsertANode();
                binaryTree = i.InsertANodeInBST(binaryTree, new BSTNode <int>(12));
                Assert.AreEqual <string>(expectedOutput, sw.ToString());

                FindAnElementInBST findNode = new FindAnElementInBST();

                Assert.AreEqual(findNode.FindMaximum(binaryTree).Data, 12);

                Assert.IsNull(findNode.FindANode(binaryTree, new BSTNode <int>(12).Left));
                Assert.IsNull(findNode.FindANode(binaryTree, new BSTNode <int>(12).Right));
            }
        }