Search in sources :

Example 21 with BranchCoverageSuiteFitness

use of org.evosuite.coverage.branch.BranchCoverageSuiteFitness in project evosuite by EvoSuite.

the class SPEA2Test method testComputeStrength.

@Test
public void testComputeStrength() {
    List<Chromosome> population = new ArrayList<Chromosome>();
    BranchCoverageSuiteFitness branch = new BranchCoverageSuiteFitness();
    LineCoverageSuiteFitness line = new LineCoverageSuiteFitness();
    // dominates all the other two chromosomes
    TestSuiteChromosome t1 = new TestSuiteChromosome();
    t1.setFitness(branch, 0.0);
    t1.setFitness(line, 0.0);
    population.add(t1);
    // t2 only dominates t3
    TestSuiteChromosome t2 = new TestSuiteChromosome();
    t2.setFitness(branch, 0.5);
    t2.setFitness(line, 0.5);
    population.add(t2);
    // t3 is dominated by all chromosomes
    TestSuiteChromosome t3 = new TestSuiteChromosome();
    t3.setFitness(branch, 1.0);
    t3.setFitness(line, 1.0);
    population.add(t3);
    SPEA2<Chromosome> algorithm = new SPEA2<Chromosome>(null);
    algorithm.computeStrength(population);
    assertEquals(0.36, t1.getDistance(), 0.01);
    assertEquals(2.36, t2.getDistance(), 0.01);
    assertEquals(3.36, t3.getDistance(), 0.01);
    // invert order of chromosomes
    population.clear();
    population.add(t3);
    population.add(t2);
    population.add(t1);
    algorithm.computeStrength(population);
    assertEquals(0.36, t1.getDistance(), 0.01);
    assertEquals(2.36, t2.getDistance(), 0.01);
    assertEquals(3.36, t3.getDistance(), 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 22 with BranchCoverageSuiteFitness

use of org.evosuite.coverage.branch.BranchCoverageSuiteFitness 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 23 with BranchCoverageSuiteFitness

use of org.evosuite.coverage.branch.BranchCoverageSuiteFitness 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 24 with BranchCoverageSuiteFitness

use of org.evosuite.coverage.branch.BranchCoverageSuiteFitness 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 25 with BranchCoverageSuiteFitness

use of org.evosuite.coverage.branch.BranchCoverageSuiteFitness in project evosuite by EvoSuite.

the class JUnitTestParsedChromosomeFactory method getManualCoverage.

@SuppressWarnings("unused")
private void getManualCoverage() {
    BranchCoverageSuiteFitness fitness = new BranchCoverageSuiteFitness();
    TestSuiteChromosome chromosome = new TestSuiteChromosome(new RandomLengthTestFactory());
    int totalLength = 0;
    for (TestCase test : userTests) {
        chromosome.addTest(test);
        totalLength += test.size();
    }
    fitness.getFitness(chromosome);
    System.out.println("PARSED," + Properties.TARGET_CLASS + "," + userTests.size() + "," + totalLength + "," + chromosome.getCoverage());
}
Also used : BranchCoverageSuiteFitness(org.evosuite.coverage.branch.BranchCoverageSuiteFitness) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome)

Aggregations

BranchCoverageSuiteFitness (org.evosuite.coverage.branch.BranchCoverageSuiteFitness)52 Test (org.junit.Test)45 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)44 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)18 TestCase (org.evosuite.testcase.TestCase)17 DefaultLocalSearchObjective (org.evosuite.ga.localsearch.DefaultLocalSearchObjective)16 TestChromosome (org.evosuite.testcase.TestChromosome)14 Properties (org.evosuite.Properties)12 InstrumentingClassLoader (org.evosuite.instrumentation.InstrumentingClassLoader)12 TestFitnessFunction (org.evosuite.testcase.TestFitnessFunction)12 Method (java.lang.reflect.Method)11 GenericMethod (org.evosuite.utils.generic.GenericMethod)11 IntPrimitiveStatement (org.evosuite.testcase.statements.numeric.IntPrimitiveStatement)10 ArrayList (java.util.ArrayList)8 BranchCoverageFactory (org.evosuite.coverage.branch.BranchCoverageFactory)7 ConstructorStatement (org.evosuite.testcase.statements.ConstructorStatement)7 VariableReference (org.evosuite.testcase.variable.VariableReference)7 GenericClass (org.evosuite.utils.generic.GenericClass)7 GenericConstructor (org.evosuite.utils.generic.GenericConstructor)7 Foo (com.examples.with.different.packagename.symbolic.Foo)6