Search in sources :

Example 21 with IntegerVariable

use of org.evosuite.symbolic.expr.bv.IntegerVariable in project evosuite by EvoSuite.

the class SymbolicObserver method after.

private void after(CharPrimitiveStatement statement, Scope scope) {
    char valueOf = statement.getValue();
    VariableReference varRef = statement.getReturnValue();
    String varRefName = varRef.getName();
    IntegerVariable integerVariable = buildIntegerVariable(varRefName, valueOf, Character.MIN_VALUE, Character.MAX_VALUE);
    symb_expressions.put(varRefName, integerVariable);
    Character character0;
    try {
        character0 = (Character) varRef.getObject(scope);
    } catch (CodeUnderTestException e) {
        throw new EvosuiteError(e);
    }
    ReferenceConstant charRef = newCharacterReference(character0, integerVariable);
    symb_references.put(varRefName, charRef);
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) IntegerVariable(org.evosuite.symbolic.expr.bv.IntegerVariable) VariableReference(org.evosuite.testcase.variable.VariableReference) EvosuiteError(org.evosuite.testcase.execution.EvosuiteError) CodeUnderTestException(org.evosuite.testcase.execution.CodeUnderTestException)

Example 22 with IntegerVariable

use of org.evosuite.symbolic.expr.bv.IntegerVariable in project evosuite by EvoSuite.

the class Solver method setConcreteValues.

/**
 * Restore all concrete values of the variables using the concrete_values
 * mapping.
 *
 * @param variables
 * @param concrete_values
 */
protected static void setConcreteValues(Set<Variable<?>> variables, Map<String, Object> concrete_values) {
    for (Variable<?> v : variables) {
        String var_name = v.getName();
        if (!concrete_values.containsKey(var_name)) {
            continue;
        }
        Object concreteValue = concrete_values.get(var_name);
        if (v instanceof StringVariable) {
            StringVariable sv = (StringVariable) v;
            String concreteString = (String) concreteValue;
            sv.setConcreteValue(concreteString);
        } else if (v instanceof IntegerVariable) {
            IntegerVariable iv = (IntegerVariable) v;
            Long concreteInteger = (Long) concreteValue;
            iv.setConcreteValue(concreteInteger);
        } else if (v instanceof RealVariable) {
            RealVariable ir = (RealVariable) v;
            Double concreteReal = (Double) concreteValue;
            ir.setConcreteValue(concreteReal);
        } else {
            logger.warn("unknow variable type " + v.getClass().getName());
        }
    }
}
Also used : IntegerVariable(org.evosuite.symbolic.expr.bv.IntegerVariable) RealVariable(org.evosuite.symbolic.expr.fp.RealVariable) StringVariable(org.evosuite.symbolic.expr.str.StringVariable)

Example 23 with IntegerVariable

use of org.evosuite.symbolic.expr.bv.IntegerVariable in project evosuite by EvoSuite.

the class TestIntegerSearch method testNEConstant.

@Test
public void testNEConstant() throws SolverEmptyQueryException {
    // TODO: Currently, the model returned by the search is null if the
    // constraint is already satisfied,
    // so in this example the concrete value has to be the target initially
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    constraints.add(new IntegerConstraint(new IntegerVariable("test1", 235082, -1000000, 1000000), Comparator.NE, new IntegerConstant(235082)));
    try {
        EvoSuiteSolver solver = new EvoSuiteSolver();
        SolverResult solverResult = solver.solve(constraints);
        assertTrue(solverResult.isSAT());
        Map<String, Object> model = solverResult.getModel();
        assertNotNull(model.get("test1"));
        assertTrue(235082 != ((Number) model.get("test1")).intValue());
    } catch (SolverTimeoutException e) {
        fail();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) EvoSuiteSolver(org.evosuite.symbolic.solver.avm.EvoSuiteSolver) ArrayList(java.util.ArrayList) SolverResult(org.evosuite.symbolic.solver.SolverResult) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) IntegerVariable(org.evosuite.symbolic.expr.bv.IntegerVariable) Test(org.junit.Test)

Example 24 with IntegerVariable

use of org.evosuite.symbolic.expr.bv.IntegerVariable in project evosuite by EvoSuite.

the class TestIntegerSearch method testLEArithmetic.

@Test
public void testLEArithmetic() throws SolverEmptyQueryException {
    int var1 = 3;
    int var2 = 1;
    int var3 = 1;
    assertTrue(var1 > var2 + var3);
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    constraints.add(new IntegerConstraint(new IntegerVariable("test1", var1, -1000000, 1000000), Comparator.LE, new IntegerBinaryExpression(new IntegerVariable("test2", var2, -1000000, 1000000), Operator.PLUS, new IntegerVariable("test3", var3, -1000000, 1000000), 0L)));
    try {
        EvoSuiteSolver solver = new EvoSuiteSolver();
        SolverResult solverResult = solver.solve(constraints);
        assertTrue(solverResult.isSAT());
        Map<String, Object> model = solverResult.getModel();
        if (model.containsKey("test1"))
            var1 = ((Number) model.get("test1")).intValue();
        if (model.containsKey("test2"))
            var2 = ((Number) model.get("test2")).intValue();
        if (model.containsKey("test3"))
            var3 = ((Number) model.get("test3")).intValue();
        assertTrue(var1 <= var2 + var3);
    } catch (SolverTimeoutException e) {
        fail();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) IntegerBinaryExpression(org.evosuite.symbolic.expr.bv.IntegerBinaryExpression) EvoSuiteSolver(org.evosuite.symbolic.solver.avm.EvoSuiteSolver) ArrayList(java.util.ArrayList) SolverResult(org.evosuite.symbolic.solver.SolverResult) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) IntegerVariable(org.evosuite.symbolic.expr.bv.IntegerVariable) Test(org.junit.Test)

Example 25 with IntegerVariable

use of org.evosuite.symbolic.expr.bv.IntegerVariable in project evosuite by EvoSuite.

the class TestIntegerSearch method testGEArithmetic.

@Test
public void testGEArithmetic() throws SolverEmptyQueryException {
    int var1 = 0;
    int var2 = 1;
    int var3 = 1;
    assertTrue(var1 < var2 + var3);
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    constraints.add(new IntegerConstraint(new IntegerVariable("test1", var1, -1000000, 1000000), Comparator.GT, new IntegerBinaryExpression(new IntegerVariable("test2", var2, -1000000, 1000000), Operator.PLUS, new IntegerVariable("test3", var3, -1000000, 1000000), 0L)));
    try {
        EvoSuiteSolver solver = new EvoSuiteSolver();
        SolverResult solverResult = solver.solve(constraints);
        assertTrue(solverResult.isSAT());
        Map<String, Object> model = solverResult.getModel();
        if (model.containsKey("test1"))
            var1 = ((Number) model.get("test1")).intValue();
        if (model.containsKey("test2"))
            var2 = ((Number) model.get("test2")).intValue();
        if (model.containsKey("test3"))
            var3 = ((Number) model.get("test3")).intValue();
        assertTrue(var1 >= var2 + var3);
    } catch (SolverTimeoutException e) {
        fail();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) IntegerBinaryExpression(org.evosuite.symbolic.expr.bv.IntegerBinaryExpression) EvoSuiteSolver(org.evosuite.symbolic.solver.avm.EvoSuiteSolver) ArrayList(java.util.ArrayList) SolverResult(org.evosuite.symbolic.solver.SolverResult) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) IntegerVariable(org.evosuite.symbolic.expr.bv.IntegerVariable) Test(org.junit.Test)

Aggregations

IntegerVariable (org.evosuite.symbolic.expr.bv.IntegerVariable)36 Constraint (org.evosuite.symbolic.expr.Constraint)26 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)25 SolverResult (org.evosuite.symbolic.solver.SolverResult)25 SolverTimeoutException (org.evosuite.symbolic.solver.SolverTimeoutException)25 EvoSuiteSolver (org.evosuite.symbolic.solver.avm.EvoSuiteSolver)24 Test (org.junit.Test)24 ArrayList (java.util.ArrayList)22 IntegerConstant (org.evosuite.symbolic.expr.bv.IntegerConstant)12 IntegerBinaryExpression (org.evosuite.symbolic.expr.bv.IntegerBinaryExpression)7 ReferenceConstant (org.evosuite.symbolic.expr.ref.ReferenceConstant)6 CodeUnderTestException (org.evosuite.testcase.execution.CodeUnderTestException)6 EvosuiteError (org.evosuite.testcase.execution.EvosuiteError)6 VariableReference (org.evosuite.testcase.variable.VariableReference)6 RealVariable (org.evosuite.symbolic.expr.fp.RealVariable)4 StringVariable (org.evosuite.symbolic.expr.str.StringVariable)4 LinkedList (java.util.LinkedList)2 IntegerValue (org.evosuite.symbolic.expr.bv.IntegerValue)2 HashSet (java.util.HashSet)1 Variable (org.evosuite.symbolic.expr.Variable)1