Exemplo n.º 1
0
        public void Insert_NodeNotFound_ReturnsFalse()
        {
            var myEmployees = new NaryTree <string>("Kim");
            var added       = myEmployees.Insert("Mikesh", "Jimmy");

            //should be false
            Assert.IsFalse(added);
        }
Exemplo n.º 2
0
        public void Insert_NodeFound_ReturnsTrue()
        {
            var myOrganizationTree = new NaryTree <string>();
            var added = false;
            NaryTreeNode <string> foundNode = null;

            //root of the tree should be null
            Assert.IsTrue(myOrganizationTree.IsEmpty());

            //create a children list
            var Children = new List <NaryTreeNode <string> >()
            {
                new NaryTreeNode <string>("Kim"),
                new NaryTreeNode <string>("Kate"),
                new NaryTreeNode <string>("Mikesh")
            };

            //add root node Jimmy with children
            added = myOrganizationTree.InsertTopLevelWithChildren("Jimmy", Children);

            //should return true as it was added
            Assert.IsTrue(added);

            //Find Mikesh node it's children list should be 0 before inserting Timmy
            foundNode = myOrganizationTree.Find("Mikesh");

            Assert.IsNotNull(foundNode);

            if (foundNode != null)
            {
                Assert.IsTrue(foundNode.Data == "Mikesh");
                Assert.IsTrue(foundNode.ChildrenList.Count == 0);
            }

            //add Timmy to Mikesh's children list
            added = myOrganizationTree.Insert("Mikesh", "Timmy");

            Assert.IsTrue(added);

            //Find Mikesh node it's children list should be 1 after inserting Timmy
            foundNode = myOrganizationTree.Find("Mikesh");

            Assert.IsNotNull(foundNode);

            if (foundNode != null)
            {
                Assert.IsTrue(foundNode.Data == "Mikesh");
                Assert.IsTrue(foundNode.ChildrenList.Count == 1);
                Assert.IsTrue(foundNode.ChildrenList[0].Data == "Timmy");
            }
        }