-
-
Notifications
You must be signed in to change notification settings - Fork 680
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix CI silently not running exercise tests (#2339)
* Fix compilation errors in Calculator Conundrum This is not the best solution, probably it would be better if the CI script is able to parse the config.json file and copy all files listed in `files.editor` and `files.exemplar`, but for now duplicating the editor files into the exemplar implementation should help to unblock the CI build. * Fix checkstyle errors in Calculator Conundrum * Link editor files instead of copying them * Fix exemplar implementation of Wizards and Warriors * Fix exemplar implementation of Remote Control Competition * Fix gradle test task By making `test` depend on `copyTestsFilteringIgnores`, Gradle would run `compileTestJava` -> `copyTestFilteringIgnores` -> `Test`. This fails because there is nothing to compile in the test sourceset, since it has not been generated yet. The correct task order should be `copyTestsFilteringIgnores` -> `compileTestJava` -> `Test`. * Use gradle test in CI to run tests * Only run checkstyle in build job, no tests * Update exemplar code for SGF Parsing to pass unit tests * Update exemplar code for Pythagorean Triplet to pass unit tests * Fix checkstyle errors in Pythagorean Triplet exemplar code
- Loading branch information
1 parent
1cae702
commit e9e9c2d
Showing
10 changed files
with
75 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...ises/concept/calculator-conundrum/.meta/src/reference/java/IllegalOperationException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../src/main/java/IllegalOperationException.java |
1 change: 1 addition & 0 deletions
1
exercises/concept/calculator-conundrum/.meta/src/reference/java/SimpleOperation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../src/main/java/SimpleOperation.java |
9 changes: 3 additions & 6 deletions
9
exercises/concept/calculator-conundrum/src/main/java/SimpleOperation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 35 additions & 85 deletions
120
exercises/practice/pythagorean-triplet/.meta/src/reference/java/PythagoreanTriplet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,117 +1,67 @@ | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
|
||
public class PythagoreanTriplet { | ||
|
||
private int a; | ||
private int b; | ||
private int c; | ||
private final int a; | ||
private final int b; | ||
private final int c; | ||
|
||
public PythagoreanTriplet(final int a, final int b, final int c) { | ||
this.a = a; | ||
this.b = b; | ||
this.c = c; | ||
} | ||
|
||
public static TripletListBuilder makeTripletsList() { | ||
return new TripletListBuilder(); | ||
} | ||
|
||
public int calculateSum() { | ||
return this.a + this.b + this.c; | ||
} | ||
|
||
public long calculateProduct() { | ||
return this.a * this.b * this.c; | ||
} | ||
|
||
public boolean isPythagorean() { | ||
return this.a * this.a + this.b * this.b == this.c * this.c; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(a, b, c); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
if (obj == null) { | ||
return false; | ||
} | ||
if (getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
final PythagoreanTriplet other = (PythagoreanTriplet) obj; | ||
if (this.a != other.a) { | ||
return false; | ||
} | ||
if (this.b != other.b) { | ||
return false; | ||
} | ||
if (this.c != other.c) { | ||
return false; | ||
} | ||
return true; | ||
public static PythagoreanTripletBuilder makeTripletsList() { | ||
return new PythagoreanTripletBuilder(); | ||
} | ||
|
||
public static class TripletListBuilder { | ||
|
||
private static final int MAX_FACTOR_DEFAULT_VALUE = 0; | ||
private static final int SUM_DEFAULT_VALUE = -1; | ||
|
||
private int maxFactor = MAX_FACTOR_DEFAULT_VALUE; | ||
private int minFactor = 1; | ||
private int sum = SUM_DEFAULT_VALUE; | ||
public static class PythagoreanTripletBuilder { | ||
private final List<PythagoreanTriplet> triplets = new ArrayList<>(); | ||
private int limit = 0; | ||
private int sum = 0; | ||
|
||
public TripletListBuilder() { | ||
} | ||
|
||
public TripletListBuilder withFactorsLessThanOrEqualTo( | ||
final int maxFactor) { | ||
this.maxFactor = maxFactor; | ||
public PythagoreanTripletBuilder withFactorsLessThanOrEqualTo(int limit) { | ||
this.limit = limit; | ||
return this; | ||
} | ||
|
||
public TripletListBuilder withFactorsGreaterThanOrEqualTo( | ||
final int minFactor) { | ||
this.minFactor = minFactor; | ||
return this; | ||
} | ||
|
||
public TripletListBuilder thatSumTo(final int sum) { | ||
public PythagoreanTripletBuilder thatSumTo(int sum) { | ||
this.sum = sum; | ||
return this; | ||
} | ||
|
||
public List<PythagoreanTriplet> build() { | ||
List<PythagoreanTriplet> triplets = new ArrayList<>(); | ||
if (this.maxFactor == MAX_FACTOR_DEFAULT_VALUE) { | ||
return triplets; | ||
if (limit == 0) { | ||
limit = sum / 2; | ||
} | ||
double sqrt; | ||
int floor; | ||
for (int n = minFactor; n < maxFactor; n++) { | ||
for (int m = n + 1; m < maxFactor; m++) { | ||
sqrt = Math.sqrt(n * n + m * m); | ||
floor = (int) Math.floor(sqrt); | ||
if (sqrt == floor) { | ||
triplets.add(new PythagoreanTriplet(n, m, floor)); | ||
int start = (int) Math.sqrt(sum); | ||
for (int a = start; a <= limit; a++) { | ||
for (int b = a; b <= limit; b++) { | ||
double c = Math.sqrt(a * a + b * b); | ||
if (c % 1 == 0 && c <= limit && a + b + c == sum) { | ||
triplets.add(new PythagoreanTriplet(a, b, (int) c)); | ||
} | ||
} | ||
} | ||
if (sum != SUM_DEFAULT_VALUE) { | ||
return triplets.stream() | ||
.filter(t -> t.calculateSum() == sum) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
return triplets; | ||
} | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(a, b, c); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj instanceof PythagoreanTriplet other) { | ||
return this.hashCode() == other.hashCode(); | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters