Skip to content

Commit e9e9c2d

Browse files
Fix CI silently not running exercise tests (exercism#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
1 parent 1cae702 commit e9e9c2d

10 files changed

Lines changed: 75 additions & 121 deletions

File tree

.github/workflows/gradle.yml

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,31 @@ on: [push, pull_request, workflow_dispatch]
77

88
jobs:
99
build:
10-
1110
runs-on: ubuntu-latest
1211

1312
steps:
14-
- uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3
15-
- name: Set up JDK 1.17
16-
uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2
17-
with:
18-
java-version: 17
19-
distribution: 'temurin'
20-
- name: Grant execute permission for gradlew
21-
run: chmod +x gradlew
22-
- name: Compile and checkstyle with Gradle
23-
run: cd exercises && ../gradlew check compileStarterSourceJava --parallel --continue --info
13+
- uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3
14+
- name: Set up JDK 1.17
15+
uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2
16+
with:
17+
java-version: 17
18+
distribution: "temurin"
19+
- name: Grant execute permission for gradlew
20+
run: chmod +x gradlew
21+
- name: Compile and checkstyle with Gradle
22+
run: cd exercises && ../gradlew check compileStarterSourceJava --exclude-task test --continue
2423

2524
test:
26-
2725
runs-on: ubuntu-latest
2826

2927
steps:
30-
- uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3
31-
- name: Set up JDK 1.17
32-
uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2
33-
with:
34-
java-version: 17
35-
distribution: 'temurin'
36-
- name: Grant execute permission for gradlew
37-
run: chmod +x gradlew
38-
- name: Journey test
39-
run: bin/journey-test.sh
28+
- uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3
29+
- name: Set up JDK 1.17
30+
uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2
31+
with:
32+
java-version: 17
33+
distribution: "temurin"
34+
- name: Grant execute permission for gradlew
35+
run: chmod +x gradlew
36+
- name: Test all exercises with Gradle
37+
run: cd exercises && ../gradlew test --continue

exercises/build.gradle

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,15 @@ subprojects {
7373

7474
// When running the standard test task, make sure we prepopulate the test source set with the
7575
// @Ignore-stripped tests.
76-
test.dependsOn(copyTestsFilteringIgnores)
77-
}
78-
79-
76+
compileTestJava.dependsOn(copyTestsFilteringIgnores)
8077

78+
// Enable test logging when running test task from the console
79+
test {
80+
testLogging {
81+
events "passed", "skipped", "failed"
82+
}
83+
}
84+
}
8185
}
8286

8387
def logCompileTaskSourcePath(Project project, String taskName) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../src/main/java/IllegalOperationException.java
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../src/main/java/SimpleOperation.java

exercises/concept/calculator-conundrum/src/main/java/SimpleOperation.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
class SimpleOperation {
2-
public static int division(int operand1, int operand2)
3-
{
2+
public static int division(int operand1, int operand2) {
43
return operand1 / operand2;
54
}
65

7-
public static int multiplication(int operand1, int operand2)
8-
{
6+
public static int multiplication(int operand1, int operand2) {
97
return operand1 * operand2;
108
}
119

12-
public static int addition(int operand1, int operand2)
13-
{
10+
public static int addition(int operand1, int operand2) {
1411
return operand1 + operand2;
1512
}
1613
}

exercises/concept/remote-control-competition/.meta/src/reference/java/ProductionRemoteControlCar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class ProductionRemoteControlCar implements RemoteControlCar, Comparable<Product
44
private int numberOfVictories;
55

66
public int compareTo(ProductionRemoteControlCar other) {
7-
return Integer.compare(this.getNumberOfVictories(), other.getNumberOfVictories());
7+
return Integer.compare(other.getNumberOfVictories(), this.getNumberOfVictories());
88
}
99

1010
public void drive() {

exercises/concept/wizards-and-warriors/.meta/src/reference/java/Fighter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ class Wizard extends Fighter {
3434

3535
boolean isSpellPrepared = false;
3636

37+
@Override
38+
public String toString() {
39+
return "Fighter is a Wizard";
40+
}
41+
3742
@Override
3843
boolean isVulnerable() {
3944
if (isSpellPrepared == false) {
Lines changed: 35 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,67 @@
1-
21
import java.util.ArrayList;
32
import java.util.List;
43
import java.util.Objects;
5-
import java.util.stream.Collectors;
64

75
public class PythagoreanTriplet {
86

9-
private int a;
10-
private int b;
11-
private int c;
7+
private final int a;
8+
private final int b;
9+
private final int c;
1210

1311
public PythagoreanTriplet(final int a, final int b, final int c) {
1412
this.a = a;
1513
this.b = b;
1614
this.c = c;
1715
}
1816

19-
public static TripletListBuilder makeTripletsList() {
20-
return new TripletListBuilder();
21-
}
22-
23-
public int calculateSum() {
24-
return this.a + this.b + this.c;
25-
}
26-
27-
public long calculateProduct() {
28-
return this.a * this.b * this.c;
29-
}
30-
31-
public boolean isPythagorean() {
32-
return this.a * this.a + this.b * this.b == this.c * this.c;
33-
}
34-
35-
@Override
36-
public int hashCode() {
37-
return Objects.hash(a, b, c);
38-
}
39-
40-
@Override
41-
public boolean equals(Object obj) {
42-
if (this == obj) {
43-
return true;
44-
}
45-
if (obj == null) {
46-
return false;
47-
}
48-
if (getClass() != obj.getClass()) {
49-
return false;
50-
}
51-
final PythagoreanTriplet other = (PythagoreanTriplet) obj;
52-
if (this.a != other.a) {
53-
return false;
54-
}
55-
if (this.b != other.b) {
56-
return false;
57-
}
58-
if (this.c != other.c) {
59-
return false;
60-
}
61-
return true;
17+
public static PythagoreanTripletBuilder makeTripletsList() {
18+
return new PythagoreanTripletBuilder();
6219
}
6320

64-
public static class TripletListBuilder {
65-
66-
private static final int MAX_FACTOR_DEFAULT_VALUE = 0;
67-
private static final int SUM_DEFAULT_VALUE = -1;
68-
69-
private int maxFactor = MAX_FACTOR_DEFAULT_VALUE;
70-
private int minFactor = 1;
71-
private int sum = SUM_DEFAULT_VALUE;
21+
public static class PythagoreanTripletBuilder {
22+
private final List<PythagoreanTriplet> triplets = new ArrayList<>();
23+
private int limit = 0;
24+
private int sum = 0;
7225

73-
public TripletListBuilder() {
74-
}
75-
76-
public TripletListBuilder withFactorsLessThanOrEqualTo(
77-
final int maxFactor) {
78-
this.maxFactor = maxFactor;
26+
public PythagoreanTripletBuilder withFactorsLessThanOrEqualTo(int limit) {
27+
this.limit = limit;
7928
return this;
8029
}
8130

82-
public TripletListBuilder withFactorsGreaterThanOrEqualTo(
83-
final int minFactor) {
84-
this.minFactor = minFactor;
85-
return this;
86-
}
87-
88-
public TripletListBuilder thatSumTo(final int sum) {
31+
public PythagoreanTripletBuilder thatSumTo(int sum) {
8932
this.sum = sum;
9033
return this;
9134
}
9235

9336
public List<PythagoreanTriplet> build() {
94-
List<PythagoreanTriplet> triplets = new ArrayList<>();
95-
if (this.maxFactor == MAX_FACTOR_DEFAULT_VALUE) {
96-
return triplets;
37+
if (limit == 0) {
38+
limit = sum / 2;
9739
}
98-
double sqrt;
99-
int floor;
100-
for (int n = minFactor; n < maxFactor; n++) {
101-
for (int m = n + 1; m < maxFactor; m++) {
102-
sqrt = Math.sqrt(n * n + m * m);
103-
floor = (int) Math.floor(sqrt);
104-
if (sqrt == floor) {
105-
triplets.add(new PythagoreanTriplet(n, m, floor));
40+
int start = (int) Math.sqrt(sum);
41+
for (int a = start; a <= limit; a++) {
42+
for (int b = a; b <= limit; b++) {
43+
double c = Math.sqrt(a * a + b * b);
44+
if (c % 1 == 0 && c <= limit && a + b + c == sum) {
45+
triplets.add(new PythagoreanTriplet(a, b, (int) c));
10646
}
10747
}
10848
}
109-
if (sum != SUM_DEFAULT_VALUE) {
110-
return triplets.stream()
111-
.filter(t -> t.calculateSum() == sum)
112-
.collect(Collectors.toList());
113-
}
49+
11450
return triplets;
11551
}
11652
}
53+
54+
@Override
55+
public int hashCode() {
56+
return Objects.hash(a, b, c);
57+
}
58+
59+
@Override
60+
public boolean equals(Object obj) {
61+
if (obj instanceof PythagoreanTriplet other) {
62+
return this.hashCode() == other.hashCode();
63+
}
64+
65+
return false;
66+
}
11767
}

exercises/practice/sgf-parsing/.meta/src/reference/java/SgfParsing.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,6 @@ private int appendCharToBuffer(String input, int index, StringBuilder buffer) {
107107
while (character == '\\') {
108108
character = input.charAt(++index);
109109
}
110-
if (character == '\t') {
111-
character = ' ';
112-
}
113110
buffer.append(character);
114111
return index;
115112
}

exercises/settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ include 'concept:salary-calculator'
1515
include 'concept:remote-control-competition'
1616
include 'concept:football-match-reports'
1717
include 'concept:wizards-and-warriors'
18+
include 'concept:calculator-conundrum'
1819

1920
// practice exercises
2021
include 'practice:accumulate'

0 commit comments

Comments
 (0)