MCPcopy Create free account
hub / github.com/cp-algorithms/cp-algorithms / main

Function main

test/test_prefix.cpp:25–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23
24
25int main() {
26 string s = "abcabcdabcabca";
27 vector<int> prefix = {0, 0, 0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 6, 4};
28 assert(slow::prefix_function(s) == prefix);
29 assert(fast::prefix_function(s) == prefix);
30
31 vector<int> pi = fast::prefix_function(s);
32 int n = s.size();
33#include "prefix_count_each_prefix.h"
34 vector<int> prefix_cnt = {15, 5, 4, 4, 3, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1};
35 assert(ans == prefix_cnt);
36
37 string t = "babcbabcad";
38 vector<int> pi_t = {0, 1, 2, 3, 0, 1, 2, 3, 4, 0};
39 vector<vector<int>> aut;
40 AutomatonSlow::compute_automaton(s, aut);
41 int pi_cur = 0;
42 for (int i = 0; i < (int)t.size(); i++) {
43 pi_cur = aut[pi_cur][t[i] - 'a'];
44 assert(pi_cur == pi_t[i]);
45 }
46
47 aut.clear();
48 AutomatonFast::compute_automaton(s, aut);
49 pi_cur = 0;
50 for (int i = 0; i < (int)t.size(); i++) {
51 pi_cur = aut[pi_cur][t[i] - 'a'];
52 assert(pi_cur == pi_t[i]);
53 }
54}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected