Skip to content

Commit 3120f4f

Browse files
Compile starter source with tests (exercism#2347)
* Add Gradle task to compile tests against the starter source * Check compilation of tests + starter source in CI * Fix stub implementation for `need-for-speed` * Fix stub implementation for `binary-search` * Fix stub implementation for `custom-set` * Fix stub implementation for `perfect-numbers` * Add missing import for @ignore in `pov` * Fix stub implementation for `prime-factors` * Fix stub implementation for `pythagorean-triplet` * Fix stub implementation for `rail-fence-cipher` * Fix stub implementation for `rational-numbers` * Fix stub implementation for `robot-simulator` * Fix stub implementation for `roman-numerals` * Fix stub implementation for `zipper`
1 parent 34711d7 commit 3120f4f

15 files changed

Lines changed: 98 additions & 48 deletions

File tree

.github/workflows/gradle.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ jobs:
1818
distribution: "temurin"
1919
- name: Grant execute permission for gradlew
2020
run: chmod +x gradlew
21-
- name: Compile and checkstyle with Gradle
22-
run: cd exercises && ../gradlew check compileStarterSourceJava --exclude-task test --continue
21+
- name: Check if tests compile cleanly with starter sources
22+
working-directory: exercises
23+
run: ../gradlew compileStarterTestJava --continue
24+
- name: Run checkstyle
25+
working-directory: exercises
26+
run: ../gradlew check --exclude-task test --continue
2327

2428
test:
2529
runs-on: ubuntu-latest
@@ -33,5 +37,6 @@ jobs:
3337
distribution: "temurin"
3438
- name: Grant execute permission for gradlew
3539
run: chmod +x gradlew
36-
- name: Test all exercises with Gradle
37-
run: cd exercises && ../gradlew test --continue
40+
- name: Test all reference implementations with Gradle
41+
working-directory: exercises
42+
run: ../gradlew test --continue

exercises/build.gradle

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ subprojects {
3131
// skip project named 'concept' or 'practice'
3232
// they are only folders containing exercises
3333
if(project.name == 'concept' || project.name == 'practice')
34-
return;
34+
return
3535

3636
sourceSets {
3737
// Set the directory containing the reference solution as the default source set. Default
@@ -40,27 +40,37 @@ subprojects {
4040
java.srcDirs = [".meta/src/reference/java"]
4141
}
4242

43+
// Set the directory containing the @Ignore-stripped tests as the default test source set.
44+
// Default test tasks will now run against this source set.
45+
test {
46+
java.srcDirs = [generatedTestSourceDir]
47+
}
48+
4349
// Define a custom source set named "starterSource" that points to the starter implementations
4450
// delivered to users. We can then use the generated "compileStarterSourceJava" task to verify
4551
// that the starter source compiles as-is.
4652
starterSource {
4753
java.srcDirs = ["src/main/java"]
4854
}
4955

50-
// Set the directory containing the @Ignore-stripped tests as the default test source set.
51-
// Default test tasks will now run against this source set.
52-
test {
53-
java.srcDirs = [generatedTestSourceDir]
56+
// Define a custom source set named "starterTest" that points to the tests delivered to users.
57+
// We can then use the generated "compileStarterTestJava" task to verify that the tests compile
58+
// cleanly against the starter source.
59+
starterTest {
60+
java.srcDirs = ["src/test/java"]
61+
compileClasspath += starterSource.runtimeClasspath
5462
}
5563

5664
// Log the source paths associated with each source set to verify they are what we expect.
57-
logCompileTaskSourcePath(project, "compileJava") // Corresponds to the "main" source set.
58-
logCompileTaskSourcePath(project, "compileStarterSourceJava")
65+
logCompileTaskSourcePath(project, "compileJava")
5966
logCompileTaskSourcePath(project, "compileTestJava")
67+
logCompileTaskSourcePath(project, "compileStarterSourceJava")
68+
logCompileTaskSourcePath(project, "compileStarterTestJava")
6069
}
6170

6271
configurations {
6372
starterSourceImplementation.extendsFrom implementation
73+
starterTestImplementation.extendsFrom testImplementation
6474
}
6575

6676
// configuration of the linter

exercises/concept/need-for-speed/src/main/java/NeedForSpeed.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
class NeedForSpeed {
2-
// TODO: define the constructor for the 'NeedForSpeed' class
2+
NeedForSpeed(int speed, int batteryDrain) {
3+
throw new UnsupportedOperationException("Please implement the NeedForSpeed constructor");
4+
}
35

46
public boolean batteryDrained() {
57
throw new UnsupportedOperationException("Please implement the NeedForSpeed.batteryDrained() method");
@@ -19,7 +21,9 @@ public static NeedForSpeed nitro() {
1921
}
2022

2123
class RaceTrack {
22-
// TODO: define the constructor for the 'RaceTrack' class
24+
RaceTrack(int distance) {
25+
throw new UnsupportedOperationException("Please implement the RaceTrack constructor");
26+
}
2327

2428
public boolean tryFinishTrack(NeedForSpeed car) {
2529
throw new UnsupportedOperationException("Please implement the RaceTrack.tryFinishTrack() method");
Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
1+
import java.util.List;
12

23
class BinarySearch {
3-
4-
int search(int a, int [] arr){
5-
throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
6-
}
7-
8-
int search(float a, float [] arr){
9-
throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
4+
BinarySearch(List<Integer> items) {
5+
throw new UnsupportedOperationException("Please implement the BinarySearch constructor");
106
}
117

12-
int search(double a, double [] arr){
13-
throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
8+
int indexOf(int item) throws ValueNotFoundException {
9+
throw new UnsupportedOperationException("Please implement the indexOf method");
1410
}
15-
16-
int search(long a,long [] arr){
17-
throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
18-
}
19-
2011
}

exercises/practice/binary-search/src/main/java/ValueNotFoundException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class ValueNotFoundException extends Exception {
1+
public class ValueNotFoundException extends Exception {
22

33
ValueNotFoundException(String message) {
44
super(message);

exercises/practice/custom-set/src/main/java/CustomSet.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import java.util.Collection;
22

33
class CustomSet<T> {
4-
54
CustomSet() {
65
throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
76
}
@@ -43,4 +42,7 @@ CustomSet<T> getDifference(CustomSet<T> other) {
4342
throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
4443
}
4544

45+
boolean isSubset(CustomSet<T> other) {
46+
throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
47+
}
4648
}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
public class NaturalNumber {
1+
class NaturalNumber {
2+
NaturalNumber(int number) {
3+
throw new UnsupportedOperationException("Delete this statement and write your own implementation");
4+
}
25

3-
public Classification getClassification() {
6+
Classification getClassification() {
47
throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
58
}
69
}

exercises/practice/pov/src/test/java/PovTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import java.util.List;
55

6+
import org.junit.Ignore;
67
import org.junit.Test;
78

89
public class PovTest {

exercises/practice/prime-factors/src/main/java/PrimeFactorsCalculator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class PrimeFactorsCalculator {
44

5-
List<Integer> calculatePrimeFactorsOf(int number) {
5+
List<Long> calculatePrimeFactorsOf(long number) {
66
throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
77
}
88

exercises/practice/pythagorean-triplet/src/main/java/PythagoreanTriplet.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ class PythagoreanTriplet {
66
throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
77
}
88

9-
TripletListBuilder makeTripletsList() {
9+
static TripletListBuilder makeTripletsList() {
1010
throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
1111
}
1212

13-
class TripletListBuilder {
13+
static class TripletListBuilder {
1414

1515
TripletListBuilder thatSumTo(int sum) {
1616
throw new UnsupportedOperationException("Delete this statement and write your own implementation.");

0 commit comments

Comments
 (0)