From cf753f8ac4bb6c6c3484621031f9bf328c1f65c2 Mon Sep 17 00:00:00 2001 From: Julien Lengrand-Lambert Date: Fri, 12 Jul 2013 21:16:33 +0200 Subject: [PATCH] Implement simple print method for single node element --- 01_binary_search_trees/bst.py | 8 +++++++- 01_binary_search_trees/bst_test.py | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/01_binary_search_trees/bst.py b/01_binary_search_trees/bst.py index 1ed75d6..561ca41 100644 --- a/01_binary_search_trees/bst.py +++ b/01_binary_search_trees/bst.py @@ -83,7 +83,7 @@ class BinarySearchTree(): Prints a nice version of the binary search node """ #TODO - return "aaa" + return self.root_node.__str__() @staticmethod def is_search_tree(a_tree_root): @@ -129,3 +129,9 @@ class BinarySearchNode(): def has_right_child(self): return self.right_child is not None + + def __str__(self): + """ + prints a single tree node. + """ + return (str(self.left_child.value) + " " + str(self.value) + " " + str(self.right_child.value) ) \ No newline at end of file diff --git a/01_binary_search_trees/bst_test.py b/01_binary_search_trees/bst_test.py index b147b41..badf96b 100644 --- a/01_binary_search_trees/bst_test.py +++ b/01_binary_search_trees/bst_test.py @@ -200,7 +200,13 @@ class test_binary_search_tree(unittest.TestCase): node_val4 = 16 bst.add(node_val4) - self.assertEqual(bst.__str__(), "aaa") + # 6 + # / \ + # 4 10 + # \ + # 16 + + self.assertEqual(bst.__str__(), "4 6 10") if __name__ == '__main__': unittest.main()