bugfix: generic search would raise an exception on certain input values
This commit is contained in:
parent
39000bda80
commit
3b84e6e5fb
|
@ -3,7 +3,7 @@ from fuzzysearch.common import Match
|
||||||
|
|
||||||
|
|
||||||
GenericSearchCandidate = namedtuple(
|
GenericSearchCandidate = namedtuple(
|
||||||
'SuperKevinSearchCandidate',
|
'GenericSearchCandidate',
|
||||||
['start', 'subseq_index', 'l_dist', 'n_subs', 'n_ins', 'n_dels'],
|
['start', 'subseq_index', 'l_dist', 'n_subs', 'n_ins', 'n_dels'],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -29,9 +29,12 @@ def find_near_matches_generic_linear_programming(subsequence, sequence,
|
||||||
# optimization: prepare some often used things in advance
|
# optimization: prepare some often used things in advance
|
||||||
_subseq_len = len(subsequence)
|
_subseq_len = len(subsequence)
|
||||||
|
|
||||||
if max_l_dist is None or \
|
maxes_sum = sum(
|
||||||
max_l_dist >= max_substitutions + max_insertions + max_deletions:
|
(x if x is not None else 0)
|
||||||
max_l_dist = max_substitutions + max_insertions + max_deletions
|
for x in [max_substitutions, max_insertions, max_deletions]
|
||||||
|
)
|
||||||
|
if max_l_dist is None or max_l_dist >= maxes_sum:
|
||||||
|
max_l_dist = maxes_sum
|
||||||
|
|
||||||
candidates = []
|
candidates = []
|
||||||
for index, char in enumerate(sequence):
|
for index, char in enumerate(sequence):
|
||||||
|
|
|
@ -125,3 +125,25 @@ class TestGenericSearch(unittest.TestCase):
|
||||||
self.search('bde', 'abcdefg', 1, 1, 1, 3),
|
self.search('bde', 'abcdefg', 1, 1, 1, 3),
|
||||||
))
|
))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_argument_handling(self):
|
||||||
|
# check that no exception is raised when some values are None
|
||||||
|
self.assertEqual(
|
||||||
|
self.search('a', 'b', 0, None, None, None),
|
||||||
|
[],
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
self.search('a', 'b', None, 0, None, None),
|
||||||
|
[],
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
self.search('a', 'b', None, None, 0, None),
|
||||||
|
[],
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
self.search('a', 'b', None, None, None, 0),
|
||||||
|
[],
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue