예제 #1
0
        public void TestNull()
        {
            TreeNode root = null;

            MirrorOfBinaryTree.Process(root);
            Assert.IsNull(root);

            root = null;
            MirrorOfBinaryTree.ProcessRecursively(root);
            Assert.IsNull(root);
        }
예제 #2
0
        public void TestOnlyOneNode()
        {
            TreeNode root     = new TreeNode(1);
            TreeNode expected = new TreeNode(1);

            MirrorOfBinaryTree.Process(root);
            Assert.IsTrue(Helper.CompareBinaryTree(expected, root));

            root = new TreeNode(1);
            MirrorOfBinaryTree.ProcessRecursively(root);
            Assert.IsTrue(Helper.CompareBinaryTree(expected, root));
        }
예제 #3
0
        public void TestNoRightChildTree()
        {
            TreeNode root     = Helper.CreateTree(TreeType.NoRightChildTree);
            TreeNode expected = Helper.CreateTree(TreeType.NoLeftChildTree);

            MirrorOfBinaryTree.Process(root);
            Assert.IsTrue(Helper.CompareBinaryTree(expected, root));

            root = Helper.CreateTree(TreeType.NoRightChildTree);
            MirrorOfBinaryTree.ProcessRecursively(root);
            Assert.IsTrue(Helper.CompareBinaryTree(expected, root));
        }
예제 #4
0
        public void TestCompleteTree()
        {
            TreeNode root     = Helper.CreateTree(TreeType.CompleteTree);
            TreeNode expected = new TreeNode(1);

            expected.Left        = new TreeNode(3);
            expected.Left.Left   = new TreeNode(7);
            expected.Left.Right  = new TreeNode(6);
            expected.Right       = new TreeNode(2);
            expected.Right.Left  = new TreeNode(5);
            expected.Right.Right = new TreeNode(4);

            MirrorOfBinaryTree.Process(root);
            Assert.IsTrue(Helper.CompareBinaryTree(expected, root));

            root = Helper.CreateTree(TreeType.CompleteTree);
            MirrorOfBinaryTree.ProcessRecursively(root);
            Assert.IsTrue(Helper.CompareBinaryTree(expected, root));
        }