Skip to content

Commit e89fa25

Browse files
committed
test(strings): add KMP empty-pattern and failure-array doctests
1 parent 215c1f0 commit e89fa25

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

‎strings/knuth_morris_pratt.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ def knuth_morris_pratt(text: str, pattern: str) -> int:
2020
... for s in ("kn", "h_m", "rr", "tt", "not there")
2121
... )
2222
True
23+
>>> knuth_morris_pratt("abc", "")
24+
0
25+
>>> knuth_morris_pratt("", "")
26+
0
2327
"""
2428

2529
# 1) Construct the failure array
@@ -47,6 +51,11 @@ def get_failure_array(pattern: str) -> list[int]:
4751
Calculates the new index we should go to if we fail a comparison
4852
:param pattern:
4953
:return:
54+
55+
>>> get_failure_array("abc")
56+
[0, 0, 0]
57+
>>> get_failure_array("aabaabaaa")
58+
[0, 1, 0, 1, 2, 3, 4, 5, 2]
5059
"""
5160
failure = [0]
5261
i = 0

0 commit comments

Comments
 (0)