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))
示例#2
0
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_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]))