From 2a4f028f8d3eef22aab3f50b6b4715a3d89aa8fc Mon Sep 17 00:00:00 2001 From: Tal Einat Date: Sat, 29 Mar 2014 13:57:17 +0300 Subject: [PATCH] added some tests for has_near_matches_* Conflicts: tests/test_generic_search.py tests/test_substitutions_only.py --- tests/test_generic_search.py | 14 ++++++++++++-- tests/test_substitutions_only.py | 27 +++++++++++++++++++-------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/tests/test_generic_search.py b/tests/test_generic_search.py index 5eec30d..b54303d 100644 --- a/tests/test_generic_search.py +++ b/tests/test_generic_search.py @@ -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) diff --git a/tests/test_substitutions_only.py b/tests/test_substitutions_only.py index 37aabf8..33c186b 100644 --- a/tests/test_substitutions_only.py +++ b/tests/test_substitutions_only.py @@ -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)