Пример #1
0
        public void TestTreeAddChild()
        {
            // Arrange
            var NAryTreeInt = new Tree <int>();
            var NAryTreeStr = new Tree <string>();
            // Act
            var root_int   = NAryTreeInt.AddChildNode(null, 1);
            var child1_int = NAryTreeInt.AddChildNode(root_int, 2);
            var root_str   = NAryTreeStr.AddChildNode(null, "A");
            var child1_str = NAryTreeStr.AddChildNode(root_str, "B");

            // Assert
            Assert.Multiple(() =>
            {
                // Check Count
                Assert.That(NAryTreeInt.Count == 2);
                Assert.That(NAryTreeStr.Count == 2);

                // Check CountLeaf
                Assert.That(NAryTreeInt.LeafCount == 1);
                Assert.That(NAryTreeStr.LeafCount == 1);

                // Check if it is added
                Assert.Contains(child1_int, NAryTreeInt.TheTree);

                // If root has a child
                Assert.Contains(child1_int, root_int.Child);
            });
        }
Пример #2
0
        public void AddChildNodeString()
        {
            // Arrange
            string        InitialValue = "Uien";
            Tree <string> tree         = new Tree <string>(InitialValue);

            // Act
            TreeNode <string> Child1     = tree.AddChildNode("hebben", tree.TopParent);
            TreeNode <string> Child2     = tree.AddChildNode("laagjes", tree.TopParent);
            TreeNode <string> Child1_1   = tree.AddChildNode("Knoflook", Child1);
            TreeNode <string> Child1_1_1 = tree.AddChildNode("stinkt", Child1_1);

            // Assert
            Assert.Multiple(() =>
            {
                Assert.AreEqual("hebben", tree.TopParent.Children[0].Value);
                Assert.AreEqual("laagjes", tree.TopParent.Children[1].Value);
                Assert.AreEqual("Knoflook", tree.TopParent.Children[0].Children[0].Value);
                Assert.AreEqual("stinkt", tree.TopParent.Children[0].Children[0].Children[0].Value);

                Assert.That(tree.Count == 5);
                Assert.That(tree.LeafCount == 2);
                Assert.AreEqual(Child1_1.Parent, Child1);
                Assert.IsNull(tree.TopParent.Parent);
            });
        }
Пример #3
0
        public void TestTreeSumOfLeaves()
        {
            //Arrange
            Tree <int>    TreeInt = new Tree <int>();
            Tree <string> TreeStr = new Tree <string>();

            //Act
            //int
            var root     = TreeInt.AddChildNode(null, 1);
            var child1   = TreeInt.AddChildNode(root, 2);
            var child2   = TreeInt.AddChildNode(root, 3);
            var child11  = TreeInt.AddChildNode(child1, 4);
            var sumleafs = TreeInt.SumToLeafs();
            //str
            var rootstr     = TreeStr.AddChildNode(null, "A");
            var child1str   = TreeStr.AddChildNode(rootstr, "B");
            var child2str   = TreeStr.AddChildNode(rootstr, "C");
            var child11str  = TreeStr.AddChildNode(child1str, "D");
            var sumleafsstr = TreeStr.SumToLeafs();

            //Assert

            Assert.Multiple(() =>
            {
                // controle of sumofleaves goed worden opgeteld
                Assert.That(sumleafs[1] == 7);
                Assert.That(sumleafsstr[0] == "CA");
            });
        }
Пример #4
0
        public void AddChildNodeIntegers()
        {
            // Arrange
            int        InitialValue = 4;
            Tree <int> tree         = new Tree <int>(InitialValue);

            // Act
            TreeNode <int> Child1     = tree.AddChildNode(3, tree.TopParent);
            TreeNode <int> Child2     = tree.AddChildNode(4, tree.TopParent);
            TreeNode <int> Child1_1   = tree.AddChildNode(8, Child1);
            TreeNode <int> Child1_1_1 = tree.AddChildNode(9, Child1_1);

            // Assert
            Assert.Multiple(() =>
            {
                Assert.AreEqual(3, tree.TopParent.Children[0].Value);
                Assert.AreEqual(4, tree.TopParent.Children[1].Value);
                Assert.AreEqual(8, tree.TopParent.Children[0].Children[0].Value);
                Assert.AreEqual(9, tree.TopParent.Children[0].Children[0].Children[0].Value);

                Assert.That(tree.Count == 5);
                Assert.That(tree.LeafCount == 2);
                Assert.AreEqual(Child1_1.Parent, Child1);
                Assert.IsNull(tree.TopParent.Parent);
            });
        }
Пример #5
0
        public void TestTree_AddChildNode()
        {
            // Arrange
            Tree <string> Tree = new Tree <string>();

            // Act
            var Root  = Tree.AddChildNode(null, "Root");
            var Node1 = Tree.AddChildNode(Root, "Node1");

            // Assert
            Assert.True(Root.Value == "Root" && Root.Children[0] == Node1);
        }
Пример #6
0
            public void Test_Tree_Remove()
            {
                //Arrange
                Tree <int> tree = new Tree <int>(2);

                //Act
                tree.AddChildNode(tree.ParentNode, 1);
                tree.AddChildNode(tree.ParentNode, 2);
                tree.RemoveNode(tree.children[1]);
                //Assert
                Assert.Contains(1, new System.Collections.Generic.List <int>(tree));
            }
Пример #7
0
        public void Testing_SumToLeaf()
        {
            // arrange
            Tree <double> boom = new Tree <double>();

            // act
            TreeNode <double> root        = boom.AddChildNode(2.0, null);
            TreeNode <double> Hanneke     = boom.AddChildNode(3.3, root);
            List <double>     somnaarleaf = boom.SumtoLeafs;

            // Assert
            Assert.That(somnaarleaf[0] == 5.3);
        }
Пример #8
0
        public void TestN_ARY_Remove()
        {
            //Test if the removal of parents and children is done right
            Tree <string> beginningTree = new Tree <string>("Chaos");


            beginningTree.AddChildNode(beginningTree.headOfTreeNode, "Erebus");
            beginningTree.AddChildNode(beginningTree.headOfTreeNode, "Nyx");

            TreeNode <string> Parent1 = beginningTree.headOfTreeNode.Child[1];

            beginningTree.AddChildNode(Parent1, "Hemera");
            beginningTree.AddChildNode(Parent1, "Aether");
            beginningTree.AddChildNode(Parent1, "Gaia");
            beginningTree.AddChildNode(Parent1, "Tartar");

            TreeNode <string> Parent2 = Parent1.Child[2];

            beginningTree.AddChildNode(Parent2, "Pontus");
            beginningTree.AddChildNode(Parent2, "Ouranos");

            beginningTree.RemoveNode(Parent2);

            Assert.Multiple(() =>
            {
                Assert.That(beginningTree.treeTotal.Count == 6);
                Assert.AreEqual(Parent1, beginningTree.headOfTreeNode.Child[1]);
                Assert.Contains(Parent1, beginningTree.treeTotal);
            });
        }
Пример #9
0
        public void Test_TreeConstructorSumLeafs()
        {
            //arange
            var tree   = new Tree <int>();
            var root   = tree.AddChildNode(null, 1);
            var child1 = tree.AddChildNode(root, 2);
            var child2 = tree.AddChildNode(child1, 3);

            //act
            List <int> sum = tree.SumToLeafs();

            //assert
            Assert.AreEqual(6, sum[0]);  //Check if sum of first leave is 6
        }
Пример #10
0
        public void Test_TreeConstructorDeleteNode()
        {
            //arrange
            var tree   = new Tree <int>();
            var root   = tree.AddChildNode(null, 1);
            var child1 = tree.AddChildNode(root, 2);
            var child2 = tree.AddChildNode(child1, 3);

            //act
            tree.removeNode(child1); // Remove child1

            //Assert
            Assert.Contains(child2, tree.TheTree); //Check if child2 is in the tree
        }
Пример #11
0
        public void Testing_LeafCount()
        {
            // arrange
            Tree <int> boom = new Tree <int>();

            //act
            TreeNode <int> root    = boom.AddChildNode(2, null);
            TreeNode <int> Hanneke = boom.AddChildNode(4, root);
            TreeNode <int> Marieke = boom.AddChildNode(5, root);
            int            leafs   = boom.LeafCount;

            // Assert
            Assert.That(leafs == 2);
        }
Пример #12
0
        public void Testing_Count()
        {
            // arrange
            Tree <int> boom = new Tree <int>();

            //act
            TreeNode <int> root    = boom.AddChildNode(2, null);
            TreeNode <int> Hanneke = boom.AddChildNode(4, root);
            TreeNode <int> Marieke = boom.AddChildNode(5, root);
            int            aantal  = boom.Count;

            // Assert
            Assert.That(aantal == 3);
        }
Пример #13
0
 public void Test_SumToLeafs()
 {
     // Arrange
     var TreeInt = new Tree<int>();
     var root = new TreeNode<int>(0, null, new List<TreeNode<int>>());
     var gen1c1 = TreeInt.AddChildNode(root, 10);
     var gen2p1 = TreeInt.NextGen(gen1c1);
     var gen2c1 = TreeInt.AddChildNode(gen2p1, 9);
     var gen2c2 = TreeInt.AddChildNode(gen2p1, 8);
     // Act
     var sum = TreeInt.SumToLeafs();
     // Assert
     Assert.That(sum[0] == 19);
     Assert.That(sum[1] == 18);
 }
Пример #14
0
        public void Test_Tree_TraverseNodes()
        {
            // Arrange
            var NAryTree = new Tree <int>();
            var root     = new TreeNode <int>(3, null, new List <TreeNode <int> >());
            var child1   = NAryTree.AddChildNode(root, 3);
            var child2   = NAryTree.AddChildNode(child1, 2);
            // Act
            List <int> traversed = NAryTree.TraverseNodes();

            // Assert
            int[] validation = { 2, 3 };
            Assert.That(traversed, Is.EquivalentTo(validation));
            // weet niet goed wat ik nog meer moet testen
        }
Пример #15
0
        public void TraverseNodesTest()
        {
            // Arrange
            int            InitialValue = 1;
            Tree <int>     tree         = new Tree <int>(InitialValue);
            TreeNode <int> Child1       = tree.AddChildNode(2, tree.TopParent);
            TreeNode <int> Child2       = tree.AddChildNode(3, tree.TopParent);
            TreeNode <int> Child1_1     = tree.AddChildNode(4, Child1);

            // Act
            string TraverseTree = tree.TraverseNodes();

            // Assert
            Assert.AreEqual("1[ 2,[ 4,] 3,]", TraverseTree);
        }
Пример #16
0
        public void TestTreeRemoveNode()
        {
            // Arrange
            Tree <int> Tree  = new Tree <int>();
            var        Root  = Tree.AddChildNode(null, 4);
            var        Node1 = Tree.AddChildNode(Root, 2);
            var        Node2 = Tree.AddChildNode(Root, 24);
            var        Node3 = Tree.AddChildNode(Node2, 8);
            var        Node4 = Tree.AddChildNode(Node2, 6);

            // Act
            Tree.RemoveNode(Node2);

            // Assert
            Assert.True(Root.Children.Count == 1);
        }
Пример #17
0
        public void Testing_AddChildNode()
        {
            // arrange
            Tree <int> boom = new Tree <int>();

            //act
            TreeNode <int> root    = boom.AddChildNode(2, null);
            TreeNode <int> Hanneke = boom.AddChildNode(4, root);

            // Assert
            Assert.Multiple(() =>
            {
                Assert.That(Hanneke.parent.Value == 2);
                Assert.Contains(Hanneke, boom.Root.children);
            });
        }
Пример #18
0
            public void Test_Tree_SumLeafs()
            {
                //Arrange
                Tree <int> tree_test = new Tree <int>(2);

                tree_test.AddChildNode(tree_test.ParentNode, 3);
                tree_test.AddChildNode(tree_test.ParentNode, 4);
                tree_test.AddChildNode(tree_test.ParentNode, 5);

                //Act
                List <int> Som = tree_test.SumToLeafs();

                //Assert
                int[] antwoord = { 5, 6, 7 };
                Assert.That(antwoord, Is.EquivalentTo(Som));
            }
Пример #19
0
        public void Test_TreeConstructorAddChild()
        {
            //arrange
            var tree = new Tree <int>();

            //act
            var root   = tree.AddChildNode(null, 1);
            var child1 = tree.AddChildNode(root, 2);

            //Assert
            Assert.Multiple(() =>
            {
                Assert.That(child1.Parent.Value == 1); //Check if parent of child1 has value 1
                Assert.Contains(child1, tree.TheTree); //Check if child1 is in the tree
            });
        }
Пример #20
0
 public void Test_Traversenodes()
 {
     // Arrange
     var TreeInt = new Tree<string>();
     var root = new TreeNode<string>(null, null, new List<TreeNode<string>>());
     var gen1c1 = TreeInt.AddChildNode(root, "Keeper");
     var gen2p1 = TreeInt.NextGen(gen1c1);
     var gen2c1 = TreeInt.AddChildNode(gen2p1, "Linker Centrale Verdediger");
     var gen2c2 = TreeInt.AddChildNode(gen2p1, "Rechter Centrale Verdediger");
     var gen3p1 = TreeInt.NextGen(gen2c1);
     var gen3c1 = TreeInt.AddChildNode(gen3p1, "Linksback");
     // Act
     var traverseNodes = TreeInt.TraverseNodes();
     // Assert
     Assert.AreEqual(traverseNodes.Count, TreeInt.TotalChildren.Count);
 }
Пример #21
0
        public void Test_removeNode()
        {
            // Arrange
            var TreeInt = new Tree<string>();
            var root = new TreeNode<string>(null, null, new List<TreeNode<string>>());

            var gen1c1 = TreeInt.AddChildNode(root, "Keeper");
            var gen2p1 = TreeInt.NextGen(gen1c1);
            var gen2c1 = TreeInt.AddChildNode(gen2p1, "Linker Centrale Verdediger");
            var gen2c2 = TreeInt.AddChildNode(gen2p1, "Rechter Centrale Verdediger");
            var gen3p1 = TreeInt.NextGen(gen2c1);
            var gen3c1 = TreeInt.AddChildNode(gen3p1, "Linksback");
            // Act
            TreeInt.removeNode(gen2c1);
            // Assert
            Assert.That(TreeInt.TotalChildren.Count == 2);
        }
Пример #22
0
            public void Test_Tree_Traverse()
            {
                //Arrange
                Tree <int>     tree_test = new Tree <int>(2);
                TreeNode <int> Parent;

                tree_test.AddChildNode(tree_test.ParentNode, 3);
                tree_test.AddChildNode(tree_test.ParentNode, 4);
                tree_test.AddChildNode(tree_test.ParentNode, 5);
                Parent = tree_test.ParentNode.Children[0];
                tree_test.AddChildNode(Parent, 9);
                tree_test.AddChildNode(tree_test.ParentNode, 6);
                //Act
                tree_test.TraverseNodes();
                //Assert
                Assert.IsNotEmpty(tree_test);
            }
Пример #23
0
        public void Testing_TraverseNodes()
        {
            // arrange
            Tree <string> boom = new Tree <string>();

            // act
            TreeNode <string> root    = boom.AddChildNode("Oma", null);
            TreeNode <string> Hanneke = boom.AddChildNode("Hanneke", root);
            TreeNode <string> Marieke = boom.AddChildNode("Marieke", root);
            List <string>     waardes = boom.TraverseNodes;

            var checklist = new List <string> {
                "Oma", "Hanneke", "Marieke"
            };

            // Assert
            Assert.That(waardes.SequenceEqual(checklist));
        }
Пример #24
0
        static void Main(string[] args)
        {
            Tree <int> TreeInt = new Tree <int>();
            var        root    = new TreeNode <int>(0, null, new List <TreeNode <int> >());

            var gen1c1 = TreeInt.AddChildNode(root, 10);

            var gen2p  = TreeInt.NextGen(gen1c1);
            var gen2c1 = TreeInt.AddChildNode(gen2p, 9);
            var gen2c2 = TreeInt.AddChildNode(gen2p, 6);

            var gen3p  = TreeInt.NextGen(gen2c1);
            var gen3c1 = TreeInt.AddChildNode(gen3p, 7);

            var gen3p2 = TreeInt.NextGen(gen2c2);
            var gen3c2 = TreeInt.AddChildNode(gen3p2, 7);


            var sum1 = TreeInt.SumToLeafs();

            foreach (var sum in sum1)
            {
                Console.WriteLine(sum);
            }
            Console.ReadLine();

            TreeInt.removeNode(gen2c2);

            var traversed = TreeInt.TraverseNodes();

            foreach (var integer in traversed)
            {
                Console.WriteLine(integer);
            }
            Console.ReadLine();

            var sum2 = TreeInt.SumToLeafs();

            foreach (var sum in sum2)
            {
                Console.WriteLine(sum);
            }
            Console.ReadLine();
        }
Пример #25
0
        public void TestTreeRemoveNode()
        {
            //Arrange
            Tree <int>    TreeInt = new Tree <int>();
            Tree <string> TreeStr = new Tree <string>();

            //Act
            //int
            var root    = TreeInt.AddChildNode(null, 1);
            var child1  = TreeInt.AddChildNode(root, 2);
            var child2  = TreeInt.AddChildNode(root, 3);
            var child11 = TreeInt.AddChildNode(child1, 4);

            TreeInt.removeNode(child1);
            //str
            var rootstr    = TreeStr.AddChildNode(null, "A");
            var child1str  = TreeStr.AddChildNode(rootstr, "B");
            var child2str  = TreeStr.AddChildNode(rootstr, "C");
            var child11str = TreeStr.AddChildNode(child1str, "D");

            TreeStr.removeNode(child1str);
            //Assert

            Assert.Multiple(() =>
            {
                // controle lengte
                Assert.That(TreeInt.count == 2);
                Assert.That(TreeStr.count == 2);
                // check aantal leafs
                Assert.That(TreeInt.leafcount == 1);
                Assert.That(TreeStr.leafcount == 1);
                // controle of alle kinderen zijn verwijderd
                for (int i = 0; i < TreeInt.count; i++)
                {
                    Assert.AreNotSame(child11, TreeStr.TheTree[i]);
                    Assert.AreNotSame(child1, TreeInt.TheTree[i]);
                }
                for (int i = 0; i < TreeStr.count; i++)
                {
                    Assert.AreNotSame(child11, TreeStr.TheTree[i]);
                    Assert.AreNotSame(child1str, TreeStr.TheTree[i]);
                }
            });
        }
Пример #26
0
        public void Test_Tree_SumToLeafs_int()
        {
            // Arrange
            var NAryTree = new Tree <int>();
            var root     = new TreeNode <int>(3, null, new List <TreeNode <int> >());
            var child1   = NAryTree.AddChildNode(root, 3);
            var child2   = NAryTree.AddChildNode(child1, 2);
            var child3   = NAryTree.AddChildNode(child1, 1);
            // Act
            var sum = NAryTree.SumToLeafs();

            // Assert
            Assert.Multiple(() =>
            {
                Assert.AreEqual(sum.Count, NAryTree.LeafCount);
                Assert.Contains(4, sum);
                Assert.Contains(5, sum);
            });
        }
Пример #27
0
        public void TraverseNodesTest()
        {
            // Arrange
            Tree <string>     Groot     = new Tree <string>("I ");
            TreeNode <string> Gchild1_1 = Groot.AddChildNode("suck.");
            TreeNode <string> Gchild1_2 = Groot.AddChildNode("am ");
            TreeNode <string> Gchild2_1 = Groot.AddChildNode("Groot", Gchild1_2);
            TreeNode <string> Gchild3_1 = Groot.AddChildNode("!!!", Gchild2_1);

            // Act
            List <TreeNode <string> > NodeList = Groot.TraverseNodes();

            // Assert
            Assert.Multiple(() =>
            {
                Assert.AreEqual(NodeList.Count, Groot.NrNodes);
                Assert.That(NodeList.Contains(Gchild1_2));
            });
        }
Пример #28
0
        public void TestTreeTraverseNode()
        {
            // Arrange
            var NAryTreeInt = new Tree <int>();
            var NAryTreeStr = new Tree <string>();
            // Act
            var        root_int   = NAryTreeInt.AddChildNode(null, 1);
            var        child1_int = NAryTreeInt.AddChildNode(root_int, 2);
            var        child2_int = NAryTreeInt.AddChildNode(root_int, 3);
            var        child3_int = NAryTreeInt.AddChildNode(child1_int, 4);
            List <int> real       = NAryTreeInt.TraverseNodes();

            // Assert
            // Check if values correspond with input
            for (int i = 0; i < 4; i++)
            {
                Assert.That(i + 1 == real[i]);
            }
        }
Пример #29
0
        public void Test_Tree_SumToLeafs_string()
        {
            // Arrange
            var NAryTree = new Tree <string>();
            var root     = new TreeNode <string>("Oma", null, new List <TreeNode <string> >());
            var child1   = NAryTree.AddChildNode(root, "Mama");
            var child2   = NAryTree.AddChildNode(child1, "Ik");
            var child3   = NAryTree.AddChildNode(child1, "Zus");
            // Act
            var sum = NAryTree.SumToLeafs();

            // Assert
            Assert.Multiple(() =>
            {
                Assert.AreEqual(sum.Count, NAryTree.LeafCount);
                Assert.Contains("IkMama", sum);
                Assert.Contains("ZusMama", sum);
            });
        }
Пример #30
0
        public void SumToLeafsTestIntegers()
        {
            // Arrange
            int            InitialValue = 1;
            Tree <int>     tree         = new Tree <int>(InitialValue);
            TreeNode <int> Child1       = new TreeNode <int>(2, tree.TopParent);
            TreeNode <int> Child2       = tree.AddChildNode(3, tree.TopParent);
            TreeNode <int> Child1_1     = tree.AddChildNode(4, Child1);

            // Act
            List <int> SumLeafs = tree.SumToLeafs();

            // Assert
            Assert.Multiple(() =>
            {
                Assert.Contains(4, SumLeafs);
                Assert.Contains(7, SumLeafs);
            });
        }