Commit 543fdb4f authored by Jeroen F.J. Laros's avatar Jeroen F.J. Laros

Added more tests.

parent 5f6cdc3a
......@@ -10,6 +10,9 @@ class TestTrie(object):
def setup(self):
self._trie = Trie(['abc', 'abd', 'test', 'te'])
def test_empty(self):
assert Trie().root == {}
def test_root(self):
assert self._trie.root == {
'a': {
......@@ -53,6 +56,44 @@ class TestTrie(object):
def test_prefix_order(self):
assert Trie(['test', 'te']).root == Trie(['te', 'test']).root
def test_add(self):
assert 'abx' in self._trie
def test_remove_present(self):
assert self._trie.remove('test')
assert 'test' not in self._trie
assert 'te' in self._trie
def test_remove_prefix_present(self):
assert self._trie.remove('te')
assert 'te' not in self._trie
assert 'test' in self._trie
def test_remove_absent(self):
assert not self._trie.remove('xxxx')
def test_remove_prefix_absent(self):
assert not self._trie.remove('ab')
def test_iter(self):
assert list(self._trie) == ['abc', 'abd', 'te', 'test']
def test_fill(self):
trie = Trie()
trie.fill(('a', 'b'), 3)
assert list(trie) == [
'aaa', 'aab', 'aba', 'abb', 'baa', 'bab', 'bba', 'bbb']
def test_all_hamming_1_perfect(self):
assert list(self._trie.all_hamming('abc', 1)) == ['abc', 'abd']
def test_all_hamming_1_not_perfect(self):
assert list(self._trie.all_hamming('abx', 1)) == ['abc', 'abd']
def test_all_hamming_1_no_match(self):
assert not list(self._trie.all_hamming('xbx', 1))
def test_hamming_0_no_prefix(self):
assert self._trie.hamming('ab', 0) == ''
......@@ -104,6 +145,9 @@ class TestTrie(object):
def test_best_hamming_match(self):
assert self._trie.best_hamming('abd', 1) == 'abd'
def test_all_levenshtein_1_not_perfect(self):
assert list(self._trie.all_levenshtein('tes', 1)) == ['te', 'test']
def test_levenshtein_0_match_1(self):
assert self._trie.levenshtein('abc', 0) == 'abc'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment