Repository: TheAlgorithms/C-Plus-Plus
File: strings/boyer_moore.cpp (C++)

Code before:
 * @brief Check if pat is prefix of str.
 *
 * @param str pointer to some part of the input text.
 * @param pat the searched pattern.
 * @param len length of the searched pattern
 * @return true if pat is prefix of str. false otherwise.
 */
bool is_prefix(const char* str, const char* pat, size_t len) {
    if (strlen(str) < len) {
        return false;
    }

    for (size_t i = 0; i < len; i++) {
        if (str[i] != pat[i]) {
            return false;
        }
    }

    return true;
}
}  // namespace boyer_moore
}  // namespace strings
/**
 * @brief A test case in which we search for every appearance of the word 'and'
 * @param text The text in which we search for appearance of the word 'and'
 */
void and_test(const char* text) {
    strings::boyer_moore::pattern ands;
    strings::boyer_moore::init_pattern("and", ands);
    std::vector<size_t> indexes = strings::boyer_moore::search(text, ands);

    assert(indexes.size() == 2);
    assert(strings::boyer_moore::is_prefix(text + indexes[0], "and", 3));
    assert(strings::boyer_moore::is_prefix(text + indexes[1], "and", 3));
}

/**
 * @brief  A test case in which we search for every appearance of the word 'pat'
 * @param text The text in which we search for appearance of the word 'pat'
 */
void pat_test(const char* text) {
    strings::boyer_moore::pattern pat;
    strings::boyer_moore::init_pattern("pat", pat);
    std::vector<size_t> indexes = strings::boyer_moore::search(text, pat);

    assert(indexes.size() == 6);

    for (const auto& idx : indexes) {
        assert(strings::boyer_moore::is_prefix(text + idx, "pat", 3));
    }
}

Review comment (suggestion):
```suggestion
 * @param text The text in which we search for appearance of the word 'and'
 * @returns void
```

Code after:
 * @brief Check if pat is prefix of str.
 *
 * @param str pointer to some part of the input text.
 * @param pat the searched pattern.
 * @param len length of the searched pattern
 * @returns `true` if pat IS prefix of str.
 * @returns `false` if pat is NOT a prefix of str.
 */
bool is_prefix(const char* str, const char* pat, size_t len) {
    if (strlen(str) < len) {
        return false;
    }

    for (size_t i = 0; i < len; i++) {
        if (str[i] != pat[i]) {
            return false;
        }
    }

    return true;
}
}  // namespace boyer_moore
}  // namespace strings
/**
 * @brief A test case in which we search for every appearance of the word 'and'
 * @param text The text in which we search for appearance of the word 'and'
 * @returns void
 */
void and_test(const char* text) {
    strings::boyer_moore::pattern ands;
    strings::boyer_moore::init_pattern("and", ands);
    std::vector<size_t> indexes = strings::boyer_moore::search(text, ands);

    assert(indexes.size() == 2);
    assert(strings::boyer_moore::is_prefix(text + indexes[0], "and", 3));
    assert(strings::boyer_moore::is_prefix(text + indexes[1], "and", 3));
}

/**
 * @brief  A test case in which we search for every appearance of the word 'pat'
 * @param text The text in which we search for appearance of the word 'pat'
 * @returns void
 */
void pat_test(const char* text) {
    strings::boyer_moore::pattern pat;
    strings::boyer_moore::init_pattern("pat", pat);
    std::vector<size_t> indexes = strings::boyer_moore::search(text, pat);

    assert(indexes.size() == 6);

    for (const auto& currentIndex : indexes) {