Search in sources :

Example 11 with Constraint

use of org.evosuite.symbolic.expr.Constraint 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;
}
Also used : Constraint(org.evosuite.symbolic.expr.Constraint) EvoSuiteSolver(org.evosuite.symbolic.solver.avm.EvoSuiteSolver) SolverResult(org.evosuite.symbolic.solver.SolverResult) Constraint(org.evosuite.symbolic.expr.Constraint) LinkedList(java.util.LinkedList)

Example 12 with Constraint

use of org.evosuite.symbolic.expr.Constraint in project evosuite by EvoSuite.

the class TestSolverBitwise method testShiftLeft.

public static Map<String, Object> testShiftLeft(Solver solver) throws SecurityException, NoSuchMethodException, SolverTimeoutException {
    DefaultTestCase tc = buildTestCaseShiftLeft();
    Collection<Constraint<?>> constraints = DefaultTestCaseConcolicExecutor.execute(tc);
    Map<String, Object> solution = solve(solver, constraints);
    return solution;
}
Also used : Constraint(org.evosuite.symbolic.expr.Constraint) DefaultTestCase(org.evosuite.testcase.DefaultTestCase)

Example 13 with Constraint

use of org.evosuite.symbolic.expr.Constraint in project evosuite by EvoSuite.

the class TestSolverBitwise method testBitOr.

public static Map<String, Object> testBitOr(Solver solver) throws SecurityException, NoSuchMethodException, SolverTimeoutException {
    DefaultTestCase tc = buildTestCaseBitOr();
    Collection<Constraint<?>> constraints = DefaultTestCaseConcolicExecutor.execute(tc);
    Map<String, Object> solution = solve(solver, constraints);
    return solution;
}
Also used : Constraint(org.evosuite.symbolic.expr.Constraint) DefaultTestCase(org.evosuite.testcase.DefaultTestCase)

Example 14 with Constraint

use of org.evosuite.symbolic.expr.Constraint in project evosuite by EvoSuite.

the class TestSolverMath method testMin.

public static void testMin(Solver solver) throws SecurityException, NoSuchMethodException, SolverTimeoutException {
    DefaultTestCase tc = buildTestCaseMin();
    Collection<Constraint<?>> constraints = DefaultTestCaseConcolicExecutor.execute(tc);
    Map<String, Object> solution = solve(solver, constraints);
    assertNotNull(solution);
    Long var0 = (Long) solution.get("var0");
    Long var1 = (Long) solution.get("var1");
    assertEquals(10, Math.min(var0.intValue(), var1.intValue()));
}
Also used : Constraint(org.evosuite.symbolic.expr.Constraint) DefaultTestCase(org.evosuite.testcase.DefaultTestCase)

Example 15 with Constraint

use of org.evosuite.symbolic.expr.Constraint in project evosuite by EvoSuite.

the class TestSolverMath method testMax.

public static void testMax(Solver solver) throws SecurityException, NoSuchMethodException, SolverTimeoutException {
    DefaultTestCase tc = buildTestCaseMax();
    Collection<Constraint<?>> constraints = DefaultTestCaseConcolicExecutor.execute(tc);
    Map<String, Object> solution = solve(solver, constraints);
    assertNotNull(solution);
    Long var0 = (Long) solution.get("var0");
    Long var1 = (Long) solution.get("var1");
    assertEquals(10, Math.max(var0.intValue(), var1.intValue()));
}
Also used : Constraint(org.evosuite.symbolic.expr.Constraint) DefaultTestCase(org.evosuite.testcase.DefaultTestCase)

Aggregations

Constraint (org.evosuite.symbolic.expr.Constraint)210 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)101 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)83 Test (org.junit.Test)81 EvoSuiteSolver (org.evosuite.symbolic.solver.avm.EvoSuiteSolver)76 SolverTimeoutException (org.evosuite.symbolic.solver.SolverTimeoutException)75 ArrayList (java.util.ArrayList)68 IntegerConstant (org.evosuite.symbolic.expr.bv.IntegerConstant)42 SolverResult (org.evosuite.symbolic.solver.SolverResult)36 StringVariable (org.evosuite.symbolic.expr.str.StringVariable)34 StringConstraint (org.evosuite.symbolic.expr.StringConstraint)33 TestCaseStringAppendString (com.examples.with.different.packagename.solver.TestCaseStringAppendString)28 TestCaseStringIndexOfString (com.examples.with.different.packagename.solver.TestCaseStringIndexOfString)28 TestCaseStringLastIndexOfString (com.examples.with.different.packagename.solver.TestCaseStringLastIndexOfString)28 RealConstraint (org.evosuite.symbolic.expr.RealConstraint)26 IntegerVariable (org.evosuite.symbolic.expr.bv.IntegerVariable)26 RealVariable (org.evosuite.symbolic.expr.fp.RealVariable)23 StringConstant (org.evosuite.symbolic.expr.str.StringConstant)22 StringBinaryComparison (org.evosuite.symbolic.expr.bv.StringBinaryComparison)17 RealConstant (org.evosuite.symbolic.expr.fp.RealConstant)16