Search in sources :

Example 6 with LineCoverageSuiteFitness

use of org.evosuite.coverage.line.LineCoverageSuiteFitness in project evosuite by EvoSuite.

the class SPEA2Test method testDistanceOfDifferentChromosomes.

@Test
public void testDistanceOfDifferentChromosomes() {
    SPEA2<Chromosome> algorithm = new SPEA2<Chromosome>(null);
    BranchCoverageSuiteFitness branch = new BranchCoverageSuiteFitness();
    LineCoverageSuiteFitness line = new LineCoverageSuiteFitness();
    TestSuiteChromosome t1 = new TestSuiteChromosome();
    t1.setFitness(branch, 0.5);
    t1.setFitness(line, 0.3);
    TestSuiteChromosome t2 = new TestSuiteChromosome();
    t2.setFitness(branch, 0.3);
    t2.setFitness(line, 0.5);
    assertEquals(0.28, algorithm.distanceBetweenObjectives(t1, t2), 0.01);
}
Also used : LineCoverageSuiteFitness(org.evosuite.coverage.line.LineCoverageSuiteFitness) BranchCoverageSuiteFitness(org.evosuite.coverage.branch.BranchCoverageSuiteFitness) Chromosome(org.evosuite.ga.Chromosome) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Test(org.junit.Test)

Example 7 with LineCoverageSuiteFitness

use of org.evosuite.coverage.line.LineCoverageSuiteFitness in project evosuite by EvoSuite.

the class SPEA2Test method testEnvironmentalSelection_ArchiveTruncation.

@Test
public void testEnvironmentalSelection_ArchiveTruncation() {
    List<Chromosome> population = new ArrayList<Chromosome>();
    BranchCoverageSuiteFitness branch = new BranchCoverageSuiteFitness();
    LineCoverageSuiteFitness line = new LineCoverageSuiteFitness();
    // fill population with good solutions
    TestSuiteChromosome t1 = new TestSuiteChromosome();
    t1.setFitness(branch, 0.0);
    t1.setFitness(line, 0.0);
    population.add(t1);
    TestSuiteChromosome t2 = new TestSuiteChromosome();
    t2.setFitness(branch, 0.01);
    t2.setFitness(line, 0.1);
    population.add(t2);
    TestSuiteChromosome t3 = new TestSuiteChromosome();
    t3.setFitness(branch, 0.5);
    t3.setFitness(line, 0.5);
    population.add(t3);
    TestSuiteChromosome t4 = new TestSuiteChromosome();
    t4.setFitness(branch, 0.75);
    t4.setFitness(line, 0.5);
    population.add(t4);
    TestSuiteChromosome t5 = new TestSuiteChromosome();
    t5.setFitness(branch, 0.75);
    t5.setFitness(line, 0.5);
    population.add(t5);
    TestSuiteChromosome t6 = new TestSuiteChromosome();
    t6.setFitness(branch, 0.80);
    t6.setFitness(line, 0.80);
    population.add(t6);
    // max number of solutions
    Properties.POPULATION = 3;
    SPEA2<Chromosome> algorithm = new SPEA2<Chromosome>(null);
    List<Chromosome> archive = algorithm.environmentalSelection(population);
    assertEquals(3, archive.size());
    assertTrue(t1.equals(archive.get(0)));
    assertTrue(t3.equals(archive.get(1)));
    assertTrue(t6.equals(archive.get(2)));
}
Also used : LineCoverageSuiteFitness(org.evosuite.coverage.line.LineCoverageSuiteFitness) BranchCoverageSuiteFitness(org.evosuite.coverage.branch.BranchCoverageSuiteFitness) ArrayList(java.util.ArrayList) Chromosome(org.evosuite.ga.Chromosome) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Test(org.junit.Test)

Example 8 with LineCoverageSuiteFitness

use of org.evosuite.coverage.line.LineCoverageSuiteFitness in project evosuite by EvoSuite.

the class SPEA2Test method testEuclideanDistanceMatrix.

@Test
public void testEuclideanDistanceMatrix() {
    List<Chromosome> population = new ArrayList<Chromosome>();
    BranchCoverageSuiteFitness branch = new BranchCoverageSuiteFitness();
    LineCoverageSuiteFitness line = new LineCoverageSuiteFitness();
    TestSuiteChromosome t1 = new TestSuiteChromosome();
    t1.setFitness(branch, 0.5);
    t1.setFitness(line, 0.3);
    population.add(t1);
    TestSuiteChromosome t2 = new TestSuiteChromosome();
    t2.setFitness(branch, 0.3);
    t2.setFitness(line, 0.5);
    population.add(t2);
    SPEA2<Chromosome> algorithm = new SPEA2<Chromosome>(null);
    double[][] matrix = algorithm.euclideanDistanceMatrix(population);
    assertEquals(2, matrix.length);
    assertEquals(2, matrix[0].length);
    assertEquals(2, matrix[1].length);
    assertEquals(0.0, matrix[0][0], 0.0);
    assertEquals(0.0, matrix[1][1], 0.0);
    assertEquals(0.28, matrix[0][1], 0.01);
    assertEquals(0.28, matrix[1][0], 0.01);
}
Also used : LineCoverageSuiteFitness(org.evosuite.coverage.line.LineCoverageSuiteFitness) BranchCoverageSuiteFitness(org.evosuite.coverage.branch.BranchCoverageSuiteFitness) ArrayList(java.util.ArrayList) Chromosome(org.evosuite.ga.Chromosome) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Test(org.junit.Test)

Example 9 with LineCoverageSuiteFitness

use of org.evosuite.coverage.line.LineCoverageSuiteFitness in project evosuite by EvoSuite.

the class ChromosomeTest method testCompositionalGetFitnessForTwoFunctions.

@Test
public void testCompositionalGetFitnessForTwoFunctions() {
    Properties.ALGORITHM = Algorithm.MONOTONIC_GA;
    TestSuiteChromosome c = new TestSuiteChromosome();
    LineCoverageSuiteFitness f1 = new LineCoverageSuiteFitness();
    OnlyBranchCoverageSuiteFitness f2 = new OnlyBranchCoverageSuiteFitness();
    c.addFitness(f1);
    c.addFitness(f2);
    c.setFitness(f1, ANY_DOUBLE_1);
    c.setFitness(f2, ANY_DOUBLE_2);
    c.setCoverage(f1, ANY_DOUBLE_BETWEEN_0_AND_1_1);
    c.setCoverage(f2, ANY_DOUBLE_BETWEEN_0_AND_1_2);
    assertEquals(ANY_DOUBLE_1, c.getFitnessInstanceOf(LineCoverageSuiteFitness.class), 0.001);
    assertEquals(ANY_DOUBLE_2, c.getFitnessInstanceOf(OnlyBranchCoverageSuiteFitness.class), 0.001);
    assertEquals(ANY_DOUBLE_BETWEEN_0_AND_1_1, c.getCoverageInstanceOf(LineCoverageSuiteFitness.class), 0.001);
    assertEquals(ANY_DOUBLE_BETWEEN_0_AND_1_2, c.getCoverageInstanceOf(OnlyBranchCoverageSuiteFitness.class), 0.001);
    assertEquals(ANY_DOUBLE_1 + ANY_DOUBLE_2, c.getFitness(), 0.001);
    assertEquals((ANY_DOUBLE_BETWEEN_0_AND_1_1 + ANY_DOUBLE_BETWEEN_0_AND_1_2) / 2, c.getCoverage(), 0.001);
}
Also used : LineCoverageSuiteFitness(org.evosuite.coverage.line.LineCoverageSuiteFitness) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) OnlyBranchCoverageSuiteFitness(org.evosuite.coverage.branch.OnlyBranchCoverageSuiteFitness) Test(org.junit.Test)

Example 10 with LineCoverageSuiteFitness

use of org.evosuite.coverage.line.LineCoverageSuiteFitness in project evosuite by EvoSuite.

the class ChromosomeTest method testGetFitnessForOneFunctionNoCompositional.

@Test
public void testGetFitnessForOneFunctionNoCompositional() {
    Properties.ALGORITHM = Algorithm.MONOTONIC_GA;
    TestSuiteChromosome c = new TestSuiteChromosome();
    c.addFitness(new LineCoverageSuiteFitness(), ANY_DOUBLE_1);
    assertEquals(ANY_DOUBLE_1, c.getFitness(), 0.001);
}
Also used : LineCoverageSuiteFitness(org.evosuite.coverage.line.LineCoverageSuiteFitness) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Test(org.junit.Test)

Aggregations

LineCoverageSuiteFitness (org.evosuite.coverage.line.LineCoverageSuiteFitness)12 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)12 Test (org.junit.Test)12 BranchCoverageSuiteFitness (org.evosuite.coverage.branch.BranchCoverageSuiteFitness)6 Chromosome (org.evosuite.ga.Chromosome)5 ArrayList (java.util.ArrayList)3 IntExampleWithNoElse (com.examples.with.different.packagename.coverage.IntExampleWithNoElse)1 OnlyBranchCoverageSuiteFitness (org.evosuite.coverage.branch.OnlyBranchCoverageSuiteFitness)1 ExceptionCoverageSuiteFitness (org.evosuite.coverage.exception.ExceptionCoverageSuiteFitness)1 OutputCoverageSuiteFitness (org.evosuite.coverage.io.output.OutputCoverageSuiteFitness)1 MethodNoExceptionCoverageSuiteFitness (org.evosuite.coverage.method.MethodNoExceptionCoverageSuiteFitness)1 IntPrimitiveStatement (org.evosuite.testcase.statements.numeric.IntPrimitiveStatement)1