Exemplo n.º 1
0
def test_ceil_floor(tree):
    tree = bst.put(tree, 23, 'book21')
    tree = bst.put(tree, 7, 'book7')
    tree = bst.put(tree, 30, 'book30')
    tree = bst.put(tree, 5, 'book5')
    tree = bst.put(tree, 4, 'book4')
    tree = bst.put(tree, 3, 'book3')
    tree = bst.put(tree, 20, 'book20')
    tree = bst.put(tree, 25, 'book25')
    tree = bst.put(tree, 35, 'book35')
    tree = bst.put(tree, 29, 'book29')
    tree = bst.put(tree, 11, 'book11')
    tree = bst.put(tree, 15, 'book15')
    tree = bst.put(tree, 10, 'book10')
    assert bst.floor(tree, 21) == 20
    assert bst.floor(tree, 25) == 25
    assert bst.floor(tree, 18) == 15
    assert bst.ceiling(tree, 16) == 20
    assert bst.ceiling(tree, 15) == 15
    assert bst.ceiling(tree, 27) == 29
def floor(map, key):
    """
    Retorna la llave mas grande en la tabla de simbolos,
    menor o igual a la llave key
    Args:
        map: La tabla de simbolos
        key: La llave de búsqueda
    Returns:
        La llave más grande menor o igual a key
    Raises:
        Exception
    """
    if (map['type'] == 'BST'):
        return bst.floor(map, key)
    else:
        return rbt.floor(map, key)