MCPcopy Create free account
hub / github.com/SuprDewd/CompetitiveProgramming / test

Function test

code/graph/tarjan_olca.test.cpp:132–168  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

130};
131
132void test() {
133 int tests = 100;
134
135 for (int t = 0; t < tests; t++) {
136 int n = rng() % 10000 + 1;
137 int q = rng() % 10000 + 1;
138
139 pair<vi*, int> xadj = random_tree(n);
140 vi *adj = xadj.first;
141 int root = xadj.second;
142
143 int *ps = pars(n, adj);
144
145 lca_tree tr(n, root, adj);
146 tarjan_olca lca(n, adj);
147
148 vii qs;
149 for (int i = 0; i < q; i++) {
150 int a = rng() % n,
151 b = rng() % n;
152
153 qs.push_back(ii(a, b));
154 lca.query(a, b);
155 }
156
157 lca.process(root);
158
159 for (int i = 0; i < q; i++) {
160 int correct = lca_slow(n, ps, qs[i].first, qs[i].second);
161 int maybe = lca.answers[i];
162 int maybe2 = tr.lca(qs[i].first, qs[i].second);
163 assert_equal(correct, maybe);
164 assert_equal(correct, maybe2);
165 }
166 }
167
168}
169// vim: cc=60 ts=2 sts=2 sw=2:

Callers

nothing calls this directly

Calls 8

random_treeFunction · 0.85
parsFunction · 0.85
lca_slowFunction · 0.85
push_backMethod · 0.80
processMethod · 0.80
assert_equalFunction · 0.50
queryMethod · 0.45
lcaMethod · 0.45

Tested by

no test coverage detected