def test_search_phrase(self): max_results_count = 5 trie = Trie() initial_word_list = [ "app", "apple", "applet", "application", "appetite" ] [trie.add_word(word) for word in initial_word_list] assert (collections.Counter( trie.search_phrase("ap", max_len_closest_words=max_results_count)) == collections.Counter(initial_word_list))
def test_invalid_phrase(self): invalid_phrase = "apa" trie = Trie() initial_word_list = [ "app", "apple", "applet", "application", "appetite" ] [trie.add_word(word) for word in initial_word_list] max_results_count = 2 result = trie.search_phrase(invalid_phrase, max_len_closest_words=max_results_count) assert len(result) == 0
def test_search_phrase_max(self): trie = Trie() initial_word_list = [ "app", "apple", "applet", "application", "appetite" ] [trie.add_word(word) for word in initial_word_list] max_results_count = 2 result = trie.search_phrase(initial_word_list[0], max_len_closest_words=max_results_count) assert len(result) == max_results_count assert all(word in initial_word_list for word in result)