Exemplo n.º 1
0
def test_pop_max_reverse_ordered():
    bst = BinarySearchTree()

    item_list = list(range(10))[::-1]

    for item in item_list:
        bst.add_value(item)

    assert bst.pop_max() == 9
Exemplo n.º 2
0
def test_pop_min_ordered():
    bst = BinarySearchTree()

    item_list = list(range(10))

    for item in item_list:
        bst.add_value(item)

    assert bst.pop_min() == 0
Exemplo n.º 3
0
def test_traverse_ordered():
    bst = BinarySearchTree()

    item_list = list(range(10))

    for item in item_list:
        bst.add_value(item)

    assert_traverse_order(item_list, bst)
Exemplo n.º 4
0
def test_pop_min_random():
    bst = BinarySearchTree()

    item_list = list(range(10))

    shuffled_item_list = item_list[:]
    random.shuffle(shuffled_item_list)

    for item in shuffled_item_list:
        bst.add_value(item)

    assert bst.pop_min() == 0
Exemplo n.º 5
0
def test_traverse_random():
    bst = BinarySearchTree()

    item_list = list(range(10))

    shuffled_item_list = item_list[:]
    random.shuffle(shuffled_item_list)

    for item in shuffled_item_list:
        bst.add_value(item)

    assert_traverse_order(item_list, bst)
Exemplo n.º 6
0
from trees import BinarySearchTree

if __name__ == '__main__':
    bst = BinarySearchTree()

    bst.add_value(5)
    bst.add_value(3)
    bst.add_value(2)
    bst.add_value(1)
    bst.add_value(20)
    bst.add_value(24)
    a = bst.add_value(25)
    bst.add_value(26)
    bst.add_value(7)
    bst.add_value(4)
    bst.add_value(6)
    bst.add_value(8)
    bst.add_value(23)
    bst.add_value(21)
    bst.add_value(22)

    print(bst.pop_min_at_parent(a))

    print(bst.pop_min())
    print(bst.pop_min())
    print(bst.pop_min())
    print(bst.pop_min())
    print(bst.pop_min())

    print('-----')