Search in sources :

Example 1 with GeneticAlgorithm

use of org.evosuite.ga.metaheuristics.GeneticAlgorithm 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;
}
Also used : Arrays(java.util.Arrays) GeneticAlgorithm(org.evosuite.ga.metaheuristics.GeneticAlgorithm) RuntimeVariable(org.evosuite.statistics.RuntimeVariable) MethodCoverageFitnessFunctionSystemTest(org.evosuite.coverage.method.MethodCoverageFitnessFunctionSystemTest) OutputVariable(org.evosuite.statistics.OutputVariable) ArrayList(java.util.ArrayList) MethodTraceCoverageSuiteFitness(org.evosuite.coverage.method.MethodTraceCoverageSuiteFitness) FitnessFunction(org.evosuite.ga.FitnessFunction) SystemTestBase(org.evosuite.SystemTestBase) Properties(org.evosuite.Properties) com.examples.with.different.packagename.reflection(com.examples.with.different.packagename.reflection) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) TestCaseExecutor(org.evosuite.testcase.execution.TestCaseExecutor) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) EvoSuite(org.evosuite.EvoSuite) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) MethodCoverageSuiteFitness(org.evosuite.coverage.method.MethodCoverageSuiteFitness) LineCoverageSuiteFitness(org.evosuite.coverage.line.LineCoverageSuiteFitness) Optional(java.util.Optional) Assert(org.junit.Assert) TestSuiteFitnessFunction(org.evosuite.testsuite.TestSuiteFitnessFunction) Assert.assertEquals(org.junit.Assert.assertEquals) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) MethodTraceCoverageSuiteFitness(org.evosuite.coverage.method.MethodTraceCoverageSuiteFitness) FitnessFunction(org.evosuite.ga.FitnessFunction) TestSuiteFitnessFunction(org.evosuite.testsuite.TestSuiteFitnessFunction) MethodCoverageSuiteFitness(org.evosuite.coverage.method.MethodCoverageSuiteFitness) GeneticAlgorithm(org.evosuite.ga.metaheuristics.GeneticAlgorithm)

Example 2 with GeneticAlgorithm

use of org.evosuite.ga.metaheuristics.GeneticAlgorithm in project evosuite by EvoSuite.

the class NoveltyFitnessEvaluationListener method iteration.

@Override
public void iteration(GeneticAlgorithm<?> algorithm) {
    List<TestChromosome> population = ((GeneticAlgorithm<TestChromosome>) algorithm).getPopulation();
    TestSuiteChromosome suite = createMergedSolution(population);
    for (FitnessFunction fitnessFunction : fitnessFunctions) {
        fitnessFunction.getFitness(suite);
    }
    // Update fitness functions based on goals just added to archive
    algorithm.updateFitnessFunctionsAndValues();
}
Also used : TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) FitnessFunction(org.evosuite.ga.FitnessFunction) TestSuiteFitnessFunction(org.evosuite.testsuite.TestSuiteFitnessFunction) TestChromosome(org.evosuite.testcase.TestChromosome) GeneticAlgorithm(org.evosuite.ga.metaheuristics.GeneticAlgorithm)

Aggregations

FitnessFunction (org.evosuite.ga.FitnessFunction)2 GeneticAlgorithm (org.evosuite.ga.metaheuristics.GeneticAlgorithm)2 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)2 TestSuiteFitnessFunction (org.evosuite.testsuite.TestSuiteFitnessFunction)2 com.examples.with.different.packagename.reflection (com.examples.with.different.packagename.reflection)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Optional (java.util.Optional)1 EvoSuite (org.evosuite.EvoSuite)1 Properties (org.evosuite.Properties)1 SystemTestBase (org.evosuite.SystemTestBase)1 LineCoverageSuiteFitness (org.evosuite.coverage.line.LineCoverageSuiteFitness)1 MethodCoverageFitnessFunctionSystemTest (org.evosuite.coverage.method.MethodCoverageFitnessFunctionSystemTest)1 MethodCoverageSuiteFitness (org.evosuite.coverage.method.MethodCoverageSuiteFitness)1 MethodTraceCoverageSuiteFitness (org.evosuite.coverage.method.MethodTraceCoverageSuiteFitness)1 OutputVariable (org.evosuite.statistics.OutputVariable)1 RuntimeVariable (org.evosuite.statistics.RuntimeVariable)1 TestChromosome (org.evosuite.testcase.TestChromosome)1