Skip to content

Commit

Permalink
Finally, finally, implement search.
Browse files Browse the repository at this point in the history
  • Loading branch information
skytreader committed May 27, 2017
1 parent 2f23709 commit d0ce5e2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
4 changes: 2 additions & 2 deletions data_structures/binary_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ def search(self, query, search_type=Traversals.INORDER):
"""
walkthrough = BinaryTree.ITERATORS[search_type](self)

for node in walkthrough:
if node.node_data == query:
for data in walkthrough:
if data == query:
return True

return False
21 changes: 9 additions & 12 deletions data_structures/tests/binary_tree_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,6 @@

class NaiveBinaryTreeTest(unittest.TestCase):

def setUp(self):
self.bt1 = NaiveBinaryTree("root")

def test_init(self):
self.assertEqual(self.bt1.left_son, None)
self.assertEqual(self.bt1.right_son, None)

class IteratorTest(unittest.TestCase):
"""
Test all the iterators in this class.
"""

def setUp(self):
"""
Creates a binary tree with the letters of the alphabet (A-O) laid out in
Expand Down Expand Up @@ -71,6 +59,15 @@ def test_setUp(self):
# iteration
self.assertEqual(len(self.node_data), len(self.inorder))

def test_search(self):
self.assertFalse(self.test_root.search("P"))
self.assertTrue(self.test_root.search("A"))

class IteratorTest(NaiveBinaryTreeTest):
"""
Test all the iterators in this class.
"""

def test_inorder(self):
inorder = InorderIterator(self.test_root)
iterator_order = ""
Expand Down

0 comments on commit d0ce5e2

Please sign in to comment.