예제 #1
0
def insertarTablaHash(arregloLleno: List, tablaHash : HashTable):

    '''
    Para insertar en la tabla hash los usuarios registrados
    :param arregloLleno: arreglo de 2-tuplas compuesto por el nombre de usuario y el 
    arreglo de volumen
    :param tablaHash: tabla hash donde se guardarn todos los nombres de los usuarios y el 
    arreglo de volumen 
    '''

    for i in arregloLleno:
        tablaHash.set(i[0],i[1])
예제 #2
0
def test_get_returns_value_of_key_provided():
    """Test that get function returns the value of key provided."""
    from hash import HashTable, additive_hash
    t = HashTable(10, additive_hash)
    t.set('word', 444)
    assert t.get('word')
예제 #3
0
def test_set_places_key_value_pairs_in_hash_table():
    """Test that set function places key value pairs in hash table correctly."""
    from hash import HashTable, additive_hash
    t = HashTable(10, additive_hash)
    t.set('word', 444)
    assert t.buckets[4][0] == ['word', 444]
예제 #4
0
def test_set_raises_error_if_key_not_string():
    """Test that type error raised if key not string in set."""
    from hash import HashTable, additive_hash
    t = HashTable(10, additive_hash)
    with pytest.raises(TypeError):
        t.set(12, 44)
예제 #5
0
def test_hash_fill_table(read_test_lexicon):
    ht = HashTable()
    for i in read_test_lexicon:
        ht.set(i)
    for i in read_test_lexicon:
        assert ht.get(i) == i
예제 #6
0
def dict_hash():
    dict_hash = HashTable(1024)
    dictionary = open("/usr/share/dict/words", 'r')
    for word in dictionary:
        dict_hash.set(word.rstrip(), 1)
    return dict_hash