/** * {@inheritDoc} * * Generate a random chromosome */ @Override public TestChromosome getChromosome() { TestChromosome c = new TestChromosome(); c.setTestCase(getRandomTestCase(Properties.CHROMOSOME_LENGTH)); return c; }
/** * {@inheritDoc} * * Generate a random chromosome */ @Override public TestChromosome getChromosome() { TestChromosome c = new TestChromosome(); c.setTestCase(getRandomTestCase(Properties.CHROMOSOME_LENGTH)); return c; }
/** * Add a test to a test suite * * @param test * a {@link org.evosuite.testcase.TestCase} object. */ public TestChromosome addTest(TestCase test) { TestChromosome c = new TestChromosome(); c.setTestCase(test); addTest(c); return c; }
/** * {@inheritDoc} * * Generate a random chromosome */ @Override public TestChromosome getChromosome() { TestChromosome c = new TestChromosome(); c.setTestCase(getRandomTestCase(Properties.CHROMOSOME_LENGTH)); return c; }
/** * Helper function if this is used without a chromosome * * @param result * @return */ public boolean isCovered(ExecutionResult result) { TestChromosome chromosome = new TestChromosome(); chromosome.setTestCase(result.test); chromosome.setLastExecutionResult(result); chromosome.setChanged(false); return isCovered(chromosome, result); }
protected void restore(TestChromosome test) { if (backup == null) return; test.setTestCase(backup.getTestCase().clone()); test.copyCachedResults(backup); //test.setFitness(backup.getFitness()); test.setFitnessValues(backup.getFitnessValues()); test.setPreviousFitnessValues(backup.getPreviousFitnessValues()); test.setChanged(backup.isChanged()); }
@Test public void compareBetterRank() { TestChromosome tch1 = new TestChromosome(); tch1.setTestCase(new DefaultTestCase()); tch1.setRank(0); TestChromosome tch2 = new TestChromosome(); tch2.setTestCase(new DefaultTestCase()); tch2.setRank(1); RankAndCrowdingDistanceComparator comparator = new RankAndCrowdingDistanceComparator(); double result = comparator.compare(tch1, tch2); assertEquals(-1, result, 0.00001); }
@Test public void compareEqual() { BranchCoverageGoal goal = Mockito.mock(BranchCoverageGoal.class); BranchCoverageTestFitness fitness = new BranchCoverageTestFitness(goal); TestChromosome tch1 = new TestChromosome(); tch1.setTestCase(new DefaultTestCase()); tch1.setFitness(fitness, 1); TestChromosome tch2 = new TestChromosome(); tch2.setTestCase(new DefaultTestCase()); tch2.setFitness(fitness, 1); PreferenceSortingComparator comparator = new PreferenceSortingComparator(fitness); double value = comparator.compare(tch1, tch2); assertEquals(0.0, value, 0.0001); }
@Test public void compareBetterRank_maximization() { TestChromosome tch1 = new TestChromosome(); tch1.setTestCase(new DefaultTestCase()); tch1.setRank(0); TestChromosome tch2 = new TestChromosome(); tch2.setTestCase(new DefaultTestCase()); tch2.setRank(1); RankAndCrowdingDistanceComparator comparator = new RankAndCrowdingDistanceComparator(true); double result = comparator.compare(tch1, tch2); assertEquals(+1, result, 0.00001); }
@Test public void compareHigherRank_maximization() { TestChromosome tch1 = new TestChromosome(); tch1.setTestCase(new DefaultTestCase()); tch1.setRank(1); TestChromosome tch2 = new TestChromosome(); tch2.setTestCase(new DefaultTestCase()); tch2.setRank(0); RankAndCrowdingDistanceComparator comparator = new RankAndCrowdingDistanceComparator(true); double result = comparator.compare(tch1, tch2); assertEquals(-1, result, 0.00001); }
@Test public void compareLarger() { BranchCoverageGoal goal = Mockito.mock(BranchCoverageGoal.class); BranchCoverageTestFitness fitness = new BranchCoverageTestFitness(goal); TestChromosome tch1 = new TestChromosome(); tch1.setTestCase(new DefaultTestCase()); tch1.setFitness(fitness, 2); TestChromosome tch2 = new TestChromosome(); tch2.setTestCase(new DefaultTestCase()); tch2.setFitness(fitness, 1); PreferenceSortingComparator comparator = new PreferenceSortingComparator(fitness); double value = comparator.compare(tch1, tch2); assertEquals(+1, value, 0.0001); }
@Test public void compareHigherRank() { TestChromosome tch1 = new TestChromosome(); tch1.setTestCase(new DefaultTestCase()); tch1.setRank(1); TestChromosome tch2 = new TestChromosome(); tch2.setTestCase(new DefaultTestCase()); tch2.setRank(0); RankAndCrowdingDistanceComparator comparator = new RankAndCrowdingDistanceComparator(); double result = comparator.compare(tch1, tch2); assertEquals(+1, result, 0.00001); }
@Test public void compareEqual_maximization() { TestChromosome tch1 = new TestChromosome(); tch1.setTestCase(new DefaultTestCase()); tch1.setRank(0); TestChromosome tch2 = new TestChromosome(); tch2.setTestCase(new DefaultTestCase()); tch2.setRank(0); RankAndCrowdingDistanceComparator comparator = new RankAndCrowdingDistanceComparator(); comparator.setMaximize(true); double result = comparator.compare(tch1, tch2); assertEquals(0, result, 0.00001); }
@Test public void compareBetterDistance() { TestChromosome tch1 = new TestChromosome(); tch1.setTestCase(new DefaultTestCase()); tch1.setRank(0); tch1.setDistance(1); TestChromosome tch2 = new TestChromosome(); tch2.setTestCase(new DefaultTestCase()); tch2.setRank(0); tch2.setDistance(0); RankAndCrowdingDistanceComparator comparator = new RankAndCrowdingDistanceComparator(); double result = comparator.compare(tch1, tch2); assertEquals(-1, result, 0.00001); }
@Test public void compareLowerDistance_maximization() { TestChromosome tch1 = new TestChromosome(); tch1.setTestCase(new DefaultTestCase()); tch1.setRank(0); tch1.setDistance(0); TestChromosome tch2 = new TestChromosome(); tch2.setTestCase(new DefaultTestCase()); tch2.setRank(0); tch2.setDistance(1); RankAndCrowdingDistanceComparator comparator = new RankAndCrowdingDistanceComparator(true); double result = comparator.compare(tch1, tch2); assertEquals(+1, result, 0.00001); }
@Test public void compareEqual() { TestChromosome tch1 = new TestChromosome(); tch1.setTestCase(new DefaultTestCase()); tch1.setRank(0); tch1.setDistance(0); TestChromosome tch2 = new TestChromosome(); tch2.setTestCase(new DefaultTestCase()); tch2.setRank(0); tch1.setDistance(0); RankAndCrowdingDistanceComparator comparator = new RankAndCrowdingDistanceComparator(); double result = comparator.compare(tch1, tch2); assertEquals(0, result, 0.00001); }
@Test public void compareLowerDistance() { TestChromosome tch1 = new TestChromosome(); tch1.setTestCase(new DefaultTestCase()); tch1.setRank(0); tch1.setDistance(0); TestChromosome tch2 = new TestChromosome(); tch2.setTestCase(new DefaultTestCase()); tch2.setRank(0); tch2.setDistance(1); RankAndCrowdingDistanceComparator comparator = new RankAndCrowdingDistanceComparator(); double result = comparator.compare(tch1, tch2); assertEquals(+1, result, 0.00001); }
@Test public void compareBetterDistance_maximization() { TestChromosome tch1 = new TestChromosome(); tch1.setTestCase(new DefaultTestCase()); tch1.setRank(0); tch1.setDistance(1); TestChromosome tch2 = new TestChromosome(); tch2.setTestCase(new DefaultTestCase()); tch2.setRank(0); tch2.setDistance(0); RankAndCrowdingDistanceComparator comparator = new RankAndCrowdingDistanceComparator(true); double result = comparator.compare(tch1, tch2); assertEquals(-1, result, 0.00001); }
@Test public void testNull() { BranchCoverageGoal goal = Mockito.mock(BranchCoverageGoal.class); BranchCoverageTestFitness fitness = new BranchCoverageTestFitness(goal); TestChromosome tch1 = new TestChromosome(); tch1.setTestCase(new DefaultTestCase()); tch1.setFitness(fitness, 0); PreferenceSortingComparator comparator = new PreferenceSortingComparator(fitness); double value = comparator.compare(tch1, null); assertEquals(-1, value, 0.0001); value = comparator.compare(null, tch1); assertEquals(+1, value, 0.0001); }
@Test public void testNull() { TestChromosome tch1 = new TestChromosome(); tch1.setTestCase(new DefaultTestCase()); RankAndCrowdingDistanceComparator comparator = new RankAndCrowdingDistanceComparator(); double value = comparator.compare(tch1, null); assertEquals(-1, value, 0.0001); value = comparator.compare(null, tch1); assertEquals(+1, value, 0.0001); } }