Search in sources :

Example 1 with RealConstant

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

the class LocalsVM method LDC.

@Override
public void LDC(float x) {
    RealConstant realConstant = ExpressionFactory.buildNewRealConstant(x);
    env.topFrame().operandStack.pushFp32(realConstant);
}
Also used : RealConstant(org.evosuite.symbolic.expr.fp.RealConstant)

Example 2 with RealConstant

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

the class ExpressionFactory method buildAddNormalized.

private static RealValue buildAddNormalized(RealValue right, RealValue left, double con) {
    // can only optimize if left is a literal
    if (!(left instanceof RealConstant))
        return new RealBinaryExpression(left, Operator.PLUS, right, con);
    /*
		 * (add 0 x) --> x
		 */
    if (((RealConstant) left).getConcreteValue() == 0) {
        return right;
    }
    /*
		 * (add a b) --> result of a+b
		 */
    if (right instanceof RealConstant) {
        double a = left.getConcreteValue();
        double b = right.getConcreteValue();
        return buildNewRealConstant(a + b);
    }
    /*
		 * (add a (add b x)) --> (add (a+b) x)
		 */
    if (right instanceof RealBinaryExpression && ((RealBinaryExpression) right).getOperator() == Operator.PLUS) {
        RealBinaryExpression add = (RealBinaryExpression) right;
        if (add.getLeftOperand() instanceof RealConstant) {
            double a = left.getConcreteValue();
            double b = add.getLeftOperand().getConcreteValue();
            RealConstant a_plus_b = buildNewRealConstant(a + b);
            return new RealBinaryExpression(a_plus_b, Operator.PLUS, add.getRightOperand(), con);
        }
    }
    return new RealBinaryExpression(left, Operator.PLUS, right, con);
}
Also used : RealConstant(org.evosuite.symbolic.expr.fp.RealConstant) RealBinaryExpression(org.evosuite.symbolic.expr.fp.RealBinaryExpression)

Example 3 with RealConstant

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

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

use of org.evosuite.symbolic.expr.fp.RealConstant 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)

Aggregations

RealConstant (org.evosuite.symbolic.expr.fp.RealConstant)22 Constraint (org.evosuite.symbolic.expr.Constraint)16 RealConstraint (org.evosuite.symbolic.expr.RealConstraint)16 RealVariable (org.evosuite.symbolic.expr.fp.RealVariable)16 ArrayList (java.util.ArrayList)15 SolverTimeoutException (org.evosuite.symbolic.solver.SolverTimeoutException)15 EvoSuiteSolver (org.evosuite.symbolic.solver.avm.EvoSuiteSolver)15 Test (org.junit.Test)14 RealBinaryExpression (org.evosuite.symbolic.expr.fp.RealBinaryExpression)3