# CS122: Auto-completing keyboard using Tries # # Tests for your trie implementation # # YOUR NAME HERE from trie_dict import create_trie_node, add_word, is_word, num_completions, get_completions t = create_trie_node() add_word("a", t) add_word("an", t) add_word("and", t) add_word("are", t) add_word("bee", t) # Write your tests here # Example of an assertion. If "bee" was not inserted # correctly in the trie, the following statement will # cause the program to exit with an error message. assert is_word("bee", t)
from trie_dict import create_trie_node, add_word, is_word, num_completions, get_completions t = create_trie_node() add_word("a", t) add_word("an", t) add_word("and", t) add_word("ant", t) add_word("ants", t) add_word("andy", t) #print("THE TRIE", t) add_word("are", t) add_word("be", t) add_word("bet", t) add_word("bee", t) add_word("beet", t) add_word("beer", t) add_word("beers", t) #print(t) # Write your tests here # Example of an assertion. If "bee" was not inserted # correctly in the trie, the following statement will # cause the program to exit with an error message. #assert is_word("bee", t) #print(is_word("ar", t)) rv1 = get_completions("an", t) rv2 = get_completions("bee", t) rv3 = get_completions("as", t)
def test_add_words(words): t = create_trie_node() for word in words: add_word(word, t) return t
from trie_dict import create_trie_node, add_word, is_word, num_completions, get_completions t = create_trie_node() add_word("a", t) add_word("an", t) add_word("and", t) add_word("are", t) add_word("bee", t) # Write your tests here # Example of an assertion. If "bee" was not inserted # correctly in the trie, the following statement will # cause the program to exit with an error message. assert is_word("bee", t)
print(is_word("a", t)) print(is_word("an", t)) print(is_word("bee", t)) print(get_next_letters(t['a'])) print("and", num_completions("and", t))#1 print("b", num_completions("b", t)) #1 print("be", num_completions("be", t))#1 print("a", num_completions("a", t)) #4 print(trie_prefix("an", t)) ''' ''' t2 = create_trie_node() add_word("a", t2) add_word("are", t2) ''' '''t3 = create_trie_node() add_word("a", t3) add_word("and", t3) add_word("are", t3) add_word("art", t3) add_word("ate", t3) print(get_completions("a", t3))'''