use of org.evosuite.symbolic.expr.bv.IntegerBinaryExpression in project evosuite by EvoSuite.
the class TestIntegerSearch method testNEArithmetic.
@Test
public void testNEArithmetic() throws SolverEmptyQueryException {
int var1 = 2;
int var2 = 1;
int var3 = 1;
assertTrue(var1 == var2 + var3);
List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
constraints.add(new IntegerConstraint(new IntegerVariable("test1", var1, -1000000, 1000000), Comparator.NE, new IntegerBinaryExpression(new IntegerVariable("test2", var2, -1000000, 1000000), Operator.PLUS, new IntegerVariable("test3", var3, -1000000, 1000000), 0L)));
try {
EvoSuiteSolver solver = new EvoSuiteSolver();
SolverResult solverResult = solver.solve(constraints);
assertTrue(solverResult.isSAT());
Map<String, Object> model = solverResult.getModel();
if (model.containsKey("test1"))
var1 = ((Number) model.get("test1")).intValue();
if (model.containsKey("test2"))
var2 = ((Number) model.get("test2")).intValue();
if (model.containsKey("test3"))
var3 = ((Number) model.get("test3")).intValue();
assertTrue(var1 != var2 + var3);
} catch (SolverTimeoutException e) {
fail();
}
}
use of org.evosuite.symbolic.expr.bv.IntegerBinaryExpression 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