Beispiel #1
0
        public void TestTestTreeIfCanBeConnected()
        {
            //K
            //|
            //A     B
            //|\     \
            //C D     E
            // / \   / \
            // F  G  H  I
            //     \/
            //     J
            SortedTree <ClassAsTreeValue <string> > tree = new SortedTree <ClassAsTreeValue <string> >();

            AddNodeWholeTreeTestHelper(ref tree);
            SortedTree <ClassAsTreeValue <string> > tree2 = tree.GetSubtreeFromNode(B);

            tree2.RemoveValue(J, false);
            bool result;

            result = tree.TestTreeIfCanBeConnected(J, 0, tree2, 0);
            Assert.AreEqual(false, result, "This trees cannot be connected");
            tree.RemoveValue(B, false);
            result = tree.TestTreeIfCanBeConnected(J, 0, tree2, 0);
            Assert.AreEqual(true, result, "This trees can be connected");
        }
Beispiel #2
0
        public void TestConnectTheTreeToTheNode()
        {
            //K
            //|
            //A     B
            //|\     \
            //C D     E
            // / \   / \
            // F  G  H  I
            //     \/
            //     J
            SortedTree <ClassAsTreeValue <string> > tree = new SortedTree <ClassAsTreeValue <string> >();

            AddNodeWholeTreeTestHelper(ref tree);
            SortedTree <ClassAsTreeValue <string> > tree2 = tree.GetSubtreeFromNode(B);

            //tree2:
            //   B
            //   |
            //   E
            //  / \
            // H  I
            // |
            // J
            AreEqualGetFroeachRepresentationHelper("JHIEB", tree2, "prep step1");
            tree2.RemoveValue(J, false);
            AreEqualGetFroeachRepresentationHelper("HIEB", tree2, "prep step2");
            tree.RemoveValue(B, false);
            AreEqualGetFroeachRepresentationHelper("CFJGDAK", tree, "prep step3");

            //main test
            //K
            //|
            //A
            //|\ 
            //C D
            // / \ 
            // F  G
            //     \
            //     J
            //    /
            //   B
            //   |
            //   E
            //  / \
            // H  I
            tree.ConnectTheTreeToTheNode(J, 0, tree2, 0);
            AreEqualGetFroeachRepresentationHelper("CFHIEBJGDAK", tree, "main test");
        }
Beispiel #3
0
        public void TestGetSubtree()
        {
            //K
            //|
            //A     B
            //|\     \
            //C D     E
            // / \   / \
            // F  G  H  I
            //     \/
            //     J
            SortedTree <ClassAsTreeValue <string> > tree = new SortedTree <ClassAsTreeValue <string> >();
            SortedTree <ClassAsTreeValue <string> > tree2;

            AddNodeWholeTreeTestHelper(ref tree);

            string expected;
            string actual;

            tree2 = tree.GetSubtreeFromNode(A);

            //
            //
            //A
            //|\ 
            //C D
            // / \ 
            // F  G
            //     \/
            //     J
            expected = "CFJGDA";
            actual   = GetForeachRepresentation(tree2);
            Assert.AreEqual(expected, actual, "Problem with foreach statement: tree are not the same");

            tree2 = tree.GetSubtreeFromNode(D);
            //  D
            // / \ 
            // F  G
            //     \
            //     J
            expected = "FJGD";
            actual   = GetForeachRepresentation(tree2);
            Assert.AreEqual(expected, actual, "Problem with foreach statement: tree are not the same");

            tree2 = tree2.GetSubtreeFromNode(D);
            //  D
            // / \ 
            // F  G
            //     \
            //     J
            expected = "FJGD";
            actual   = GetForeachRepresentation(tree2);
            Assert.AreEqual(expected, actual, "Problem with foreach statement: tree are not the same");


            tree2    = tree2.GetSubtreeFromNode(F);
            expected = "F";
            actual   = GetForeachRepresentation(tree2);
            Assert.AreEqual(expected, actual, "Problem with foreach statement: tree are not the same");

            tree2 = tree.GetSubtreeFromNode(G);
            //  D
            // / \ 
            // F  G
            //     \
            //     J
            expected = "JG";
            actual   = GetForeachRepresentation(tree2);
            Assert.AreEqual(expected, actual, "Problem with foreach statement: tree are not the same");
        }