diff --git a/01_binary_search_trees/bst.py b/01_binary_search_trees/bst.py index 86d06ae..1ed75d6 100644 --- a/01_binary_search_trees/bst.py +++ b/01_binary_search_trees/bst.py @@ -78,33 +78,12 @@ class BinarySearchTree(): # we have the leaf return node.value - # def __str__(self): - # """ - # Prints a nice version of the binary search node - # """ - # #TODO - # return "aaa" - - @staticmethod - def is_search_tree_old(a_tree_root): + def __str__(self): """ - Returns true of the input binary tree is a valid search binary tree. + Prints a nice version of the binary search node """ #TODO - # no check for now, let s imagine we have a correct binary tree. - root_node = a_tree_root - print root_node.value - if (root_node.has_left_child()): - if (root_node.value < root_node.left_child.value): # breaks rules - return False - else: - return BinarySearchTree.is_search_tree(root_node.left_child) - - if (root_node.has_right_child()): - if (root_node.value < root_node.right_child.value): # breaks rules - return False - else: - return BinarySearchTree.is_search_tree(root_node.right_child) + return "aaa" @staticmethod def is_search_tree(a_tree_root): diff --git a/01_binary_search_trees/bst_test.py b/01_binary_search_trees/bst_test.py index 79a32fb..b147b41 100644 --- a/01_binary_search_trees/bst_test.py +++ b/01_binary_search_trees/bst_test.py @@ -107,23 +107,6 @@ class test_binary_search_tree(unittest.TestCase): self.assertEqual(bst.min(), node_val2) - def test_print(self): - # No assertion here, I just want a beautifully designed tree. - bst = BinarySearchTree() - - self.assertEqual(bst.min(), None) - - node_val1 = 6 - bst.add(node_val1) - node_val2 = 4 - bst.add(node_val2) - node_val3 = 10 - bst.add(node_val3) - node_val4 = 16 - bst.add(node_val4) - - #print(bst) - def test_is_search_node(self): bst = BinarySearchTree() @@ -203,7 +186,21 @@ class test_binary_search_tree(unittest.TestCase): self.assertEqual(bst.root_node.right_child.value, 20) self.assertFalse(BinarySearchTree.is_search_tree(bst.root_node)) + def test_print(self): + bst = BinarySearchTree() + self.assertEqual(bst.min(), None) + + node_val1 = 6 + bst.add(node_val1) + node_val2 = 4 + bst.add(node_val2) + node_val3 = 10 + bst.add(node_val3) + node_val4 = 16 + bst.add(node_val4) + + self.assertEqual(bst.__str__(), "aaa") if __name__ == '__main__': unittest.main()