Search in sources :

Example 61 with SolverTimeoutException

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

the class TestIntegerSearch method testEvosuiteExample4_2.

@Test
public void testEvosuiteExample4_2() throws SolverEmptyQueryException {
    IntegerVariable var20 = new IntegerVariable("var20", 17433, Integer.MIN_VALUE, Integer.MAX_VALUE);
    IntegerVariable var39 = new IntegerVariable("var39", -1819, Integer.MIN_VALUE, Integer.MAX_VALUE);
    IntegerVariable var40 = new IntegerVariable("var40", -1819, Integer.MIN_VALUE, Integer.MAX_VALUE);
    IntegerConstant c_11060 = new IntegerConstant(11060);
    IntegerConstant c_12089 = new IntegerConstant(12089);
    IntegerConstant c_14414 = new IntegerConstant(14414);
    IntegerValue left = sub(mul(c_12089, var40), rem(mul(var39, c_14414), var20));
    IntegerValue right = c_11060;
    IntegerConstraint constr = new IntegerConstraint(left, Comparator.GT, 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_20 = ((Number) model.get("var20")).intValue();
        int v_39 = ((Number) model.get("var39")).intValue();
        int v_40 = ((Number) model.get("var40")).intValue();
        assertTrue((12089 * v_40) - ((v_39 * 14414) % v_20) > 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 62 with SolverTimeoutException

use of org.evosuite.symbolic.solver.SolverTimeoutException 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 63 with SolverTimeoutException

use of org.evosuite.symbolic.solver.SolverTimeoutException 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 64 with SolverTimeoutException

use of org.evosuite.symbolic.solver.SolverTimeoutException 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 65 with SolverTimeoutException

use of org.evosuite.symbolic.solver.SolverTimeoutException 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)

Aggregations

SolverTimeoutException (org.evosuite.symbolic.solver.SolverTimeoutException)79 Constraint (org.evosuite.symbolic.expr.Constraint)75 Test (org.junit.Test)75 EvoSuiteSolver (org.evosuite.symbolic.solver.avm.EvoSuiteSolver)74 ArrayList (java.util.ArrayList)68 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)48 IntegerConstant (org.evosuite.symbolic.expr.bv.IntegerConstant)35 SolverResult (org.evosuite.symbolic.solver.SolverResult)34 IntegerVariable (org.evosuite.symbolic.expr.bv.IntegerVariable)25 StringVariable (org.evosuite.symbolic.expr.str.StringVariable)24 RealConstraint (org.evosuite.symbolic.expr.RealConstraint)22 StringConstraint (org.evosuite.symbolic.expr.StringConstraint)22 RealVariable (org.evosuite.symbolic.expr.fp.RealVariable)22 StringConstant (org.evosuite.symbolic.expr.str.StringConstant)18 RealConstant (org.evosuite.symbolic.expr.fp.RealConstant)15 StringBinaryComparison (org.evosuite.symbolic.expr.bv.StringBinaryComparison)13 StringBinaryToIntegerExpression (org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression)10 IntegerBinaryExpression (org.evosuite.symbolic.expr.bv.IntegerBinaryExpression)8 StringUnaryExpression (org.evosuite.symbolic.expr.str.StringUnaryExpression)5 Expression (org.evosuite.symbolic.expr.Expression)4