Search in sources :

Example 1 with IntegerVariable

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

the class SymbolicObserver method after.

private void after(BooleanPrimitiveStatement statement, Scope scope) {
    boolean valueOf = statement.getValue();
    VariableReference varRef = statement.getReturnValue();
    String varRefName = varRef.getName();
    IntegerVariable integerVariable = buildIntegerVariable(varRefName, valueOf ? 1 : 0, 0, 1);
    Boolean boolean_instance;
    try {
        boolean_instance = (Boolean) varRef.getObject(scope);
    } catch (CodeUnderTestException e) {
        throw new EvosuiteError(e);
    }
    symb_expressions.put(varRefName, integerVariable);
    ReferenceConstant booleanRef = newBooleanReference(boolean_instance, integerVariable);
    symb_references.put(varRefName, booleanRef);
}
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 2 with IntegerVariable

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

the class SymbolicObserver method buildIntegerVariable.

private IntegerVariable buildIntegerVariable(String name, long conV, long minValue, long maxValue) {
    IntegerVariable integerVariable;
    if (integerVariables.containsKey(name)) {
        integerVariable = integerVariables.get(name);
        integerVariable.setConcreteValue(conV);
        assert minValue == integerVariable.getMinValue();
        assert maxValue == integerVariable.getMaxValue();
    } else {
        integerVariable = new IntegerVariable(name, conV, minValue, maxValue);
        integerVariables.put(name, integerVariable);
    }
    return integerVariable;
}
Also used : IntegerVariable(org.evosuite.symbolic.expr.bv.IntegerVariable)

Example 3 with IntegerVariable

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

the class SymbolicObserver method after.

private void after(ShortPrimitiveStatement statement, Scope scope) {
    short valueOf = statement.getValue();
    VariableReference varRef = statement.getReturnValue();
    String varRefName = varRef.getName();
    IntegerVariable integerVariable = buildIntegerVariable(varRefName, valueOf, Short.MIN_VALUE, Short.MAX_VALUE);
    symb_expressions.put(varRefName, integerVariable);
    Short short_instance;
    try {
        short_instance = (Short) varRef.getObject(scope);
    } catch (CodeUnderTestException e) {
        throw new EvosuiteError(e);
    }
    ReferenceConstant shortRef = newShortReference(short_instance, integerVariable);
    symb_references.put(varRefName, shortRef);
}
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 4 with IntegerVariable

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

the class SymbolicObserver method after.

private void after(IntPrimitiveStatement statement, Scope scope) {
    int valueOf = statement.getValue();
    VariableReference varRef = statement.getReturnValue();
    String varRefName = varRef.getName();
    IntegerVariable integerVariable = buildIntegerVariable(varRefName, valueOf, Integer.MIN_VALUE, Integer.MAX_VALUE);
    symb_expressions.put(varRefName, integerVariable);
    Integer integer_instance;
    try {
        integer_instance = (Integer) varRef.getObject(scope);
    } catch (CodeUnderTestException e) {
        throw new EvosuiteError(e);
    }
    ReferenceConstant integerRef = newIntegerReference(integer_instance, integerVariable);
    symb_references.put(varRefName, integerRef);
}
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 5 with IntegerVariable

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

the class TestIntegerSearch method testEQVariable.

@Test
public void testEQVariable() throws SolverEmptyQueryException {
    int var1 = 0;
    int var2 = 1;
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    constraints.add(new IntegerConstraint(new IntegerVariable("test1", var1, -1000000, 1000000), Comparator.EQ, new IntegerVariable("test2", var2, -1000000, 1000000)));
    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();
        assertEquals(var1, var2);
    } 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) 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