예제 #1
0
        public void InsertTopLevel_NonEmptyTree_ReturnsTrue()
        {
            var myOrganizationTree = new NaryTree <string>("Jimmy");
            var added = false;
            NaryTreeNode <string> foundNode = null;

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

            //add Kim to Jimmy(Root)
            added = myOrganizationTree.InsertTopLevel("Kim");
            Assert.IsTrue(added);

            //find the root
            foundNode = myOrganizationTree.Find("Jimmy");

            if (foundNode != null)
            {
                Assert.IsTrue(foundNode.Data == "Jimmy");

                //Added Kim to Jimmy's Children list
                Assert.IsTrue(foundNode.ChildrenList.Count == 1);
                Assert.IsTrue(foundNode.ChildrenList[0].Data == "Kim");
            }

            added = myOrganizationTree.InsertTopLevel("Kate");
            Assert.IsTrue(added);

            //find the root
            foundNode = myOrganizationTree.Find("Jimmy");

            if (foundNode != null)
            {
                Assert.IsTrue(foundNode.Data == "Jimmy");

                //Added Kim to Jimmy's Children list
                Assert.IsTrue(foundNode.ChildrenList.Count == 2);
                Assert.IsTrue(foundNode.ChildrenList[0].Data == "Kim");
                Assert.IsTrue(foundNode.ChildrenList[1].Data == "Kate");
            }


            added = myOrganizationTree.InsertTopLevel("Mikesh");
            //find the root
            foundNode = myOrganizationTree.Find("Jimmy");

            if (foundNode != null)
            {
                Assert.IsTrue(foundNode.Data == "Jimmy");

                //Added Kim to Jimmy's Children list
                Assert.IsTrue(foundNode.ChildrenList.Count == 3);
                Assert.IsTrue(foundNode.ChildrenList[0].Data == "Kim");
                Assert.IsTrue(foundNode.ChildrenList[1].Data == "Kate");
                Assert.IsTrue(foundNode.ChildrenList[2].Data == "Mikesh");
            }
        }
예제 #2
0
        public void InsertTopLevel_EmptyTree_ReturnsTrue()
        {
            var myIntegerTree = new NaryTree <int>();

            //test to see if the tree is empty
            var isEmpty = myIntegerTree.IsEmpty();

            Assert.IsTrue(isEmpty);

            var added = myIntegerTree.InsertTopLevel(9);

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

            var foundNode = myIntegerTree.Find(9);

            //should find 9 at root and should not be null
            Assert.IsNotNull(foundNode);

            if (foundNode != null)
            {
                //data should be 9 as the root
                Assert.IsTrue(foundNode.Data == 9);

                //children list should have no children
                Assert.IsTrue(foundNode.ChildrenList.Count == 0);
            }
        }
예제 #3
0
        public void Clear_NonEmptyTree_Tree_ShouldBe_Empty()
        {
            var myIntegerTree = new NaryTree <int>();

            //test to see if the tree is empty
            var isEmpty = myIntegerTree.IsEmpty();

            Assert.IsTrue(isEmpty);

            var added = myIntegerTree.InsertTopLevel(9);

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

            myIntegerTree.Clear();

            Assert.IsTrue(myIntegerTree.IsEmpty());
        }