2015-08-01 21:25:14 +08:00
|
|
|
from __future__ import print_function
|
|
|
|
from nose.tools import assert_equal
|
|
|
|
|
|
|
|
|
|
|
|
class TestTree(object):
|
|
|
|
|
|
|
|
def test_tree(self):
|
2015-08-02 05:44:14 +08:00
|
|
|
node = Node(5)
|
|
|
|
insert(node, 2)
|
|
|
|
insert(node, 8)
|
|
|
|
insert(node, 1)
|
|
|
|
insert(node, 3)
|
2015-08-01 21:25:14 +08:00
|
|
|
|
|
|
|
with captured_output() as (out, err):
|
2015-08-02 05:44:14 +08:00
|
|
|
in_order_traversal(node, sys.stdout.write)
|
2015-08-01 21:25:14 +08:00
|
|
|
assert_equal(out.getvalue().strip(), '12358')
|
|
|
|
|
2015-08-02 05:44:14 +08:00
|
|
|
node = Node(1)
|
|
|
|
insert(node, 2)
|
|
|
|
insert(node, 3)
|
|
|
|
insert(node, 4)
|
|
|
|
insert(node, 5)
|
2015-08-01 21:25:14 +08:00
|
|
|
|
|
|
|
with captured_output() as (out, err):
|
2015-08-02 05:44:14 +08:00
|
|
|
in_order_traversal(node, sys.stdout.write)
|
2015-08-01 21:25:14 +08:00
|
|
|
assert_equal(out.getvalue().strip(), '12345')
|
|
|
|
|
|
|
|
print('Success: test_tree')
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
test = TestTree()
|
|
|
|
test.test_tree()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|