forked from cp-algorithms/cp-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_aho_corasick.cpp
More file actions
58 lines (50 loc) · 1.17 KB
/
test_aho_corasick.cpp
File metadata and controls
58 lines (50 loc) · 1.17 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
#include <cassert>
#include <vector>
#include <string>
#include <iostream>
using namespace std;
namespace Trie {
#include "aho_corasick_trie_definition.h"
#include "aho_corasick_trie_add.h"
}
namespace Automaton {
#include "aho_corasick_automaton.h"
}
void test_trie() {
using namespace Trie;
vector<string> set = {"a", "to", "tea", "ted", "ten", "i", "in", "inn"};
for (string s : set) {
add_string(s);
}
assert(trie.size() == 11);
}
void test_automaton() {
using namespace Automaton;
vector<string> set = {"a", "ab", "bab", "bc", "bca", "c", "caa"};
for (string s : set) {
add_string(s);
}
assert(t.size() == 11);
int v = 0;
v = go(v, 'a');
assert(t[v].output == true);
v = go(v, 'b');
assert(t[v].output == true);
v = go(v, 'c');
assert(t[v].output == true);
v = go(v, 'd');
assert(t[v].output == false);
assert(v == 0);
v = go(v, 'b');
assert(t[v].output == false);
v = go(v, 'a');
assert(t[v].output == false);
v = go(v, 'a');
assert(t[v].output == true);
v = go(v, 'b');
assert(t[v].output == true);
}
int main() {
test_trie();
test_automaton();
}