Beispiel #1
0
 def test_kmp_algorithm_other(self):
     pat = 'abcdabcy'
     txt = 'abcxabcdabcdabcy'
     expected = [m.start() for m in re.finditer(pat, txt)]
     assert modified_kmp.kmp(pat, txt, 0) == expected
Beispiel #2
0
 def test_all_kmp(self):
     for i in range(2, 1000):
         pat = random_string(random.randint(1, i))
         txt = random_string(i)
         expected = [m.start() for m in re.finditer(pat, txt)]
         assert modified_kmp.kmp(pat, txt, 0) == expected
Beispiel #3
0
 def test_kmp_algorithm(self):
     pat = 'abc'
     txt = 'abcdabcdabcd'
     expected = [1, 5, 9]
     assert modified_kmp.kmp(pat, txt) == expected
Beispiel #4
0
 def test_kmp_no_match_3(self):
     """Test no match when pattern > text."""
     pat = '6FjKojoBhRk8YbMH9fau0fHk9S38S5LcJ2LSzOApSw9ScEOlN4p0bKbbLlmurKYG0epr5O3RrU2avmQA1pPK02'  # noqa: E501
     txt = '02mTAg8avVRF01uKrsuuLJzKU36WzL6VUJiHvBDQxfA7PoN4vy9JR7oEg3x76yeRsEOOoDRNmwfXgEXIlmtjJrEwSp7ptRwFquP8u0'  # noqa: E501
     expected = [m.start() for m in re.finditer(pat, txt)]
     assert modified_kmp.kmp(pat, txt, 0) == expected
Beispiel #5
0
 def test_kmp_no_match_4(self):
     """Test no match when pattern > text."""
     pat = 'l'
     txt = 'lFx0OyuczjmH'
     expected = [m.start() for m in re.finditer(pat, txt)]
     assert modified_kmp.kmp(pat, txt, 0) == expected
Beispiel #6
0
 def test_kmp_no_match_2(self):
     """Test no match when pattern > text."""
     pat = 'Ap'
     txt = 'poFfTzfHQAOD9Duwe9eB3gRaJIGIgyW35DWJjplV'
     expected = [m.start() for m in re.finditer(pat, txt)]
     assert modified_kmp.kmp(pat, txt, 0) == expected
Beispiel #7
0
 def test_kmp_incorrect_len(self):
     """Test no match when pattern > text."""
     pat = 'abcd'
     txt = 'abc'
     expected = [m.start() for m in re.finditer(pat, txt)]
     assert modified_kmp.kmp(pat, txt, 0) == expected
Beispiel #8
0
 def test_kmp_no_match(self):
     """Test no matches."""
     pat = 'abc'
     txt = 'abdabdabe'
     expected = [m.start() for m in re.finditer(pat, txt)]
     assert modified_kmp.kmp(pat, txt, 0) == expected
Beispiel #9
0
 def test_kmp_match_2(self):
     """Test matches on further iteration."""
     pat = 'abc'
     txt = 'abcdabcd'
     expected = [m.start() for m in re.finditer(pat, txt)]
     assert modified_kmp.kmp(pat, txt, 0) == expected
Beispiel #10
0
 def test_kmp_match_13(self):
     pat = '33'
     txt = 'abc'
     expected = [m.start() for m in re.finditer(pat, txt)]
     assert modified_kmp.kmp(pat, txt, 0) == expected