def check_get_all_exact_matches(self, t, w, n, m, reference):
     for algorithm in EXACT_STRING_MATCHING_ALGORITHMS:
         self.assertEqual(
             list(algorithm(t, w, n, m)), reference,
             'Algorithm {}, text {}, pattern {}'.format(
                 algorithm.__name__, t, w))
     self.assertEqual(
         list(suffix_tree.contains(suffix_tree.naive(t, n), t, w, n, m)),
         reference, 'Suffix tree, text {}, pattern {}'.format(t, w))
     self.assertEqual(
         list(suffix_array.contains(suffix_array.naive(t, n), t, w, n, m)),
         reference, 'Suffix array, text {}, pattern {}'.format(t, w))
 def check_no_match(self, t, w, n, m):
     for algorithm in EXACT_STRING_MATCHING_ALGORITHMS:
         self.assertFalse(
             list(algorithm(t, w, n, m)),
             'Algorithm {}, text {}, pattern {}'.format(
                 algorithm.__name__, t, w))
     self.assertFalse(
         list(suffix_tree.contains(suffix_tree.naive(t, n), t, w, n, m)),
         'Suffix tree, text {}, pattern {}'.format(t, w))
     self.assertFalse(
         list(suffix_array.contains(suffix_array.naive(t, n), t, w, n, m)),
         'Suffix array, text {}, pattern {}'.format(t, w))
示例#3
0
  def test_random_lcp_lr_matching(self):
    T, n, A = 1000, 500, ['a', 'b']
    m, TT = 10, 10
    for _ in range(T):
      text = rand.random_word(n, A)
      sa = suffix_array.skew(text, n)
      lcp = suffix_array.lcp_kasai(sa, text, n)
      lcplr = lcp_lr.lcplr_from_lcp(lcp, n)

      for _ in range(TT):
        word = rand.random_word(m, A)
        reference = suffix_array.contains(sa, text, word, n, m)
        self.assertEqual(list(lcp_lr.contains_with_lcplr(
            sa, lcplr, text, word, n, m)), list(reference))
    [
        'Boyer-Moore-Apostolico-Giancarlo',
        backward.boyer_moore_apostolico_giancarlo
    ],
    ['Horspool', backward.horspool],
    ['Karp-Rabin', other.karp_rabin],
    ['fast-on-average', other.fast_on_average],
    ['two-way constant space', other.two_way],
    [
        'suffix tree',
        lambda t, w, n, m: suffix_tree.contains(
            suffix_tree.mccreight(t, n)[0], t, w, n, m),
    ],
    [
        'suffix array',
        lambda t, w, n, m: suffix_array.contains(
            suffix_array.prefix_doubling(t, n), t, w, n, m),
    ],
    ['lcp-lr array', lcp_lr_contains],
]


class TestExactStringMatching(unittest.TestCase):
    run_large = unittest.skipUnless(os.environ.get('LARGE', False),
                                    'Skip test in small runs')

    def check_first_exact_match(self, t, w, n, m, reference, algorithm):
        self.assertEqual(next(algorithm(t, w, n, m)), reference)

    def check_all_exact_matches(self, t, w, n, m, reference, algorithm):
        self.assertEqual(list(algorithm(t, w, n, m)), reference)