use of org.evosuite.coverage.method.MethodTraceCoverageSuiteFitness in project evosuite by EvoSuite.
the class CompositionalFitnessSystemTest method testCompositionalGetFitnessForSeveralFunctions.
@Test
public void testCompositionalGetFitnessForSeveralFunctions() {
Properties.TARGET_CLASS = Compositional.class.getCanonicalName();
TestSuiteChromosome c = new TestSuiteChromosome();
MethodTraceCoverageSuiteFitness f1 = new MethodTraceCoverageSuiteFitness();
c.addFitness(f1);
c.setFitness(f1, ANY_DOUBLE_1);
MethodNoExceptionCoverageSuiteFitness f2 = new MethodNoExceptionCoverageSuiteFitness();
c.addFitness(f2);
c.setFitness(f2, ANY_DOUBLE_2);
OutputCoverageSuiteFitness f3 = new OutputCoverageSuiteFitness();
c.addFitness(f3);
c.setFitness(f3, ANY_DOUBLE_3);
ExceptionCoverageSuiteFitness f4 = new ExceptionCoverageSuiteFitness();
c.addFitness(f4);
c.setFitness(f4, ANY_DOUBLE_4);
double sum = ANY_DOUBLE_1 + ANY_DOUBLE_2 + ANY_DOUBLE_3 + ANY_DOUBLE_4;
assertEquals(sum, c.getFitness(), 0.001);
}
use of org.evosuite.coverage.method.MethodTraceCoverageSuiteFitness in project evosuite by EvoSuite.
the class PrivateReflectionSystemTest method testPrivateConstructor.
private TestSuiteChromosome testPrivateConstructor() {
Properties.P_REFLECTION_ON_PRIVATE = 0.9;
Properties.REFLECTION_START_PERCENT = 0.0;
GeneticAlgorithm ga = do100percentLineTestOnStandardCriteriaWithMethodTrace(PrivateConstructor.class);
TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
System.out.println("EvolvedTestSuite:\n" + best);
assertTrue(!best.getTests().isEmpty());
double cov = best.getCoverageInstanceOf(MethodCoverageSuiteFitness.class);
Assert.assertEquals("Non-optimal method coverage: ", 1d, cov, 0.001);
Optional<FitnessFunction<?>> ff = ga.getFitnessFunctions().stream().filter(m -> m instanceof MethodCoverageSuiteFitness).findAny();
assertEquals(1, best.getNumOfCoveredGoals(ff.get()));
cov = best.getCoverageInstanceOf(MethodTraceCoverageSuiteFitness.class);
Assert.assertEquals("Non-optimal method trace coverage: ", 1d, cov, 0.001);
ff = ga.getFitnessFunctions().stream().filter(m -> m instanceof MethodTraceCoverageSuiteFitness).findAny();
assertEquals(1, best.getNumOfCoveredGoals(ff.get()));
return best;
}
Aggregations