This repository was archived by the owner on Feb 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlongest_repeated_substring.hpp
More file actions
69 lines (60 loc) · 2.2 KB
/
longest_repeated_substring.hpp
File metadata and controls
69 lines (60 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Andrew Naplavkov
#ifndef STEP_TEST_LONGEST_REPEATED_SUBSTRING_HPP
#define STEP_TEST_LONGEST_REPEATED_SUBSTRING_HPP
#include <map>
#include <step/longest_repeated_substring.hpp>
#include <step/test/case_insensitive.hpp>
#include <string_view>
TEST_CASE("longest_repeated_substring_hello_world")
{
auto range = step::longest_repeated_substring::find_with_suffix_array(
"the longest substring of a string that occurs at least twice");
CHECK("string " == std::string(range.first, range.second));
}
TEST_CASE("longest_repeated_substring_find")
{
struct {
std::string_view str;
std::string_view expect;
} tests[] = {
{"GEEKSFORGEEKS$", "GEEKS"},
{"AAAAAAAAAA$", "AAAAAAAAA"},
{"ABCDEFG$", ""},
{"ABABABA$", "ABABA"},
{"ATCGATCGA$", "ATCGA"},
{"banana$", "ana"},
{"ATCGATCGA$", "ATCGA"},
{"mississippi$", "issi"},
{"abcabcaacb$", "abca"},
{"aababa$", "aba"},
};
for (auto& [str, expect] : tests) {
auto arr_rng =
step::longest_repeated_substring::find_with_suffix_array(str);
CHECK(expect == std::string(arr_rng.first, arr_rng.second));
auto tree_rng =
step::longest_repeated_substring::find_with_suffix_tree<std::map>(
str);
CHECK(expect == std::string(tree_rng.first, tree_rng.second));
}
}
TEST_CASE("longest_repeated_substring_case_insensitive")
{
const char str[] = "geeksForGeeks";
const std::string expect = "geeks";
auto arr_rng = step::longest_repeated_substring::find_with_suffix_array<
step::case_insensitive::less>(str);
CHECK(std::equal(expect.begin(),
expect.end(),
arr_rng.first,
arr_rng.second,
step::case_insensitive::equal_to{}));
auto tree_rng = step::longest_repeated_substring::find_with_suffix_tree<
step::case_insensitive::unordered_map>(str);
CHECK(std::equal(expect.begin(),
expect.end(),
tree_rng.first,
tree_rng.second,
step::case_insensitive::equal_to{}));
}
#endif // STEP_TEST_LONGEST_REPEATED_SUBSTRING_HPP