Search in sources :

Example 11 with IntegerConstant

use of org.evosuite.symbolic.expr.bv.IntegerConstant in project evosuite by EvoSuite.

the class ConstraintToZ3Visitor method visit.

@Override
public SmtExpr visit(StringConstraint c, Void arg) {
    ExprToZ3Visitor v = new ExprToZ3Visitor();
    StringComparison stringComparison = (StringComparison) c.getLeftOperand();
    IntegerConstant integerConstant = (IntegerConstant) c.getRightOperand();
    SmtExpr left = stringComparison.accept(v, null);
    SmtExpr right = integerConstant.accept(v, null);
    if (left == null || right == null) {
        return null;
    }
    Comparator cmp = c.getComparator();
    return mkComparison(left, cmp, right);
}
Also used : StringComparison(org.evosuite.symbolic.expr.bv.StringComparison) SmtExpr(org.evosuite.symbolic.solver.smt.SmtExpr) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant) Comparator(org.evosuite.symbolic.expr.Comparator)

Example 12 with IntegerConstant

use of org.evosuite.symbolic.expr.bv.IntegerConstant 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();
    }
}
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) StringBinaryToIntegerExpression(org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression) ArrayList(java.util.ArrayList) SolverResult(org.evosuite.symbolic.solver.SolverResult) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant) IntegerVariable(org.evosuite.symbolic.expr.bv.IntegerVariable) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) StringConstant(org.evosuite.symbolic.expr.str.StringConstant) Test(org.junit.Test)

Example 13 with IntegerConstant

use of org.evosuite.symbolic.expr.bv.IntegerConstant 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();
    }
}
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) 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 14 with IntegerConstant

use of org.evosuite.symbolic.expr.bv.IntegerConstant 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();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) IntegerVariable(org.evosuite.symbolic.expr.bv.IntegerVariable) 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) Test(org.junit.Test)

Example 15 with IntegerConstant

use of org.evosuite.symbolic.expr.bv.IntegerConstant in project evosuite by EvoSuite.

the class TestIntegerSearch method testEvosuiteExample3.

@Test
public void testEvosuiteExample3() throws SolverEmptyQueryException {
    Properties.DSE_VARIABLE_RESETS = 3;
    // (var42__SYM(25721) * (var22__SYM(-1043) - 6860)) == 8275
    int var1 = 25721;
    int var2 = -1043;
    IntegerConstant iconst1 = new IntegerConstant(6860);
    IntegerConstant iconst2 = new IntegerConstant(8275);
    IntegerVariable ivar1 = new IntegerVariable("test1", var1, Integer.MIN_VALUE, Integer.MAX_VALUE);
    IntegerVariable ivar2 = new IntegerVariable("test2", var2, Integer.MIN_VALUE, Integer.MAX_VALUE);
    IntegerBinaryExpression sub = new IntegerBinaryExpression(ivar2, Operator.MINUS, iconst1, -7903L);
    IntegerBinaryExpression mul = new IntegerBinaryExpression(ivar1, Operator.MUL, sub, -203273063L);
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    constraints.add(new IntegerConstraint(mul, Comparator.EQ, iconst2));
    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 - 6860) == 8275);
    } catch (SolverTimeoutException e) {
        fail();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) IntegerBinaryExpression(org.evosuite.symbolic.expr.bv.IntegerBinaryExpression) 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) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant) IntegerVariable(org.evosuite.symbolic.expr.bv.IntegerVariable) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Test(org.junit.Test)

Aggregations

IntegerConstant (org.evosuite.symbolic.expr.bv.IntegerConstant)65 Constraint (org.evosuite.symbolic.expr.Constraint)42 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)42 EvoSuiteSolver (org.evosuite.symbolic.solver.avm.EvoSuiteSolver)36 Test (org.junit.Test)36 SolverTimeoutException (org.evosuite.symbolic.solver.SolverTimeoutException)35 ArrayList (java.util.ArrayList)34 StringVariable (org.evosuite.symbolic.expr.str.StringVariable)29 StringConstraint (org.evosuite.symbolic.expr.StringConstraint)26 StringConstant (org.evosuite.symbolic.expr.str.StringConstant)23 StringBinaryComparison (org.evosuite.symbolic.expr.bv.StringBinaryComparison)17 SolverResult (org.evosuite.symbolic.solver.SolverResult)14 StringBinaryToIntegerExpression (org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression)13 IntegerVariable (org.evosuite.symbolic.expr.bv.IntegerVariable)12 IntegerValue (org.evosuite.symbolic.expr.bv.IntegerValue)7 Expression (org.evosuite.symbolic.expr.Expression)6 StringMultipleComparison (org.evosuite.symbolic.expr.bv.StringMultipleComparison)5 StringUnaryToIntegerExpression (org.evosuite.symbolic.expr.bv.StringUnaryToIntegerExpression)5 StringUnaryExpression (org.evosuite.symbolic.expr.str.StringUnaryExpression)5 IntegerBinaryExpression (org.evosuite.symbolic.expr.bv.IntegerBinaryExpression)3