Commit c699ee6b authored by Jeroen F.J. Laros's avatar Jeroen F.J. Laros

Fixed bug in Levenshtein function.

parent c4696045
......@@ -136,8 +136,8 @@ def _levenshtein(path, node, word, distance):
if not word:
if '' in node:
yield path
return
car, cdr = '', ''
else:
car, cdr = word[0], word[1:]
# Deletion.
......@@ -145,10 +145,12 @@ def _levenshtein(path, node, word, distance):
yield result
for char in node:
# Substitution and insertion.
# Substitution.
if car:
for result in _levenshtein(
path + char, node[char], cdr, distance - int(char != car)):
yield result
# Insertion.
for result in _levenshtein(
path + char, node[char], word, distance - 1):
yield result
......
......@@ -116,5 +116,8 @@ class TestTrie(object):
def test_levenshtein_1_del(self):
assert self._trie.levenshtein('ac', 1) == 'abc'
def test_levenshtein_1_prefex(self):
assert self._trie.levenshtein('ab', 1) == 'abc'
def test_levenshtein_1_ins(self):
assert self._trie.levenshtein('abbc', 1) == '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