def words_table(): ht = HashTable(10 ** 6) with open('/usr/share/dict/words', 'r') as fh: for line in fh: ht.set(line.strip(), line.strip()) return ht
def test_set(): ht = HashTable(4) ht.set('pterodactyl', 'pterodactyl') ht.set assert ht.table_list[3] == [('pterodactyl', 'pterodactyl')] ht.set('c', 'c') assert ht.table_list[3] == [('pterodactyl', 'pterodactyl'), ('c', 'c')] ht.set('a', 'a') assert ht.table_list[1] == [('a', 'a')] with pytest.raises(TypeError): ht.set(1, 2)
def test_update_key(): ht = HashTable(4) ht.set('b', 5) assert ht.get('b') == 5 ht.set('b', 7) assert ht.get('b') == 7