Exemple #1
0
def test_remove():
    mytrie = Trie()
    mytrie.insert('test', 3)
    mytrie.insert('again', 2)
    mytrie.remove('test')
    with pytest.raises(KeyError):
        mytrie.get('test')
Exemple #2
0
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')
Exemple #3
0
    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)
Exemple #4
0
    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)
Exemple #5
0
    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)
Exemple #6
0
    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)
Exemple #7
0
    def test_get__word_not_in_trie(self):
        trie = Trie()
        word = 'their'

        self.assertIsNone(trie.get(word))
Exemple #8
0
    def test_get__word_is_in_trie__no_data(self):
        trie = Trie()
        word = 'their'

        trie.add(word)
        self.assertDictEqual(trie.get(word), {})
Exemple #9
0
def test_overwrite():
    mytrie = Trie()
    mytrie.insert('test', 3)
    mytrie.insert('test', 4)
    assert mytrie.get('test') == 4