Search in sources :

Example 21 with SolverTimeoutException

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

the class TestRealSearch method testEvosuiteExample2.

@Test
public void testEvosuiteExample2() {
    double var1 = 355.80758027529504;
    // var3__SYM(355.80758027529504) >= 0.0 dist: 177.90379013764752
    // var3__SYM(355.80758027529504) == 0.0 dist: 177.90379013764752
    RealVariable realVar = new RealVariable("test1", var1, -1000000, 1000000);
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    constraints.add(new RealConstraint(realVar, Comparator.GE, new RealConstant(0.0)));
    constraints.add(new RealConstraint(realVar, Comparator.EQ, new RealConstant(0.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();
        assertEquals(0, var1, 0.0001);
    } 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) ArrayList(java.util.ArrayList) RealVariable(org.evosuite.symbolic.expr.fp.RealVariable) RealConstant(org.evosuite.symbolic.expr.fp.RealConstant) RealConstraint(org.evosuite.symbolic.expr.RealConstraint) Test(org.junit.Test)

Example 22 with SolverTimeoutException

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

the class TestStringSearch2 method testSolveIndexOfConstant.

@Test
public void testSolveIndexOfConstant() throws SecurityException, NoSuchMethodException {
    DefaultTestCase tc = buildTestCase("V*X-:o%tp");
    List<BranchCondition> branch_conditions = executeTest(tc);
    Collection<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    for (int i = 0; i < branch_conditions.size() - 2; i++) {
        BranchCondition b = branch_conditions.get(i);
        constraints.addAll(b.getSupportingConstraints());
        constraints.add(b.getConstraint());
    }
    BranchCondition last_branch = branch_conditions.get(branch_conditions.size() - 2);
    constraints.addAll(last_branch.getSupportingConstraints());
    constraints.add(last_branch.getConstraint().negate());
    EvoSuiteSolver solver = new EvoSuiteSolver();
    Map<String, Object> solution;
    try {
        solution = solve(solver, constraints);
        assertNotNull(solution);
        System.out.println(solution);
    } catch (SolverTimeoutException e) {
        fail();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) Constraint(org.evosuite.symbolic.expr.Constraint) EvoSuiteSolver(org.evosuite.symbolic.solver.avm.EvoSuiteSolver) ArrayList(java.util.ArrayList) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) BranchCondition(org.evosuite.symbolic.BranchCondition) Constraint(org.evosuite.symbolic.expr.Constraint) Test(org.junit.Test)

Example 23 with SolverTimeoutException

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

the class TestStringSearch2 method testSolvePathConstraint.

@Test
public void testSolvePathConstraint() throws SecurityException, NoSuchMethodException {
    DefaultTestCase tc = buildTestCase("urn:pBth:/A/B/C/doc.html#gilada");
    List<BranchCondition> branch_conditions = executeTest(tc);
    Collection<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    for (int i = 0; i < branch_conditions.size() - 1; i++) {
        BranchCondition b = branch_conditions.get(i);
        constraints.addAll(b.getSupportingConstraints());
        constraints.add(b.getConstraint());
    }
    BranchCondition last_branch = branch_conditions.get(branch_conditions.size() - 1);
    constraints.addAll(last_branch.getSupportingConstraints());
    constraints.add(last_branch.getConstraint().negate());
    EvoSuiteSolver solver = new EvoSuiteSolver();
    Map<String, Object> solution;
    try {
        solution = solve(solver, constraints);
        assertNotNull(solution);
        System.out.println(solution);
    } catch (SolverTimeoutException e) {
        fail();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) Constraint(org.evosuite.symbolic.expr.Constraint) EvoSuiteSolver(org.evosuite.symbolic.solver.avm.EvoSuiteSolver) ArrayList(java.util.ArrayList) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) BranchCondition(org.evosuite.symbolic.BranchCondition) Constraint(org.evosuite.symbolic.expr.Constraint) Test(org.junit.Test)

Example 24 with SolverTimeoutException

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

the class TestIsInteger method testIsInteger.

@Test
public void testIsInteger() throws SolverEmptyQueryException {
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    constraints.add(new IntegerConstraint(new StringUnaryToIntegerExpression(new StringVariable("var0", "hello"), Operator.IS_INTEGER, 0L), Comparator.NE, new IntegerConstant(0)));
    EvoSuiteSolver solver = new EvoSuiteSolver();
    try {
        SolverResult result = solver.solve(constraints);
        assertTrue(result.isSAT());
    } catch (SolverTimeoutException e) {
        fail();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) 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) StringUnaryToIntegerExpression(org.evosuite.symbolic.expr.bv.StringUnaryToIntegerExpression) StringVariable(org.evosuite.symbolic.expr.str.StringVariable) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant) Test(org.junit.Test)

Example 25 with SolverTimeoutException

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

the class TestStringSearch method testRegexMatchesTrue.

@Test
public void testRegexMatchesTrue() {
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    String var1 = "test";
    String const2 = "TEST";
    StringVariable strVar = new StringVariable("test1", var1);
    StringConstant strConst = new StringConstant(const2);
    StringBinaryComparison strComp = new StringBinaryComparison(strVar, Operator.PATTERNMATCHES, 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(result.get("test1").toString().matches(const2));
    } 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)

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