예제 #1
0
 def check_lcp_array(self, t, n, reference):
     self.assertEqual(
         suffix_array.lcp_from_suffix_array(
             suffix_array.prefix_doubling(t, n), t, n), reference,
         'LCP array from suffix array')
     self.assertEqual(
         suffix_array.lcp_from_suffix_tree(suffix_tree.mccreight(t, n)[0]),
         reference, 'LCP array from suffix tree')
     self.assertEqual(
         suffix_array.lcp_kasai(suffix_array.prefix_doubling(t, n), t, n),
         reference, 'Algorithm: kasai')
예제 #2
0
 def test_random_lcp_array(self):
   T, n, A = 100, 500, ['a', 'b']
   for _ in range(T):
     t = rand.random_word(n, A)
     reference = suffix_array.lcp_from_suffix_array(
         suffix_array.prefix_doubling(t, n), t, n)
     self.check_lcp_array(t, n, reference)
예제 #3
0
 def test_all_lcp_array(self):
   N, A = 12, ['a', 'b']
   for n in range(2, N + 1):
     for t in itertools.product(A, repeat = n):
       t = '#' + ''.join(t)
       reference = suffix_array.lcp_from_suffix_array(
           suffix_array.prefix_doubling(t, n), t, n)
       self.check_lcp_array(t, n, 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)
예제 #5
0
import os
import unittest

import parameterized

from generator import rand
from string_indexing import farach, lcp, suffix_array, suffix_tree

LCP_ARRAY_ALGORITHMS = [
    [
        'Farach',
        farach.lcp_array,
    ],
    [
        'Kasai',
        lambda t, n: lcp.kasai(suffix_array.prefix_doubling(t, n), t, n),
    ],
    [
        'from suffix tree',
        lambda t, n: lcp.from_suffix_tree(suffix_tree.mccreight(t, n)[0]),
    ],
    [
        'from suffix array',
        lambda t, n: lcp.from_suffix_array(suffix_array.prefix_doubling(t, n),
                                           t, n),
    ]
]


class TestLcpArrays(unittest.TestCase):
    run_large = unittest.skipUnless(os.environ.get('LARGE', False),