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

Function test

code/other/two_sat.test.cpp:1–44  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1void test() {
2 /* Field testing: NWERC 2012 Problem I, Kattis pieceittogether */
3 /* TODO: UVa 11294, UVa 10319 */
4
5 for (int n = 1; n <= 15; n++) {
6 for (int iter = 0; iter < 100; iter++) {
7 int cnt = randint(1, 100);
8 vii clauses(cnt);
9 for (int i = 0; i < cnt; i++) {
10 int a = randint(1, n) * (randint(1, 2) == 1 ? 1 : -1);
11 int b = randint(1, n) * (randint(1, 2) == 1 ? 1 : -1);
12 clauses[i] = ii(a, b);
13 }
14 // cout << n << " " << iter << " " << cnt << endl;
15
16 TwoSat ts(n);
17 iter(it,clauses) {
18 ts.add_or(it->first, it->second);
19 }
20 if (ts.sat()) {
21 vector<bool> is_true(n+1, false);
22 // for (int i = 0; i < size(all_truthy); i++) if (all_truthy[i] > 0) is_true[all_truthy[i]] = true;
23 rep(i,0,n) if (V[n+(i+1)].val == 1) is_true[i+1] = true;
24 for (int i = 0; i < cnt; i++) {
25 bool a = is_true[abs(clauses[i].first)],
26 b = is_true[abs(clauses[i].second)];
27 assert_true((clauses[i].first > 0 ? a : !a) || (clauses[i].second > 0 ? b : !b), true);
28 }
29 } else {
30 for (int j = 0; j < (1<<n); j++) {
31
32 bool ok = true;
33 for (int i = 0; i < cnt; i++) {
34 bool a = j & (1 << (abs(clauses[i].first) - 1)),
35 b = j & (1 << (abs(clauses[i].second) - 1));
36 ok = ok && ((clauses[i].first > 0 ? a : !a) || (clauses[i].second > 0 ? b : !b));
37 }
38
39 assert_false(ok, true);
40 }
41 }
42 }
43 }
44}
45// vim: cc=60 ts=2 sts=2 sw=2:

Callers

nothing calls this directly

Calls 4

assert_trueFunction · 0.85
assert_falseFunction · 0.85
satMethod · 0.80
randintFunction · 0.50

Tested by

no test coverage detected