Search in sources :

Example 16 with PrimitiveStatement

use of org.evosuite.testcase.statements.PrimitiveStatement in project evosuite by EvoSuite.

the class LegacyInsertion method selectRandomVariableForCall.

private VariableReference selectRandomVariableForCall(TestCase test, int position) {
    if (test.isEmpty() || position == 0)
        return null;
    List<VariableReference> allVariables = test.getObjects(position);
    Set<VariableReference> candidateVariables = new LinkedHashSet<VariableReference>();
    for (VariableReference var : allVariables) {
        if (!(var instanceof NullReference) && !var.isVoid() && !(test.getStatement(var.getStPosition()) instanceof PrimitiveStatement) && !var.isPrimitive())
            candidateVariables.add(var);
    }
    if (candidateVariables.isEmpty()) {
        return null;
    } else {
        VariableReference choice = Randomness.choice(candidateVariables);
        return choice;
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) VariableReference(org.evosuite.testcase.variable.VariableReference) PrimitiveStatement(org.evosuite.testcase.statements.PrimitiveStatement) NullReference(org.evosuite.testcase.variable.NullReference)

Aggregations

PrimitiveStatement (org.evosuite.testcase.statements.PrimitiveStatement)16 VariableReference (org.evosuite.testcase.variable.VariableReference)11 Statement (org.evosuite.testcase.statements.Statement)6 MethodStatement (org.evosuite.testcase.statements.MethodStatement)5 CodeUnderTestException (org.evosuite.testcase.execution.CodeUnderTestException)4 TestCase (org.evosuite.testcase.TestCase)3 ArrayStatement (org.evosuite.testcase.statements.ArrayStatement)3 AssignmentStatement (org.evosuite.testcase.statements.AssignmentStatement)3 ConstructorStatement (org.evosuite.testcase.statements.ConstructorStatement)3 NullReference (org.evosuite.testcase.variable.NullReference)3 ArrayList (java.util.ArrayList)2 LinkedHashSet (java.util.LinkedHashSet)2 ClassPrimitiveStatement (org.evosuite.testcase.statements.ClassPrimitiveStatement)2 ImmutableStringPrimitiveStatement (org.evosuite.testcase.statements.ImmutableStringPrimitiveStatement)2 URL (java.net.URL)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 TimeoutException (java.util.concurrent.TimeoutException)1