public void getHeigh_EmptyTree_ReturnsZero() { // arrange var myTree = new binarySearchTree(); // act // assert }
public void deleteNodeTest_emptyTree_throwError() { //arrange var myBST = new binarySearchTree <int>(); //act myBST.deleteNode(1); //assert }
public void nodeExistsTest_Empty_ReturnFalse() { //arrange var myBST = new binarySearchTree <int>(); //act //assert Assert.AreEqual(false, myBST.nodeExists(1)); }
public void getHeightTest_EmptyTree_ReturnZero() { //arrange var myBST = new binarySearchTree <String>(); //act //assert Assert.AreEqual(0, myBST.getHeight()); }
public void deleteNodeTest_NodeThatDoesNotExist_throwError() { //arrange var myBST = new binarySearchTree <int>(); //act myBST.addNode(2); myBST.deleteNode(1); //assert }
public void addNodeTest_singleNode_returnNode() { //arrange var myBST = new binarySearchTree <int>(); //act int myTestInt = myBST.addNode(1).val; //assert Assert.AreEqual(1, myTestInt); }
public void addNodeTest_duplicateNode_throwError() { //arrange var myBST = new binarySearchTree <int>(); //act myBST.addNode(1); myBST.addNode(1); //assert }
public void getHeightTest_TwoNode_ReturnTwo() { //arrange var myBST = new binarySearchTree <int>(); //act myBST.addNode(1); myBST.addNode(2); //assert Assert.AreEqual(2, myBST.getHeight()); }
public void nodeExistsTest_AddNode_ReturnTrue() { //arrange var myBST = new binarySearchTree <int>(); //act myBST.addNode(1); myBST.addNode(3); myBST.addNode(2); myBST.addNode(4); //assert Assert.AreEqual(true, myBST.nodeExists(1)); }
public void deleteNodeTest_SingleInt_Returnint() { //arrange var myBST = new binarySearchTree <int>(); //act myBST.addNode(1); myBST.addNode(2); myBST.addNode(3); myBST.addNode(4); int testDeleteNoteVal = myBST.deleteNode(4); //assert Assert.AreEqual(4, testDeleteNoteVal); }
public void postOrder_Test_Returninorder() { //arrange var myBST = new binarySearchTree <int>(); //act myBST.addNode(4); myBST.addNode(2); myBST.addNode(6); myBST.addNode(1); myBST.addNode(3); myBST.addNode(5); myBST.addNode(7); int[] myArray = new int[] { 4, 2, 1, 3, 6, 5, 7 }; //assert Assert.AreEqual(myArray, myBST.postOrderTraversal()); }
public void breadthFirstSearch_Test_ReturnBreadthFirstStructure() { //arrange var myBST = new binarySearchTree <int>(); //act myBST.addNode(4); myBST.addNode(2); myBST.addNode(6); myBST.addNode(1); myBST.addNode(3); myBST.addNode(5); myBST.addNode(7); int[] myArray = new int[] { 4, 2, 6, 1, 3, 5, 7 }; //assert Assert.AreEqual(myArray, myBST.breadthFirstSearch()); }
static void Main() { binarySearchTree binaryTree = new binarySearchTree(5); binaryTree.Add(4); binaryTree.Add(24); binaryTree.Add(72); binaryTree.Add(12); binaryTree.Add(-4); binaryTree.Add(8); binaryTree.Add(5); binaryTree.Add(7); binaryTree.Add(10); binaryTree.Add(24); System.Console.WriteLine("In Order Traversal"); Console.WriteLine(binaryTree.traverseInOrder()); Debug.Assert(binaryTree.traverseInOrder() == "-4 4 5 5 7 8 10 12 24 24 72 "); System.Console.WriteLine(); System.Console.WriteLine("Pre Order Traversal"); Console.WriteLine(binaryTree.traversePreOrder()); Debug.Assert(binaryTree.traversePreOrder() == "5 4 -4 5 24 12 8 7 10 24 72 "); System.Console.WriteLine(); System.Console.WriteLine("Post Order Traversal"); Console.WriteLine(binaryTree.traversePostOrder()); Debug.Assert(binaryTree.traversePostOrder() == "-4 5 4 7 10 8 24 12 72 24 5 "); System.Console.WriteLine(); System.Console.WriteLine("binaryTree contains value 7: "); Debug.Assert(binaryTree.Contains(7) == true); System.Console.WriteLine(); System.Console.WriteLine("binaryTree contains value 30: "); Debug.Assert(binaryTree.Contains(30) == false); System.Console.WriteLine(); ExpressionParser expressionParser = new ExpressionParser(); ExpressionTree expressionTree = new ExpressionTree(expressionParser.BuildTree("5 + 2 * 8 - 6 / 4")); System.Console.WriteLine("Expression Parser In Order Traversal"); Console.WriteLine(expressionTree.traverseInOrder()); Debug.Assert(expressionTree.traverseInOrder() == "5 + 2 * 8 - 6 / 4 "); System.Console.WriteLine(); System.Console.WriteLine("Expression Parser Pre Order Traversal"); Console.WriteLine(expressionTree.traversePreOrder()); Debug.Assert(expressionTree.traversePreOrder() == "- + 5 * 2 8 / 6 4 "); System.Console.WriteLine(); System.Console.WriteLine("Expression Parser Post Order Traversal"); Console.WriteLine(expressionTree.traversePostOrder()); Debug.Assert(expressionTree.traversePostOrder() == "5 2 8 * + 6 4 / - "); System.Console.WriteLine(); Console.WriteLine("Expression Tree Evaluated"); Console.WriteLine(expressionTree.EvaluateRecursive()); Debug.Assert(expressionTree.EvaluateRecursive() == (5 + 2 * 8 - 6 / 4)); Console.WriteLine(); /// binaryTree /// 5 /// / \ /// / \ /// 4 24 /// / \ / \ /// -4 5 12 72 /// / \ /// 8 20 /// / \ /// 7 10 }
public void binarySearchTree_GetHieght_EmptyTree_ReturnsZero() { binarySearchTree <String> mytree = new binarySearchTree <String>(); }