use of org.evosuite.testcase.variable.ArrayReference in project evosuite by EvoSuite.
the class ArrayLocalSearch method stripAssignments.
private int stripAssignments(ArrayStatement statement, TestChromosome test, LocalSearchObjective<TestChromosome> objective) {
int difference = 0;
ArrayReference arrRef = (ArrayReference) statement.getReturnValue();
TestFactory factory = TestFactory.getInstance();
for (int position = test.size() - 1; position > statement.getPosition(); position--) {
logger.debug("Current delete position: " + position);
if (test.getTestCase().getStatement(position) instanceof AssignmentStatement) {
logger.debug("Is assignment statement");
AssignmentStatement assignment = (AssignmentStatement) test.getTestCase().getStatement(position);
Statement valueStatement = test.getTestCase().getStatement(assignment.getValue().getStPosition());
if (assignment.getReturnValue().getAdditionalVariableReference() == arrRef) {
int currentDelta = 0;
int differenceDelta = 0;
logger.debug("Assigns to target array. Checking if we can remove it without worsening fitness");
backup(test);
try {
factory.deleteStatement(test.getTestCase(), position);
if (valueStatement instanceof PrimitiveStatement || valueStatement instanceof NullStatement) {
if (!test.getTestCase().hasReferences(valueStatement.getReturnValue())) {
if (valueStatement.getPosition() < statement.getPosition())
differenceDelta = 1;
currentDelta = 1;
logger.debug("Deleting primitive statement assigned to this array at " + valueStatement.getPosition());
factory.deleteStatement(test.getTestCase(), valueStatement.getPosition());
}
}
if (!objective.hasNotWorsened(test)) {
logger.debug("Fitness has decreased, so restoring test");
restore(test);
currentDelta = 0;
differenceDelta = 0;
}
} catch (ConstructionFailedException e) {
currentDelta = 0;
differenceDelta = 0;
restore(test);
}
position -= currentDelta;
difference += differenceDelta;
}
}
}
return difference;
}
use of org.evosuite.testcase.variable.ArrayReference in project evosuite by EvoSuite.
the class SymbolicObserverTest method build_test_input_9.
private static DefaultTestCase build_test_input_9() throws SecurityException, NoSuchMethodException, NoSuchFieldException {
test_input9();
Method checkEquals = Assertions.class.getMethod("checkEquals", int.class, int.class);
TestCaseBuilder tc = new TestCaseBuilder();
ArrayReference intArray0 = tc.appendArrayStmt(int[].class, 10);
tc.appendArrayStmt(double[].class, 11);
tc.appendArrayStmt(String[].class, 12);
tc.appendArrayStmt(int[].class, 3, 3);
VariableReference int0 = tc.appendIntPrimitive(Integer.MAX_VALUE);
tc.appendAssignment(intArray0, 1, int0);
VariableReference int1 = tc.appendIntPrimitive(Integer.MIN_VALUE);
tc.appendAssignment(int1, intArray0, 1);
tc.appendMethod(null, checkEquals, int0, int1);
return tc.getDefaultTestCase();
}
use of org.evosuite.testcase.variable.ArrayReference in project evosuite by EvoSuite.
the class TestCaseBuilder method appendArrayStmt.
public ArrayReference appendArrayStmt(Type type, int... length) {
ArrayStatement arrayStmt = new ArrayStatement(tc, type, length);
tc.addStatement(arrayStmt);
return (ArrayReference) arrayStmt.getReturnValue();
}
use of org.evosuite.testcase.variable.ArrayReference in project evosuite by EvoSuite.
the class TestDefaultValue method testShort.
@Test
public void testShort() throws SecurityException, NoSuchMethodException {
TestCaseBuilder builder = new TestCaseBuilder();
ArrayReference integerArray0 = builder.appendArrayStmt(Short[].class, 10);
VariableReference integer0 = builder.appendNull(Short.class);
builder.appendAssignment(integerArray0, 0, integer0);
builder.appendAssignment(integer0, integerArray0, 0);
builder.appendMethod(integer0, Short.class.getMethod("toString"));
DefaultTestCase tc = builder.getDefaultTestCase();
ExecutionResult ret_val = TestCaseExecutor.runTest(tc);
assertNotNull(ret_val);
assertFalse(ret_val.explicitExceptions.isEmpty());
}
use of org.evosuite.testcase.variable.ArrayReference in project evosuite by EvoSuite.
the class TestDefaultValue method testInteger.
@Test
public void testInteger() throws SecurityException, NoSuchMethodException {
TestCaseBuilder builder = new TestCaseBuilder();
ArrayReference integerArray0 = builder.appendArrayStmt(Integer[].class, 10);
VariableReference integer0 = builder.appendNull(Integer.class);
builder.appendAssignment(integerArray0, 0, integer0);
builder.appendAssignment(integer0, integerArray0, 0);
builder.appendMethod(integer0, Integer.class.getMethod("toString"));
DefaultTestCase tc = builder.getDefaultTestCase();
ExecutionResult ret_val = TestCaseExecutor.runTest(tc);
assertNotNull(ret_val);
assertFalse(ret_val.explicitExceptions.isEmpty());
}
Aggregations