Example #1
0
        public void FindMaxNode()
        {
            BSTNode <int>      binaryTree         = TestDataForBST.CreateBinaryTree();
            FindAnElementInBST findAnElementInBST = new FindAnElementInBST();
            int min = findAnElementInBST.FindMaximum(binaryTree).Data;

            Assert.AreEqual(min, 10);

            Assert.AreEqual(findAnElementInBST.FindMaximumIteratively(binaryTree).Data, 10);
        }
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));
            }
        }