use of org.evosuite.testcase.statements.numeric.IntPrimitiveStatement in project evosuite by EvoSuite.
the class ChangeMutationSystemTest method getIntTest.
private TestCase getIntTest(int x) throws NoSuchMethodException, SecurityException, ConstructionFailedException, ClassNotFoundException {
Class<?> sut = TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(Properties.TARGET_CLASS);
GenericClass clazz = new GenericClass(sut);
DefaultTestCase test = new DefaultTestCase();
GenericConstructor gc = new GenericConstructor(clazz.getRawClass().getConstructors()[0], clazz);
TestFactory testFactory = TestFactory.getInstance();
VariableReference callee = testFactory.addConstructor(test, gc, 0, 0);
VariableReference intVar = test.addStatement(new IntPrimitiveStatement(test, x));
Method m = clazz.getRawClass().getMethod("testMe", new Class<?>[] { int.class });
GenericMethod method = new GenericMethod(m, sut);
MethodStatement ms = new MethodStatement(test, method, callee, Arrays.asList(new VariableReference[] { intVar }));
test.addStatement(ms);
return test;
}
use of org.evosuite.testcase.statements.numeric.IntPrimitiveStatement in project evosuite by EvoSuite.
the class ChangeMutationSystemTest method testTwoInts.
@Test
public void testTwoInts() throws NoSuchMethodException, SecurityException, ClassNotFoundException, ConstructionFailedException {
Properties.TARGET_CLASS = IntExampleWithNoElse.class.getCanonicalName();
TestChromosome test1 = new TestChromosome();
test1.setTestCase(getTwoIntTest(1000, 100));
TestChromosome test2 = new TestChromosome();
test2.setTestCase(getTwoIntTest(-23423423, 234234234));
TestChromosome test3 = new TestChromosome();
test3.setTestCase(getTwoIntTest(0, 0));
TestSuiteChromosome suite = new TestSuiteChromosome();
BranchCoverageSuiteFitness fitness = new BranchCoverageSuiteFitness();
assertEquals(6.0, fitness.getFitness(suite), 0.0F);
suite.addTest(test1);
assertEquals(2.0, fitness.getFitness(suite), 0.0F);
suite.addTest(test2);
// 0.99...
assertEquals(1.99, fitness.getFitness(suite), 0.01F);
suite.addTest(test3);
// 0.99...
assertEquals(0.99, fitness.getFitness(suite), 0.01F);
Properties.P_TEST_CHANGE = 1.0;
Properties.P_TEST_DELETE = 0.0;
Properties.P_TEST_INSERT = 0.0;
Properties.PRIMITIVE_POOL = 0.0;
double oldFitness = suite.getFitness();
int notChanged = 0;
for (int i = 0; i < 10000; i++) {
TestChromosome testNew = (TestChromosome) test1.clone();
testNew.mutate();
if (testNew.isChanged()) {
suite.deleteTest(test1);
suite.addTest(testNew);
double newFitness = fitness.getFitness(suite);
if (newFitness < oldFitness) {
test1 = testNew;
oldFitness = newFitness;
System.out.println("" + i + ":" + ((IntPrimitiveStatement) test1.getTestCase().getStatement(1)).getValue());
System.out.println(" " + ((IntPrimitiveStatement) test1.getTestCase().getStatement(2)).getValue());
if (newFitness == 0.0) {
System.out.println("Iterations: " + i);
System.out.println("Not changed: " + notChanged);
break;
}
} else {
suite.deleteTest(testNew);
suite.addTest(test1);
fitness.getFitness(suite);
}
} else {
notChanged++;
}
}
System.out.println("Fitness: " + fitness.getFitness(suite));
System.out.println("Test suite: " + suite);
assertEquals(0.0, fitness.getFitness(suite), 0.1F);
}
use of org.evosuite.testcase.statements.numeric.IntPrimitiveStatement in project evosuite by EvoSuite.
the class ChangeMutationSystemTest method getTwoIntTest.
private TestCase getTwoIntTest(int x, int y) throws NoSuchMethodException, SecurityException, ConstructionFailedException, ClassNotFoundException {
Class<?> sut = TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(Properties.TARGET_CLASS);
GenericClass clazz = new GenericClass(sut);
DefaultTestCase test = new DefaultTestCase();
GenericConstructor gc = new GenericConstructor(clazz.getRawClass().getConstructors()[0], clazz);
TestFactory testFactory = TestFactory.getInstance();
VariableReference callee = testFactory.addConstructor(test, gc, 0, 0);
VariableReference intVar1 = test.addStatement(new IntPrimitiveStatement(test, x));
VariableReference intVar2 = test.addStatement(new IntPrimitiveStatement(test, y));
Method m = clazz.getRawClass().getMethod("testMe", new Class<?>[] { int.class, int.class });
GenericMethod method = new GenericMethod(m, sut);
MethodStatement ms = new MethodStatement(test, method, callee, Arrays.asList(new VariableReference[] { intVar1, intVar2 }));
test.addStatement(ms);
return test;
}
use of org.evosuite.testcase.statements.numeric.IntPrimitiveStatement in project evosuite by EvoSuite.
the class LocalSearchNumericSystemTest method getIntTest.
private TestCase getIntTest(int x, int y) throws NoSuchMethodException, SecurityException, ConstructionFailedException, ClassNotFoundException {
Class<?> sut = TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(Properties.TARGET_CLASS);
GenericClass clazz = new GenericClass(sut);
DefaultTestCase test = new DefaultTestCase();
GenericConstructor gc = new GenericConstructor(clazz.getRawClass().getConstructors()[0], clazz);
TestFactory testFactory = TestFactory.getInstance();
VariableReference callee = testFactory.addConstructor(test, gc, 0, 0);
VariableReference intVar1 = test.addStatement(new IntPrimitiveStatement(test, x));
VariableReference intVar0 = test.addStatement(new IntPrimitiveStatement(test, y));
Method m = clazz.getRawClass().getMethod("testMe", new Class<?>[] { int.class, int.class });
GenericMethod method = new GenericMethod(m, sut);
MethodStatement ms = new MethodStatement(test, method, callee, Arrays.asList(new VariableReference[] { intVar0, intVar1 }));
test.addStatement(ms);
return test;
}
Aggregations