public void TestMethodInvertTree()
        {
            var tree = new TreeNode(10);

            tree.left       = new TreeNode(8);
            tree.right      = new TreeNode(12);
            tree.left.left  = new TreeNode(7);
            tree.left.right = new TreeNode(9);

            tree = InvertBinaryTreeSolution.InvertTree(tree);

            Assert.AreEqual(10, tree.val);
            Assert.AreEqual(8, tree.right.val);
            Assert.AreEqual(12, tree.left.val);
            Assert.AreEqual(7, tree.right.right.val);
            Assert.AreEqual(9, tree.right.left.val);
        }
Ejemplo n.º 2
0
        public void InvertTree_Test()
        {
            //Arrange
            TreeNode inputTreeNode = new TreeNode();

            inputTreeNode.val  = 4;
            inputTreeNode.left = new TreeNode
            {
                val  = 2,
                left = new TreeNode
                {
                    val = 1
                },
                right = new TreeNode
                {
                    val = 3
                }
            };
            inputTreeNode.right = new TreeNode
            {
                val  = 7,
                left = new TreeNode
                {
                    val = 6
                },
                right = new TreeNode
                {
                    val = 9
                }
            };

            TreeNode outputTreeNode = new TreeNode();

            outputTreeNode.val   = 4;
            outputTreeNode.right = new TreeNode
            {
                val   = 2,
                right = new TreeNode
                {
                    val = 1
                },
                left = new TreeNode
                {
                    val = 3
                }
            };
            outputTreeNode.left = new TreeNode
            {
                val   = 7,
                right = new TreeNode
                {
                    val = 6
                },
                left = new TreeNode
                {
                    val = 9
                }
            };
            //Act
            InvertBinaryTreeSolution solution = new InvertBinaryTreeSolution();
            var invertedTree = solution.InvertTree(inputTreeNode);

            //Assert

            invertedTree.Should().BeEquivalentTo(outputTreeNode);
        }