-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
40 lines (28 loc) · 1 KB
/
Copy pathexample.py
File metadata and controls
40 lines (28 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python3
import unittest
from src.string.kmp.template import KMP
class TestKMP(unittest.TestCase):
def test_single_match(self):
kmp = KMP("hello world", "world")
self.assertEqual(kmp.matches, [6])
def test_multiple_matches(self):
kmp = KMP("abababa", "aba")
self.assertEqual(kmp.matches, [0, 2, 4])
def test_no_match(self):
kmp = KMP("abcdef", "xyz")
self.assertEqual(kmp.matches, [])
def test_pattern_longer_than_text(self):
kmp = KMP("ab", "abcdef")
self.assertEqual(kmp.matches, [])
def test_overlapping_pattern(self):
kmp = KMP("aaaaa", "aa")
self.assertEqual(kmp.matches, [0, 1, 2, 3])
def test_single_character(self):
kmp = KMP("abcabc", "a")
self.assertEqual(kmp.matches, [0, 3])
def test_compute_nxt(self):
kmp = KMP("", "abcab")
nxt = kmp.computeNxt("abcab")
self.assertEqual(nxt, [0, 0, 0, 1, 2])
if __name__ == "__main__":
unittest.main()