예제 #1
0
 def test_prefix_exists(self):
     trie = Trie()
     trie.add('foob', 1)
     trie.add('fooba', 2)
     trie.add('foobb', 3)
     trie.add('foobar', 4)
     trie.add('foobaz', 5)
     values = list(trie.values_for_prefix('foo'))
     assert len(values) == 5
     for i in range(1, 6):
         assert i in values
예제 #2
0
 def test_key_does_not_exist(self):
     trie = Trie()
     with pytest.raises(KeyNotFound):
         trie.values('foobar')
예제 #3
0
 def test_key_does_not_exist(self):
     trie = Trie()
     assert not trie.has_prefix('foobar')
예제 #4
0
 def test_key_exists(self):
     trie = Trie()
     trie.add('foobar', 1)
     trie.add('foobar', 2)
     assert trie.values('foobar') == [1, 2]
예제 #5
0
 def test_prefix_exists(self):
     trie = Trie()
     trie.add('foobar', 1)
     assert trie.has_prefix('foo')
예제 #6
0
 def test_whole_key_as_prefix(self):
     trie = Trie()
     trie.add('foobar', 1)
     assert trie.has_prefix('foobar')
예제 #7
0
 def test_key_exists(self):
     trie = Trie()
     trie.add('foo', 1)
     assert trie.has('foo')
예제 #8
0
 def test_key_does_not_exist(self):
     trie = Trie()
     assert not trie.has('foo')
예제 #9
0
 def test_many(self):
     trie = Trie()
     trie.add_many([('foo', 1), ('bar', 2)])
     assert_has_key(trie, 'foo', 1)
     assert_has_key(trie, 'bar', 2)
예제 #10
0
 def test_multiple_with_same_key_prefix(self):
     trie = Trie()
     trie.add('foo', 1)
     trie.add('foobar', 2)
     assert_has_key(trie, 'foo', 1)
     assert_has_key(trie, 'foobar', 2)
예제 #11
0
 def test_multiple_with_different_keys(self):
     trie = Trie()
     trie.add('foo', 1)
     trie.add('bar', 2)
     assert_has_key(trie, 'foo', 1)
     assert_has_key(trie, 'bar', 2)
예제 #12
0
 def test_single(self):
     trie = Trie()
     trie.add('foo', 1)
     assert_has_key(trie, 'foo', 1)
예제 #13
0
 def test_prefix_does_not_exist(self):
     trie = Trie()
     with pytest.raises(KeyNotFound):
         trie.values_for_prefix('foobar')