View Javadoc

1   package org.sat4j;
2   
3   import static org.junit.Assert.assertEquals;
4   
5   import org.junit.Before;
6   import org.junit.Test;
7   import org.sat4j.core.VecInt;
8   import org.sat4j.minisat.SolverFactory;
9   import org.sat4j.specs.ContradictionException;
10  import org.sat4j.specs.ISolver;
11  import org.sat4j.specs.TimeoutException;
12  import org.sat4j.tools.GateTranslator;
13  
14  public class BugSAT79 {
15  
16      private ISolver solver;
17  
18      @Before
19      public void setUp() throws Exception {
20          solver = SolverFactory.newDefault();
21          solver.addClause(new VecInt(new int[] { 1, -2, 3 }));
22      }
23  
24      @Test
25      public void testSuccessiveCallsInGlobalTimeout() throws TimeoutException,
26              InterruptedException {
27          int nbthreads = Thread.activeCount();
28          for (int i = 0; i < 10; i++) {
29              solver.isSatisfiable(true);
30              Thread.sleep(500);
31              assertEquals(nbthreads + 1, Thread.activeCount());
32          }
33      }
34  
35      // starting from here, the Timer thread exists, so it should not increase
36      // the number of available threads.
37  
38      @Test
39      public void testSuccessiveCallsInLocalTimeout() throws TimeoutException,
40              InterruptedException {
41          int nbthreads = Thread.activeCount();
42          for (int i = 0; i < 10; i++) {
43              solver.isSatisfiable(false);
44              Thread.sleep(500);
45              assertEquals(nbthreads, Thread.activeCount());
46          }
47      }
48  
49      @Test
50      public void testSuccessiveCallsWithDifferentSolvers()
51              throws TimeoutException, ContradictionException,
52              InterruptedException {
53          int nbthreads = Thread.activeCount();
54          ISolver localSolver;
55          for (int i = 0; i < 10; i++) {
56              localSolver = SolverFactory.newDefault();
57              localSolver.addClause(new VecInt(new int[] { 1, -2, 3 }));
58              localSolver.isSatisfiable(false);
59              Thread.sleep(500);
60              assertEquals(nbthreads, Thread.activeCount());
61          }
62      }
63  
64      @Test
65      public void testSuccessiveCallsWithDifferentSolversInsideDecorators()
66              throws TimeoutException, ContradictionException,
67              InterruptedException {
68          int nbthreads = Thread.activeCount();
69          ISolver localSolver;
70          for (int i = 0; i < 10; i++) {
71              localSolver = new GateTranslator(SolverFactory.newDefault());
72              localSolver.addClause(new VecInt(new int[] { 1, -2, 3 }));
73              localSolver.isSatisfiable(false);
74              Thread.sleep(500);
75              assertEquals(nbthreads, Thread.activeCount());
76          }
77      }
78  }