use of org.evosuite.testcase.variable.NullReference in project evosuite by EvoSuite.
the class LegacyInsertion method selectVariableForCall.
/**
* Randomly select one of the variables in the test defined up to position
* to insert a call for
*
* @param test
* @param position
* @return
*/
private VariableReference selectVariableForCall(TestCase test, int position) {
if (test.isEmpty() || position == 0)
return null;
double sum = 0.0;
for (int i = 0; i < position; i++) {
// sum += 1d / (10 * test.getStatement(i).getReturnValue().getDistance() + 1d);
sum += 1d / (test.getStatement(i).getReturnValue().getDistance() + 1d);
if (logger.isDebugEnabled()) {
logger.debug(test.getStatement(i).getCode() + ": Distance = " + test.getStatement(i).getReturnValue().getDistance());
}
}
double rnd = Randomness.nextDouble() * sum;
for (int i = 0; i < position; i++) {
double dist = 1d / (test.getStatement(i).getReturnValue().getDistance() + 1d);
if (dist >= rnd && !(test.getStatement(i).getReturnValue() instanceof NullReference) && !(test.getStatement(i).getReturnValue().isPrimitive()) && !(test.getStatement(i).getReturnValue().isVoid()) && !(test.getStatement(i) instanceof PrimitiveStatement))
return test.getStatement(i).getReturnValue();
else
rnd = rnd - dist;
}
if (position > 0)
position = Randomness.nextInt(position);
VariableReference var = test.getStatement(position).getReturnValue();
if (!(var instanceof NullReference) && !var.isVoid() && !(test.getStatement(position) instanceof PrimitiveStatement) && !var.isPrimitive())
return var;
else
return null;
}
use of org.evosuite.testcase.variable.NullReference 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;
}
}
Aggregations