Search in sources :

Example 1 with RealVariable

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

the class SymbolicObserver method after.

private void after(FloatPrimitiveStatement statement, Scope scope) {
    float valueOf = statement.getValue();
    VariableReference varRef = statement.getReturnValue();
    String varRefName = varRef.getName();
    RealVariable realVariable = buildRealVariable(varRefName, valueOf, -Float.MAX_VALUE, Float.MAX_VALUE);
    symb_expressions.put(varRefName, realVariable);
    Float float_instance;
    try {
        float_instance = (Float) varRef.getObject(scope);
    } catch (CodeUnderTestException e) {
        throw new EvosuiteError(e);
    }
    ReferenceConstant floatRef = newFloatReference(float_instance, realVariable);
    symb_references.put(varRefName, floatRef);
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) VariableReference(org.evosuite.testcase.variable.VariableReference) EvosuiteError(org.evosuite.testcase.execution.EvosuiteError) RealVariable(org.evosuite.symbolic.expr.fp.RealVariable) CodeUnderTestException(org.evosuite.testcase.execution.CodeUnderTestException)

Example 2 with RealVariable

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

the class SymbolicObserver method after.

private void after(DoublePrimitiveStatement statement, Scope scope) {
    double valueOf = statement.getValue();
    VariableReference varRef = statement.getReturnValue();
    String varRefName = varRef.getName();
    RealVariable realVariable = buildRealVariable(varRefName, valueOf, -Double.MAX_VALUE, Double.MAX_VALUE);
    symb_expressions.put(varRefName, realVariable);
    Double double_instance;
    try {
        double_instance = (Double) varRef.getObject(scope);
    } catch (CodeUnderTestException e) {
        throw new EvosuiteError(e);
    }
    ReferenceConstant doubleRef = newDoubleReference(double_instance, realVariable);
    symb_references.put(varRefName, doubleRef);
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) VariableReference(org.evosuite.testcase.variable.VariableReference) EvosuiteError(org.evosuite.testcase.execution.EvosuiteError) RealVariable(org.evosuite.symbolic.expr.fp.RealVariable) CodeUnderTestException(org.evosuite.testcase.execution.CodeUnderTestException)

Example 3 with RealVariable

use of org.evosuite.symbolic.expr.fp.RealVariable 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();
    }
}
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 4 with RealVariable

use of org.evosuite.symbolic.expr.fp.RealVariable 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();
    }
}
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 5 with RealVariable

use of org.evosuite.symbolic.expr.fp.RealVariable 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();
    }
}
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) RealConstraint(org.evosuite.symbolic.expr.RealConstraint) Test(org.junit.Test)

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