Search in sources :

Example 21 with RealConstraint

use of org.evosuite.symbolic.expr.RealConstraint in project evosuite by EvoSuite.

the class TestRealSearch method testEvosuiteExample1.

@Test
public void testEvosuiteExample1() {
    double var1 = 1;
    double var2 = 1;
    RealVariable realVar1 = new RealVariable("test1", var1, -1000000, 1000000);
    RealVariable realVar2 = new RealVariable("test2", var2, -1000000, 1000000);
    // x <= 0
    // x < y
    // x >= 0
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    constraints.add(new RealConstraint(realVar1, Comparator.LE, new RealConstant(0)));
    constraints.add(new RealConstraint(realVar1, Comparator.LT, realVar2));
    constraints.add(new RealConstraint(realVar1, Comparator.GE, new RealConstant(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();
        assertEquals(0, var1, 0.0001);
        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) RealConstant(org.evosuite.symbolic.expr.fp.RealConstant) RealConstraint(org.evosuite.symbolic.expr.RealConstraint) Test(org.junit.Test)

Example 22 with RealConstraint

use of org.evosuite.symbolic.expr.RealConstraint in project evosuite by EvoSuite.

the class TestRealSearch method testLEVariable.

@Test
public void testLEVariable() {
    double var1 = 2.6576;
    double var2 = 1.434;
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    constraints.add(new RealConstraint(new RealVariable("test1", var1, -1000000.0, 1000000.0), Comparator.LE, 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)

Example 23 with RealConstraint

use of org.evosuite.symbolic.expr.RealConstraint in project evosuite by EvoSuite.

the class TestRealSearch method testGEVariable.

@Test
public void testGEVariable() {
    double var1 = 0.7868;
    double var2 = 1.9765;
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    constraints.add(new RealConstraint(new RealVariable("test1", var1, -1000000.0, 1000000.0), Comparator.GE, 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

RealConstraint (org.evosuite.symbolic.expr.RealConstraint)23 Constraint (org.evosuite.symbolic.expr.Constraint)22 RealVariable (org.evosuite.symbolic.expr.fp.RealVariable)22 ArrayList (java.util.ArrayList)21 SolverTimeoutException (org.evosuite.symbolic.solver.SolverTimeoutException)21 EvoSuiteSolver (org.evosuite.symbolic.solver.avm.EvoSuiteSolver)21 Test (org.junit.Test)20 RealConstant (org.evosuite.symbolic.expr.fp.RealConstant)16 RealBinaryExpression (org.evosuite.symbolic.expr.fp.RealBinaryExpression)2 DistanceCalculator (org.evosuite.symbolic.expr.DistanceCalculator)1 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)1 StringConstraint (org.evosuite.symbolic.expr.StringConstraint)1