use of org.evosuite.symbolic.solver.SolverTimeoutException 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.solver.SolverTimeoutException in project evosuite by EvoSuite.
the class TestConstraintSolver1 method test.
@Test
public void test() throws SolverEmptyQueryException {
// 5000000000000L; TODO - ??
Properties.LOCAL_SEARCH_BUDGET = 100;
Properties.LOCAL_SEARCH_BUDGET_TYPE = LocalSearchBudgetType.FITNESS_EVALUATIONS;
Collection<Constraint<?>> constraints = buildConstraintSystem();
System.out.println("Constraints:");
for (Constraint<?> c : constraints) {
System.out.println(c.toString());
}
EvoSuiteSolver seeker = new EvoSuiteSolver();
try {
SolverResult solverResult = seeker.solve(constraints);
assertTrue(solverResult.isSAT());
Map<String, Object> model = solverResult.getModel();
System.out.println(model);
Object var0 = model.get("var0");
System.out.println("Expected: " + EXPECTED_STRING);
System.out.println("Found: " + var0);
assertEquals(EXPECTED_STRING, var0);
} catch (SolverTimeoutException e) {
fail();
}
}
use of org.evosuite.symbolic.solver.SolverTimeoutException in project evosuite by EvoSuite.
the class TestConstraintSolver3 method test.
@Test
public void test() throws SolverEmptyQueryException {
// 5000000000000L; TODO - ??
Properties.LOCAL_SEARCH_BUDGET = 100;
Properties.LOCAL_SEARCH_BUDGET_TYPE = LocalSearchBudgetType.FITNESS_EVALUATIONS;
Collection<Constraint<?>> constraints = buildConstraintSystem();
System.out.println("Constraints:");
for (Constraint<?> c : constraints) {
System.out.println(c.toString());
}
System.out.println("");
System.out.println("Initial: " + INIT_STRING);
EvoSuiteSolver solver = new EvoSuiteSolver();
try {
SolverResult result = solver.solve(constraints);
if (result.isUNSAT()) {
fail("search was unsuccessfull");
} else {
Map<String, Object> model = result.getModel();
Object var0 = model.get("var0");
System.out.println("Expected: " + EXPECTED_INTEGER);
System.out.println("Found: " + var0);
assertEquals(String.valueOf(EXPECTED_INTEGER), var0);
}
} catch (SolverTimeoutException e) {
fail();
}
}
use of org.evosuite.symbolic.solver.SolverTimeoutException 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