Skip to content

Commit 769b3c7

Browse files
jasonjyurealstealthninja
andauthoredNov 17, 2024··
Added to z_function test corner cases for empty text and pattern (#2863)
Co-authored-by: realstealthninja <[email protected]>
1 parent acb9ac2 commit 769b3c7

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
 

‎strings/z_function.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,22 @@ static void test() {
8585
// matching_indexes2 gets the indexes where pattern2 exists in text2
8686
std::vector<uint64_t> matching_indexes2 = find_pat_in_text(pattern2, text2);
8787
assert((matching_indexes2 == std::vector<uint64_t>{}));
88+
89+
// corner case - empty text
90+
std::string text3 = "";
91+
std::string pattern3 = "abc";
92+
93+
// matching_indexes3 gets the indexes where pattern3 exists in text3
94+
std::vector<uint64_t> matching_indexes3 = find_pat_in_text(pattern3, text3);
95+
assert((matching_indexes3 == std::vector<uint64_t>{}));
96+
97+
// corner case - empty pattern
98+
std::string text4 = "redsand";
99+
std::string pattern4 = "";
100+
101+
// matching_indexes4 gets the indexes where pattern4 exists in text4
102+
std::vector<uint64_t> matching_indexes4 = find_pat_in_text(pattern4, text4);
103+
assert((matching_indexes4 == std::vector<uint64_t>{0, 1, 2, 3, 4, 5, 6}));
88104
}
89105

90106
/**

0 commit comments

Comments
 (0)
Please sign in to comment.