MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / test_rabin_karp

Function test_rabin_karp

strings/rabin_karp.py:54–87  ·  view source on GitHub ↗

>>> test_rabin_karp() Success.

()

Source from the content-addressed store, hash-verified

52
53
54def test_rabin_karp() -> None:
55 """
56 >>> test_rabin_karp()
57 Success.
58 """
59 # Test 1)
60 pattern = "abc1abc12"
61 text1 = "alskfjaldsabc1abc1abc12k23adsfabcabc"
62 text2 = "alskfjaldsk23adsfabcabc"
63 assert rabin_karp(pattern, text1)
64 assert not rabin_karp(pattern, text2)
65
66 # Test 2)
67 pattern = "ABABX"
68 text = "ABABZABABYABABX"
69 assert rabin_karp(pattern, text)
70
71 # Test 3)
72 pattern = "AAAB"
73 text = "ABAAAAAB"
74 assert rabin_karp(pattern, text)
75
76 # Test 4)
77 pattern = "abcdabcy"
78 text = "abcxabcdabxabcdabcdabcy"
79 assert rabin_karp(pattern, text)
80
81 # Test 5)
82 pattern = "Lü"
83 text = "Lüsai"
84 assert rabin_karp(pattern, text)
85 pattern = "Lue"
86 assert not rabin_karp(pattern, text)
87 print("Success.")
88
89
90if __name__ == "__main__":

Callers 1

rabin_karp.pyFile · 0.85

Calls 1

rabin_karpFunction · 0.85

Tested by

no test coverage detected