def test_add_name(self): root = trie.TrieNode('*') self.assertEqual(trie.find_autocomplete(root, 'WhatsApp Messenger'), []) trie.add(root, 'WhatsApp Messenger') self.assertEqual(trie.find_autocomplete(root, 'WhatsApp Messenger'), ['WhatsApp Messenger'])
def get_autocomplete(): """ API entrypoint for the autocomplete search Input prefix: the prefix to search for the autocomplete Returns json with list of possible autocompletitions """ prefix = request.get_data() results = trie.find_autocomplete(root, prefix.decode("utf-8")) return json.dumps(results)
def test_space_on_prefix(self): self.assertEqual(trie.find_autocomplete(self.root, 'Facebook L'), ['Facebook Lite'])
def test_multiple_match(self): self.assertEqual(len(trie.find_autocomplete(self.root, 'W')), 4)
def test_unique_match(self): self.assertEqual(trie.find_autocomplete(self.root, 'What'), ['WhatsApp Messenger'])
def test_not_found(self): self.assertEqual(trie.find_autocomplete(self.root, 'ABCD1234'), [])
def test_empty_trie(self): root = trie.TrieNode('*') self.assertEqual(trie.find_autocomplete(root, ''), [])