Search in sources :

Example 1 with EnumPrimitiveStatement

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

the class EnumLocalSearch method doSearch.

/* (non-Javadoc)
	 * @see org.evosuite.testcase.LocalSearch#doSearch(org.evosuite.testcase.TestChromosome, int, org.evosuite.ga.LocalSearchObjective)
	 */
/**
 * {@inheritDoc}
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public boolean doSearch(TestChromosome test, int statement, LocalSearchObjective<TestChromosome> objective) {
    EnumPrimitiveStatement p = (EnumPrimitiveStatement) test.getTestCase().getStatement(statement);
    ExecutionResult oldResult = test.getLastExecutionResult();
    oldValue = p.getValue();
    for (Object value : p.getEnumValues()) {
        p.setValue(value);
        if (!objective.hasImproved(test)) {
            // Restore original
            p.setValue(oldValue);
            test.setLastExecutionResult(oldResult);
            test.setChanged(false);
        } else {
            logger.debug("Finished local search with result " + p.getCode());
            return true;
        }
    }
    return false;
}
Also used : EnumPrimitiveStatement(org.evosuite.testcase.statements.EnumPrimitiveStatement) ExecutionResult(org.evosuite.testcase.execution.ExecutionResult)

Example 2 with EnumPrimitiveStatement

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

the class TestCaseBuilder method appendEnumPrimitive.

public VariableReference appendEnumPrimitive(Enum<?> value) {
    EnumPrimitiveStatement primitiveStmt = new EnumPrimitiveStatement(tc, value);
    tc.addStatement(primitiveStmt);
    return primitiveStmt.getReturnValue();
}
Also used : EnumPrimitiveStatement(org.evosuite.testcase.statements.EnumPrimitiveStatement)

Aggregations

EnumPrimitiveStatement (org.evosuite.testcase.statements.EnumPrimitiveStatement)2 ExecutionResult (org.evosuite.testcase.execution.ExecutionResult)1