use of org.evosuite.symbolic.solver.avm.EvoSuiteSolver in project evosuite by EvoSuite.
the class TestConstraintSolver method executeSolver.
private SolverResult executeSolver(List<BranchCondition> branch_conditions) throws SolverTimeoutException, SolverEmptyQueryException {
final int lastBranchIndex = branch_conditions.size() - 1;
BranchCondition last_branch = branch_conditions.get(lastBranchIndex);
List<Constraint<?>> constraints = new LinkedList<Constraint<?>>();
for (int i = 0; i < lastBranchIndex; i++) {
BranchCondition c = branch_conditions.get(i);
constraints.addAll(c.getSupportingConstraints());
constraints.add(c.getConstraint());
}
constraints.addAll(last_branch.getSupportingConstraints());
Constraint<?> lastConstraint = last_branch.getConstraint();
Constraint<?> targetConstraint = lastConstraint.negate();
constraints.add(targetConstraint);
System.out.println("Target constraints");
printConstraints(constraints);
EvoSuiteSolver solver = new EvoSuiteSolver();
SolverResult solverResult = solver.solve(constraints);
if (solverResult.isUNSAT())
System.out.println("No new model was found");
else {
Map<String, Object> model = solverResult.getModel();
System.out.println(model.toString());
}
return solverResult;
}
use of org.evosuite.symbolic.solver.avm.EvoSuiteSolver in project evosuite by EvoSuite.
the class TestConstraintSolver2 method test.
@Test
public void test() throws SolverEmptyQueryException {
// 5000000000000L; TODO - ??
Properties.LOCAL_SEARCH_BUDGET = 100;
Properties.LOCAL_SEARCH_BUDGET_TYPE = LocalSearchBudgetType.FITNESS_EVALUATIONS;
Collection<Constraint<?>> constraints = buildConstraintSystem();
System.out.println("Constraints:");
for (Constraint<?> c : constraints) {
System.out.println(c.toString());
}
System.out.println("");
System.out.println("Initial: " + INIT_STRING);
EvoSuiteSolver solver = new EvoSuiteSolver();
try {
SolverResult solverResult = solver.solve(constraints);
assertTrue(solverResult.isSAT());
Map<String, Object> model = solverResult.getModel();
assertNotNull(model);
Object var0 = model.get("var0");
System.out.println("Expected: " + EXPECTED_STRING);
System.out.println("Found: " + var0);
assertEquals(EXPECTED_STRING, var0);
} catch (SolverTimeoutException e) {
fail();
}
}
use of org.evosuite.symbolic.solver.avm.EvoSuiteSolver in project evosuite by EvoSuite.
the class TestIntegerSearch method testEQVariable.
@Test
public void testEQVariable() 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.EQ, 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();
assertEquals(var1, var2);
} catch (SolverTimeoutException e) {
fail();
}
}
use of org.evosuite.symbolic.solver.avm.EvoSuiteSolver 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.avm.EvoSuiteSolver 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();
}
}
Aggregations