Exemplo n.º 1
0
        public void TestInvalidInput()
        {
            int[] preOrder = new int[] { 1, 2, 4, 5, 3, 6, 7 };
            int[] inOrder  = new int[] { 4, 2, 8, 1, 6, 3, 7 };

            ConstructBinaryTree.ProcessRecursively(preOrder, inOrder);
            ConstructBinaryTree.ProcessIteratively(preOrder, inOrder);
        }
Exemplo n.º 2
0
        public void TestArrayLengthNotMatch()
        {
            int[] preOrder = new int[] { 1 };
            int[] inOrder  = new int[] { 2, 1 };

            ConstructBinaryTree.ProcessRecursively(preOrder, inOrder);
            ConstructBinaryTree.ProcessIteratively(preOrder, inOrder);
        }
Exemplo n.º 3
0
        public void TestCompleteTree()
        {
            int[]    preOrder = new int[] { 1, 2, 4, 5, 3, 6, 7 };
            int[]    inOrder  = new int[] { 4, 2, 5, 1, 6, 3, 7 };
            TreeNode expected = Helper.CreateTree(TreeType.CompleteTree);

            Assert.IsTrue(Helper.CompareBinaryTree(expected, ConstructBinaryTree.ProcessRecursively(preOrder, inOrder)));
            Assert.IsTrue(Helper.CompareBinaryTree(expected, ConstructBinaryTree.ProcessIteratively(preOrder, inOrder)));
        }
Exemplo n.º 4
0
        public void TestOnlyRootTree()
        {
            int[]    preOrder = new int[] { 1 };
            int[]    inOrder  = new int[] { 1 };
            TreeNode expected = new TreeNode(1);

            Assert.IsTrue(Helper.CompareBinaryTree(expected, ConstructBinaryTree.ProcessRecursively(preOrder, inOrder)));
            Assert.IsTrue(Helper.CompareBinaryTree(expected, ConstructBinaryTree.ProcessIteratively(preOrder, inOrder)));
        }
Exemplo n.º 5
0
        public void TestNoLeftChildTree()
        {
            int[]    preOrder = new int[] { 1, 2, 3, 4, 5 };
            int[]    inOrder  = new int[] { 1, 2, 3, 4, 5 };
            TreeNode expected = Helper.CreateTree(TreeType.NoLeftChildTree);

            Assert.IsTrue(Helper.CompareBinaryTree(expected, ConstructBinaryTree.ProcessRecursively(preOrder, inOrder)));
            Assert.IsTrue(Helper.CompareBinaryTree(expected, ConstructBinaryTree.ProcessIteratively(preOrder, inOrder)));
        }
Exemplo n.º 6
0
 public void TestEmptyArray()
 {
     Assert.IsNull(ConstructBinaryTree.ProcessRecursively(new int[0], new int[0]));
     Assert.IsNull(ConstructBinaryTree.ProcessIteratively(new int[0], new int[0]));
 }
Exemplo n.º 7
0
 public void TestNull()
 {
     Assert.IsNull(ConstructBinaryTree.ProcessRecursively(null, null));
     Assert.IsNull(ConstructBinaryTree.ProcessIteratively(null, null));
 }