Search in sources :

Example 41 with SolverResult

use of org.evosuite.symbolic.solver.SolverResult in project evosuite by EvoSuite.

the class TestIntegerSearch method testEvosuiteExample4_1.

@Test
public void testEvosuiteExample4_1() throws SolverEmptyQueryException {
    IntegerVariable var24 = new IntegerVariable("var24", 21458, Integer.MIN_VALUE, Integer.MAX_VALUE);
    IntegerVariable var10 = new IntegerVariable("var10", 1172, Integer.MIN_VALUE, Integer.MAX_VALUE);
    IntegerVariable var14 = new IntegerVariable("var14", -1903, Integer.MIN_VALUE, Integer.MAX_VALUE);
    IntegerConstant c_19072 = new IntegerConstant(19072);
    IntegerConstant c_11060 = new IntegerConstant(11060);
    IntegerValue left = mul(sub(var24, div(var10, var14)), c_19072);
    IntegerValue right = c_11060;
    IntegerConstraint constr = new IntegerConstraint(left, Comparator.LT, right);
    List<Constraint<?>> constraints = Collections.<Constraint<?>>singletonList(constr);
    try {
        EvoSuiteSolver solver = new EvoSuiteSolver();
        SolverResult solverResult = solver.solve(constraints);
        assertTrue(solverResult.isSAT());
        Map<String, Object> model = solverResult.getModel();
        int v_24 = ((Number) model.get("var24")).intValue();
        int v_10 = ((Number) model.get("var10")).intValue();
        int v_14 = ((Number) model.get("var14")).intValue();
        assertTrue((v_24 - (v_10 / v_14) * 19072) < 11060);
    } catch (SolverTimeoutException e) {
        fail();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) EvoSuiteSolver(org.evosuite.symbolic.solver.avm.EvoSuiteSolver) SolverResult(org.evosuite.symbolic.solver.SolverResult) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) IntegerVariable(org.evosuite.symbolic.expr.bv.IntegerVariable) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Test(org.junit.Test)

Example 42 with SolverResult

use of org.evosuite.symbolic.solver.SolverResult in project evosuite by EvoSuite.

the class TestIntegerSearch method testEvosuiteExample6.

@Test
public void testEvosuiteExample6() throws SolverEmptyQueryException {
    Properties.DSE_VARIABLE_RESETS = 3;
    // Cnstr 0 : var2__SYM(1890) >= 0 dist: 682.3333333333334
    // Cnstr 1 : var1__SYM(-157) <= 0 dist: 682.3333333333334
    // Cnstr 2 : var2__SYM(1890) <= var1__SYM(-157) dist: 682.3333333333334
    // y >= 0
    // x <= 0
    // y <= x
    int x = -157;
    int y = 1890;
    // TestSuiteDSE.setStart();
    // int x = 879254357;
    // int y = 1013652704;
    IntegerVariable ivar1 = new IntegerVariable("test1", x, Integer.MIN_VALUE, Integer.MAX_VALUE);
    IntegerVariable ivar2 = new IntegerVariable("test2", y, Integer.MIN_VALUE, Integer.MAX_VALUE);
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    constraints.add(new IntegerConstraint(ivar2, Comparator.GE, new IntegerConstant(0)));
    constraints.add(new IntegerConstraint(ivar1, Comparator.LE, new IntegerConstant(0)));
    constraints.add(new IntegerConstraint(ivar2, Comparator.LE, ivar1));
    try {
        EvoSuiteSolver solver = new EvoSuiteSolver();
        SolverResult solverResult = solver.solve(constraints);
        assertTrue(solverResult.isSAT());
        Map<String, Object> model = solverResult.getModel();
        if (model.containsKey("test1"))
            x = ((Number) model.get("test1")).intValue();
        if (model.containsKey("test2"))
            y = ((Number) model.get("test2")).intValue();
        assertTrue(y >= 0);
        assertTrue(x <= 0);
        assertTrue(y <= x);
    } 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) IntegerVariable(org.evosuite.symbolic.expr.bv.IntegerVariable) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Test(org.junit.Test)

Example 43 with SolverResult

use of org.evosuite.symbolic.solver.SolverResult in project evosuite by EvoSuite.

the class TestIntegerSearch method testNEArithmetic.

@Test
public void testNEArithmetic() 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.NE, 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();
    }
}
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) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) IntegerVariable(org.evosuite.symbolic.expr.bv.IntegerVariable) Test(org.junit.Test)

Example 44 with SolverResult

use of org.evosuite.symbolic.solver.SolverResult in project evosuite by EvoSuite.

the class TestIntegerSearch method testLTConstant.

@Test
public void testLTConstant() 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", 235086, -1000000, 1000000), Comparator.LT, 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 45 with SolverResult

use of org.evosuite.symbolic.solver.SolverResult in project evosuite by EvoSuite.

the class TestIntegerSearch method testLEConstant.

@Test
public void testLEConstant() 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", 235086, -1000000, 1000000), Comparator.LE, 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)

Aggregations

SolverResult (org.evosuite.symbolic.solver.SolverResult)50 Test (org.junit.Test)37 Constraint (org.evosuite.symbolic.expr.Constraint)36 SolverTimeoutException (org.evosuite.symbolic.solver.SolverTimeoutException)34 EvoSuiteSolver (org.evosuite.symbolic.solver.avm.EvoSuiteSolver)31 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)27 IntegerVariable (org.evosuite.symbolic.expr.bv.IntegerVariable)26 ArrayList (java.util.ArrayList)24 IntegerConstant (org.evosuite.symbolic.expr.bv.IntegerConstant)14 IntegerBinaryExpression (org.evosuite.symbolic.expr.bv.IntegerBinaryExpression)7 HashMap (java.util.HashMap)6 Variable (org.evosuite.symbolic.expr.Variable)4 StringVariable (org.evosuite.symbolic.expr.str.StringVariable)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 HashSet (java.util.HashSet)3 LinkedList (java.util.LinkedList)3 Solver (org.evosuite.symbolic.solver.Solver)3 SolverCache (org.evosuite.symbolic.solver.SolverCache)3 SolverEmptyQueryException (org.evosuite.symbolic.solver.SolverEmptyQueryException)3 SolverErrorException (org.evosuite.symbolic.solver.SolverErrorException)3