Search in sources :

Example 21 with IntegerBinaryExpression

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

the class TestIntegerSearch method div.

private static IntegerValue div(IntegerValue left, IntegerValue right) {
    int left_val = left.getConcreteValue().intValue();
    int right_val = right.getConcreteValue().intValue();
    return new IntegerBinaryExpression(left, Operator.DIV, right, (long) left_val / right_val);
}
Also used : IntegerBinaryExpression(org.evosuite.symbolic.expr.bv.IntegerBinaryExpression) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint)

Example 22 with IntegerBinaryExpression

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

the class TestIntegerSearch method testLEArithmetic.

@Test
public void testLEArithmetic() throws SolverEmptyQueryException {
    int var1 = 3;
    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.LE, 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 23 with IntegerBinaryExpression

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

the class TestIntegerSearch method rem.

private static IntegerValue rem(IntegerValue left, IntegerValue right) {
    int left_val = left.getConcreteValue().intValue();
    int right_val = right.getConcreteValue().intValue();
    return new IntegerBinaryExpression(left, Operator.REM, right, (long) left_val % right_val);
}
Also used : IntegerBinaryExpression(org.evosuite.symbolic.expr.bv.IntegerBinaryExpression) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint)

Example 24 with IntegerBinaryExpression

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

the class TestIntegerSearch method testGEArithmetic.

@Test
public void testGEArithmetic() 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.GT, 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 25 with IntegerBinaryExpression

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

Aggregations

IntegerBinaryExpression (org.evosuite.symbolic.expr.bv.IntegerBinaryExpression)27 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)22 IntegerValue (org.evosuite.symbolic.expr.bv.IntegerValue)14 Constraint (org.evosuite.symbolic.expr.Constraint)12 ArrayList (java.util.ArrayList)8 SolverTimeoutException (org.evosuite.symbolic.solver.SolverTimeoutException)8 EvoSuiteSolver (org.evosuite.symbolic.solver.avm.EvoSuiteSolver)8 Test (org.junit.Test)8 IntegerVariable (org.evosuite.symbolic.expr.bv.IntegerVariable)7 SolverResult (org.evosuite.symbolic.solver.SolverResult)7 IntegerConstant (org.evosuite.symbolic.expr.bv.IntegerConstant)3 StringBinaryToIntegerExpression (org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression)1 StringUnaryToIntegerExpression (org.evosuite.symbolic.expr.bv.StringUnaryToIntegerExpression)1 StringVariable (org.evosuite.symbolic.expr.str.StringVariable)1