def test_random_big(self, _, build, algorithm): T, n, m, A = 100, 1000, 100, ['a', 'b', 'c'] for _ in range(T): t = random_word(n, A) W = {random_word(random.randint(2, 5), A) for _ in range(m)} reference = [(w[1:], i) for w in W for i in forward.brute_force(t, w, n, len(w) - 1)] self.check_all_matches(t, n, W, reference, build, algorithm)
def test_all_exact_string_matching(self): N, M, A = 7, 3, ['a', 'b'] for n in range(2, N + 1): for m in range(1, M + 1): for t in itertools.product(A, repeat=n): t = '#' + ''.join(t) for w in itertools.product(A, repeat=m): w = '#' + ''.join(w) reference = list(forward.brute_force(t, w, n, m)) self.check_get_all_exact_matches(t, w, n, m, reference)
def test_random_small(self): n, m, A = 100, 25, ['a', 'b', 'c'] for _ in range(100): t = random_word(n, A) patterns = {(random_word(randint(2, 5), A)) for _ in range(m)} cw_automat = commentz_walter_build(patterns) expected = set() for p in patterns: starts = brute_force(t, p, n, len(p) - 1) indices = [(p, i) for i in starts] expected.union(set(indices)) found = set(commentz_walter_search(t[1::], n, cw_automat)) self.assertSetEqual(expected, found)
def test_random(self): n, m, A = 500, 30, ['a', 'b', 'c'] for _ in range(100): t = random_word(n, A) patterns = {random_word(randint(2, 10), A) for _ in range(m)} automaton = self._create_from(patterns) expected = set() for p in patterns: starts = brute_force(t, f'#{p}', n, len(p) + 1) expected.union({(p, i) for i in starts}) found = set(find_occurrences(t, n, automaton)) self.assertSetEqual(expected, found)
def test_random_small(self): n, m, A = 100, 25, ['a', 'b', 'c'] for _ in range(100): t = random_word(n, A) patterns = {(random_word(randint(2, 5), A)) for _ in range(m)} cw_automat = fast_practical_multi_string_matching_build(patterns) expected = set() for p in patterns: starts = brute_force(t, p, n, len(p) - 1) indices = [(p, i) for i in starts] expected.union(set(indices)) found = set( fast_practical_multi_string_matching(t[1::], n, cw_automat)) self.assertSetEqual(expected, found)
def test_random_exact_string_matching(self): T, n, m, A = 100, 500, 10, ['a', 'b'] for _ in range(T): t, w = rand.random_word(n, A), rand.random_word(m, A) reference = list(forward.brute_force(t, w, n, m)) self.check_get_all_exact_matches(t, w, n, m, reference)