Search in sources :

Example 51 with IntegerConstant

use of org.evosuite.symbolic.expr.bv.IntegerConstant 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 52 with IntegerConstant

use of org.evosuite.symbolic.expr.bv.IntegerConstant 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 53 with IntegerConstant

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

Example 54 with IntegerConstant

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

the class TestSolverStringFunctions method testNegativeLength.

public static Map<String, Object> testNegativeLength(Solver solver) throws SecurityException, NoSuchMethodException, SolverTimeoutException {
    IntegerConstraint newIntegerConstraint = new IntegerConstraint(new StringUnaryToIntegerExpression(new StringVariable("var0", "01234"), Operator.LENGTH, (long) 5), Comparator.LT, new IntegerConstant(0));
    Collection<Constraint<?>> constraints = Collections.<Constraint<?>>singleton(newIntegerConstraint);
    Map<String, Object> solution = solve(solver, constraints);
    return solution;
}
Also used : IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) StringUnaryToIntegerExpression(org.evosuite.symbolic.expr.bv.StringUnaryToIntegerExpression) StringVariable(org.evosuite.symbolic.expr.str.StringVariable) TestCaseStringAppendString(com.examples.with.different.packagename.solver.TestCaseStringAppendString) TestCaseStringLastIndexOfString(com.examples.with.different.packagename.solver.TestCaseStringLastIndexOfString) TestCaseStringIndexOfString(com.examples.with.different.packagename.solver.TestCaseStringIndexOfString) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant)

Example 55 with IntegerConstant

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

the class TestStringDistance method createConstraints.

private Collection<Constraint<?>> createConstraints(final String str1, final String str2) {
    StringVariable var1 = new StringVariable("var0", str1);
    StringConstant const1 = new StringConstant(str2);
    StringBinaryComparison comp = new StringBinaryComparison(var1, Operator.EQUALS, const1, 0L);
    IntegerConstant zero = new IntegerConstant(0);
    StringConstraint stringConstraint = new StringConstraint(comp, Comparator.NE, zero);
    Collection<Constraint<?>> cnstr = Collections.<Constraint<?>>singletonList(stringConstraint);
    return cnstr;
}
Also used : StringConstraint(org.evosuite.symbolic.expr.StringConstraint) StringConstraint(org.evosuite.symbolic.expr.StringConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) StringBinaryComparison(org.evosuite.symbolic.expr.bv.StringBinaryComparison) StringVariable(org.evosuite.symbolic.expr.str.StringVariable) StringConstant(org.evosuite.symbolic.expr.str.StringConstant) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant)

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