This notebook was prepared by [Donne Martin](https://github.com/donnemartin). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges).
In [1]:
%run ../bst/bst.py
In [2]:
%%writefile height.py
def height(node):
if node is None:
return 0
return 1 + max(height(node.left),
height(node.right))
In [3]:
%run height.py
In [4]:
%%writefile test_height.py
from nose.tools import assert_equal
class TestHeight(object):
def test_height(self):
root = Node(5)
assert_equal(height(root), 1)
insert(root, 2)
insert(root, 8)
insert(root, 1)
insert(root, 3)
assert_equal(height(root), 3)
print('Success: test_height')
def main():
test = TestHeight()
test.test_height()
if __name__ == '__main__':
main()
In [5]:
%run -i test_height.py