added some tests for has_near_matches_*
Conflicts: tests/test_generic_search.py tests/test_substitutions_only.py
This commit is contained in:
parent
a8965879f2
commit
2a4f028f8d
|
@ -1,9 +1,11 @@
|
|||
from tests.compat import unittest
|
||||
from tests.test_levenshtein import TestFindNearMatchesLevenshteinBase
|
||||
from fuzzysearch.common import Match, get_best_match_in_group, group_matches
|
||||
from tests.test_substitutions_only import TestSubstitionsOnlyBase
|
||||
from tests.test_substitutions_only import TestSubstitionsOnlyBase, \
|
||||
TestHasNearMatchSubstitionsOnly
|
||||
from fuzzysearch.generic_search import \
|
||||
find_near_matches_generic_linear_programming as fnm_generic_lp
|
||||
find_near_matches_generic_linear_programming as fnm_generic_lp, \
|
||||
has_near_match_generic_ngrams
|
||||
|
||||
|
||||
class TestGenericSearchAsLevenshtein(TestFindNearMatchesLevenshteinBase,
|
||||
|
@ -147,3 +149,11 @@ class TestGenericSearch(unittest.TestCase):
|
|||
self.search('a', 'b', None, None, None, 0),
|
||||
[],
|
||||
)
|
||||
|
||||
|
||||
class TestHasNearMatchGenericNgramsAsSubstitutionsOnly(
|
||||
TestHasNearMatchSubstitionsOnly,
|
||||
):
|
||||
def search(self, subsequence, sequence, max_subs):
|
||||
return has_near_match_generic_ngrams(subsequence, sequence,
|
||||
max_subs, 0, 0, max_subs)
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
from fuzzysearch.substitutions_only import \
|
||||
find_near_matches_substitutions_linear_programming as fnm_subs_lp, \
|
||||
find_near_matches_substitutions_ngrams as fnm_subs_ngrams
|
||||
find_near_matches_substitutions_ngrams as fnm_subs_ngrams, \
|
||||
has_near_match_substitutions_ngrams
|
||||
from fuzzysearch._substitutions_only import \
|
||||
substitutions_only_has_near_matches_byteslike as hnm_subs_byteslike
|
||||
|
||||
from tests.compat import unittest
|
||||
|
||||
import textwrap
|
||||
from fuzzysearch.common import Match
|
||||
|
||||
|
||||
|
@ -276,12 +278,12 @@ class TestHasNearMatchSubstitionsOnlyBase(object):
|
|||
|
||||
def test_dna_search(self):
|
||||
# see: http://stackoverflow.com/questions/19725127/
|
||||
text = ''.join('''\
|
||||
GACTAGCACTGTAGGGATAACAATTTCACACAGGTGGACAATTACATTGAAAATCACAGATTGGT
|
||||
CACACACACATTGGACATACATAGAAACACACACACATACATTAGATACGAACATAGAAACACAC
|
||||
ATTAGACGCGTACATAGACACAAACACATTGACAGGCAGTTCAGATGATGACGCCCGACTGATAC
|
||||
TCGCGTAGTCGTGGGAGGCAAGGCACACAGGGGATAGG
|
||||
'''.split())
|
||||
text = ''.join(textwrap.dedent('''\
|
||||
GACTAGCACTGTAGGGATAACAATTTCACACAGGTGGACAATTACATTGAAAATCACAGATTGGT
|
||||
CACACACACATTGGACATACATAGAAACACACACACATACATTAGATACGAACATAGAAACACAC
|
||||
ATTAGACGCGTACATAGACACAAACACATTGACAGGCAGTTCAGATGATGACGCCCGACTGATAC
|
||||
TCGCGTAGTCGTGGGAGGCAAGGCACACAGGGGATAGG
|
||||
''').split())
|
||||
pattern = 'TGCACTGTAGGGATAACAAT'
|
||||
|
||||
self.assertTrue(self.search(pattern, text, max_subs=2))
|
||||
|
@ -290,7 +292,16 @@ TCGCGTAGTCGTGGGAGGCAAGGCACACAGGGGATAGG
|
|||
self.assertFalse(self.search("ATTEST", "TESTOSTERONE", max_subs=2))
|
||||
|
||||
|
||||
class TestFindNearMatchesSubstitionsByteslike(TestHasNearMatchSubstitionsOnlyBase, unittest.TestCase):
|
||||
class TestHasNearMatchSubstitionsOnly(TestHasNearMatchSubstitionsOnlyBase,
|
||||
unittest.TestCase):
|
||||
def search(self, subsequence, sequence, max_subs):
|
||||
return has_near_match_substitutions_ngrams(subsequence, sequence, max_subs)
|
||||
|
||||
|
||||
class TestFindNearMatchesSubstitionsByteslike(
|
||||
TestHasNearMatchSubstitionsOnlyBase,
|
||||
unittest.TestCase
|
||||
):
|
||||
def search(self, subsequence, sequence, max_subs):
|
||||
return hnm_subs_byteslike(subsequence, sequence, max_subs)
|
||||
|
||||
|
|
Loading…
Reference in New Issue