use of org.evosuite.symbolic.expr.str.StringVariable in project evosuite by EvoSuite.
the class TestStringSearch method testRegexMatchesFalse.
@Test
public void testRegexMatchesFalse() {
List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
String var1 = "testsomestring";
String const2 = "testsomestring";
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.EQ, new IntegerConstant(0)));
EvoSuiteSolver skr = new EvoSuiteSolver();
Map<String, Object> result;
try {
result = solve(skr, constraints);
assertNotNull(result);
assertNotNull(result.get("test1"));
assertFalse("Result should not match TEST: " + result.get("test1").toString(), result.get("test1").toString().matches(const2));
} catch (SolverTimeoutException e) {
fail();
}
}
use of org.evosuite.symbolic.expr.str.StringVariable in project evosuite by EvoSuite.
the class TestStringSearch method testStartsWithTrueConstant.
@Test
public void testStartsWithTrueConstant() {
List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
String var1 = "foo";
String const2 = "test";
StringVariable strVar = new StringVariable("test1", var1);
StringConstant strConst = new StringConstant(const2);
IntegerConstant offs_expr = new IntegerConstant(2);
ArrayList<Expression<?>> other = new ArrayList<Expression<?>>();
other.add(offs_expr);
StringMultipleComparison strComp = new StringMultipleComparison(strVar, Operator.STARTSWITH, strConst, other, 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()).startsWith(const2, 2));
} catch (SolverTimeoutException e) {
fail();
}
}
use of org.evosuite.symbolic.expr.str.StringVariable 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);
}
use of org.evosuite.symbolic.expr.str.StringVariable 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();
}
}
Aggregations