def test_almost_right_search(self): keys = ["internet", "interview", "inter", "internally", "web", "world"] trie = Trie() for key in keys: trie.insert(key) key = "wel" self.assertFalse(trie.search(key))
def test_prefix_visitor(self): keys = [ "internet", "interview", "inter", "internally", "web", "world", "key", "keys" ] trie = Trie() for key in keys: trie.insert(key) self.assertEqual("(inter(n(et)(ally))(view))(w(eb)(orld))(key(s))", str(trie))
def __init__(self, file): self._input = TrieFile(file) self._trie = Trie() self._rapport = Exercise1Rapport() for word in self._input.words(): self._trie.insert(word) self._rapport.register_insert(self._trie, word) for key in self._input.keys(): result = self._trie.search(key) self._rapport.register_search(key, result)
class Exercise1: """Undestands solving Oblig""" def __init__(self, file): self._input = TrieFile(file) self._trie = Trie() self._rapport = Exercise1Rapport() for word in self._input.words(): self._trie.insert(word) self._rapport.register_insert(self._trie, word) for key in self._input.keys(): result = self._trie.search(key) self._rapport.register_search(key, result) def write_to_output(self, out_file): self._rapport.write(out_file)
def test_rapport(self): keys = [ "internet", "interview", "inter", "internally", "web", "world", "key", "keys" ] searches = [ "inter", "internet", "web", "key", "waldo", "w", "i", "cool" ] trie = Trie() rap = Exercise1Rapport() for key in keys: trie.insert(key) rap.register_insert(trie, key) for key in searches: result = trie.search(key) rap.register_search(key, result) result = rap.build() print(result)
def test_to_str(self): keys = ["internet", "key", "bollocks"] trie = Trie() for key in keys: trie.insert(key) self.assertEqual("(internet)(key)(bollocks)", str(trie))
def test_to_str(self): keys = ["internet"] trie = Trie() for key in keys: trie.insert(key) self.assertEqual("(internet)", str(trie))
def test_sub_and_super_word(self): keys = ["inter", "internet"] trie = Trie() for key in keys: trie.insert(key) self.assertEqual("(inter(net))", str(trie))
def test_prefix_visitor_distinct_words(self): keys = ["internet", "web", "key"] trie = Trie() for key in keys: trie.insert(key) self.assertEqual("(internet)(web)(key)", str(trie))
def test_prefix_visitor_single_word(self): keys = ["internet"] trie = Trie() for key in keys: trie.insert(key) self.assertEqual("(internet)", str(trie))
def test_not_word(self): keys = ["internet", "interview", "inter"] trie = Trie() for key in keys: trie.insert(key) self.assertFalse(trie.search("cool"))
def test_sub_word(self): keys = ["internet", "interview", "inter"] trie = Trie() for key in keys: trie.insert(key) self.assertTrue(trie.search(keys[2]))
def test_search_same_word(self): keys = ["internet"] trie = Trie() for key in keys: trie.insert(key) self.assertTrue(trie.search(keys[0]))
def test_first_char_split(self): keys = ["internet", "web", "world"] trie = Trie() for key in keys: trie.insert(key) print(trie)
def test_end_2_end(self): trie = Trie() for key in inserts: trie.insert(key) print(trie)