Search in sources :

Example 11 with StringBinaryToIntegerExpression

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

the class TestConstraintSolver1 method buildConstraintSystem.

private static Collection<Constraint<?>> buildConstraintSystem() {
    StringVariable var0 = new StringVariable("var0", INIT_STRING);
    StringUnaryToIntegerExpression length = new StringUnaryToIntegerExpression(var0, Operator.LENGTH, (long) INIT_STRING.length());
    IntegerConstant const3 = new IntegerConstant(3);
    StringBinaryToIntegerExpression charAt3 = new StringBinaryToIntegerExpression(var0, Operator.CHARAT, const3, (long) INIT_STRING.charAt(3));
    IntegerConstant const4 = new IntegerConstant(4);
    StringBinaryToIntegerExpression charAt4 = new StringBinaryToIntegerExpression(var0, Operator.CHARAT, const4, (long) INIT_STRING.charAt(4));
    IntegerConstant const5 = new IntegerConstant(INIT_STRING.length());
    IntegerConstant const95 = new IntegerConstant(EXPECTED_STRING.charAt(3));
    IntegerConstant const43 = new IntegerConstant(EXPECTED_STRING.charAt(4));
    IntegerConstraint constr1 = new IntegerConstraint(length, Comparator.EQ, const5);
    IntegerConstraint constr2 = new IntegerConstraint(charAt3, Comparator.EQ, const95);
    IntegerConstraint constr3 = new IntegerConstraint(charAt4, Comparator.EQ, const43);
    return Arrays.<Constraint<?>>asList(constr1, constr2, constr3);
}
Also used : IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) StringBinaryToIntegerExpression(org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression) StringUnaryToIntegerExpression(org.evosuite.symbolic.expr.bv.StringUnaryToIntegerExpression) StringVariable(org.evosuite.symbolic.expr.str.StringVariable) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant)

Example 12 with StringBinaryToIntegerExpression

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

the class TestStringSearch3 method testCharAt.

// (var3("<V6h") charAt 0) >= 0,
// (var3("<V6h").length() - 1) >= 0,
// (var3("<V6h") charAt 0) == 10]
@Test
public void testCharAt() {
    StringVariable var3 = new StringVariable("var3", "<\n V6h");
    StringBinaryToIntegerExpression var3_charAt_0 = new StringBinaryToIntegerExpression(var3, Operator.CHARAT, new IntegerConstant(0), (long) "<\n V6h".charAt(0));
    IntegerConstraint cnstr1 = new IntegerConstraint(var3_charAt_0, Comparator.GE, new IntegerConstant(0));
    StringUnaryToIntegerExpression var3_length = new StringUnaryToIntegerExpression(var3, Operator.LENGTH, (long) "<\n V6h".length());
    IntegerBinaryExpression length_minus_one = new IntegerBinaryExpression(var3_length, Operator.MINUS, new IntegerConstant(1), (long) "<\n V6h".length() - 1);
    IntegerConstraint cnstr2 = new IntegerConstraint(length_minus_one, Comparator.GE, new IntegerConstant(0));
    IntegerConstraint cnstr3 = new IntegerConstraint(var3_charAt_0, Comparator.EQ, new IntegerConstant(10));
    ArrayList<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    constraints.add(cnstr1);
    constraints.add(cnstr2);
    constraints.add(cnstr3);
    EvoSuiteSolver solver = new EvoSuiteSolver();
    Map<String, Object> solution;
    try {
        solution = solve(solver, constraints);
        assertNotNull(solution);
    } 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) StringBinaryToIntegerExpression(org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression) ArrayList(java.util.ArrayList) StringUnaryToIntegerExpression(org.evosuite.symbolic.expr.bv.StringUnaryToIntegerExpression) StringVariable(org.evosuite.symbolic.expr.str.StringVariable) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Test(org.junit.Test)

Aggregations

StringBinaryToIntegerExpression (org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression)12 IntegerConstant (org.evosuite.symbolic.expr.bv.IntegerConstant)9 Constraint (org.evosuite.symbolic.expr.Constraint)7 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)7 ArrayList (java.util.ArrayList)6 StringVariable (org.evosuite.symbolic.expr.str.StringVariable)6 SolverTimeoutException (org.evosuite.symbolic.solver.SolverTimeoutException)6 EvoSuiteSolver (org.evosuite.symbolic.solver.avm.EvoSuiteSolver)6 Test (org.junit.Test)6 StringConstraint (org.evosuite.symbolic.expr.StringConstraint)4 ReferenceConstant (org.evosuite.symbolic.expr.ref.ReferenceConstant)3 StringValue (org.evosuite.symbolic.expr.str.StringValue)3 StringUnaryToIntegerExpression (org.evosuite.symbolic.expr.bv.StringUnaryToIntegerExpression)2 IntegerBinaryExpression (org.evosuite.symbolic.expr.bv.IntegerBinaryExpression)1 IntegerValue (org.evosuite.symbolic.expr.bv.IntegerValue)1 IntegerVariable (org.evosuite.symbolic.expr.bv.IntegerVariable)1 StringConstant (org.evosuite.symbolic.expr.str.StringConstant)1 SolverResult (org.evosuite.symbolic.solver.SolverResult)1