/** * {@inheritDoc} * * Replace chromosome at position */ @SuppressWarnings("unchecked") @Override public void crossOver(Chromosome other, int position) throws ConstructionFailedException { if (!(other instanceof AbstractTestSuiteChromosome<?>)) { throw new IllegalArgumentException( "AbstractTestSuiteChromosome.crossOver() called with parameter of unsupported type " + other.getClass()); } AbstractTestSuiteChromosome<T> chromosome = (AbstractTestSuiteChromosome<T>) other; T otherTest = chromosome.tests.get(position); T clonedTest = (T) otherTest.clone(); tests.add(clonedTest); this.setChanged(true); }
/** * {@inheritDoc} * * Keep up to position1, append copy of other from position2 on */ @SuppressWarnings("unchecked") @Override public void crossOver(Chromosome other, int position1, int position2) throws ConstructionFailedException { if (!(other instanceof AbstractTestSuiteChromosome<?>)) { throw new IllegalArgumentException( "AbstractTestSuiteChromosome.crossOver() called with parameter of unsupported type " + other.getClass()); } AbstractTestSuiteChromosome<T> chromosome = (AbstractTestSuiteChromosome<T>) other; while (tests.size() > position1) { tests.remove(position1); } for (int num = position2; num < other.size(); num++) { T otherTest = chromosome.tests.get(num); T clonedTest = (T) otherTest.clone(); tests.add(clonedTest); } this.setChanged(true); }
/** * Creates a deep copy of source. * * @param source a {@link org.evosuite.testsuite.AbstractTestSuiteChromosome} object. */ @SuppressWarnings("unchecked") protected AbstractTestSuiteChromosome(AbstractTestSuiteChromosome<T> source) { this(source.testChromosomeFactory); for (T test : source.tests) { addTest((T) test.clone()); } //this.setFitness(source.getFitness()); this.setFitnessValues(source.getFitnessValues()); this.setPreviousFitnessValues(source.getPreviousFitnessValues()); this.setChanged(source.isChanged()); this.setCoverageValues(source.getCoverageValues()); this.setNumsOfCoveredGoals(source.getNumsOfCoveredGoals()); this.setNumsOfNotCoveredGoals(source.getNumsNotCoveredGoals()); this.setNumberOfMutations(source.getNumberOfMutations()); this.setNumberOfEvaluations(source.getNumberOfEvaluations()); this.setKineticEnergy(source.getKineticEnergy()); this.setNumCollisions(source.getNumCollisions()); }