Search in sources :

Example 1 with TestCaseExpander

use of org.evosuite.testcase.TestCaseExpander in project evosuite by EvoSuite.

the class ArrayLocalSearch method doSearch.

/* (non-Javadoc)
	 * @see org.evosuite.testcase.LocalSearch#doSearch(org.evosuite.testcase.TestChromosome, int, org.evosuite.ga.LocalSearchObjective)
	 */
/**
 * {@inheritDoc}
 */
@Override
public boolean doSearch(TestChromosome test, int statement, LocalSearchObjective<TestChromosome> objective) {
    boolean hasImproved = false;
    ArrayStatement p = (ArrayStatement) test.getTestCase().getStatement(statement);
    logger.debug("Doing array local search on statement " + statement + ": " + test.getTestCase().toCode());
    int difference = stripAssignments(p, test, objective);
    logger.debug("Adjusting position from " + statement + " to " + (statement - difference) + ": " + test.getTestCase().toCode());
    positionDelta = difference;
    statement = statement - difference;
    p = (ArrayStatement) test.getTestCase().getStatement(statement);
    hasImproved = searchLength(test, statement, objective);
    TestCaseExpander expander = new TestCaseExpander();
    int lengthWithoutAssignments = test.size();
    p = (ArrayStatement) test.getTestCase().getStatement(statement);
    expander.visitArrayStatement(test.getTestCase(), p);
    int assignmentLength = test.size() - lengthWithoutAssignments;
    for (int position = statement + 1; position < statement + assignmentLength; position++) {
        logger.debug("Local search on statement " + position);
        StatementLocalSearch search = StatementLocalSearch.getLocalSearchFor(test.getTestCase().getStatement(position));
        if (search != null) {
            if (search.doSearch(test, position, objective)) {
                hasImproved = true;
            }
        }
    }
    logger.debug("Finished local search with result {}", p.getCode());
    return hasImproved;
}
Also used : ArrayStatement(org.evosuite.testcase.statements.ArrayStatement) TestCaseExpander(org.evosuite.testcase.TestCaseExpander)

Aggregations

TestCaseExpander (org.evosuite.testcase.TestCaseExpander)1 ArrayStatement (org.evosuite.testcase.statements.ArrayStatement)1