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);
}
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);
}
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)));
}
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);
}
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());
}
Aggregations