Skip to content

Commit

Permalink
Merge branch 'fix-refactorcopy' into 'master'
Browse files Browse the repository at this point in the history
Define copy constructor that initialises all attributes of RefactorSequence...

See merge request se2/litterbox!458
  • Loading branch information
gofraser committed Aug 13, 2021
2 parents 4599d77 + e18db08 commit 1bdf042
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import de.uni_passau.fim.se2.litterbox.refactor.refactorings.Refactoring;
import de.uni_passau.fim.se2.litterbox.utils.PropertyLoader;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -108,6 +107,18 @@ public RefactorSequence(Program originalProgram, Mutation<RefactorSequence> muta
this.refactoringFinders = refactoringFinders;
}

/**
* Copy constructor
*
* @param other RefactoringSequence to copy
*/
RefactorSequence(RefactorSequence other) {
super(other);
this.originalProgram = other.originalProgram;
this.productions = new LinkedList<>(other.productions);
this.refactoringFinders = other.refactoringFinders;
}

/**
* Apply the refactoring sequence to a given program, without modifying the original program.
*
Expand Down Expand Up @@ -145,8 +156,7 @@ private Refactoring getExecutedRefactoring(Program program, Integer nthProductio

@Override
public RefactorSequence copy() {
return new RefactorSequence(originalProgram, getMutation(), getCrossover(),
new ArrayList<>(productions), refactoringFinders);
return new RefactorSequence(this);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ protected Solution(Mutation<C> mutation, Crossover<C> crossover, Map<FitnessFunc
protected Solution(C other) throws NullPointerException {
super(other);
this.fitnessMap = new LinkedHashMap<>(other.getFitnessMap());
this.rank = other.getRank();
this.distance = other.getDistance();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@

public class BinaryRankTournament<C extends Solution<C>> implements Selection<C> {

public BinaryRankTournament() {
}

/**
* Selects a chromosome to be used as parent for mutation or crossover from the given non-null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ void testSelectionByDistance() {
refactorSequence1.setDistance(2.0);
mockedRandomness.when(() -> Randomness.nextInt(2)).thenReturn(0).thenReturn(1);
RefactorSequence candidate2 = selection.apply(population);
assertNotSame(refactorSequence1, candidate1);
assertEquals(refactorSequence1, candidate1);
assertNotSame(refactorSequence1, candidate2);
assertEquals(refactorSequence1, candidate2);
}

@Test
Expand Down

0 comments on commit 1bdf042

Please sign in to comment.