Search in sources :

Example 51 with EvoSuiteSolver

use of org.evosuite.symbolic.solver.avm.EvoSuiteSolver in project evosuite by EvoSuite.

the class TestRealSearch method testEQVariable.

@Test
public void testEQVariable() {
    double var1 = 0.23123;
    double var2 = 1.12321;
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    constraints.add(new RealConstraint(new RealVariable("test1", var1, -1000000.0, 1000000.0), Comparator.EQ, 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);
        assertEquals(var1, var2, 0.001);
    } 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 52 with EvoSuiteSolver

use of org.evosuite.symbolic.solver.avm.EvoSuiteSolver 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 53 with EvoSuiteSolver

use of org.evosuite.symbolic.solver.avm.EvoSuiteSolver 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 54 with EvoSuiteSolver

use of org.evosuite.symbolic.solver.avm.EvoSuiteSolver 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)

Example 55 with EvoSuiteSolver

use of org.evosuite.symbolic.solver.avm.EvoSuiteSolver in project evosuite by EvoSuite.

the class TestStringEqualsIgnoreCase method testStringEqualsIgnoreCase.

@Test
public void testStringEqualsIgnoreCase() throws SecurityException, NoSuchMethodException, SolverTimeoutException {
    IntegerConstant zero = new IntegerConstant(0);
    StringVariable stringVar0 = new StringVariable("var0", "");
    StringConstant strConst = new StringConstant("bar");
    StringBinaryComparison cmp1 = new StringBinaryComparison(stringVar0, Operator.EQUALS, strConst, 0L);
    StringConstraint constr1 = new StringConstraint(cmp1, Comparator.EQ, zero);
    StringBinaryComparison cmp2 = new StringBinaryComparison(stringVar0, Operator.EQUALSIGNORECASE, strConst, 1L);
    StringConstraint constr2 = new StringConstraint(cmp2, Comparator.NE, zero);
    Collection<Constraint<?>> constraints = Arrays.<Constraint<?>>asList(constr1, constr2);
    EvoSuiteSolver solver = new EvoSuiteSolver();
    Map<String, Object> solution = solve(solver, constraints);
    assertNotNull(solution);
    String var0 = (String) solution.get("var0");
    assertNotNull(var0);
    assertTrue(!var0.equals("bar"));
    assertTrue(var0.equalsIgnoreCase("bar"));
}
Also used : StringConstraint(org.evosuite.symbolic.expr.StringConstraint) StringConstraint(org.evosuite.symbolic.expr.StringConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) EvoSuiteSolver(org.evosuite.symbolic.solver.avm.EvoSuiteSolver) StringBinaryComparison(org.evosuite.symbolic.expr.bv.StringBinaryComparison) StringVariable(org.evosuite.symbolic.expr.str.StringVariable) StringConstant(org.evosuite.symbolic.expr.str.StringConstant) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant) Test(org.junit.Test)

Aggregations

Constraint (org.evosuite.symbolic.expr.Constraint)76 EvoSuiteSolver (org.evosuite.symbolic.solver.avm.EvoSuiteSolver)76 SolverTimeoutException (org.evosuite.symbolic.solver.SolverTimeoutException)74 Test (org.junit.Test)74 ArrayList (java.util.ArrayList)67 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)48 IntegerConstant (org.evosuite.symbolic.expr.bv.IntegerConstant)36 SolverResult (org.evosuite.symbolic.solver.SolverResult)31 IntegerVariable (org.evosuite.symbolic.expr.bv.IntegerVariable)24 StringVariable (org.evosuite.symbolic.expr.str.StringVariable)24 StringConstraint (org.evosuite.symbolic.expr.StringConstraint)23 RealConstraint (org.evosuite.symbolic.expr.RealConstraint)22 RealVariable (org.evosuite.symbolic.expr.fp.RealVariable)21 StringConstant (org.evosuite.symbolic.expr.str.StringConstant)19 RealConstant (org.evosuite.symbolic.expr.fp.RealConstant)15 StringBinaryComparison (org.evosuite.symbolic.expr.bv.StringBinaryComparison)14 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