Search in sources :

Example 11 with IntegerConstraint

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

the class TestIntegerSearch method testLEVariable.

@Test
public void testLEVariable() throws SolverEmptyQueryException {
    int var1 = 2;
    int var2 = 1;
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    constraints.add(new IntegerConstraint(new IntegerVariable("test1", var1, -1000000, 1000000), Comparator.LE, 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();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) EvoSuiteSolver(org.evosuite.symbolic.solver.avm.EvoSuiteSolver) ArrayList(java.util.ArrayList) SolverResult(org.evosuite.symbolic.solver.SolverResult) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) IntegerVariable(org.evosuite.symbolic.expr.bv.IntegerVariable) Test(org.junit.Test)

Example 12 with IntegerConstraint

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

the class TestIntegerSearch method testGEConstant.

@Test
public void testGEConstant() throws SolverEmptyQueryException {
    // TODO: Currently, the model returned by the search is null if the
    // constraint is already satisfied,
    // so in this example the concrete value has to be the target initially
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    constraints.add(new IntegerConstraint(new IntegerVariable("test1", 0, -1000000, 1000000), Comparator.GE, new IntegerConstant(235082)));
    try {
        EvoSuiteSolver solver = new EvoSuiteSolver();
        SolverResult solverResult = solver.solve(constraints);
        assertTrue(solverResult.isSAT());
        Map<String, Object> model = solverResult.getModel();
        assertNotNull(model.get("test1"));
        assertTrue(235082 <= ((Number) model.get("test1")).intValue());
    } catch (SolverTimeoutException e) {
        fail();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) EvoSuiteSolver(org.evosuite.symbolic.solver.avm.EvoSuiteSolver) ArrayList(java.util.ArrayList) SolverResult(org.evosuite.symbolic.solver.SolverResult) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) IntegerVariable(org.evosuite.symbolic.expr.bv.IntegerVariable) Test(org.junit.Test)

Example 13 with IntegerConstraint

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

the class TestSolverUNSAT method testUNSAT.

public static void testUNSAT(Solver solver) throws SolverTimeoutException, IOException, SolverParseException, SolverEmptyQueryException, SolverErrorException {
    Collection<Constraint<?>> constraints = new LinkedList<Constraint<?>>();
    IntegerVariable x = new IntegerVariable("x", 1L, Long.MIN_VALUE, Long.MAX_VALUE);
    IntegerConstraint unsat_constraint = ConstraintFactory.neq(x, x);
    constraints.add(unsat_constraint);
    SolverResult result = solver.solve(constraints);
    assertTrue(result.isUNSAT());
}
Also used : IntegerVariable(org.evosuite.symbolic.expr.bv.IntegerVariable) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) LinkedList(java.util.LinkedList)

Example 14 with IntegerConstraint

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

the class TestConstraintSolver3 method buildConstraintSystem.

private static Collection<Constraint<?>> buildConstraintSystem() {
    StringVariable var0 = new StringVariable("var0", INIT_STRING);
    StringToIntegerCast castStr = new StringToIntegerCast(var0, (long) Integer.parseInt(INIT_STRING));
    IntegerConstant const126 = new IntegerConstant(EXPECTED_INTEGER);
    IntegerConstraint constr1 = new IntegerConstraint(castStr, Comparator.EQ, const126);
    return Arrays.<Constraint<?>>asList(constr1);
}
Also used : IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) StringToIntegerCast(org.evosuite.symbolic.expr.bv.StringToIntegerCast) StringVariable(org.evosuite.symbolic.expr.str.StringVariable) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant)

Example 15 with IntegerConstraint

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

the class TestIsInteger method testIsInteger.

@Test
public void testIsInteger() throws SolverEmptyQueryException {
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    constraints.add(new IntegerConstraint(new StringUnaryToIntegerExpression(new StringVariable("var0", "hello"), Operator.IS_INTEGER, 0L), Comparator.NE, new IntegerConstant(0)));
    EvoSuiteSolver solver = new EvoSuiteSolver();
    try {
        SolverResult result = solver.solve(constraints);
        assertTrue(result.isSAT());
    } catch (SolverTimeoutException e) {
        fail();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) EvoSuiteSolver(org.evosuite.symbolic.solver.avm.EvoSuiteSolver) ArrayList(java.util.ArrayList) SolverResult(org.evosuite.symbolic.solver.SolverResult) StringUnaryToIntegerExpression(org.evosuite.symbolic.expr.bv.StringUnaryToIntegerExpression) StringVariable(org.evosuite.symbolic.expr.str.StringVariable) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant) Test(org.junit.Test)

Aggregations

IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)43 Constraint (org.evosuite.symbolic.expr.Constraint)37 SolverTimeoutException (org.evosuite.symbolic.solver.SolverTimeoutException)30 EvoSuiteSolver (org.evosuite.symbolic.solver.avm.EvoSuiteSolver)30 Test (org.junit.Test)30 ArrayList (java.util.ArrayList)28 IntegerVariable (org.evosuite.symbolic.expr.bv.IntegerVariable)25 SolverResult (org.evosuite.symbolic.solver.SolverResult)25 IntegerConstant (org.evosuite.symbolic.expr.bv.IntegerConstant)24 StringVariable (org.evosuite.symbolic.expr.str.StringVariable)9 IntegerBinaryExpression (org.evosuite.symbolic.expr.bv.IntegerBinaryExpression)8 StringConstraint (org.evosuite.symbolic.expr.StringConstraint)7 StringBinaryToIntegerExpression (org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression)7 IntegerValue (org.evosuite.symbolic.expr.bv.IntegerValue)6 StringUnaryToIntegerExpression (org.evosuite.symbolic.expr.bv.StringUnaryToIntegerExpression)4 RealConstraint (org.evosuite.symbolic.expr.RealConstraint)3 LinkedList (java.util.LinkedList)2 Vector (java.util.Vector)2 Comparator (org.evosuite.symbolic.expr.Comparator)2 TestCaseStringAppendString (com.examples.with.different.packagename.solver.TestCaseStringAppendString)1