示例#1
0
def create_bst_2():
    btree = BST()
    vals = [10, 5, 15, 2, 7, 20, 6, 8, 17]

    for val in vals:
        btree.insert(val=val)

    return btree
示例#2
0
def test_insert_second_value_greater_than_root():
    """When inserting a value larger than the root, it should go in a new
    node as right_child to root in a tree with only root."""

    btree = BST()

    btree.insert(val=3)
    btree.insert(val=10)

    assert btree.root.right_child is not None
    assert btree.root.right_child.val == 10
示例#3
0
def test_insert_second_value_smaller_than_root():
    """When inserting a value smaller than the root, it should go in a new
    node as left_child to root in a tree with only root."""

    btree = BST()

    btree.insert(val=3)
    btree.insert(val=2)

    assert btree.root.left_child is not None
    assert btree.root.right_child is None
    assert btree.root.left_child.val == 2
示例#4
0
def test_insert_first_value():
    """First insertion should set root to that node, and that node
    should have no parents or children."""

    btree = BST()

    btree.insert(val=7)
    assert btree.root is not None
    assert btree.root.val == 7
    assert btree.root.parent is None
    assert btree.root.left_child is None
    assert btree.root.right_child is None