Implement simple print method for single node element

This commit is contained in:
2013-07-12 21:16:33 +02:00
parent 6c14c68d93
commit cf753f8ac4
2 changed files with 14 additions and 2 deletions

View File

@@ -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) )

View File

@@ -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()