interactive-coding-challenges/graphs_trees/bst/test_bst.py

40 lines
881 B
Python
Raw Normal View History

2015-08-01 21:25:14 +08:00
from nose.tools import assert_equal
class TestTree(object):
2015-08-05 07:33:42 +08:00
def __init__(self):
self.results = Results()
2016-08-14 20:20:06 +08:00
def test_tree_one(self):
bst = Bst()
bst.insert(5)
bst.insert(2)
bst.insert(8)
bst.insert(1)
bst.insert(3)
in_order_traversal(bst.root, self.results.add_result)
2015-08-05 07:33:42 +08:00
assert_equal(str(self.results), '[1, 2, 3, 5, 8]')
self.results.clear_results()
2015-08-01 21:25:14 +08:00
2016-08-14 20:20:06 +08:00
def test_tree_two(self):
bst = Bst()
bst.insert(1)
bst.insert(2)
bst.insert(3)
bst.insert(4)
bst.insert(5)
in_order_traversal(bst.root, self.results.add_result)
2015-08-05 07:33:42 +08:00
assert_equal(str(self.results), '[1, 2, 3, 4, 5]')
2015-08-01 21:25:14 +08:00
print('Success: test_tree')
def main():
test = TestTree()
2016-08-14 20:20:06 +08:00
test.test_tree_one()
test.test_tree_two()
2015-08-01 21:25:14 +08:00
if __name__ == '__main__':
main()