diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index c79cf9556..d685332f3 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -7,33 +7,31 @@ on: [push, pull_request, workflow_dispatch] jobs: build: - runs-on: ubuntu-latest steps: - - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 - - name: Set up JDK 1.17 - uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 - with: - java-version: 17 - distribution: 'temurin' - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - name: Compile and checkstyle with Gradle - run: cd exercises && ../gradlew check compileStarterSourceJava --parallel --continue --info + - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 + - name: Set up JDK 1.17 + uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 + with: + java-version: 17 + distribution: "temurin" + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Compile and checkstyle with Gradle + run: cd exercises && ../gradlew check compileStarterSourceJava --exclude-task test --continue test: - runs-on: ubuntu-latest steps: - - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 - - name: Set up JDK 1.17 - uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 - with: - java-version: 17 - distribution: 'temurin' - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - name: Journey test - run: bin/journey-test.sh + - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 + - name: Set up JDK 1.17 + uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 + with: + java-version: 17 + distribution: "temurin" + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Test all exercises with Gradle + run: cd exercises && ../gradlew test --continue diff --git a/exercises/build.gradle b/exercises/build.gradle index 4bec7f0c7..0a019cfab 100644 --- a/exercises/build.gradle +++ b/exercises/build.gradle @@ -73,11 +73,15 @@ subprojects { // When running the standard test task, make sure we prepopulate the test source set with the // @Ignore-stripped tests. - test.dependsOn(copyTestsFilteringIgnores) - } - - + compileTestJava.dependsOn(copyTestsFilteringIgnores) + // Enable test logging when running test task from the console + test { + testLogging { + events "passed", "skipped", "failed" + } + } + } } def logCompileTaskSourcePath(Project project, String taskName) { diff --git a/exercises/concept/calculator-conundrum/.meta/src/reference/java/IllegalOperationException.java b/exercises/concept/calculator-conundrum/.meta/src/reference/java/IllegalOperationException.java new file mode 120000 index 000000000..cb8ab2932 --- /dev/null +++ b/exercises/concept/calculator-conundrum/.meta/src/reference/java/IllegalOperationException.java @@ -0,0 +1 @@ +../../../../src/main/java/IllegalOperationException.java \ No newline at end of file diff --git a/exercises/concept/calculator-conundrum/.meta/src/reference/java/SimpleOperation.java b/exercises/concept/calculator-conundrum/.meta/src/reference/java/SimpleOperation.java new file mode 120000 index 000000000..3392fc8a4 --- /dev/null +++ b/exercises/concept/calculator-conundrum/.meta/src/reference/java/SimpleOperation.java @@ -0,0 +1 @@ +../../../../src/main/java/SimpleOperation.java \ No newline at end of file diff --git a/exercises/concept/calculator-conundrum/src/main/java/SimpleOperation.java b/exercises/concept/calculator-conundrum/src/main/java/SimpleOperation.java index 86d881908..d408f064f 100644 --- a/exercises/concept/calculator-conundrum/src/main/java/SimpleOperation.java +++ b/exercises/concept/calculator-conundrum/src/main/java/SimpleOperation.java @@ -1,16 +1,13 @@ class SimpleOperation { - public static int division(int operand1, int operand2) - { + public static int division(int operand1, int operand2) { return operand1 / operand2; } - public static int multiplication(int operand1, int operand2) - { + public static int multiplication(int operand1, int operand2) { return operand1 * operand2; } - public static int addition(int operand1, int operand2) - { + public static int addition(int operand1, int operand2) { return operand1 + operand2; } } diff --git a/exercises/concept/remote-control-competition/.meta/src/reference/java/ProductionRemoteControlCar.java b/exercises/concept/remote-control-competition/.meta/src/reference/java/ProductionRemoteControlCar.java index e0c8e1b7a..b84aff013 100644 --- a/exercises/concept/remote-control-competition/.meta/src/reference/java/ProductionRemoteControlCar.java +++ b/exercises/concept/remote-control-competition/.meta/src/reference/java/ProductionRemoteControlCar.java @@ -4,7 +4,7 @@ class ProductionRemoteControlCar implements RemoteControlCar, Comparable 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 build() { - List 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; + } } diff --git a/exercises/practice/sgf-parsing/.meta/src/reference/java/SgfParsing.java b/exercises/practice/sgf-parsing/.meta/src/reference/java/SgfParsing.java index 304019c2e..94422d3e7 100644 --- a/exercises/practice/sgf-parsing/.meta/src/reference/java/SgfParsing.java +++ b/exercises/practice/sgf-parsing/.meta/src/reference/java/SgfParsing.java @@ -107,9 +107,6 @@ private int appendCharToBuffer(String input, int index, StringBuilder buffer) { while (character == '\\') { character = input.charAt(++index); } - if (character == '\t') { - character = ' '; - } buffer.append(character); return index; } diff --git a/exercises/settings.gradle b/exercises/settings.gradle index 927fe083a..ba35d31a4 100644 --- a/exercises/settings.gradle +++ b/exercises/settings.gradle @@ -15,6 +15,7 @@ include 'concept:salary-calculator' include 'concept:remote-control-competition' include 'concept:football-match-reports' include 'concept:wizards-and-warriors' +include 'concept:calculator-conundrum' // practice exercises include 'practice:accumulate'