Skip to content

Commit a841b20

Browse files
committed
Added to z_function test corner cases for empty text and pattern
1 parent 34d3568 commit a841b20

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

strings/z_function.cpp

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

89105
/**

0 commit comments

Comments
 (0)