2020-07-11 09:02:32 +08:00
|
|
|
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))
|
|
|
|
|
|
|
|
|
2020-07-11 09:02:32 +08:00
|
|
|
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)
|
2020-07-11 09:02:32 +08:00
|
|
|
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)
|
2020-07-11 09:02:32 +08:00
|
|
|
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__':
|
2020-07-11 09:02:32 +08:00
|
|
|
main()
|