interactive-coding-challenges/graphs_trees/bst_min/test_bst_min.py

33 lines
669 B
Python
Raw Normal View History

2015-08-06 06:16:26 +08:00
from nose.tools import assert_equal
2016-08-14 20:22:07 +08:00
def height(node):
if node is None:
return 0
return 1 + max(height(node.left),
height(node.right))
2015-08-06 06:16:26 +08:00
class TestBstMin(object):
def test_bst_min(self):
2016-08-14 20:22:07 +08:00
min_bst = MinBst()
2015-08-06 06:16:26 +08:00
array = [0, 1, 2, 3, 4, 5, 6]
2016-08-14 20:22:07 +08:00
root = min_bst.create_min_bst(array)
2015-08-06 06:16:26 +08:00
assert_equal(height(root), 3)
2016-08-14 20:22:07 +08:00
min_bst = MinBst()
2015-08-06 06:16:26 +08:00
array = [0, 1, 2, 3, 4, 5, 6, 7]
2016-08-14 20:22:07 +08:00
root = min_bst.create_min_bst(array)
2015-08-06 06:16:26 +08:00
assert_equal(height(root), 4)
print('Success: test_bst_min')
def main():
test = TestBstMin()
test.test_bst_min()
if __name__ == '__main__':
main()