Search in sources :

Example 6 with RealVariable

use of org.evosuite.symbolic.expr.fp.RealVariable in project evosuite by EvoSuite.

the class TestRealSearch method testLTConstantAfterComma.

@Test
public void testLTConstantAfterComma() {
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    constraints.add(new RealConstraint(new RealVariable("test1", 2.35086, -1000000.0, 1000000.0), Comparator.LT, 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();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) RealConstant(org.evosuite.symbolic.expr.fp.RealConstant) 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) RealConstraint(org.evosuite.symbolic.expr.RealConstraint) Test(org.junit.Test)

Example 7 with RealVariable

use of org.evosuite.symbolic.expr.fp.RealVariable in project evosuite by EvoSuite.

the class TestRealSearch method testGTConstant.

@Test
public void testGTConstant() {
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    constraints.add(new RealConstraint(new RealVariable("test1", 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();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) RealConstant(org.evosuite.symbolic.expr.fp.RealConstant) 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) RealConstraint(org.evosuite.symbolic.expr.RealConstraint) Test(org.junit.Test)

Example 8 with RealVariable

use of org.evosuite.symbolic.expr.fp.RealVariable 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 9 with RealVariable

use of org.evosuite.symbolic.expr.fp.RealVariable in project evosuite by EvoSuite.

the class TestRealConstraint method buildConstraintSystem.

private static Collection<Constraint<?>> buildConstraintSystem() {
    RealVariable var0 = new RealVariable("var0", INIT_DOUBLE, Double.MIN_VALUE, Double.MAX_VALUE);
    RealConstant constPi = new RealConstant(Math.PI);
    RealConstraint constr1 = new RealConstraint(var0, Comparator.EQ, constPi);
    return Arrays.<Constraint<?>>asList(constr1);
}
Also used : RealConstant(org.evosuite.symbolic.expr.fp.RealConstant) Constraint(org.evosuite.symbolic.expr.Constraint) RealConstraint(org.evosuite.symbolic.expr.RealConstraint) RealVariable(org.evosuite.symbolic.expr.fp.RealVariable) RealConstraint(org.evosuite.symbolic.expr.RealConstraint)

Example 10 with RealVariable

use of org.evosuite.symbolic.expr.fp.RealVariable in project evosuite by EvoSuite.

the class Z3Solver method buildSmtQuery.

private static SmtCheckSatQuery buildSmtQuery(Collection<Constraint<?>> constraints, Set<Variable<?>> variables) {
    List<SmtConstantDeclaration> constantDeclarations = new LinkedList<SmtConstantDeclaration>();
    for (Variable<?> v : variables) {
        String varName = v.getName();
        if (v instanceof IntegerVariable) {
            SmtConstantDeclaration intVar = SmtExprBuilder.mkIntConstantDeclaration(varName);
            constantDeclarations.add(intVar);
        } else if (v instanceof RealVariable) {
            SmtConstantDeclaration realVar = SmtExprBuilder.mkRealConstantDeclaration(varName);
            constantDeclarations.add(realVar);
        } else if (v instanceof StringVariable) {
        // ignore string variables
        } else {
            throw new RuntimeException("Unknown variable type " + v.getClass().getCanonicalName());
        }
    }
    List<SmtAssertion> assertions = new LinkedList<SmtAssertion>();
    for (Constraint<?> c : constraints) {
        ConstraintToZ3Visitor v = new ConstraintToZ3Visitor();
        SmtExpr bool_expr = c.accept(v, null);
        if (bool_expr != null && bool_expr.isSymbolic()) {
            SmtAssertion newAssertion = new SmtAssertion(bool_expr);
            assertions.add(newAssertion);
        }
    }
    SmtCheckSatQuery smtCheckSatQuery = new SmtCheckSatQuery(constantDeclarations, assertions);
    return smtCheckSatQuery;
}
Also used : SmtAssertion(org.evosuite.symbolic.solver.smt.SmtAssertion) SmtExpr(org.evosuite.symbolic.solver.smt.SmtExpr) RealVariable(org.evosuite.symbolic.expr.fp.RealVariable) StringVariable(org.evosuite.symbolic.expr.str.StringVariable) SmtConstantDeclaration(org.evosuite.symbolic.solver.smt.SmtConstantDeclaration) LinkedList(java.util.LinkedList) IntegerVariable(org.evosuite.symbolic.expr.bv.IntegerVariable) SmtCheckSatQuery(org.evosuite.symbolic.solver.smt.SmtCheckSatQuery)

Aggregations

RealVariable (org.evosuite.symbolic.expr.fp.RealVariable)29 Constraint (org.evosuite.symbolic.expr.Constraint)23 RealConstraint (org.evosuite.symbolic.expr.RealConstraint)22 SolverTimeoutException (org.evosuite.symbolic.solver.SolverTimeoutException)22 ArrayList (java.util.ArrayList)21 EvoSuiteSolver (org.evosuite.symbolic.solver.avm.EvoSuiteSolver)21 Test (org.junit.Test)20 RealConstant (org.evosuite.symbolic.expr.fp.RealConstant)16 IntegerVariable (org.evosuite.symbolic.expr.bv.IntegerVariable)4 StringVariable (org.evosuite.symbolic.expr.str.StringVariable)4 RealBinaryExpression (org.evosuite.symbolic.expr.fp.RealBinaryExpression)2 ReferenceConstant (org.evosuite.symbolic.expr.ref.ReferenceConstant)2 CodeUnderTestException (org.evosuite.testcase.execution.CodeUnderTestException)2 EvosuiteError (org.evosuite.testcase.execution.EvosuiteError)2 VariableReference (org.evosuite.testcase.variable.VariableReference)2 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Variable (org.evosuite.symbolic.expr.Variable)1 SolverResult (org.evosuite.symbolic.solver.SolverResult)1 SmtAssertion (org.evosuite.symbolic.solver.smt.SmtAssertion)1