Search in sources :

Example 26 with IntegerVariable

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

the class TestIntegerSearch method testEQArithmetic.

@Test
public void testEQArithmetic() throws SolverEmptyQueryException {
    int var1 = 0;
    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.EQ, 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 27 with IntegerVariable

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

the class TestIntegerSearch method testNEVariable.

@Test
public void testNEVariable() 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.NE, 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 28 with IntegerVariable

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

the class TestIntegerSearch method testGEVariable.

@Test
public void testGEVariable() throws SolverEmptyQueryException {
    int var1 = 0;
    int var2 = 1;
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    constraints.add(new IntegerConstraint(new IntegerVariable("test1", var1, -1000000, 1000000), Comparator.GE, 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 29 with IntegerVariable

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

the class TestIntegerSearch method testGTConstant.

@Test
public void testGTConstant() 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.GT, 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 30 with IntegerVariable

use of org.evosuite.symbolic.expr.bv.IntegerVariable 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)

Aggregations

IntegerVariable (org.evosuite.symbolic.expr.bv.IntegerVariable)36 Constraint (org.evosuite.symbolic.expr.Constraint)26 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)25 SolverResult (org.evosuite.symbolic.solver.SolverResult)25 SolverTimeoutException (org.evosuite.symbolic.solver.SolverTimeoutException)25 EvoSuiteSolver (org.evosuite.symbolic.solver.avm.EvoSuiteSolver)24 Test (org.junit.Test)24 ArrayList (java.util.ArrayList)22 IntegerConstant (org.evosuite.symbolic.expr.bv.IntegerConstant)12 IntegerBinaryExpression (org.evosuite.symbolic.expr.bv.IntegerBinaryExpression)7 ReferenceConstant (org.evosuite.symbolic.expr.ref.ReferenceConstant)6 CodeUnderTestException (org.evosuite.testcase.execution.CodeUnderTestException)6 EvosuiteError (org.evosuite.testcase.execution.EvosuiteError)6 VariableReference (org.evosuite.testcase.variable.VariableReference)6 RealVariable (org.evosuite.symbolic.expr.fp.RealVariable)4 StringVariable (org.evosuite.symbolic.expr.str.StringVariable)4 LinkedList (java.util.LinkedList)2 IntegerValue (org.evosuite.symbolic.expr.bv.IntegerValue)2 HashSet (java.util.HashSet)1 Variable (org.evosuite.symbolic.expr.Variable)1