Exemple #1
0
        public void AreSameTreesTests(object[] tree1Nodes, object[] tree2Nodes, bool expectedAreSameTrees)
        {
            // arrange
            var root1 = TreeNode.Build(tree1Nodes);
            var root2 = TreeNode.Build(tree2Nodes);

            // act
            bool areSame = SameTree.IsSameTree(root1, root2);

            // assert
            Assert.AreEqual(expectedAreSameTrees, areSame, $"Tree1: { root1 } and Tree2: {root2} failed when compared");
        }
Exemple #2
0
        public void SameTreeTestMethod()
        {
            SameTree sameTree = new SameTree();
            TreeNode root     = new TreeNode(1)
            {
                left  = new TreeNode(2),
                right = new TreeNode(3)
            };


            TreeNode root1 = new TreeNode(1)
            {
                left  = new TreeNode(2),
                right = new TreeNode(3)
            };

            Assert.AreEqual(true, sameTree.IsSameTree(root, root1));
        }
        public void SameTree()
        {
            TreeNode tree = new TreeNode(1);

            tree.left  = new TreeNode(2);
            tree.right = new TreeNode(3);
            // tree.left.left = new TreeNode(4);
            // tree.left.right = new TreeNode(5);

            TreeNode tree2 = new TreeNode(1);

            tree2.left  = new TreeNode(2);
            tree2.right = new TreeNode(3);
            //tree2.left.left = new TreeNode(4);
            // tree2.left.right = new TreeNode(5);

            SameTree SameTree = new SameTree();
            var      answer   = SameTree.IsSameTree(tree, tree2);
        }