use of org.evosuite.testcase.execution.ExecutionResult in project evosuite by EvoSuite.
the class NullReferenceSearch method doSearch.
/* (non-Javadoc)
* @see org.evosuite.testcase.LocalSearch#doSearch(org.evosuite.testcase.TestChromosome, int, org.evosuite.ga.LocalSearchObjective)
*/
@Override
public boolean doSearch(TestChromosome test, int statement, LocalSearchObjective<TestChromosome> objective) {
NullStatement nullStatement = (NullStatement) test.getTestCase().getStatement(statement);
TestCase newTest = test.getTestCase();
TestCase oldTest = newTest.clone();
ExecutionResult oldResult = test.getLastExecutionResult();
// double oldFitness = test.getFitness();
Map<FitnessFunction<?>, Double> oldFitnesses = test.getFitnessValues();
Map<FitnessFunction<?>, Double> oldLastFitnesses = test.getPreviousFitnessValues();
try {
TestFactory.getInstance().attemptGeneration(newTest, nullStatement.getReturnType(), statement);
if (!objective.hasImproved(test)) {
test.setTestCase(oldTest);
test.setLastExecutionResult(oldResult);
// test.setFitness(oldFitness);
test.setFitnessValues(oldFitnesses);
test.setPreviousFitnessValues(oldLastFitnesses);
} else {
return true;
}
} catch (ConstructionFailedException e) {
// If we can't construct it, then ignore
}
return false;
}
use of org.evosuite.testcase.execution.ExecutionResult in project evosuite by EvoSuite.
the class StringAVMLocalSearch method iterate.
private boolean iterate(long delta, LocalSearchObjective<TestChromosome> objective, TestChromosome test, StringPrimitiveStatement p, int character, int statement) {
boolean improvement = false;
oldValue = p.getValue();
ExecutionResult oldResult = test.getLastExecutionResult();
logger.debug("Trying increment " + delta + " of " + p.getCode());
char oldChar = oldValue.charAt(character);
logger.info(" -> Character " + character + ": " + oldChar);
char[] characters = oldValue.toCharArray();
char replacement = oldChar;
replacement += delta;
characters[character] = replacement;
String newString = new String(characters);
p.setValue(newString);
while (objective.hasImproved(test)) {
oldValue = p.getValue();
oldResult = test.getLastExecutionResult();
improvement = true;
delta = 2 * delta;
logger.info(" " + character + " " + oldValue + "/" + oldValue.length() + " -> " + newString + "/" + newString.length());
replacement += delta;
characters[character] = replacement;
newString = new String(characters);
p.setValue(newString);
}
logger.debug("No improvement on " + p.getCode());
p.setValue(oldValue);
test.setLastExecutionResult(oldResult);
test.setChanged(false);
logger.debug("Final value of this iteration: " + p.getValue());
return improvement;
}
use of org.evosuite.testcase.execution.ExecutionResult in project evosuite by EvoSuite.
the class BooleanLocalSearch method doSearch.
/* (non-Javadoc)
* @see org.evosuite.testcase.LocalSearch#doSearch(org.evosuite.testcase.TestChromosome, int, org.evosuite.ga.LocalSearchObjective)
*/
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public boolean doSearch(TestChromosome test, int statement, LocalSearchObjective<TestChromosome> objective) {
PrimitiveStatement<Boolean> p = (PrimitiveStatement<Boolean>) test.getTestCase().getStatement(statement);
ExecutionResult oldResult = test.getLastExecutionResult();
oldValue = p.getValue();
p.setValue(!oldValue);
if (!objective.hasImproved(test)) {
// Restore original
p.setValue(oldValue);
test.setLastExecutionResult(oldResult);
test.setChanged(false);
return false;
} else {
return true;
}
}
Aggregations