use of org.evosuite.symbolic.solver.SolverResult in project evosuite by EvoSuite.
the class TestIntegerSearch method testGTVariable.
@Test
public void testGTVariable() throws SolverEmptyQueryException {
int var1 = 0;
int var2 = 1;
List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
constraints.add(new IntegerConstraint(new IntegerVariable("test1", var1, -1000000, 1000000), Comparator.GT, new IntegerVariable("test2", var2, -1000000, 1000000)));
try {
EvoSuiteSolver solver = new EvoSuiteSolver();
SolverResult solverResult = solver.solve(constraints);
assertTrue(solverResult.isSAT());
Map<String, Object> model = solverResult.getModel();
if (model.containsKey("test1"))
var1 = ((Number) model.get("test1")).intValue();
if (model.containsKey("test2"))
var2 = ((Number) model.get("test2")).intValue();
assertTrue(var1 > var2);
} catch (SolverTimeoutException e) {
fail();
}
}
use of org.evosuite.symbolic.solver.SolverResult in project evosuite by EvoSuite.
the class TestIntegerSearch method testLTArithmetic.
@Test
public void testLTArithmetic() throws SolverEmptyQueryException {
int var1 = 2;
int var2 = 1;
int var3 = 1;
assertTrue(var1 >= var2 + var3);
List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
constraints.add(new IntegerConstraint(new IntegerVariable("test1", var1, -1000000, 1000000), Comparator.LT, new IntegerBinaryExpression(new IntegerVariable("test2", var2, -1000000, 1000000), Operator.PLUS, new IntegerVariable("test3", var3, -1000000, 1000000), 0L)));
try {
EvoSuiteSolver solver = new EvoSuiteSolver();
SolverResult solverResult = solver.solve(constraints);
assertTrue(solverResult.isSAT());
Map<String, Object> model = solverResult.getModel();
if (model.containsKey("test1"))
var1 = ((Number) model.get("test1")).intValue();
if (model.containsKey("test2"))
var2 = ((Number) model.get("test2")).intValue();
if (model.containsKey("test3"))
var3 = ((Number) model.get("test3")).intValue();
assertTrue(var1 < var2 + var3);
} catch (SolverTimeoutException e) {
fail();
}
}
use of org.evosuite.symbolic.solver.SolverResult in project evosuite by EvoSuite.
the class TestIntegerSearch method testEvosuiteExample5.
@Test
public void testEvosuiteExample5() throws SolverEmptyQueryException {
// TestSuiteDSE.setStart();
// Cnstr 0 : var6__SYM(84) != (y charAt 0) dist: 8.0
// Cnstr 1 : var6__SYM(84) != 115 dist: 8.0
// Cnstr 2 : var6__SYM(84) == 108 dist: 8.0
int var1 = 84;
int const1 = 115;
int const2 = 108;
String const3 = "y";
IntegerConstant iconst1 = new IntegerConstant(const1);
IntegerConstant iconst2 = new IntegerConstant(const2);
StringConstant strConst = new StringConstant(const3);
IntegerVariable ivar1 = new IntegerVariable("test1", var1, Integer.MIN_VALUE, Integer.MAX_VALUE);
StringBinaryToIntegerExpression sBExpr = new StringBinaryToIntegerExpression(strConst, Operator.CHARAT, new IntegerConstant(0), (long) "y".charAt(0));
List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
constraints.add(new IntegerConstraint(ivar1, Comparator.NE, sBExpr));
constraints.add(new IntegerConstraint(ivar1, Comparator.NE, iconst1));
constraints.add(new IntegerConstraint(ivar1, Comparator.EQ, iconst2));
try {
EvoSuiteSolver solver = new EvoSuiteSolver();
SolverResult solverResult = solver.solve(constraints);
assertTrue(solverResult.isSAT());
Map<String, Object> model = solverResult.getModel();
var1 = ((Number) model.get("test1")).intValue();
assertTrue(var1 == 108);
} catch (SolverTimeoutException e) {
fail();
}
}
use of org.evosuite.symbolic.solver.SolverResult in project evosuite by EvoSuite.
the class TestIntegerSearch method testEvosuiteExample1.
@Test
public void testEvosuiteExample1() throws SolverEmptyQueryException {
int var1 = 1;
int var2 = 1;
List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
constraints.add(new IntegerConstraint(new IntegerVariable("test1", var1, -1000000, 1000000), Comparator.LE, new IntegerConstant(0)));
constraints.add(new IntegerConstraint(new IntegerVariable("test1", var1, -1000000, 1000000), Comparator.LT, new IntegerVariable("test2", var2, -1000000, 1000000)));
constraints.add(new IntegerConstraint(new IntegerVariable("test1", var1, -1000000, 1000000), Comparator.GE, new IntegerConstant(0)));
try {
EvoSuiteSolver solver = new EvoSuiteSolver();
SolverResult solverResult = solver.solve(constraints);
assertTrue(solverResult.isSAT());
Map<String, Object> model = solverResult.getModel();
if (model.containsKey("test1"))
var1 = ((Number) model.get("test1")).intValue();
if (model.containsKey("test2"))
var2 = ((Number) model.get("test2")).intValue();
assertEquals(0, var1);
assertTrue(var1 < var2);
} catch (SolverTimeoutException e) {
fail();
}
}
use of org.evosuite.symbolic.solver.SolverResult in project evosuite by EvoSuite.
the class TestIntegerSearch method testEQConstant.
@Test
public void testEQConstant() throws SolverEmptyQueryException {
List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
constraints.add(new IntegerConstraint(new IntegerVariable("test1", 0, -1000000, 1000000), Comparator.EQ, new IntegerConstant(235082)));
try {
EvoSuiteSolver solver = new EvoSuiteSolver();
SolverResult solverResult = solver.solve(constraints);
assertTrue(solverResult.isSAT());
Map<String, Object> model = solverResult.getModel();
assertNotNull(model);
assertNotNull(model.get("test1"));
assertEquals(235082, ((Number) model.get("test1")).intValue());
} catch (SolverTimeoutException e) {
fail();
}
}
Aggregations