2015-08-06 18:09:30 +08:00
|
|
|
from nose.tools import assert_equal
|
2016-06-26 10:13:15 +08:00
|
|
|
from nose.tools import raises
|
2015-08-06 18:09:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
class TestCheckBalance(object):
|
|
|
|
|
2016-06-26 10:13:15 +08:00
|
|
|
@raises(Exception)
|
|
|
|
def test_check_balance_empty(self):
|
|
|
|
check_balance(None)
|
2016-06-25 20:42:16 +08:00
|
|
|
|
2016-06-26 10:13:15 +08:00
|
|
|
def test_check_balance(self):
|
2015-08-06 18:09:30 +08:00
|
|
|
node = Node(5)
|
2016-06-25 20:42:16 +08:00
|
|
|
assert_equal(check_balance(node), True)
|
|
|
|
|
2015-08-06 18:09:30 +08:00
|
|
|
insert(node, 3)
|
|
|
|
insert(node, 8)
|
|
|
|
insert(node, 1)
|
|
|
|
insert(node, 4)
|
|
|
|
assert_equal(check_balance(node), True)
|
|
|
|
|
|
|
|
node = Node(5)
|
|
|
|
insert(node, 3)
|
|
|
|
insert(node, 8)
|
|
|
|
insert(node, 9)
|
|
|
|
insert(node, 10)
|
|
|
|
assert_equal(check_balance(node), False)
|
|
|
|
|
2015-10-10 13:24:01 +08:00
|
|
|
node = Node(3)
|
|
|
|
insert(node, 2)
|
|
|
|
insert(node, 1)
|
|
|
|
insert(node, 5)
|
|
|
|
insert(node, 4)
|
|
|
|
insert(node, 6)
|
|
|
|
insert(node, 7)
|
|
|
|
assert_equal(check_balance(node), False)
|
|
|
|
|
2015-08-06 18:09:30 +08:00
|
|
|
print('Success: test_check_balance')
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
test = TestCheckBalance()
|
2016-06-26 10:13:15 +08:00
|
|
|
test.test_check_balance_empty()
|
2015-08-06 18:09:30 +08:00
|
|
|
test.test_check_balance()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|