Search in sources :

Example 66 with SolverTimeoutException

use of org.evosuite.symbolic.solver.SolverTimeoutException 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();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) EvoSuiteSolver(org.evosuite.symbolic.solver.avm.EvoSuiteSolver) ArrayList(java.util.ArrayList) SolverResult(org.evosuite.symbolic.solver.SolverResult) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) IntegerVariable(org.evosuite.symbolic.expr.bv.IntegerVariable) Test(org.junit.Test)

Example 67 with SolverTimeoutException

use of org.evosuite.symbolic.solver.SolverTimeoutException 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();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) EvoSuiteSolver(org.evosuite.symbolic.solver.avm.EvoSuiteSolver) ArrayList(java.util.ArrayList) SolverResult(org.evosuite.symbolic.solver.SolverResult) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) IntegerVariable(org.evosuite.symbolic.expr.bv.IntegerVariable) Test(org.junit.Test)

Example 68 with SolverTimeoutException

use of org.evosuite.symbolic.solver.SolverTimeoutException in project evosuite by EvoSuite.

the class TestRealConstraint method test.

@Test
public void test() throws SolverEmptyQueryException {
    // 5000000000000L; TODO - ??
    Properties.LOCAL_SEARCH_BUDGET = 100;
    Properties.LOCAL_SEARCH_BUDGET_TYPE = LocalSearchBudgetType.FITNESS_EVALUATIONS;
    Collection<Constraint<?>> constraints = buildConstraintSystem();
    System.out.println("Constraints:");
    for (Constraint<?> c : constraints) {
        System.out.println(c.toString());
    }
    System.out.println("");
    System.out.println("Initial: " + String.valueOf(INIT_DOUBLE));
    EvoSuiteSolver seeker = new EvoSuiteSolver();
    try {
        SolverResult result = seeker.solve(constraints);
        if (result.isUNSAT()) {
            fail("search was unsuccessfull");
        } else {
            Map<String, Object> model = result.getModel();
            Object var0 = model.get("var0");
            System.out.println("Expected: " + EXPECTED_DOUBLE);
            System.out.println("Found: " + var0);
            assertEquals(EXPECTED_DOUBLE, var0);
        }
    } catch (SolverTimeoutException e) {
        fail();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) Constraint(org.evosuite.symbolic.expr.Constraint) RealConstraint(org.evosuite.symbolic.expr.RealConstraint) EvoSuiteSolver(org.evosuite.symbolic.solver.avm.EvoSuiteSolver) SolverResult(org.evosuite.symbolic.solver.SolverResult) Test(org.junit.Test)

Example 69 with SolverTimeoutException

use of org.evosuite.symbolic.solver.SolverTimeoutException in project evosuite by EvoSuite.

the class TestStringSearch method testEqualsTrueConstant.

@Test
public void testEqualsTrueConstant() {
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    String var1 = "foo";
    String const2 = "test";
    StringVariable strVar = new StringVariable("test1", var1);
    StringConstant strConst = new StringConstant(const2);
    StringBinaryComparison strComp = new StringBinaryComparison(strVar, Operator.EQUALS, strConst, 0L);
    constraints.add(new StringConstraint(strComp, Comparator.NE, new IntegerConstant(0)));
    EvoSuiteSolver skr = new EvoSuiteSolver();
    Map<String, Object> result;
    try {
        result = solve(skr, constraints);
        assertNotNull(result);
        assertNotNull(result.get("test1"));
        assertTrue(const2.equals(result.get("test1").toString()));
    } catch (SolverTimeoutException e) {
        fail();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) StringConstraint(org.evosuite.symbolic.expr.StringConstraint) StringConstraint(org.evosuite.symbolic.expr.StringConstraint) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) EvoSuiteSolver(org.evosuite.symbolic.solver.avm.EvoSuiteSolver) ArrayList(java.util.ArrayList) StringVariable(org.evosuite.symbolic.expr.str.StringVariable) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant) StringBinaryComparison(org.evosuite.symbolic.expr.bv.StringBinaryComparison) StringConstant(org.evosuite.symbolic.expr.str.StringConstant) Test(org.junit.Test)

Example 70 with SolverTimeoutException

use of org.evosuite.symbolic.solver.SolverTimeoutException in project evosuite by EvoSuite.

the class TestStringSearch method testRegionMatchesICTrueConstant.

@Test
public void testRegionMatchesICTrueConstant() {
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    String var1 = "teXto";
    String const2 = "rtestooo";
    boolean ignore_case = true;
    int offset1 = 0;
    int offset2 = 1;
    int len = 4;
    StringVariable strVar = new StringVariable("test1", var1);
    StringConstant strConst = new StringConstant(const2);
    IntegerConstant len_expr = new IntegerConstant(len);
    IntegerConstant offs_one = new IntegerConstant(offset1);
    IntegerConstant offs_two = new IntegerConstant(offset2);
    IntegerConstant ign_case = new IntegerConstant(ignore_case ? 1 : 0);
    ArrayList<Expression<?>> other = new ArrayList<Expression<?>>();
    other.add(offs_one);
    other.add(offs_two);
    other.add(len_expr);
    other.add(ign_case);
    StringMultipleComparison strComp = new StringMultipleComparison(strVar, Operator.REGIONMATCHES, strConst, other, 0L);
    constraints.add(new StringConstraint(strComp, Comparator.NE, new IntegerConstant(0)));
    EvoSuiteSolver skr = new EvoSuiteSolver();
    Map<String, Object> result;
    try {
        result = solve(skr, constraints);
        assertNotNull(result);
        assertNotNull(result.get("test1"));
        assertTrue((result.get("test1").toString()).regionMatches(ignore_case, offset1, const2, offset2, len));
    } catch (SolverTimeoutException e) {
        fail();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) StringMultipleComparison(org.evosuite.symbolic.expr.bv.StringMultipleComparison) StringConstraint(org.evosuite.symbolic.expr.StringConstraint) StringConstraint(org.evosuite.symbolic.expr.StringConstraint) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) EvoSuiteSolver(org.evosuite.symbolic.solver.avm.EvoSuiteSolver) ArrayList(java.util.ArrayList) StringVariable(org.evosuite.symbolic.expr.str.StringVariable) StringConstraint(org.evosuite.symbolic.expr.StringConstraint) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant) Expression(org.evosuite.symbolic.expr.Expression) StringBinaryToIntegerExpression(org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression) StringUnaryExpression(org.evosuite.symbolic.expr.str.StringUnaryExpression) StringConstant(org.evosuite.symbolic.expr.str.StringConstant) Test(org.junit.Test)

Aggregations

SolverTimeoutException (org.evosuite.symbolic.solver.SolverTimeoutException)79 Constraint (org.evosuite.symbolic.expr.Constraint)75 Test (org.junit.Test)75 EvoSuiteSolver (org.evosuite.symbolic.solver.avm.EvoSuiteSolver)74 ArrayList (java.util.ArrayList)68 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)48 IntegerConstant (org.evosuite.symbolic.expr.bv.IntegerConstant)35 SolverResult (org.evosuite.symbolic.solver.SolverResult)34 IntegerVariable (org.evosuite.symbolic.expr.bv.IntegerVariable)25 StringVariable (org.evosuite.symbolic.expr.str.StringVariable)24 RealConstraint (org.evosuite.symbolic.expr.RealConstraint)22 StringConstraint (org.evosuite.symbolic.expr.StringConstraint)22 RealVariable (org.evosuite.symbolic.expr.fp.RealVariable)22 StringConstant (org.evosuite.symbolic.expr.str.StringConstant)18 RealConstant (org.evosuite.symbolic.expr.fp.RealConstant)15 StringBinaryComparison (org.evosuite.symbolic.expr.bv.StringBinaryComparison)13 StringBinaryToIntegerExpression (org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression)10 IntegerBinaryExpression (org.evosuite.symbolic.expr.bv.IntegerBinaryExpression)8 StringUnaryExpression (org.evosuite.symbolic.expr.str.StringUnaryExpression)5 Expression (org.evosuite.symbolic.expr.Expression)4