From 769b3c71c1e10d5134f926435e012172d79d7166 Mon Sep 17 00:00:00 2001 From: jasonjyu Date: Sat, 16 Nov 2024 23:09:59 -0500 Subject: [PATCH] Added to z_function test corner cases for empty text and pattern (#2863) Co-authored-by: realstealthninja <68815218+realstealthninja@users.noreply.github.com> --- strings/z_function.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/strings/z_function.cpp b/strings/z_function.cpp index d32f19b9f..627e2ef68 100644 --- a/strings/z_function.cpp +++ b/strings/z_function.cpp @@ -85,6 +85,22 @@ static void test() { // matching_indexes2 gets the indexes where pattern2 exists in text2 std::vector matching_indexes2 = find_pat_in_text(pattern2, text2); assert((matching_indexes2 == std::vector{})); + + // corner case - empty text + std::string text3 = ""; + std::string pattern3 = "abc"; + + // matching_indexes3 gets the indexes where pattern3 exists in text3 + std::vector matching_indexes3 = find_pat_in_text(pattern3, text3); + assert((matching_indexes3 == std::vector{})); + + // corner case - empty pattern + std::string text4 = "redsand"; + std::string pattern4 = ""; + + // matching_indexes4 gets the indexes where pattern4 exists in text4 + std::vector matching_indexes4 = find_pat_in_text(pattern4, text4); + assert((matching_indexes4 == std::vector{0, 1, 2, 3, 4, 5, 6})); } /**