Exemple #1
0
 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)
Exemple #3
0
 def test_space_on_prefix(self):
     self.assertEqual(trie.find_autocomplete(self.root, 'Facebook L'),
                      ['Facebook Lite'])
Exemple #4
0
 def test_multiple_match(self):
     self.assertEqual(len(trie.find_autocomplete(self.root, 'W')), 4)
Exemple #5
0
 def test_unique_match(self):
     self.assertEqual(trie.find_autocomplete(self.root, 'What'),
                      ['WhatsApp Messenger'])
Exemple #6
0
 def test_not_found(self):
     self.assertEqual(trie.find_autocomplete(self.root, 'ABCD1234'), [])
Exemple #7
0
 def test_empty_trie(self):
     root = trie.TrieNode('*')
     self.assertEqual(trie.find_autocomplete(root, ''), [])