Skip to content

Commit

Permalink
fix tiny mistakes; typo, unused method, and field modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
shinsuke-mat committed Oct 12, 2020
1 parent 5dea556 commit 9599224
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public SecondVariantSelectionStrategy getSecondVariantSelectionStrategy() {
* @param variantStore 交叉対象の個体群
* @return 交叉により生成された個体群
*/
//@Override
@Override
public List<Variant> exec(final VariantStore variantStore) {
final List<Variant> validVariants = filter(variantStore.getCurrentVariants());
final List<Variant> variants = new ArrayList<>();
Expand All @@ -91,36 +91,6 @@ public List<Variant> exec(final VariantStore variantStore) {
return variants.subList(0, generatingCount);
}

//@Override
public final List<Variant> execx(final VariantStore variantStore) {

final List<Variant> filteredVariants = variantStore.getCurrentVariants()
.stream()
.filter(e -> 1 < e.getGene() // 遺伝子の長さが2に満たないバリアントは交叉に使えない
.getBases()
.size())
.collect(Collectors.toList());

// filteredVariantsの要素数が2に満たない場合は交叉しない
if (filteredVariants.size() < 2) {
return Collections.emptyList();
}

final List<Variant> variants = new ArrayList<>();
try {
// generatingCountを超えるまでバリアントを作りづづける
while (variants.size() < generatingCount) {
final List<Variant> newVariants = makeVariants(filteredVariants, variantStore);
variants.addAll(newVariants);
}
} catch (final CrossoverInfeasibleException e) {
log.debug(e.getMessage());
}

// バリアントを作りすぎた場合はそれを除いてリターン
return variants.subList(0, generatingCount);
}

protected abstract List<Variant> makeVariants(List<Variant> variants, VariantStore variantStore)
throws CrossoverInfeasibleException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
public class JDTASTLocation implements ASTLocation {

public final ASTNode node;
protected final SourcePath sourcePath;
protected final GeneratedJDTAST<?> generatedAST;
private final SourcePath sourcePath;
private final GeneratedJDTAST<?> generatedAST;

public JDTASTLocation(final SourcePath sourcePath, final ASTNode node,
final GeneratedJDTAST<?> generatedAST) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void setup() {
*/
@Test
public void testForSimpleInsertions01() {
// 親1: n=0の後ろにn=0を2つ追加
// 親1: n=0の後ろにn=2を2つ追加
final Base base1a = new Base(loc0, new InsertAfterOperation(loc2.getNode()));
final Base base1b = new Base(loc0, new InsertAfterOperation(loc2.getNode()));
final Gene gene1 = new Gene(Arrays.asList(base1a, base1b));
Expand All @@ -79,7 +79,7 @@ public void testForSimpleInsertions01() {
+ "}"
+ "n=2;}}");

// 親2: n=1の後ろにn=1を2つ追加
// 親2: n=1の後ろにn=2を2つ追加
final Base base2a = new Base(loc1, new InsertAfterOperation(loc2.getNode()));
final Base base2b = new Base(loc1, new InsertAfterOperation(loc2.getNode()));
final Gene gene2 = new Gene(Arrays.asList(base2a, base2b));
Expand All @@ -94,14 +94,14 @@ public void testForSimpleInsertions01() {
+ "n=2;}}");

// setup mocked objects used in crossover
final VariantStore spyedStore = createMockedStore(parent1, parent2);
final VariantStore spiedStore = createMockedStore(parent1, parent2);
final FirstVariantSelectionStrategy strategy1 = createMocked1stStrategy(parent1);
final SecondVariantSelectionStrategy strategy2 = createMocked2ndStrategy(parent2);

// テスト対象のセットアップ
final Crossover crossover = new CascadeCrossover(strategy1, strategy2);

final List<Variant> variants = crossover.exec(spyedStore);
final List<Variant> variants = crossover.exec(spiedStore);
assertThat(variants)
.hasSize(2)
.doesNotContainNull();
Expand Down Expand Up @@ -163,14 +163,14 @@ public void testForSimpleInsertions02() {
+ "n=2;}}");

// setup mocked objects used in crossover
final VariantStore spyedStore = createMockedStore(parent1, parent2);
final VariantStore spiedStore = createMockedStore(parent1, parent2);
final FirstVariantSelectionStrategy strategy1 = createMocked1stStrategy(parent1);
final SecondVariantSelectionStrategy strategy2 = createMocked2ndStrategy(parent2);

// テスト対象のセットアップ
Crossover crossover = new CascadeCrossover(strategy1, strategy2);

final List<Variant> variants = crossover.exec(spyedStore);
final List<Variant> variants = crossover.exec(spiedStore);
assertThat(variants)
.hasSize(2)
.doesNotContainNull();
Expand Down Expand Up @@ -202,7 +202,7 @@ public void testForSimpleInsertions02() {
*/
@Test
public void testForComplicatedMutations() {
// 親1: n=0の後ろにn=2を追加,さらにn=0後ろにn=1を追加
// 親1: n=0の後ろにn=2を追加,さらにn=0の後ろにn=1を追加
final Base base1a = new Base(loc0, new InsertAfterOperation(loc2.getNode()));
final Base base1b = new Base(loc0, new InsertAfterOperation(loc1.getNode()));
final Gene gene1 = new Gene(Arrays.asList(base1a, base1b));
Expand Down Expand Up @@ -232,14 +232,14 @@ public void testForComplicatedMutations() {
+ "n=2;}}");

// setup mocked objects used in crossover
final VariantStore spyedStore = createMockedStore(parent1, parent2);
final VariantStore spiedStore = createMockedStore(parent1, parent2);
final FirstVariantSelectionStrategy strategy1 = createMocked1stStrategy(parent1);
final SecondVariantSelectionStrategy strategy2 = createMocked2ndStrategy(parent2);

// テスト対象のセットアップ
Crossover crossover = new CascadeCrossover(strategy1, strategy2);

final List<Variant> variants = crossover.exec(spyedStore);
final List<Variant> variants = crossover.exec(spiedStore);
assertThat(variants)
.hasSize(2)
.doesNotContainNull();
Expand Down Expand Up @@ -269,7 +269,7 @@ public void testForComplicatedMutations() {

/**
* 2つの親が矛盾する塩基を持つケース.
* 親2によってlocate先のstmtが消えてしまうため親1の生成に失敗
* 親2によってlocate先のstmtが消えてしまうため子2の生成に失敗
*/
@Test
public void testForInconsistentParents() {
Expand Down Expand Up @@ -301,14 +301,14 @@ public void testForInconsistentParents() {
+ "n=2;}}");

// setup mocked objects used in crossover
final VariantStore spyedStore = createMockedStore(parent1, parent2);
final VariantStore spiedStore = createMockedStore(parent1, parent2);
final FirstVariantSelectionStrategy strategy1 = createMocked1stStrategy(parent1);
final SecondVariantSelectionStrategy strategy2 = createMocked2ndStrategy(parent2);

// テスト対象のセットアップ
Crossover crossover = new CascadeCrossover(strategy1, strategy2);

final List<Variant> variants = crossover.exec(spyedStore);
final List<Variant> variants = crossover.exec(spiedStore);
assertThat(variants)
.hasSize(2)
.doesNotContainNull();
Expand Down Expand Up @@ -373,14 +373,14 @@ public void testForDerivedParents() {
+ "n=2;}}");

// setup mocked objects used in crossover
final VariantStore spyedStore = createMockedStore(parent1, parent2);
final VariantStore spiedStore = createMockedStore(parent1, parent2);
final FirstVariantSelectionStrategy strategy1 = createMocked1stStrategy(parent1);
final SecondVariantSelectionStrategy strategy2 = createMocked2ndStrategy(parent2);

// テスト対象のセットアップ
Crossover crossover = new CascadeCrossover(strategy1, strategy2);

final List<Variant> variants = crossover.exec(spyedStore);
final List<Variant> variants = crossover.exec(spiedStore);
assertThat(variants)
.hasSize(2)
.doesNotContainNull();
Expand Down Expand Up @@ -427,10 +427,10 @@ private JDTASTLocation getLocation(final Variant v, int idx) {

private VariantStore createMockedStore(final Variant v1, final Variant v2) {
// always return the specified variants for store#getCurrentVariants()
final VariantStore spyedStore = Mockito.spy(store);
when(spyedStore.getGeneratedVariants()).thenReturn(Arrays.asList(v1, v2));
when(spyedStore.getCurrentVariants()).thenReturn(Arrays.asList(v1, v2));
return spyedStore;
final VariantStore spiedStore = Mockito.spy(store);
when(spiedStore.getGeneratedVariants()).thenReturn(Arrays.asList(v1, v2));
when(spiedStore.getCurrentVariants()).thenReturn(Arrays.asList(v1, v2));
return spiedStore;
}

private FirstVariantSelectionStrategy createMocked1stStrategy(final Variant v) {
Expand Down

0 comments on commit 9599224

Please sign in to comment.