use of org.evosuite.symbolic.expr.IntegerConstraint 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.IntegerConstraint in project evosuite by EvoSuite.
the class TestIntegerSearch method testLTConstant.
@Test
public void testLTConstant() 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", 235086, -1000000, 1000000), Comparator.LT, 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();
}
}
use of org.evosuite.symbolic.expr.IntegerConstraint in project evosuite by EvoSuite.
the class TestIntegerSearch method testLEConstant.
@Test
public void testLEConstant() 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", 235086, -1000000, 1000000), Comparator.LE, 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();
}
}
use of org.evosuite.symbolic.expr.IntegerConstraint in project evosuite by EvoSuite.
the class TestIntegerSearch method testLTVariable.
@Test
public void testLTVariable() throws SolverEmptyQueryException {
int var1 = 2;
int var2 = 1;
List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
constraints.add(new IntegerConstraint(new IntegerVariable("test1", var1, -1000000, 1000000), Comparator.LT, new IntegerVariable("test2", var2, -1000000, 1000000)));
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();
assertTrue(var1 < var2);
} catch (SolverTimeoutException e) {
fail();
}
}
use of org.evosuite.symbolic.expr.IntegerConstraint in project evosuite by EvoSuite.
the class TestSolverStringFunctions method testNegativeLength.
public static Map<String, Object> testNegativeLength(Solver solver) throws SecurityException, NoSuchMethodException, SolverTimeoutException {
IntegerConstraint newIntegerConstraint = new IntegerConstraint(new StringUnaryToIntegerExpression(new StringVariable("var0", "01234"), Operator.LENGTH, (long) 5), Comparator.LT, new IntegerConstant(0));
Collection<Constraint<?>> constraints = Collections.<Constraint<?>>singleton(newIntegerConstraint);
Map<String, Object> solution = solve(solver, constraints);
return solution;
}
Aggregations