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-11-17 18:38:28 +08:00
|
|
|
@raises(TypeError)
|
2016-06-26 10:13:15 +08:00
|
|
|
def test_check_balance_empty(self):
|
2016-09-07 17:46:47 +08:00
|
|
|
bst = BstBalance(None)
|
|
|
|
bst.check_balance()
|
2016-06-25 20:42:16 +08:00
|
|
|
|
2016-06-26 10:13:15 +08:00
|
|
|
def test_check_balance(self):
|
2016-09-07 17:46:47 +08:00
|
|
|
bst = BstBalance(Node(5))
|
|
|
|
assert_equal(bst.check_balance(), True)
|
|
|
|
|
|
|
|
bst.insert(3)
|
|
|
|
bst.insert(8)
|
|
|
|
bst.insert(1)
|
|
|
|
bst.insert(4)
|
|
|
|
assert_equal(bst.check_balance(), True)
|
|
|
|
|
|
|
|
bst = BstBalance(Node(5))
|
|
|
|
bst.insert(3)
|
|
|
|
bst.insert(8)
|
|
|
|
bst.insert(9)
|
|
|
|
bst.insert(10)
|
|
|
|
assert_equal(bst.check_balance(), False)
|
|
|
|
|
|
|
|
bst = BstBalance(Node(3))
|
|
|
|
bst.insert(2)
|
|
|
|
bst.insert(1)
|
|
|
|
bst.insert(5)
|
|
|
|
bst.insert(4)
|
|
|
|
bst.insert(6)
|
|
|
|
bst.insert(7)
|
|
|
|
assert_equal(bst.check_balance(), True)
|
2015-10-10 13:24:01 +08:00
|
|
|
|
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()
|