Search in sources :

Example 91 with ExecutionResult

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;
}
Also used : NullStatement(org.evosuite.testcase.statements.NullStatement) TestCase(org.evosuite.testcase.TestCase) ExecutionResult(org.evosuite.testcase.execution.ExecutionResult) FitnessFunction(org.evosuite.ga.FitnessFunction) ConstructionFailedException(org.evosuite.ga.ConstructionFailedException)

Example 92 with ExecutionResult

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;
}
Also used : ExecutionResult(org.evosuite.testcase.execution.ExecutionResult)

Example 93 with ExecutionResult

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;
    }
}
Also used : PrimitiveStatement(org.evosuite.testcase.statements.PrimitiveStatement) ExecutionResult(org.evosuite.testcase.execution.ExecutionResult)

Aggregations

ExecutionResult (org.evosuite.testcase.execution.ExecutionResult)93 TestChromosome (org.evosuite.testcase.TestChromosome)33 HashSet (java.util.HashSet)15 TestFitnessFunction (org.evosuite.testcase.TestFitnessFunction)15 ArrayList (java.util.ArrayList)11 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)10 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)9 TestCase (org.evosuite.testcase.TestCase)9 VariableReference (org.evosuite.testcase.variable.VariableReference)9 Test (org.junit.Test)9 LinkedHashSet (java.util.LinkedHashSet)8 HashMap (java.util.HashMap)7 LinkedHashMap (java.util.LinkedHashMap)7 TestCaseBuilder (org.evosuite.symbolic.TestCaseBuilder)7 ArrayReference (org.evosuite.testcase.variable.ArrayReference)7 Set (java.util.Set)6 AbstractTestSuiteChromosome (org.evosuite.testsuite.AbstractTestSuiteChromosome)6 Map (java.util.Map)4 Entry (java.util.Map.Entry)3 ExecutionTrace (org.evosuite.testcase.execution.ExecutionTrace)3