use of org.evosuite.symbolic.solver.SolverResult in project evosuite by EvoSuite.
the class TestIntegerSearch method testGTArithmetic.
@Test
public void testGTArithmetic() 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.GE, 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.solver.SolverResult in project evosuite by EvoSuite.
the class TestIntegerSearch method testEvosuiteExample3.
@Test
public void testEvosuiteExample3() throws SolverEmptyQueryException {
Properties.DSE_VARIABLE_RESETS = 3;
// (var42__SYM(25721) * (var22__SYM(-1043) - 6860)) == 8275
int var1 = 25721;
int var2 = -1043;
IntegerConstant iconst1 = new IntegerConstant(6860);
IntegerConstant iconst2 = new IntegerConstant(8275);
IntegerVariable ivar1 = new IntegerVariable("test1", var1, Integer.MIN_VALUE, Integer.MAX_VALUE);
IntegerVariable ivar2 = new IntegerVariable("test2", var2, Integer.MIN_VALUE, Integer.MAX_VALUE);
IntegerBinaryExpression sub = new IntegerBinaryExpression(ivar2, Operator.MINUS, iconst1, -7903L);
IntegerBinaryExpression mul = new IntegerBinaryExpression(ivar1, Operator.MUL, sub, -203273063L);
List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
constraints.add(new IntegerConstraint(mul, Comparator.EQ, iconst2));
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 - 6860) == 8275);
} catch (SolverTimeoutException e) {
fail();
}
}
use of org.evosuite.symbolic.solver.SolverResult in project evosuite by EvoSuite.
the class TestIntegerSearch method testLEVariable.
@Test
public void testLEVariable() 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.LE, 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.solver.SolverResult in project evosuite by EvoSuite.
the class TestIntegerSearch method testGEConstant.
@Test
public void testGEConstant() 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.GE, 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.solver.SolverResult in project evosuite by EvoSuite.
the class TestPatternSearch method testMatcherMatches.
@Test
public void testMatcherMatches() throws SolverEmptyQueryException {
String input = "random_value";
String format = "(\\d+)-(\\d\\d)-(\\d)";
// String format = "^(\\d+)-(\\d\\d)-(\\d)$";
StringVariable var0 = new StringVariable("var0", input);
StringConstant symb_regex = ExpressionFactory.buildNewStringConstant(format);
StringBinaryComparison strComp = new StringBinaryComparison(symb_regex, Operator.PATTERNMATCHES, var0, 0L);
StringConstraint constraint = new StringConstraint(strComp, Comparator.NE, new IntegerConstant(0));
List<Constraint<?>> constraints = Collections.<Constraint<?>>singletonList(constraint);
try {
EvoSuiteSolver solver = new EvoSuiteSolver();
SolverResult result = solver.solve(constraints);
assertTrue(result.isSAT());
Map<String, Object> model = result.getModel();
String var0_value = (String) model.get("var0");
Pattern pattern = Pattern.compile(format);
Matcher matcher = pattern.matcher(var0_value);
assertTrue(matcher.matches());
} catch (SolverTimeoutException e) {
fail();
}
}
Aggregations