1 |
|
package org.sat4j; |
2 |
|
|
3 |
|
import junit.framework.TestCase; |
4 |
|
|
5 |
|
import org.sat4j.core.VecInt; |
6 |
|
import org.sat4j.minisat.SolverFactory; |
7 |
|
import org.sat4j.specs.ContradictionException; |
8 |
|
import org.sat4j.specs.ISolver; |
9 |
|
import org.sat4j.specs.IVecInt; |
10 |
|
import org.sat4j.specs.TimeoutException; |
11 |
|
import org.sat4j.tools.SingleSolutionDetector; |
12 |
|
|
|
|
| 95,7% |
Uncovered Elements: 2 (47) |
Complexity: 3 |
Complexity Density: 0,14 |
|
13 |
|
public class SingleSolutionTest extends TestCase { |
14 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
15 |
2
|
public SingleSolutionTest(String name) {... |
16 |
2
|
super(name); |
17 |
|
} |
18 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
19 |
2
|
@Override... |
20 |
|
protected void setUp() throws Exception { |
21 |
2
|
solver = SolverFactory.newMiniSAT(); |
22 |
2
|
detector = new SingleSolutionDetector(solver); |
23 |
2
|
detector.newVar(3); |
24 |
|
} |
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
|
|
| 95% |
Uncovered Elements: 1 (20) |
Complexity: 2 |
Complexity Density: 0,1 |
1
PASS
|
|
30 |
1
|
public void testHasASingleSolution() throws ContradictionException,... |
31 |
|
TimeoutException { |
32 |
1
|
IVecInt clause = new VecInt(); |
33 |
1
|
clause.push(1).push(2); |
34 |
1
|
detector.addClause(clause); |
35 |
1
|
clause.clear(); |
36 |
1
|
clause.push(-1).push(-2); |
37 |
1
|
detector.addClause(clause); |
38 |
1
|
assertTrue(detector.isSatisfiable()); |
39 |
1
|
assertFalse(detector.hasASingleSolution()); |
40 |
1
|
clause.clear(); |
41 |
1
|
clause.push(-1).push(2); |
42 |
1
|
detector.addClause(clause); |
43 |
1
|
assertTrue(detector.isSatisfiable()); |
44 |
1
|
assertTrue(detector.hasASingleSolution()); |
45 |
1
|
clause.clear(); |
46 |
1
|
clause.push(1).push(-2); |
47 |
1
|
detector.addClause(clause); |
48 |
1
|
assertFalse(detector.isSatisfiable()); |
49 |
1
|
try { |
50 |
1
|
assertFalse(detector.hasASingleSolution()); |
51 |
0
|
fail(); |
52 |
|
} catch (UnsupportedOperationException e) { |
53 |
|
|
54 |
|
} |
55 |
|
} |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
|
|
| 94,7% |
Uncovered Elements: 1 (19) |
Complexity: 2 |
Complexity Density: 0,11 |
1
PASS
|
|
61 |
1
|
public void testHasASingleSolutionIVecInt() throws ContradictionException,... |
62 |
|
TimeoutException { |
63 |
1
|
IVecInt clause = new VecInt(); |
64 |
1
|
clause.push(1).push(2); |
65 |
1
|
detector.addClause(clause); |
66 |
1
|
IVecInt assumptions = new VecInt(); |
67 |
1
|
assumptions.push(1); |
68 |
1
|
assertTrue(detector.isSatisfiable(assumptions)); |
69 |
1
|
assertFalse(detector.hasASingleSolution(assumptions)); |
70 |
1
|
clause.clear(); |
71 |
1
|
clause.push(-1).push(2); |
72 |
1
|
detector.addClause(clause); |
73 |
1
|
assertTrue(detector.isSatisfiable(assumptions)); |
74 |
1
|
assertTrue(detector.hasASingleSolution(assumptions)); |
75 |
1
|
clause.clear(); |
76 |
1
|
clause.push(-1).push(-2); |
77 |
1
|
detector.addClause(clause); |
78 |
1
|
assertFalse(detector.isSatisfiable(assumptions)); |
79 |
1
|
try { |
80 |
1
|
assertFalse(detector.hasASingleSolution(assumptions)); |
81 |
0
|
fail(); |
82 |
|
} catch (UnsupportedOperationException e) { |
83 |
|
|
84 |
|
} |
85 |
|
} |
86 |
|
|
87 |
|
private ISolver solver; |
88 |
|
|
89 |
|
private SingleSolutionDetector detector; |
90 |
|
} |