Search in sources :

Example 16 with IntegerConstant

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

the class TestIntegerSearch method testGEConstant.

@Test
public void testGEConstant() 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.GE, 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 17 with IntegerConstant

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

the class TestPatternSearch method testMatcherMatches.

@Test
public void testMatcherMatches() throws SolverEmptyQueryException {
    String input = "random_value";
    String format = "(\\d+)-(\\d\\d)-(\\d)";
    // String format = "^(\\d+)-(\\d\\d)-(\\d)$";
    StringVariable var0 = new StringVariable("var0", input);
    StringConstant symb_regex = ExpressionFactory.buildNewStringConstant(format);
    StringBinaryComparison strComp = new StringBinaryComparison(symb_regex, Operator.PATTERNMATCHES, var0, 0L);
    StringConstraint constraint = new StringConstraint(strComp, Comparator.NE, new IntegerConstant(0));
    List<Constraint<?>> constraints = Collections.<Constraint<?>>singletonList(constraint);
    try {
        EvoSuiteSolver solver = new EvoSuiteSolver();
        SolverResult result = solver.solve(constraints);
        assertTrue(result.isSAT());
        Map<String, Object> model = result.getModel();
        String var0_value = (String) model.get("var0");
        Pattern pattern = Pattern.compile(format);
        Matcher matcher = pattern.matcher(var0_value);
        assertTrue(matcher.matches());
    } catch (SolverTimeoutException e) {
        fail();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) Pattern(java.util.regex.Pattern) StringConstraint(org.evosuite.symbolic.expr.StringConstraint) StringConstraint(org.evosuite.symbolic.expr.StringConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) Matcher(java.util.regex.Matcher) EvoSuiteSolver(org.evosuite.symbolic.solver.avm.EvoSuiteSolver) SolverResult(org.evosuite.symbolic.solver.SolverResult) StringVariable(org.evosuite.symbolic.expr.str.StringVariable) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant) StringBinaryComparison(org.evosuite.symbolic.expr.bv.StringBinaryComparison) StringConstant(org.evosuite.symbolic.expr.str.StringConstant) Test(org.junit.Test)

Example 18 with IntegerConstant

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

the class TestConstraintSolver3 method buildConstraintSystem.

private static Collection<Constraint<?>> buildConstraintSystem() {
    StringVariable var0 = new StringVariable("var0", INIT_STRING);
    StringToIntegerCast castStr = new StringToIntegerCast(var0, (long) Integer.parseInt(INIT_STRING));
    IntegerConstant const126 = new IntegerConstant(EXPECTED_INTEGER);
    IntegerConstraint constr1 = new IntegerConstraint(castStr, Comparator.EQ, const126);
    return Arrays.<Constraint<?>>asList(constr1);
}
Also used : IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) StringToIntegerCast(org.evosuite.symbolic.expr.bv.StringToIntegerCast) StringVariable(org.evosuite.symbolic.expr.str.StringVariable) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant)

Example 19 with IntegerConstant

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

the class TestIsInteger method testIsInteger.

@Test
public void testIsInteger() throws SolverEmptyQueryException {
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    constraints.add(new IntegerConstraint(new StringUnaryToIntegerExpression(new StringVariable("var0", "hello"), Operator.IS_INTEGER, 0L), Comparator.NE, new IntegerConstant(0)));
    EvoSuiteSolver solver = new EvoSuiteSolver();
    try {
        SolverResult result = solver.solve(constraints);
        assertTrue(result.isSAT());
    } catch (SolverTimeoutException e) {
        fail();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) 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) StringUnaryToIntegerExpression(org.evosuite.symbolic.expr.bv.StringUnaryToIntegerExpression) StringVariable(org.evosuite.symbolic.expr.str.StringVariable) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant) Test(org.junit.Test)

Example 20 with IntegerConstant

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

the class TestStringSearch method testRegexMatchesTrue.

@Test
public void testRegexMatchesTrue() {
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    String var1 = "test";
    String const2 = "TEST";
    StringVariable strVar = new StringVariable("test1", var1);
    StringConstant strConst = new StringConstant(const2);
    StringBinaryComparison strComp = new StringBinaryComparison(strVar, Operator.PATTERNMATCHES, strConst, 0L);
    constraints.add(new StringConstraint(strComp, Comparator.NE, new IntegerConstant(0)));
    EvoSuiteSolver skr = new EvoSuiteSolver();
    Map<String, Object> result;
    try {
        result = solve(skr, constraints);
        assertNotNull(result);
        assertNotNull(result.get("test1"));
        assertTrue(result.get("test1").toString().matches(const2));
    } catch (SolverTimeoutException e) {
        fail();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) StringConstraint(org.evosuite.symbolic.expr.StringConstraint) StringConstraint(org.evosuite.symbolic.expr.StringConstraint) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) EvoSuiteSolver(org.evosuite.symbolic.solver.avm.EvoSuiteSolver) ArrayList(java.util.ArrayList) StringVariable(org.evosuite.symbolic.expr.str.StringVariable) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant) StringBinaryComparison(org.evosuite.symbolic.expr.bv.StringBinaryComparison) StringConstant(org.evosuite.symbolic.expr.str.StringConstant) 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