| 1 |
|
package org.sat4j.minisat; |
| 2 |
|
|
| 3 |
|
import java.io.IOException; |
| 4 |
|
|
| 5 |
|
import junit.framework.TestCase; |
| 6 |
|
|
| 7 |
|
import org.sat4j.core.VecInt; |
| 8 |
|
import org.sat4j.minisat.core.ILits; |
| 9 |
|
import org.sat4j.minisat.core.Solver; |
| 10 |
|
import org.sat4j.reader.InstanceReader; |
| 11 |
|
import org.sat4j.reader.ParseFormatException; |
| 12 |
|
import org.sat4j.specs.ContradictionException; |
| 13 |
|
import org.sat4j.specs.IConstr; |
| 14 |
|
import org.sat4j.specs.ISolver; |
| 15 |
|
import org.sat4j.specs.IVecInt; |
| 16 |
|
import org.sat4j.specs.TimeoutException; |
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
|
| 23 |
|
|
| 24 |
|
|
| 25 |
|
@author |
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
|
|
|
| 0% |
Uncovered Elements: 153 (153) |
Complexity: 22 |
Complexity Density: 0,26 |
|
| 30 |
|
public class TestsFonctionnels extends TestCase { |
| 31 |
|
|
| 32 |
|
private static final String PREFIX = System.getProperty("test.prefix"); |
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
@param |
| 38 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 39 |
0
|
public TestsFonctionnels(String arg0) {... |
| 40 |
0
|
super(arg0); |
| 41 |
|
} |
| 42 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 3 |
Complexity Density: 0,6 |
4
-
|
|
| 43 |
0
|
public void testSat() {... |
| 44 |
0
|
try { |
| 45 |
0
|
reader.parseInstance(PREFIX + "aim-50-yes-ok.cnf"); |
| 46 |
0
|
assertTrue(solver.isSatisfiable()); |
| 47 |
|
} catch (TimeoutException e) { |
| 48 |
0
|
fail(); |
| 49 |
|
} catch (Exception e) { |
| 50 |
0
|
fail(); |
| 51 |
|
} |
| 52 |
|
} |
| 53 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 4 |
Complexity Density: 0,8 |
4
-
|
|
| 54 |
0
|
public void testUnsat() throws TimeoutException {... |
| 55 |
0
|
try { |
| 56 |
0
|
reader.parseInstance(PREFIX + "aim-50-no-ok.cnf"); |
| 57 |
0
|
assertFalse(solver.isSatisfiable()); |
| 58 |
|
} catch (IOException e) { |
| 59 |
0
|
fail(); |
| 60 |
|
} catch (ParseFormatException e) { |
| 61 |
0
|
fail(); |
| 62 |
|
} catch (ContradictionException e) { |
| 63 |
|
|
| 64 |
|
} |
| 65 |
|
} |
| 66 |
|
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 3 |
Complexity Density: 0,23 |
4
-
|
|
| 67 |
0
|
public void testTrivialUnsat() {... |
| 68 |
0
|
solver.newVar(1); |
| 69 |
0
|
IVecInt vec = new VecInt(); |
| 70 |
0
|
solver.newVar(); |
| 71 |
0
|
solver.newVar(); |
| 72 |
0
|
vec.push(1); |
| 73 |
0
|
try { |
| 74 |
0
|
solver.addClause(vec); |
| 75 |
|
} catch (ContradictionException e) { |
| 76 |
0
|
fail(); |
| 77 |
|
} |
| 78 |
0
|
vec.clear(); |
| 79 |
0
|
vec.push(-1); |
| 80 |
0
|
try { |
| 81 |
0
|
solver.addClause(vec); |
| 82 |
0
|
fail(); |
| 83 |
|
} catch (ContradictionException e1) { |
| 84 |
|
} |
| 85 |
|
} |
| 86 |
|
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 2 |
Complexity Density: 0,18 |
4
-
|
|
| 87 |
0
|
public void testTrivialSat() throws TimeoutException {... |
| 88 |
0
|
solver.reset(); |
| 89 |
0
|
solver.newVar(2); |
| 90 |
0
|
try { |
| 91 |
0
|
IVecInt vec = new VecInt(); |
| 92 |
0
|
vec.push(1); |
| 93 |
0
|
solver.addClause(vec); |
| 94 |
0
|
vec.clear(); |
| 95 |
0
|
vec.push(-2); |
| 96 |
0
|
solver.addClause(vec); |
| 97 |
0
|
assertTrue(solver.isSatisfiable()); |
| 98 |
|
} catch (ContradictionException e) { |
| 99 |
0
|
fail(); |
| 100 |
|
} |
| 101 |
|
} |
| 102 |
|
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 2 |
Complexity Density: 0,17 |
4
-
|
|
| 103 |
0
|
public void testTrivialSatNewVar() throws TimeoutException {... |
| 104 |
0
|
try { |
| 105 |
0
|
solver.newVar(0); |
| 106 |
0
|
solver.newVar(); |
| 107 |
0
|
IVecInt vec = new VecInt(); |
| 108 |
0
|
vec.push(1); |
| 109 |
0
|
solver.addClause(vec); |
| 110 |
0
|
vec.clear(); |
| 111 |
0
|
solver.newVar(); |
| 112 |
0
|
vec.push(-2); |
| 113 |
0
|
solver.addClause(vec); |
| 114 |
0
|
assertTrue(solver.isSatisfiable()); |
| 115 |
|
} catch (ContradictionException e) { |
| 116 |
0
|
fail(); |
| 117 |
|
} |
| 118 |
|
} |
| 119 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0,33 |
4
-
|
|
| 120 |
0
|
public void testBug001() throws TimeoutException {... |
| 121 |
0
|
solver.reset(); |
| 122 |
0
|
try { |
| 123 |
0
|
reader.parseInstance(PREFIX + "bug001.cnf"); |
| 124 |
|
} catch (Exception e) { |
| 125 |
0
|
e.printStackTrace(); |
| 126 |
0
|
fail(); |
| 127 |
|
} |
| 128 |
0
|
assertTrue(solver.isSatisfiable()); |
| 129 |
|
} |
| 130 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0,5 |
4
-
|
|
| 131 |
0
|
public void testTrivialInconsistentFormula() {... |
| 132 |
0
|
solver.reset(); |
| 133 |
0
|
try { |
| 134 |
0
|
reader.parseInstance(PREFIX + "test3.dimacs"); |
| 135 |
0
|
assertFalse(solver.isSatisfiable()); |
| 136 |
|
} catch (ContradictionException e) { |
| 137 |
|
|
| 138 |
|
} catch (Exception e) { |
| 139 |
0
|
e.printStackTrace(); |
| 140 |
0
|
fail(); |
| 141 |
|
} |
| 142 |
|
} |
| 143 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0,5 |
4
-
|
|
| 144 |
0
|
public void testCommentsInInstance() {... |
| 145 |
0
|
solver.reset(); |
| 146 |
0
|
try { |
| 147 |
0
|
reader.parseInstance(PREFIX + "testcomments.cnf"); |
| 148 |
0
|
assertFalse(solver.isSatisfiable()); |
| 149 |
|
} catch (ContradictionException e) { |
| 150 |
|
|
| 151 |
|
} catch (Exception e) { |
| 152 |
0
|
e.printStackTrace(); |
| 153 |
0
|
fail(); |
| 154 |
|
} |
| 155 |
|
} |
| 156 |
|
|
|
|
|
| 0% |
Uncovered Elements: 31 (31) |
Complexity: 3 |
Complexity Density: 0,1 |
4
-
|
|
| 157 |
0
|
public void testRemoveConstraints() throws TimeoutException {... |
| 158 |
0
|
try { |
| 159 |
0
|
solver.newVar(3); |
| 160 |
0
|
IVecInt vec = new VecInt(); |
| 161 |
0
|
vec.push(1).push(-2); |
| 162 |
0
|
IConstr c = solver.addClause(vec); |
| 163 |
0
|
assertNotNull(c); |
| 164 |
0
|
vec.clear(); |
| 165 |
0
|
vec.push(-1).push(-2); |
| 166 |
0
|
c = solver.addClause(vec); |
| 167 |
0
|
assertNotNull(c); |
| 168 |
0
|
vec.clear(); |
| 169 |
0
|
vec.push(-1).push(2); |
| 170 |
0
|
solver.addClause(vec); |
| 171 |
|
|
| 172 |
0
|
vec.clear(); |
| 173 |
0
|
vec.push(1).push(2); |
| 174 |
0
|
solver.addClause(vec); |
| 175 |
0
|
assertEquals(4, solver.nConstraints()); |
| 176 |
|
|
| 177 |
0
|
assertFalse(solver.isSatisfiable()); |
| 178 |
0
|
solver.removeConstr(c); |
| 179 |
0
|
assertEquals(3, solver.nConstraints()); |
| 180 |
0
|
assertTrue(solver.isSatisfiable()); |
| 181 |
0
|
assertEquals(1, solver.model()[0]); |
| 182 |
0
|
assertEquals(2, solver.model()[1]); |
| 183 |
0
|
vec.clear(); |
| 184 |
0
|
vec.push(-1).push(-2); |
| 185 |
0
|
try { |
| 186 |
0
|
c = solver.addClause(vec); |
| 187 |
0
|
assertNotNull(c); |
| 188 |
0
|
assertEquals(4, solver.nConstraints()); |
| 189 |
0
|
assertFalse(solver.isSatisfiable()); |
| 190 |
|
} catch (ContradictionException ce) { |
| 191 |
|
|
| 192 |
|
} |
| 193 |
|
} catch (ContradictionException e) { |
| 194 |
0
|
fail(); |
| 195 |
|
} |
| 196 |
|
} |
| 197 |
|
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 2 |
Complexity Density: 0,18 |
4
-
|
|
| 198 |
0
|
public void testRemoveAtLeast() {... |
| 199 |
0
|
solver.newVar(3); |
| 200 |
0
|
IVecInt c1 = new VecInt().push(1).push(2).push(3); |
| 201 |
0
|
try { |
| 202 |
0
|
solver.addClause(c1); |
| 203 |
0
|
assertEquals(1, solver.nConstraints()); |
| 204 |
0
|
assertEquals(3, c1.size()); |
| 205 |
0
|
IConstr atLeast = solver.addAtLeast(c1, 2); |
| 206 |
0
|
assertEquals(2, solver.nConstraints()); |
| 207 |
0
|
solver.removeConstr(atLeast); |
| 208 |
0
|
assertEquals(1, solver.nConstraints()); |
| 209 |
|
} catch (ContradictionException e) { |
| 210 |
0
|
fail(); |
| 211 |
|
} |
| 212 |
|
} |
| 213 |
|
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 2 |
Complexity Density: 0,18 |
4
-
|
|
| 214 |
0
|
public void testIsImplied() {... |
| 215 |
0
|
Solver<ILits> mysolver = (Solver<ILits>) solver; |
| 216 |
0
|
solver.newVar(3); |
| 217 |
0
|
IVecInt c1 = new VecInt().push(1); |
| 218 |
0
|
try { |
| 219 |
0
|
mysolver.addClause(c1); |
| 220 |
0
|
assertTrue("isImplied(1) ", mysolver.getVocabulary().isImplied(2)); |
| 221 |
0
|
assertFalse("isImplied(2) :", mysolver.getVocabulary().isImplied(4)); |
| 222 |
0
|
mysolver.propagate(); |
| 223 |
0
|
assertTrue("isImplied(1) ", mysolver.getVocabulary().isImplied(2)); |
| 224 |
0
|
assertFalse("isImplied(2) :", mysolver.getVocabulary().isImplied(4)); |
| 225 |
|
} catch (ContradictionException e) { |
| 226 |
0
|
fail(); |
| 227 |
|
} |
| 228 |
|
} |
| 229 |
|
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 2 |
Complexity Density: 0,2 |
4
-
|
|
| 230 |
0
|
public void testIsImplied3() {... |
| 231 |
0
|
Solver<ILits> mysolver = (Solver<ILits>) solver; |
| 232 |
0
|
mysolver.newVar(1); |
| 233 |
0
|
IVecInt c1 = new VecInt().push(-1); |
| 234 |
0
|
try { |
| 235 |
0
|
mysolver.addClause(c1); |
| 236 |
0
|
mysolver.propagate(); |
| 237 |
|
} catch (ContradictionException e) { |
| 238 |
0
|
fail(); |
| 239 |
|
} |
| 240 |
0
|
assertTrue("isImplied(1) ", mysolver.getVocabulary().isImplied(2)); |
| 241 |
0
|
assertFalse("isSatisfiedl(1)", mysolver.getVocabulary().isSatisfied(2)); |
| 242 |
0
|
assertTrue("isFalsified(1)", mysolver.getVocabulary().isFalsified(2)); |
| 243 |
|
} |
| 244 |
|
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0,38 |
4
-
|
|
| 245 |
0
|
public void testErrorMessageWhenNewVarNotCalled() {... |
| 246 |
0
|
Solver<ILits> mysolver = (Solver<ILits>) solver; |
| 247 |
0
|
IVecInt c1 = new VecInt().push(-1); |
| 248 |
0
|
try { |
| 249 |
0
|
mysolver.addClause(c1); |
| 250 |
0
|
mysolver.propagate(); |
| 251 |
0
|
fail(); |
| 252 |
|
} catch (RuntimeException e) { |
| 253 |
0
|
System.err.append(e.getMessage()); |
| 254 |
|
} catch (ContradictionException e) { |
| 255 |
0
|
fail(); |
| 256 |
|
} |
| 257 |
|
} |
| 258 |
|
|
| 259 |
|
|
| 260 |
|
@see |
| 261 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
| 262 |
0
|
@Override... |
| 263 |
|
protected void setUp() throws Exception { |
| 264 |
0
|
solver = SolverFactory.newMiniSAT(); |
| 265 |
0
|
reader = new InstanceReader(solver); |
| 266 |
|
} |
| 267 |
|
|
| 268 |
|
private ISolver solver; |
| 269 |
|
|
| 270 |
|
private InstanceReader reader; |
| 271 |
|
} |