示例#1
0
def testOne():
    try:
        tree = BST(10)
        tree.insert(7)
        tree.insert(15)
        tree.insert(12)
        COMPARE_LISTS(list([10, 7, 15, 12]), tree.BFSTraversal())
        tree.insert(13)
        COMPARE_LISTS(list([10, 7, 15, 12, 13]), tree.BFSTraversal())
        tree.insert(14)
        COMPARE_LISTS(list([10, 7, 15, 12, 13, 14]), tree.BFSTraversal())
        tree.insert(11)
        COMPARE_LISTS(list([10, 7, 15, 12, 11, 13, 14]), tree.BFSTraversal())
        tree.insert(4)
        tree.insert(8)
        tree.insert(9)
        tree.insert(5)
        tree.insert(3)
        tree.insert(2)
        COMPARE_LISTS(list([10, 7, 15, 4, 8, 12, 3, 5, 9, 11, 13, 2, 14]),
                      tree.BFSTraversal())
    except Exception as err:
        print(err)
        print('Test 1 FAILED!')
    else:
        print('Test 1 Passed!')
    finally:
        print('Test 1 Complete.')
示例#2
0
def testFour():
    try:
        tree = BST(10)
        tree.insert(7)
        tree.insert(15)
        tree.insert(12)
        tree.insert(13)
        tree.insert(14)
        tree.insert(11)
        tree.insert(4)
        tree.insert(8)
        tree.insert(9)
        tree.insert(5)
        tree.insert(3)
        tree.insert(2)
        tree.removeElem(3)
        COMPARE_LISTS(list([10, 7, 15, 4, 8, 12, 2, 5, 9, 11, 13, 14]),
                      tree.BFSTraversal())
    except Exception as err:
        print(err)
        print('Test 4 FAILED!')
    else:
        print('Test 4 Passed!')
    finally:
        print('Test 4 Complete.')