def test_remove(): mytrie = Trie() mytrie.insert('test', 3) mytrie.insert('again', 2) mytrie.remove('test') with pytest.raises(KeyError): mytrie.get('test')
def test_creation(): mytrie = Trie() mytrie.insert('test', 3) mytrie.insert('hello', 9) assert mytrie.get('hello') == 9 assert mytrie.get('test') == 3 with pytest.raises(KeyError): mytrie.get('cat')
def test_get__word_is_in_trie__with_data(self): trie = Trie() word = 'their' payload = {'weight': 25} trie.add(word, **payload) self.assertDictEqual(trie.get(word), payload)
def test_insert__word_is_already_in_trie__update_data(self): trie = Trie() trie.add('their', weight=25) word = 'their' payload = {'weight': 30} trie.add(word, **payload) self.assertDictEqual(trie.get(word), payload)
def test_insert__zero_length_prefix__with_data(self): trie = Trie() word = 'their' payload = {'weight': 30} trie.add(word, **payload) self.assertIn(word, trie) self.assertDictEqual(trie.get(word), payload)
def test_insert__word_is_prefix_in_trie__with_data(self): trie = Trie() trie.add('their') word = 'the' payload = {'weight': 30} trie.add(word, **payload) self.assertIn(word, trie) self.assertDictEqual(trie.get(word), payload)
def test_get__word_not_in_trie(self): trie = Trie() word = 'their' self.assertIsNone(trie.get(word))
def test_get__word_is_in_trie__no_data(self): trie = Trie() word = 'their' trie.add(word) self.assertDictEqual(trie.get(word), {})
def test_overwrite(): mytrie = Trie() mytrie.insert('test', 3) mytrie.insert('test', 4) assert mytrie.get('test') == 4