use of org.evosuite.symbolic.expr.Constraint 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.expr.Constraint 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();
}
}
use of org.evosuite.symbolic.expr.Constraint in project evosuite by EvoSuite.
the class TestRealSearch method testEQConstantAfterComma.
@Test
public void testEQConstantAfterComma() {
List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
constraints.add(new RealConstraint(new RealVariable("test1", 0, -1000000.0, 1000000.0), Comparator.EQ, new RealConstant(0.35082)));
EvoSuiteSolver skr = new EvoSuiteSolver();
Map<String, Object> result;
try {
result = solve(skr, constraints);
assertNotNull(result);
assertNotNull(result.get("test1"));
assertTrue(0.35082 == ((Number) result.get("test1")).doubleValue());
} catch (SolverTimeoutException e) {
fail();
}
}
use of org.evosuite.symbolic.expr.Constraint in project evosuite by EvoSuite.
the class TestRealSearch method testGTConstantAfterComma.
@Test
public void testGTConstantAfterComma() {
List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
constraints.add(new RealConstraint(new RealVariable("test1", 2.0, -1000000.0, 1000000.0), Comparator.GT, new RealConstant(2.35082)));
EvoSuiteSolver skr = new EvoSuiteSolver();
Map<String, Object> result;
try {
result = solve(skr, constraints);
assertNotNull(result);
assertNotNull(result.get("test1"));
assertTrue(2.35082 < ((Number) result.get("test1")).doubleValue());
} catch (SolverTimeoutException e) {
fail();
}
}
use of org.evosuite.symbolic.expr.Constraint in project evosuite by EvoSuite.
the class TestRealSearch method testNEVariable.
@Test
public void testNEVariable() {
double var1 = 1.5546;
double var2 = 1.5546;
List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
constraints.add(new RealConstraint(new RealVariable("test1", var1, -1000000.0, 1000000.0), Comparator.NE, new RealVariable("test2", var2, -1000000.0, 1000000.0)));
EvoSuiteSolver skr = new EvoSuiteSolver();
Map<String, Object> result;
try {
result = solve(skr, constraints);
assertNotNull(result);
if (result.containsKey("test1"))
var1 = ((Number) result.get("test1")).doubleValue();
if (result.containsKey("test2"))
var2 = ((Number) result.get("test2")).doubleValue();
assertTrue(var1 != var2);
} catch (SolverTimeoutException e) {
fail();
}
}
Aggregations