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

Function test

code/other/dpll.test.cpp:1–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1void test() {
2 // Field testing: https://icpc.kattis.com/problems/checks
3 // Was too slow on https://open.kattis.com/problems/boardcovering
4 rep(its,0,1000) {
5 int n = rng() % 20 + 1,
6 m = rng() % (4*n);
7 vector<vi> cl;
8 rep(i,0,m) {
9 vi cur;
10 while (cur.empty()) rep(j,0,n) {
11 if (rng() % 4 == 0) {
12 if (rng() % 2 == 0) {
13 cur.push_back(-(j+1));
14 } else {
15 cur.push_back(j+1);
16 }
17 }
18 }
19 cl.push_back(cur);
20 }
21
22 bool poss = false;
23 rep(s,0,1<<n) {
24 bool ok = true;
25 rep(i,0,m) {
26 bool found = false;
27 iter(it,cl[i]) {
28 int t = abs(*it) - 1;
29 if (((s & (1<<t)) != 0) == (*it > 0)) {
30 found = true;
31 break;
32 }
33 }
34 if (!found) {
35 ok = false;
36 break;
37 }
38 }
39 if (ok) {
40 poss = true;
41 break;
42 }
43 }
44
45 SAT sat;
46 rep(i,0,n) sat.var();
47 iter(it,cl) {
48 sat.clause(*it);
49 }
50
51 bool found = sat.solve();
52
53 assert_equal(poss, found);
54
55 if (found) {
56 rep(j,0,n) {
57 assert_not_equal(sat.get_value(j+1), sat.get_value(-(j+1)));
58 }
59
60 rep(i,0,m) {

Callers

nothing calls this directly

Calls 8

assert_not_equalFunction · 0.85
assert_trueFunction · 0.85
push_backMethod · 0.80
varMethod · 0.80
solveMethod · 0.80
get_valueMethod · 0.80
assert_equalFunction · 0.50
emptyMethod · 0.45

Tested by

no test coverage detected