Skip to content

Commit 9dd07dc

Browse files
Create Test for Boolean Manager and Complete function immplementation
Test not passing yet, though
1 parent 7440f28 commit 9dd07dc

File tree

3 files changed

+98
-31
lines changed

3 files changed

+98
-31
lines changed

src/org/sosy_lab/java_smt/solvers/stp/StpBooleanFormulaManager.java

Lines changed: 55 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,70 +24,102 @@
2424
class StpBooleanFormulaManager
2525
// extends AbstractBooleanFormulaManager<TFormulaInfo, TType, TEnv, TFuncDecl> {
2626
extends AbstractBooleanFormulaManager<Long, Long, Long, Long> {
27-
27+
private final VC vc;
2828
protected StpBooleanFormulaManager(StpFormulaCreator pCreator) {
2929
super(pCreator);
30-
// TODO Auto-generated constructor stub
30+
31+
vc = pCreator.getVC();
3132
}
3233

3334
@Override
3435
protected Long makeVariableImpl(String pVar) {
35-
// TODO Auto-generated method stub
36-
return null;
36+
long boolType = getFormulaCreator().getBoolType();
37+
return getFormulaCreator().makeVariable(boolType, pVar);
3738
}
3839

3940
@Override
4041
protected Long makeBooleanImpl(boolean pValue) {
41-
// TODO Auto-generated method stub
42-
return null;
42+
Expr result = null;
43+
if (pValue) {
44+
result = StpJavaApi.vc_trueExpr(vc);
45+
} else {
46+
result = StpJavaApi.vc_falseExpr(vc);
47+
}
48+
return Expr.getCPtr(result);
4349
}
4450

4551
@Override
4652
protected Long not(Long pParam1) {
47-
// TODO Auto-generated method stub
48-
return null;
53+
Expr result = StpJavaApi.vc_notExpr(vc, new Expr(pParam1, true));
54+
return Expr.getCPtr(result);
55+
4956
}
5057

5158
@Override
5259
protected Long and(Long pParam1, Long pParam2) {
53-
// TODO Auto-generated method stub
54-
return null;
60+
Expr result = StpJavaApi.vc_andExpr(vc, new Expr(pParam1, true), new Expr(pParam2, true));
61+
return Expr.getCPtr(result);
5562
}
5663

5764
@Override
5865
protected Long or(Long pParam1, Long pParam2) {
59-
// TODO Auto-generated method stub
60-
return null;
66+
Expr result = StpJavaApi.vc_orExpr(vc, new Expr(pParam1, true), new Expr(pParam2, true));
67+
return Expr.getCPtr(result);
6168
}
6269

6370
@Override
6471
protected Long xor(Long pParam1, Long pParam2) {
65-
// TODO Auto-generated method stub
66-
return null;
72+
Expr result = StpJavaApi.vc_xorExpr(vc, new Expr(pParam1, true), new Expr(pParam2, true));
73+
return Expr.getCPtr(result);
6774
}
6875

6976
@Override
7077
protected Long equivalence(Long pBits1, Long pBits2) {
71-
// TODO Auto-generated method stub
72-
return null;
78+
// Expr result = StpJavaApi.vc_eqExpr(vc, new Expr(pBits1, true), new Expr(pBits2, true));
79+
80+
// if and only if
81+
Expr result = StpJavaApi.vc_iffExpr(vc, new Expr(pBits1, true), new Expr(pBits2, true));
82+
83+
return Expr.getCPtr(result);
7384
}
7485

7586
@Override
7687
protected boolean isTrue(Long pBits) {
77-
// TODO Auto-generated method stub
78-
return false;
88+
89+
int result = StpJavaApi.vc_isBool(new Expr(pBits, true));
90+
if (result == 1) {
91+
return true;
92+
} else {
93+
return false;
94+
}
95+
// else if (result == 0) {
96+
// return false;
97+
// }else { //-1 is not boolean
98+
// throw new Exception("The Formaula is not boolean");
99+
// }
79100
}
80101

81102
@Override
82103
protected boolean isFalse(Long pBits) {
83-
// TODO Auto-generated method stub
84-
return false;
104+
int result = StpJavaApi.vc_isBool(new Expr(pBits, true));
105+
if (result == 0) {
106+
return true;
107+
} else {
108+
return false;
109+
}
85110
}
86111

112+
/***
113+
* @return either a Bit Vector or Boolean depending on the type of formulas
114+
* @param pCond must be boolean
115+
* @param pF1 and @param pF2 must have the same type
116+
*
117+
*/
87118
@Override
88119
protected Long ifThenElse(Long pCond, Long pF1, Long pF2) {
89-
// TODO Auto-generated method stub
90-
return null;
120+
// TODO Enforce the rules stated in the doc comment above
121+
Expr result =
122+
StpJavaApi.vc_iteExpr(vc, new Expr(pCond, true), new Expr(pF1, true), new Expr(pF2, true));
123+
return Expr.getCPtr(result);
91124
}
92-
93125
}

src/org/sosy_lab/java_smt/solvers/stp/StpFormulaCreator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ protected StpFormulaCreator(VC vc) {
5454
this.vc = vc;
5555
}
5656

57+
public VC getVC() {
58+
return vc;
59+
}
5760

5861
@Override
5962
public Long getBitvectorType(int pBitwidth) {

src/org/sosy_lab/java_smt/solvers/stp/StpSolverTest.java

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
*/
2020
package org.sosy_lab.java_smt.solvers.stp;
2121

22+
import static org.junit.Assert.assertTrue;
23+
2224
import org.junit.Test;
2325
import org.sosy_lab.common.ShutdownNotifier;
2426
import org.sosy_lab.common.configuration.Configuration;
@@ -27,26 +29,56 @@
2729
import org.sosy_lab.common.log.LogManager;
2830
import org.sosy_lab.java_smt.SolverContextFactory;
2931
import org.sosy_lab.java_smt.SolverContextFactory.Solvers;
32+
import org.sosy_lab.java_smt.api.BooleanFormula;
33+
import org.sosy_lab.java_smt.api.BooleanFormulaManager;
3034
import org.sosy_lab.java_smt.api.SolverContext;
3135

3236
public class StpSolverTest {
3337

34-
@Test
35-
public void testSolverContextClass() throws InvalidConfigurationException {
38+
private Configuration config;
39+
private LogManager logger;
40+
private ShutdownNotifier shutdownNotifier;
41+
private Solvers solver;
42+
43+
public StpSolverTest() throws InvalidConfigurationException {
44+
config = Configuration.defaultConfiguration();
45+
logger = BasicLogManager.create(config);
46+
shutdownNotifier = ShutdownNotifier.createDummy();
3647

37-
Configuration config = Configuration.defaultConfiguration();
38-
LogManager logger = BasicLogManager.create(config);
39-
ShutdownNotifier notifier = ShutdownNotifier.createDummy();
48+
solver = Solvers.STP;
49+
}
4050

41-
Solvers solver = Solvers.STP;
51+
@Test
52+
public void testSolverContextClass() throws InvalidConfigurationException {
4253

4354
SolverContext context =
44-
SolverContextFactory.createSolverContext(config, logger, notifier, solver);
55+
SolverContextFactory.createSolverContext(config, logger, shutdownNotifier, solver);
4556

4657
System.out.println(context.getSolverName() + " ::: " + context.getVersion());
47-
4858
context.close();
4959

5060
}
5161

62+
63+
// USING THE CONTEXT:
64+
// test create bool variable
65+
66+
@Test
67+
public void createBooleanVariablesAndcheckEquivalence() throws InvalidConfigurationException {
68+
try (SolverContext context =
69+
SolverContextFactory.createSolverContext(config, logger, shutdownNotifier, solver)) {
70+
71+
BooleanFormulaManager boolFMgr = context.getFormulaManager().getBooleanFormulaManager();
72+
BooleanFormula falseVar = boolFMgr.makeVariable("falseVar");
73+
BooleanFormula trueVar = boolFMgr.equivalence(falseVar, boolFMgr.makeBoolean(false));
74+
assertTrue(boolFMgr.isFalse(falseVar));
75+
assertTrue(boolFMgr.isTrue(trueVar));
76+
}
77+
}
78+
79+
// test create BV variable
80+
// test create Array variable
81+
82+
// Test Prover
83+
5284
}

0 commit comments

Comments
 (0)