Exemplo n.º 1
0
def test_intiate_small():
    """."""
    from BST import BinTree
    beast = BinTree([10, 9, 8, 7, 6])
    assert beast.balance() == 1
    assert beast._root.left.val == 7
    assert beast.balance(beast._root.left) == 0
Exemplo n.º 2
0
def test_delete_one_child():
    """Delete works on a node with one child."""
    from BST import BinTree
    beast = BinTree([45, 33, 1, 8, 93, 10, 63, 44, 100, 4, 79, 69, 7, 54, 0, 16, 94, 14, 49, 11])
    assert beast.size() == 20
    beast.delete(16)
    assert beast.size() == 19
    assert not beast.contains(16)
    assert beast.search(10).right.val == 14
Exemplo n.º 3
0
def binary_tree():
    """For testing."""
    from BST import BinTree
    bst = [5, -1, 1, 8, 9, 10, 17, -3, -10, 4, 2, -100, 7, -5, 0, 16, -22, 14, 3, 11]
    bin_tree = BinTree(bst)
    return bin_tree
Exemplo n.º 4
0
def test_v_shaped_bst():
    """Test odd shape."""
    from BST import BinTree
    beast = BinTree([5, 4, 3, 2, 1, 6, 7, 8, 9, 10])
    generator = beast.in_order()
    assert list(generator) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Exemplo n.º 5
0
def small_bst():
    """For small testing."""
    from BST import BinTree
    bst = BinTree([10, 5, 11, 13, 2, 0, 20])
    return bst
Exemplo n.º 6
0
def empty_bst():
    """For more testing."""
    from BST import BinTree
    bst = BinTree()
    return bst
Exemplo n.º 7
0
def large_binary_tree():
    """For testing."""
    from BST import BinTree
    beast = BinTree([45, 33, 1, 8, 93, 10, 63, 44, 99, 34, 79, 69, 25, 54, 83, 16, 94, 14, 49, 11])
    return beast
Exemplo n.º 8
0
def smaller_binary_tree():
    """For more testing."""
    from BST import BinTree
    beast = BinTree([10, 5, 11, 13, 4, 6, 12, 20, 21, 7])
    return beast