public void Test_Queue(string strArr, int expected) { var root = TreeNodeHelper.BuildTree(strArr); var sol = new Solution(); var res = sol.MaxDepth(root); Assert.AreEqual(res, expected); }
public void Test_Recursive(string treeStr, int low, int high, int expected) { var head = TreeNodeHelper.BuildTree(treeStr); var sol = new Solution_Recursive(); var res = sol.RangeSumBST(head, low, high); Assert.AreEqual(res, expected); }
public void Test_Generic(string strArr, string expected) { var root = TreeNodeHelper.BuildTree(strArr); var sol = new Solution(); var res = sol.SubtreeWithAllDeepest(root); var expectedTree = TreeNodeHelper.BuildTree(expected); Assert.IsTrue(TreeNodeHelper.CompareTreeNode(res, expectedTree)); }
public void Test_Generic(string treeStr, string expectedStr) { var root = TreeNodeHelper.BuildTree(treeStr); var expected = ArrayHelper.ArrayFromString <int>(expectedStr); var sol = new Solution(); var ret = sol.RightSideView(root); CollectionAssert.AreEqual(ret, expected); }
public void Test_Generic(string treeStr, int val, string expectedStr) { var root = TreeNodeHelper.BuildTree(treeStr); var expected = TreeNodeHelper.BuildTree(expectedStr); var sol = new Solution(); var res = sol.SearchBST(root, val); Assert.IsTrue(TreeNodeHelper.CompareTreeNode(res, expected)); }
public void Test_Generic(string treeStr, string expectedStr) { var tree = TreeNodeHelper.BuildTree(treeStr); var sol = new Solution(); var ret = sol.PostorderTraversal(tree); var expected = ArrayHelper.ArrayFromString <int>(expectedStr); CollectionAssert.AreEquivalent(ret, expected); }
public void Test_Generic(string preorderStr, string expectedStr) { var preorder = ArrayHelper.ArrayFromString <int>(preorderStr); var expected = TreeNodeHelper.BuildTree(expectedStr); var sol = new Solution(); var res = sol.BstFromPreorder(preorder); Assert.IsTrue(CompareTreeNode(res, expected)); }
public void Test_Generic(string tree, string expectedTree) { var root = TreeNodeHelper.BuildTree(tree); var expected = TreeNodeHelper.BuildTree(expectedTree); var sol = new Solution(); var res = sol.ConvertBST(root); Assert.IsTrue(TreeNodeHelper.CompareTreeNode(res, expected)); }
public void Test_GenericStr(string treeStr, int target, string expectedStr) { var root = TreeNodeHelper.BuildTree(treeStr); var expected = TreeNodeHelper.BuildTree(expectedStr); var sol = new Solution(); var res = sol.RemoveLeafNodes(root, target); Assert.IsTrue(TreeNodeHelper.CompareTreeNode(res, expected)); }
public void Test_Generic(string treeStr, string expectedStr) { var root = TreeNodeHelper.BuildTree(treeStr); var expected = ArrayHelper.MatrixFromString <int>(expectedStr); var sol = new Solution(); var res = sol.VerticalTraversal(root); CollectionAssert.AreEqual(expected, res); }
public void Test_Generic(string tree, int low, int high, string expectedTree) { var root = TreeNodeHelper.BuildTree(tree); var expected = TreeNodeHelper.BuildTree(expectedTree); var sol = new Solution(); var res = sol.TrimBST(root, low, high); Assert.IsTrue(TreeNodeHelper.CompareTreeNode(res, expected)); }
public void Test_Generic(string strArray, int target, string expectedStr) { var root = TreeNodeHelper.BuildTree(strArray); var sol = new Solution(); var res = sol.PathSum(root, target); var expected = ArrayHelper.MatrixFromString <int>(expectedStr); CollectionAssert.AreEquivalent(res, expected); }
public void Test_Generic(string inputStr, int key, string expectedStr) { var root = TreeNodeHelper.BuildTree(inputStr); var sol = new Solution(); var res = sol.DeleteNode(root, key); var expected = TreeNodeHelper.BuildTree(expectedStr); Assert.IsTrue(TreeNodeHelper.CompareTreeNode(res, expected)); }
public void Test_GenericStr(string treeStr, string expectedStr) { var root = TreeNodeHelper.BuildTree(treeStr); var expected = TreeNodeHelper.BuildTree(expectedStr); var sol = new Solution(); sol.RecoverTree(root); Assert.IsTrue(TreeNodeHelper.CompareTreeNode(root, expected)); }
public void Test_GenericStr(string root1Str, string root2Str, string expectedStr) { var root1 = TreeNodeHelper.BuildTree(root1Str); var root2 = TreeNodeHelper.BuildTree(root2Str); var expected = ArrayHelper.ArrayFromString <int>(expectedStr).ToList(); var sol = new Solution(); var res = sol.GetAllElements(root1, root2); CollectionAssert.AreEqual(res, expected); }
public void Test_Generic(string arrStr, string expected) { var root = TreeNodeHelper.BuildTree(arrStr); Assert.IsNotNull(root); var sol = new Solution(); var res = sol.IncreasingBST(root); var expectedRoot = TreeNodeHelper.BuildTree(expected); Assert.IsTrue(TreeNodeHelper.CompareTreeNode(res, expectedRoot)); }
public void Test_GenericStr(string treeStr, int nodeVal) { var original = TreeNodeHelper.BuildTree(treeStr); var cloned = TreeNodeHelper.BuildTree(treeStr); var target = TreeNodeHelper.FindNodeWithVal(original, nodeVal); var expected = TreeNodeHelper.FindNodeWithVal(cloned, nodeVal); var sol = new Solution(); var res = sol.GetTargetCopy(original, cloned, target); Assert.AreEqual(res, expected); }
public void Test_Generic(string[] operations, string nodesArr, object[] expected) { var root = TreeNodeHelper.BuildTree(nodesArr); var sol = new BSTIterator(root); for (int i = 0; i < operations.Length; i++) { switch (operations[i]) { case "next": Assert.AreEqual(sol.Next(), expected[i]); break; case "hasNext": Assert.AreEqual(sol.HasNext(), expected[i]); break; } } }