use of org.evosuite.symbolic.expr.bv.IntegerVariable in project evosuite by EvoSuite.
the class TestIntegerSearch method testEQArithmetic.
@Test
public void testEQArithmetic() throws SolverEmptyQueryException {
int var1 = 0;
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.EQ, 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.IntegerVariable in project evosuite by EvoSuite.
the class TestIntegerSearch method testNEVariable.
@Test
public void testNEVariable() throws SolverEmptyQueryException {
int var1 = 1;
int var2 = 1;
List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
constraints.add(new IntegerConstraint(new IntegerVariable("test1", var1, -1000000, 1000000), Comparator.NE, 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.bv.IntegerVariable in project evosuite by EvoSuite.
the class TestIntegerSearch method testGEVariable.
@Test
public void testGEVariable() throws SolverEmptyQueryException {
int var1 = 0;
int var2 = 1;
List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
constraints.add(new IntegerConstraint(new IntegerVariable("test1", var1, -1000000, 1000000), Comparator.GE, 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.bv.IntegerVariable in project evosuite by EvoSuite.
the class TestIntegerSearch method testGTConstant.
@Test
public void testGTConstant() 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", 0, -1000000, 1000000), Comparator.GT, 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.bv.IntegerVariable in project evosuite by EvoSuite.
the class TestIntegerSearch method testEvosuiteExample4_2.
@Test
public void testEvosuiteExample4_2() throws SolverEmptyQueryException {
IntegerVariable var20 = new IntegerVariable("var20", 17433, Integer.MIN_VALUE, Integer.MAX_VALUE);
IntegerVariable var39 = new IntegerVariable("var39", -1819, Integer.MIN_VALUE, Integer.MAX_VALUE);
IntegerVariable var40 = new IntegerVariable("var40", -1819, Integer.MIN_VALUE, Integer.MAX_VALUE);
IntegerConstant c_11060 = new IntegerConstant(11060);
IntegerConstant c_12089 = new IntegerConstant(12089);
IntegerConstant c_14414 = new IntegerConstant(14414);
IntegerValue left = sub(mul(c_12089, var40), rem(mul(var39, c_14414), var20));
IntegerValue right = c_11060;
IntegerConstraint constr = new IntegerConstraint(left, Comparator.GT, right);
List<Constraint<?>> constraints = Collections.<Constraint<?>>singletonList(constr);
try {
EvoSuiteSolver solver = new EvoSuiteSolver();
SolverResult solverResult = solver.solve(constraints);
assertTrue(solverResult.isSAT());
Map<String, Object> model = solverResult.getModel();
int v_20 = ((Number) model.get("var20")).intValue();
int v_39 = ((Number) model.get("var39")).intValue();
int v_40 = ((Number) model.get("var40")).intValue();
assertTrue((12089 * v_40) - ((v_39 * 14414) % v_20) > 11060);
} catch (SolverTimeoutException e) {
fail();
}
}
Aggregations