1 /******************************************
2 Copyright (c) 2016, Mate Soos
3 
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 THE SOFTWARE.
21 ***********************************************/
22 
23 #include "gtest/gtest.h"
24 
25 #include <set>
26 using std::set;
27 
28 #include "src/solver.h"
29 #include "src/matrixfinder.h"
30 #include "src/solverconf.h"
31 using namespace CMSat;
32 #include "test_helper.h"
33 
34 struct gauss : public ::testing::Test {
gaussgauss35     gauss()
36     {
37         must_inter.store(false, std::memory_order_relaxed);
38         SolverConf conf;
39         //conf.verbosity = 20;
40         s = new Solver(&conf, &must_inter);
41         s->new_vars(40);
42         s->conf.gaussconf.min_gauss_xor_clauses = 0;
43         mf = new MatrixFinder(s);
44     }
~gaussgauss45     ~gauss()
46     {
47         delete s;
48     }
49 
50     Solver* s;
51     MatrixFinder* mf = NULL;
52     std::vector<uint32_t> vars;
53     std::atomic<bool> must_inter;
54     vector<Xor> xs;
55     bool can_detach;
56 };
57 
TEST_F(gauss,min_rows)58 TEST_F(gauss, min_rows)
59 {
60     //s->conf.verbosity = 20;
61     s->conf.gaussconf.min_matrix_rows = 2;
62     xs.push_back(str_to_xors("1, 2, 3 = 0")[0]);
63     xs.push_back(str_to_xors("1, 2, 3, 4 = 0")[0]);
64     s->xor_clauses_updated = true;
65     s->xorclauses = xs;
66 
67     mf->findMatrixes(can_detach, false);
68 
69     EXPECT_EQ(s->gmatrices.size(), 1);
70 }
71 
TEST_F(gauss,min_rows_2)72 TEST_F(gauss, min_rows_2)
73 {
74     //s->conf.verbosity = 20;
75     s->conf.gaussconf.min_matrix_rows = 3;
76     xs.push_back(str_to_xors("1, 2, 3 = 0")[0]);
77     xs.push_back(str_to_xors("1, 2, 3, 4 = 0")[0]);
78     s->xor_clauses_updated = true;
79     s->xorclauses = xs;
80 
81     mf->findMatrixes(can_detach, false);
82 
83     EXPECT_EQ(s->gmatrices.size(), 0);
84 }
85 
TEST_F(gauss,separate_1)86 TEST_F(gauss, separate_1)
87 {
88     //s->conf.verbosity = 20;
89     s->conf.gaussconf.min_matrix_rows = 1;
90     xs.push_back(str_to_xors("1, 2, 3 = 0")[0]);
91     xs.push_back(str_to_xors("5, 6, 7, 8 = 0")[0]);
92     s->xor_clauses_updated = true;
93     s->xorclauses = xs;
94 
95     mf->findMatrixes(can_detach, false);
96 
97     EXPECT_EQ(s->gmatrices.size(), 2);
98 }
99 
TEST_F(gauss,separate_2)100 TEST_F(gauss, separate_2)
101 {
102     //s->conf.verbosity = 20;
103     s->conf.gaussconf.min_matrix_rows = 1;
104     xs.push_back(str_to_xors("1, 2, 3 = 0")[0]);
105     xs.push_back(str_to_xors("4, 5, 6 = 0")[0]);
106     xs.push_back(str_to_xors("3, 4, 10 = 0")[0]);
107 
108     xs.push_back(str_to_xors("15, 16, 17, 18 = 0")[0]);
109     xs.push_back(str_to_xors("11, 15, 19 = 0")[0]);
110     xs.push_back(str_to_xors("19, 20, 12 = 0")[0]);
111     s->xor_clauses_updated = true;
112     s->xorclauses = xs;
113 
114     mf->findMatrixes(can_detach, false);
115 
116     EXPECT_EQ(s->gmatrices.size(), 2);
117 }
118 
TEST_F(gauss,separate_3)119 TEST_F(gauss, separate_3)
120 {
121     //s->conf.verbosity = 20;
122     s->conf.gaussconf.min_matrix_rows = 1;
123     xs.push_back(str_to_xors("1, 2, 3 = 0")[0]);
124     xs.push_back(str_to_xors("4, 5, 6 = 0")[0]);
125     xs.push_back(str_to_xors("3, 4, 10 = 0")[0]);
126 
127     xs.push_back(str_to_xors("15, 16, 17, 18 = 0")[0]);
128     xs.push_back(str_to_xors("11, 15, 19 = 0")[0]);
129     xs.push_back(str_to_xors("19, 20, 12 = 0")[0]);
130 
131     xs.push_back(str_to_xors("21, 22, 23, 29 = 0")[0]);
132     xs.push_back(str_to_xors("21, 28, 29 = 0")[0]);
133     xs.push_back(str_to_xors("25, 21, 27 = 0")[0]);
134     s->xor_clauses_updated = true;
135     s->xorclauses = xs;
136 
137     mf->findMatrixes(can_detach, false);
138 
139     EXPECT_EQ(s->gmatrices.size(), 3);
140 }
141 
main(int argc,char ** argv)142 int main(int argc, char **argv) {
143   ::testing::InitGoogleTest(&argc, argv);
144   return RUN_ALL_TESTS();
145 }
146