def test_no_common_keys():
    synonym = HashTable(1024)
    antonyms = HashTable(1024)
    synonym.add('fond', 'enamored')
    synonym.add('wrath', 'anger')
    antonyms.add('see', 'look')
    assert left_join(synonym, antonyms) == [['fond', 'enamored', 'null'],
                                            ['wrath', 'anger', 'null']]
def test_simple_left_join():

    synonym = HashTable(1024)
    antonyms = HashTable(1024)
    synonym.add('fond', 'enamored')
    synonym.add('wrath', 'anger')
    antonyms.add('fond', 'averse')
    assert left_join(synonym, antonyms) == [['fond', 'enamored', 'averse'],
                                            ['wrath', 'anger', 'null']]
示例#3
0
def test_handle_collision():
    table = HashTable()
    table.add('left', 'the building')
    table.add('felt', 'excited')
    hashed_key = table.hash('left')
    assert table.map[hashed_key].head.info == ('left', 'the building')
    assert table.map[hashed_key].head.next.info == ('felt', 'excited')
def test_2nd_dictionary_empty():

    synonym = HashTable(1024)
    antonyms = HashTable(1024)
    synonym.add('fond', 'enamored')
    synonym.add('wrath', 'anger')
    assert left_join(synonym, antonyms) == [['fond', 'enamored', 'null'],
                                            ['wrath', 'anger', 'null']]
def test_1st_dict_is_empty():
    synonym = HashTable(1024)
    antonyms = HashTable(1024)
    antonyms.add('see', 'look')
    assert left_join(synonym, antonyms) == []
def left_join(synonym, antonyms):
    output = []
    for linkedlist in synonym.map:
        if linkedlist == None:
            continue
        else:
            current = linkedlist.head
            while current:

                if antonyms.contains(current.data[0]):
                    output.append(current.data)
                    current.data.append(antonyms.get(current.data[0]))

                else:
                    output.append(current.data)
                    current.data.append('null')
                current = current.next

    return output


if __name__ == "__main__":
    synonym = HashTable(1024)
    antonyms = HashTable(1024)
    synonym.add('could', 'enamored')
    synonym.add('cloud', 'anger')
    antonyms.add('fond', 'averse')

    print(left_join(synonym, antonyms))
示例#7
0
def test_retrieve_info_with_collision():
    table = HashTable()
    table.add('left', 'the building')
    table.add('felt', 'excited')
    assert table.get('left') == 'the building'
    assert table.get('felt') == 'excited'
示例#8
0
def test_add_key_info():
    table = HashTable()
    table.add('adding', 'Add key and value')
    assert table.map[table.hash('adding')].head.info == ('adding',
                                                         'Add key and value')
def test_get_value():
    table = HashTable(1024)
    table.add('joudi', '19')
    assert table.get('joudi') == '19'
示例#10
0
def test_get_info_from_key():
    table = HashTable()
    table.add('contain', 'listen')
    assert table.get('contain') == 'listen'
示例#11
0
def test_get_info_and_key():
    table = HashTable()
    table.add('Fruit', 'Mango')
    assert table.map[table.hash('Fruit')].head.info[0] == 'Fruit'
    assert table.map[table.hash('Fruit')].head.info[1] == 'Mango'
def test_retrieve_collision():
    table = HashTable(1024)
    table.add('cloud', '19')
    table.add('could', '32')
    assert table.get('cloud') == '19'
    assert table.get('could') == '32'
def test_key_value():
    table = HashTable(1024)
    table.add('name', 'joudi')
    table.add('name', 'sali')

    assert table.map[table.hash('name')].head.data[1] == 'joudi'
def test_collision():
    table = HashTable(1024)
    table.add('cloud', '19')
    table.add('could', '32')
    assert table.map[table.hash('cloud')].head.data == ['cloud', '19']
    assert table.map[table.hash('cloud')].head.next.data == ['could', '32']
def test_value_not_in_table():
    table = HashTable(1024)
    assert table.get('joudi') == 'Not in the table'
示例#16
0
def test_get_info_not_in_table():
    table = HashTable()
    assert table.get('test') == 'Not in the table'
def test_add_key():
    table = HashTable(1024)
    table.add('joudi', '19')
    assert table.map[table.hash('joudi')].head.data == ['joudi', '19']