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

34 lines
669 B
Python
Raw Normal View History

import unittest
2015-08-06 06:16:26 +08:00
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))
class TestBstMin(unittest.TestCase):
2015-08-06 06:16:26 +08:00
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)
self.assertEqual(height(root), 3)
2015-08-06 06:16:26 +08:00
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)
self.assertEqual(height(root), 4)
2015-08-06 06:16:26 +08:00
print('Success: test_bst_min')
def main():
test = TestBstMin()
test.test_bst_min()
if __name__ == '__main__':
main()