Search in sources :

Example 46 with IntegerConstant

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

the class StringAVMTests method getPatternConstraint.

private List<Constraint<?>> getPatternConstraint(StringVariable var, String format) {
    StringConstant symb_regex = ExpressionFactory.buildNewStringConstant(format);
    StringBinaryComparison strComp = new StringBinaryComparison(symb_regex, Operator.PATTERNMATCHES, var, 0L);
    StringConstraint constraint = new StringConstraint(strComp, Comparator.NE, new IntegerConstant(0));
    List<Constraint<?>> constraints = Collections.<Constraint<?>>singletonList(constraint);
    return constraints;
}
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) StringConstant(org.evosuite.symbolic.expr.str.StringConstant) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant)

Example 47 with IntegerConstant

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

the class TestConstraintSolver2 method buildConstraintSystem.

private static Collection<Constraint<?>> buildConstraintSystem() {
    StringVariable var0 = new StringVariable("var0", INIT_STRING);
    StringConstant const0 = new StringConstant(EXPECTED_STRING);
    StringBinaryComparison strEqual = new StringBinaryComparison(var0, Operator.EQUALS, const0, (long) 0);
    IntegerConstant const_zero = new IntegerConstant(0);
    StringConstraint constr1 = new StringConstraint(strEqual, Comparator.NE, const_zero);
    return Arrays.<Constraint<?>>asList(constr1);
}
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)

Example 48 with IntegerConstant

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

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

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

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