use of org.evosuite.coverage.branch.BranchCoverageSuiteFitness in project evosuite by EvoSuite.
the class MockJOptionPaneShowMessageDialogTest method testShowMessageDialog2.
@Test
public void testShowMessageDialog2() throws Exception {
TestSuiteChromosome suite = new TestSuiteChromosome();
InstrumentingClassLoader cl = new InstrumentingClassLoader();
TestCase t0 = buildTestCase2TrueBranch(cl);
TestCase t1 = buildTestCase2FalseBranch(cl);
suite.addTest(t0);
suite.addTest(t1);
BranchCoverageSuiteFitness ff = new BranchCoverageSuiteFitness(cl);
ff.getFitness(suite);
Set<TestFitnessFunction> coveredGoals = suite.getCoveredGoals();
Assert.assertEquals(3, coveredGoals.size());
}
use of org.evosuite.coverage.branch.BranchCoverageSuiteFitness in project evosuite by EvoSuite.
the class MockJOptionPaneTest method testInlinerBug.
@Test
public void testInlinerBug() throws Exception {
Properties.TIMEOUT = Integer.MAX_VALUE;
InstrumentingClassLoader cl = new InstrumentingClassLoader();
TestCase t0 = buildTestCase0(cl);
TestCase t1 = buildTestCase1(cl);
TestSuiteChromosome suite = new TestSuiteChromosome();
suite.addTest(t0);
suite.addTest(t1);
System.out.println(suite.toString());
BranchCoverageSuiteFitness ff = new BranchCoverageSuiteFitness(cl);
ff.getFitness(suite);
ConstantInliner inliner = new ConstantInliner();
inliner.inline(suite);
System.out.println(suite.toString());
List<ExecutionResult> execResults = suite.getLastExecutionResults();
assertEquals(2, execResults.size());
ExecutionResult r1 = execResults.get(0);
ExecutionResult r2 = execResults.get(1);
r1.calledReflection();
r2.calledReflection();
}
use of org.evosuite.coverage.branch.BranchCoverageSuiteFitness in project evosuite by EvoSuite.
the class CompositionalFitnessSystemTest method testCompositionalGetFitnessForTwoFunctions.
@Test
public void testCompositionalGetFitnessForTwoFunctions() {
TestSuiteChromosome c = new TestSuiteChromosome();
LineCoverageSuiteFitness f1 = new LineCoverageSuiteFitness();
c.addFitness(f1);
c.setFitness(f1, ANY_DOUBLE_1);
BranchCoverageSuiteFitness f2 = new BranchCoverageSuiteFitness();
c.addFitness(f2);
c.setFitness(f2, ANY_DOUBLE_2);
assertEquals(ANY_DOUBLE_1 + ANY_DOUBLE_2, c.getFitness(), 0.001);
}
use of org.evosuite.coverage.branch.BranchCoverageSuiteFitness in project evosuite by EvoSuite.
the class Issre13SystemTest method testOnSpecificTest.
@Test
public void testOnSpecificTest() throws ClassNotFoundException, ConstructionFailedException, NoSuchMethodException, SecurityException {
Properties.TARGET_CLASS = DseBar.class.getCanonicalName();
// force using DSE
Properties.DSE_PROBABILITY = 1.0;
Class<?> sut = TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(Properties.TARGET_CLASS);
Class<?> fooClass = TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(DseFoo.class.getCanonicalName());
GenericClass clazz = new GenericClass(sut);
DefaultTestCase test = new DefaultTestCase();
// String string0 = "baz5";
VariableReference stringVar = test.addStatement(new StringPrimitiveStatement(test, "baz5"));
// DseFoo dseFoo0 = new DseFoo();
GenericConstructor fooConstructor = new GenericConstructor(fooClass.getConstructors()[0], fooClass);
ConstructorStatement fooConstructorStatement = new ConstructorStatement(test, fooConstructor, Arrays.asList(new VariableReference[] {}));
VariableReference fooVar = test.addStatement(fooConstructorStatement);
Method fooIncMethod = fooClass.getMethod("inc", new Class<?>[] {});
GenericMethod incMethod = new GenericMethod(fooIncMethod, fooClass);
test.addStatement(new MethodStatement(test, incMethod, fooVar, Arrays.asList(new VariableReference[] {})));
test.addStatement(new MethodStatement(test, incMethod, fooVar, Arrays.asList(new VariableReference[] {})));
test.addStatement(new MethodStatement(test, incMethod, fooVar, Arrays.asList(new VariableReference[] {})));
test.addStatement(new MethodStatement(test, incMethod, fooVar, Arrays.asList(new VariableReference[] {})));
test.addStatement(new MethodStatement(test, incMethod, fooVar, Arrays.asList(new VariableReference[] {})));
// DseBar dseBar0 = new DseBar(string0);
GenericConstructor gc = new GenericConstructor(clazz.getRawClass().getConstructors()[0], clazz);
ConstructorStatement constructorStatement = new ConstructorStatement(test, gc, Arrays.asList(new VariableReference[] { stringVar }));
VariableReference callee = test.addStatement(constructorStatement);
// dseBar0.coverMe(dseFoo0);
Method m = clazz.getRawClass().getMethod("coverMe", new Class<?>[] { fooClass });
GenericMethod method = new GenericMethod(m, sut);
MethodStatement ms = new MethodStatement(test, method, callee, Arrays.asList(new VariableReference[] { fooVar }));
test.addStatement(ms);
System.out.println(test);
TestSuiteChromosome suite = new TestSuiteChromosome();
BranchCoverageSuiteFitness fitness = new BranchCoverageSuiteFitness();
BranchCoverageMap.getInstance().searchStarted(null);
assertEquals(4.0, fitness.getFitness(suite), 0.1F);
suite.addTest(test);
assertEquals(1.0, fitness.getFitness(suite), 0.1F);
System.out.println("Test suite: " + suite);
TestSuiteLocalSearch localSearch = TestSuiteLocalSearch.selectTestSuiteLocalSearch();
LocalSearchObjective<TestSuiteChromosome> localObjective = new DefaultLocalSearchObjective<TestSuiteChromosome>();
localObjective.addFitnessFunction(fitness);
localSearch.doSearch(suite, localObjective);
System.out.println("Fitness: " + fitness.getFitness(suite));
System.out.println("Test suite: " + suite);
assertEquals(0.0, fitness.getFitness(suite), 0.1F);
BranchCoverageMap.getInstance().searchFinished(null);
}
use of org.evosuite.coverage.branch.BranchCoverageSuiteFitness in project evosuite by EvoSuite.
the class LocalSearchArraySystemTest method runArrayExample.
private void runArrayExample(int length, double expectedFitness) throws ClassNotFoundException, ConstructionFailedException, NoSuchMethodException, SecurityException {
TestCase test = getArrayTest(length);
System.out.println("Test: " + test.toCode());
TestSuiteChromosome suite = new TestSuiteChromosome();
BranchCoverageSuiteFitness fitness = new BranchCoverageSuiteFitness();
BranchCoverageMap.getInstance().searchStarted(null);
assertEquals(4.0, fitness.getFitness(suite), 0.1F);
suite.addTest(test);
// assertEquals(1.0, fitness.getFitness(suite), 0.1F);
TestSuiteLocalSearch localSearch = TestSuiteLocalSearch.selectTestSuiteLocalSearch();
LocalSearchObjective<TestSuiteChromosome> localObjective = new DefaultLocalSearchObjective<TestSuiteChromosome>();
localObjective.addFitnessFunction(fitness);
localSearch.doSearch(suite, localObjective);
System.out.println("Fitness: " + fitness.getFitness(suite));
System.out.println("Test suite: " + suite);
assertEquals(expectedFitness, fitness.getFitness(suite), 0.1F);
BranchCoverageMap.getInstance().searchFinished(null);
}
Aggregations