use of org.evosuite.symbolic.expr.bv.IntegerConstant in project evosuite by EvoSuite.
the class TestIntegerSearch method testEvosuiteExample6.
@Test
public void testEvosuiteExample6() throws SolverEmptyQueryException {
Properties.DSE_VARIABLE_RESETS = 3;
// Cnstr 0 : var2__SYM(1890) >= 0 dist: 682.3333333333334
// Cnstr 1 : var1__SYM(-157) <= 0 dist: 682.3333333333334
// Cnstr 2 : var2__SYM(1890) <= var1__SYM(-157) dist: 682.3333333333334
// y >= 0
// x <= 0
// y <= x
int x = -157;
int y = 1890;
// TestSuiteDSE.setStart();
// int x = 879254357;
// int y = 1013652704;
IntegerVariable ivar1 = new IntegerVariable("test1", x, Integer.MIN_VALUE, Integer.MAX_VALUE);
IntegerVariable ivar2 = new IntegerVariable("test2", y, Integer.MIN_VALUE, Integer.MAX_VALUE);
List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
constraints.add(new IntegerConstraint(ivar2, Comparator.GE, new IntegerConstant(0)));
constraints.add(new IntegerConstraint(ivar1, Comparator.LE, new IntegerConstant(0)));
constraints.add(new IntegerConstraint(ivar2, Comparator.LE, ivar1));
try {
EvoSuiteSolver solver = new EvoSuiteSolver();
SolverResult solverResult = solver.solve(constraints);
assertTrue(solverResult.isSAT());
Map<String, Object> model = solverResult.getModel();
if (model.containsKey("test1"))
x = ((Number) model.get("test1")).intValue();
if (model.containsKey("test2"))
y = ((Number) model.get("test2")).intValue();
assertTrue(y >= 0);
assertTrue(x <= 0);
assertTrue(y <= x);
} catch (SolverTimeoutException e) {
fail();
}
}
use of org.evosuite.symbolic.expr.bv.IntegerConstant 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.bv.IntegerConstant 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.bv.IntegerConstant 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;
}
use of org.evosuite.symbolic.expr.bv.IntegerConstant in project evosuite by EvoSuite.
the class TestStringDistance method createConstraints.
private Collection<Constraint<?>> createConstraints(final String str1, final String str2) {
StringVariable var1 = new StringVariable("var0", str1);
StringConstant const1 = new StringConstant(str2);
StringBinaryComparison comp = new StringBinaryComparison(var1, Operator.EQUALS, const1, 0L);
IntegerConstant zero = new IntegerConstant(0);
StringConstraint stringConstraint = new StringConstraint(comp, Comparator.NE, zero);
Collection<Constraint<?>> cnstr = Collections.<Constraint<?>>singletonList(stringConstraint);
return cnstr;
}
Aggregations