Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 769b3c7

Browse files
jasonjyurealstealthninja
andauthored
Added to z_function test corner cases for empty text and pattern (TheAlgorithms#2863)
Co-authored-by: realstealthninja <68815218+realstealthninja@users.noreply.github.com>
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

Lines changed: 16 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /