public void Remove_EmptyTree_ReturnsTrue() { var myTree = new NaryTree <int>(); //tree should be empty Assert.IsTrue(myTree.IsEmpty()); var removed = myTree.Remove(10); Assert.IsTrue(removed); // tree should still be empty Assert.IsTrue(myTree.IsEmpty()); }
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); } }
public void Find_ItemFound_ReturnsFoundItem() { 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); } }
public void NaryTree_DefaultConstructorTest() { var myNumberTree = new NaryTree <int>(); //is empty should return true as root is null Assert.IsTrue(myNumberTree.IsEmpty()); }
public void IsEmpty_ReturnsFalse() { var myEmployeeList = new NaryTree <string>("Jimmy"); var isEmpty = myEmployeeList.IsEmpty(); //should be false Assert.IsFalse(isEmpty); }
public void IsEmpty_ReturnsTrue() { var myEmployeeList = new NaryTree <string>(); var isEmpty = myEmployeeList.IsEmpty(); //should be true Assert.IsTrue(isEmpty); }
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"); } }
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()); }
public void Remove_Root_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 Root Jimmy foundNode = myOrganizationTree.Find("Jimmy"); Assert.IsNotNull(foundNode); if (foundNode != null) { Assert.IsTrue(foundNode.Data == "Jimmy"); 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"); } //Remove the root myOrganizationTree.Remove("Jimmy"); //root of the tree should be null after removing root Assert.IsTrue(myOrganizationTree.IsEmpty()); }
public void Find_EmptyTree_ReturnsNull() { var myStringTree = new NaryTree <String>(); //The tree should be empty Assert.IsTrue(myStringTree.IsEmpty()); var found = myStringTree.Find("Test"); //Should return null Assert.IsNull(found); }
public void Remove_ItemNotRoot_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 some children to Kate Children[1].ChildrenList.Add(new NaryTreeNode <string>("Jack")); Children[1].ChildrenList.Add(new NaryTreeNode <string>("Peter")); Children[1].ChildrenList[1].ChildrenList.Add(new NaryTreeNode <string>("Mike")); //add root node Jimmy with children added = myOrganizationTree.InsertTopLevelWithChildren("Jimmy", Children); //should return true as it was added Assert.IsTrue(added); //Find Kate foundNode = myOrganizationTree.Find("Kate"); Assert.IsNotNull(foundNode); if (foundNode != null) { Assert.IsTrue(foundNode.Data == "Kate"); Assert.IsTrue(foundNode.ChildrenList.Count == 2); Assert.IsTrue(foundNode.ChildrenList[0].Data == "Jack"); Assert.IsTrue(foundNode.ChildrenList[1].Data == "Peter"); } //Remove Kate var removed = myOrganizationTree.Remove("Kate"); Assert.IsTrue(removed); foundNode = myOrganizationTree.Find("Kate"); //Kate should not be found Assert.IsNull(foundNode); }
public void InsertTopLevelWithChildren_NonEmptyTree_ReturnsTrue() { var myOrganizationTree = new NaryTree <string>("Jimmy"); var added = false; NaryTreeNode <string> foundNode = null; //root of the tree should be not null Assert.IsFalse(myOrganizationTree.IsEmpty()); //find the root which is Jimmy and should have no children foundNode = myOrganizationTree.Find("Jimmy"); Assert.IsNotNull(foundNode); if (foundNode != null) { Assert.IsTrue(foundNode.Data == "Jimmy"); Assert.IsTrue(foundNode.ChildrenList.Count == 0); } //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("Timmy", Children); //should return true as it was added Assert.IsTrue(added); foundNode = myOrganizationTree.Find("Timmy"); //should find it Assert.IsNotNull(foundNode); if (foundNode != null) { Assert.IsTrue(foundNode.Data == "Timmy"); 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"); } }