def test_get_descendants_nodes(self, word, expected_results): auto_complete = AutoComplete(words=WIKIPEDIA_WORDS, synonyms=SYNONYMS) matched_prefix_of_last_word, rest_of_word, node, matched_words = auto_complete._prefix_autofill( word) size = 2 found_words_gen = node.get_descendants_nodes(size=size) found_words = [_node.word for _node in found_words_gen][:size + 1] print(f'word: {word}') print(f'expected_results: {expected_results}') print(f'found_words: {found_words}') assert expected_results == list(found_words)
def test_prefix_autofill(self, word, expected_matched_prefix_of_last_word, expected_rest_of_word, expected_matched_words, expected_node_path): auto_complete = AutoComplete(words=WIKIPEDIA_WORDS, synonyms=SYNONYMS) matched_prefix_of_last_word, rest_of_word, node, matched_words = auto_complete._prefix_autofill( word) print(f'word: {word}') print( f'expected_matched_prefix_of_last_word: {expected_matched_prefix_of_last_word}' ) print(f'matched_prefix_of_last_word: {matched_prefix_of_last_word}') print(f'expected_rest_of_word: {expected_rest_of_word}') print(f'rest_of_word: {rest_of_word}') print(f'node: {node}') print(f'expected_matched_words: {expected_matched_words}') print(f'matched_words: {matched_words}') expected_node = auto_complete._dwg for k in expected_node_path.split(','): expected_node = expected_node[k] assert expected_node is node assert expected_matched_prefix_of_last_word == matched_prefix_of_last_word assert expected_rest_of_word == rest_of_word assert expected_matched_words == matched_words