diff --git a/.github/workflows/pull-m4.yml b/.github/workflows/pull-m4.yml index 13e3e8b0d7..4a4c9e04e9 100644 --- a/.github/workflows/pull-m4.yml +++ b/.github/workflows/pull-m4.yml @@ -43,7 +43,7 @@ jobs: - name: Set up Maven uses: stCarolas/setup-maven@v5 with: - maven-version: 4.0.0-alpha-13 + maven-version: 4.0.0-beta-3 - name: Build with Maven run: mvn verify -Prun-its -e -B -V --no-transfer-progress diff --git a/.github/workflows/push-issue-m4.yml b/.github/workflows/push-issue-m4.yml index cfb76b4da4..6e427a8924 100644 --- a/.github/workflows/push-issue-m4.yml +++ b/.github/workflows/push-issue-m4.yml @@ -39,6 +39,6 @@ jobs: - name: Set up Maven uses: stCarolas/setup-maven@v5 with: - maven-version: 4.0.0-alpha-13 + maven-version: 4.0.0-beta-3 - name: "Building with Maven." run: mvn verify -e -B -V --no-transfer-progress diff --git a/itf-documentation/src/main/asciidoc/release-notes/_release-notes-0.14.0.adoc b/itf-documentation/src/main/asciidoc/release-notes/_release-notes-0.14.0.adoc index de70bd067f..b682d3ffc1 100644 --- a/itf-documentation/src/main/asciidoc/release-notes/_release-notes-0.14.0.adoc +++ b/itf-documentation/src/main/asciidoc/release-notes/_release-notes-0.14.0.adoc @@ -41,6 +41,7 @@ :issue-468: https://github.com/khmarbaise/maven-it-extension/issues/468[Fixed #468] :issue-474: https://github.com/khmarbaise/maven-it-extension/issues/474[Fixed #474] :issue-477: https://github.com/khmarbaise/maven-it-extension/issues/477[Fixed #477] +:issue-479: https://github.com/khmarbaise/maven-it-extension/issues/479[Fixed #479] :issue-481: https://github.com/khmarbaise/maven-it-extension/issues/481[Fixed #481] :issue-483: https://github.com/khmarbaise/maven-it-extension/issues/483[Fixed #483] :pr-460: https://github.com/khmarbaise/maven-it-extension/pull/460[Pull request #460] @@ -52,6 +53,8 @@ *Details* + * {issue-479} - The .mvn directory is not copied + - written IT's to prove it's working correct. * {issue-???} - ? diff --git a/itf-examples/src/test/java/com/soebes/itf/examples/MvnDirectoryIT.java b/itf-examples/src/test/java/com/soebes/itf/examples/MvnDirectoryIT.java new file mode 100644 index 0000000000..ee7fae84d0 --- /dev/null +++ b/itf-examples/src/test/java/com/soebes/itf/examples/MvnDirectoryIT.java @@ -0,0 +1,78 @@ +package com.soebes.itf.examples; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import com.soebes.itf.jupiter.extension.MavenCLIOptions; +import com.soebes.itf.jupiter.extension.MavenJupiterExtension; +import com.soebes.itf.jupiter.extension.MavenOption; +import com.soebes.itf.jupiter.extension.MavenTest; +import com.soebes.itf.jupiter.maven.MavenExecutionResult; + +import static com.soebes.itf.extension.assertj.MavenITAssertions.assertThat; + +@MavenJupiterExtension +@MavenOption(MavenCLIOptions.NO_TRANSFER_PROGRESS) +@MavenOption(MavenCLIOptions.BATCH_MODE) +class MvnDirectoryIT { + + @MavenTest + void non_hidden_files(MavenExecutionResult result) { + assertThat(result) + .isSuccessful() + .out() + .info() + .containsSubsequence( + "Scanning for projects...", + // This means .mvn/maven.config with -T 2 option has been read. + "Using the MultiThreadedBuilder implementation with a thread count of 2", + "--- enforcer:3.5.0:enforce (enforce-maven) @ kata-fraction ---", + "--- jacoco:0.8.12:prepare-agent (default) @ kata-fraction ---", + "--- resources:3.3.1:resources (default-resources) @ kata-fraction ---", + "--- compiler:3.13.0:compile (default-compile) @ kata-fraction ---", + "Tests run: 34, Failures: 0, Errors: 0, Skipped: 0" + ); + assertThat(result) + .isSuccessful() + .out() + .warn().isEmpty(); + } + + @MavenTest + void hidden_files_only(MavenExecutionResult result) { + assertThat(result) + .isSuccessful() + .out() + .info() + .doesNotContain("Using the MultiThreadedBuilder implementation with a thread count of 2") + .containsSubsequence( + "Scanning for projects...", + "--- enforcer:3.5.0:enforce (enforce-maven) @ kata-fraction ---", + "--- jacoco:0.8.12:prepare-agent (default) @ kata-fraction ---", + "--- resources:3.3.1:resources (default-resources) @ kata-fraction ---", + "--- compiler:3.13.0:compile (default-compile) @ kata-fraction ---", + "Tests run: 34, Failures: 0, Errors: 0, Skipped: 0" + ); + assertThat(result) + .isSuccessful() + .out() + .warn().isEmpty(); + } + +} diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/AnnotationOnClassAndInheritedIT/NestedClass/SecondLevel/ThirdLevel/on_third_level_nested_class_level/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/AnnotationOnClassAndInheritedIT/NestedClass/SecondLevel/ThirdLevel/on_third_level_nested_class_level/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/AnnotationOnClassAndInheritedIT/NestedClass/SecondLevel/on_second_level_nested_class_level/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/AnnotationOnClassAndInheritedIT/NestedClass/SecondLevel/on_second_level_nested_class_level/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/AnnotationOnClassAndInheritedIT/NestedClass/on_nested_class_level/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/AnnotationOnClassAndInheritedIT/NestedClass/on_nested_class_level/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/AnnotationOnClassAndInheritedIT/on_class_level/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/AnnotationOnClassAndInheritedIT/on_class_level/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/AnnotationOnClassAndInheritedIT/on_method_level/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/AnnotationOnClassAndInheritedIT/on_method_level/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/EARIT/basic/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/EARIT/basic/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/EARIT/packaging_excludes/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/EARIT/packaging_excludes/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/EARIT/packaging_includes/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/EARIT/packaging_includes/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/EARIT/resource_custom_directory/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/EARIT/resource_custom_directory/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/EARIT/skinny_wars_javaee5/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/EARIT/skinny_wars_javaee5/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/EARIT/transitive_excludes/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/EARIT/transitive_excludes/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/ITWithBeforeEachIT/beforeEach/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/ITWithBeforeEachIT/beforeEach/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/ITWithBeforeEachIT/the_first_test_case/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/ITWithBeforeEachIT/the_first_test_case/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/ITWithBeforeEachMavenIT/the_first_test_case/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/ITWithBeforeEachMavenIT/the_first_test_case/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/LogoutputIT/basic/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/LogoutputIT/basic/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/LogoutputIT/basic_windows/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/LogoutputIT/basic_windows/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/MavenIntegrationExampleNestedGlobalRepoIT/NestedExample/basic/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/MavenIntegrationExampleNestedGlobalRepoIT/NestedExample/basic/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/MavenIntegrationExampleNestedGlobalRepoIT/NestedExample/packaging_includes/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/MavenIntegrationExampleNestedGlobalRepoIT/NestedExample/packaging_includes/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/MavenIntegrationExampleNestedGlobalRepoIT/packaging_includes/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/MavenIntegrationExampleNestedGlobalRepoIT/packaging_includes/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/MavenIntegrationExampleNestedIT/NestedExample/basic/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/MavenIntegrationExampleNestedIT/NestedExample/basic/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/MavenIntegrationExampleNestedIT/NestedExample/packaging_includes/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/MavenIntegrationExampleNestedIT/NestedExample/packaging_includes/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/MavenIntegrationExampleNestedIT/packaging_includes/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/MavenIntegrationExampleNestedIT/packaging_includes/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/MavenIntegrationExampleNestedWithoutNoneNestedTestGlobalRepoIT/NestedExample/basic/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/MavenIntegrationExampleNestedWithoutNoneNestedTestGlobalRepoIT/NestedExample/basic/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/MavenIntegrationExampleNestedWithoutNoneNestedTestGlobalRepoIT/NestedExample/packaging_includes/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/MavenIntegrationExampleNestedWithoutNoneNestedTestGlobalRepoIT/NestedExample/packaging_includes/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/MavenIntegrationIT/first_integration_test/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/MavenIntegrationIT/first_integration_test/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/MavenIntegrationIT/setup/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/MavenIntegrationIT/setup/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/MavenIntegrationIT/setup_2/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/MavenIntegrationIT/setup_2/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/MavenProjectIT/NestedExample/test_project/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/MavenProjectIT/NestedExample/test_project/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/MavenProjectIT/packaging_includes/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/MavenProjectIT/packaging_includes/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/MavenProjectResultIT/basic/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/MavenProjectResultIT/basic/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/MavenProjectRootIT/test_project_root/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/MavenProjectRootIT/test_project_root/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/MvnDirectoryIT/hidden_files_only/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/MvnDirectoryIT/hidden_files_only/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/MvnDirectoryIT/hidden_files_only/pom.xml b/itf-examples/src/test/resources-its/com/soebes/itf/examples/MvnDirectoryIT/hidden_files_only/pom.xml new file mode 100644 index 0000000000..42a5ecfdc6 --- /dev/null +++ b/itf-examples/src/test/resources-its/com/soebes/itf/examples/MvnDirectoryIT/hidden_files_only/pom.xml @@ -0,0 +1,111 @@ + + + + + + + 4.0.0 + + + com.soebes.smpp + smpp + 7.0.0 + + + + com.soebes.katas + kata-fraction + 1.0-SNAPSHOT + + + kata-fraction + 8 + + + + + org.junit + junit-bom + 5.10.1 + import + pom + + + nl.jqno.equalsverifier + equalsverifier + 3.15.5 + + + org.assertj + assertj-core + 3.25.0 + + + org.apiguardian + apiguardian-api + 1.1.2 + + + + + + org.apiguardian + apiguardian-api + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.jupiter + junit-jupiter-params + test + + + nl.jqno.equalsverifier + equalsverifier + test + + + org.assertj + assertj-core + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + -Xlint:-options + + + + + + + diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/MvnDirectoryIT/hidden_files_only/src/main/java/com/soebes/kata/fraction/Fraction.java b/itf-examples/src/test/resources-its/com/soebes/itf/examples/MvnDirectoryIT/hidden_files_only/src/main/java/com/soebes/kata/fraction/Fraction.java new file mode 100644 index 0000000000..040bbab4d6 --- /dev/null +++ b/itf-examples/src/test/resources-its/com/soebes/itf/examples/MvnDirectoryIT/hidden_files_only/src/main/java/com/soebes/kata/fraction/Fraction.java @@ -0,0 +1,137 @@ +package com.soebes.kata.fraction; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apiguardian.api.API; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.Objects; +import java.util.StringJoiner; + +import static org.apiguardian.api.API.Status.EXPERIMENTAL; + +/** + * @author Karl Heinz Marbaise + */ +@API(status = EXPERIMENTAL) +public class Fraction implements Comparable { + private final int numerator; + private final int denominator; + + public Fraction(int numerator, int denominator) { + if (denominator == 0) { + throw new IllegalArgumentException("denominator is not allowed to be zero."); + } + int sign = Integer.signum(numerator) * Integer.signum(denominator); + + int gcd = MathUtil.calculateGcd(numerator, denominator); + this.numerator = sign * Math.abs(numerator) / gcd; + this.denominator = Math.abs(denominator) / gcd; + } + + public Fraction plus(Fraction add) { + if (this.denominator == add.denominator) { + return new Fraction(add.numerator + this.numerator, this.denominator); + } else { + return new Fraction(add.numerator * this.denominator + this.numerator * add.denominator, add.denominator * this.denominator); + } + } + + public Fraction subtract(Fraction subtrahend) { + if (this.denominator == subtrahend.denominator) { + return new Fraction(this.numerator - subtrahend.numerator, this.denominator); + } else { + return new Fraction(this.numerator * subtrahend.denominator - this.denominator * subtrahend.numerator, subtrahend.denominator * this.denominator); + } + } + + public Fraction multiply(Fraction factor) { + return new Fraction(this.numerator * factor.numerator, this.denominator * factor.denominator); + } + + public Fraction divide(Fraction divisor) { + return new Fraction(this.numerator * divisor.denominator, this.denominator * divisor.numerator); + } + + public Fraction pow(int power) { + return new Fraction(BigInteger.valueOf(this.numerator).pow(power).intValueExact(), BigInteger.valueOf(this.denominator).pow(power).intValueExact()); + } + + public int numerator() { + return numerator; + } + + public int denominator() { + return denominator; + } + + @Override + public int compareTo(Fraction compareTo) { + if (compareTo == null) { + throw new NullPointerException("compareTo is not allowed to be null."); + } + return this.subtract(compareTo).signum(); + } + + /** + * Returns the signum function of this {@code Fraction}. + * + * @return -1, 0, or 1 as the value of this {@code Fraction} + * is negative, zero, or positive. + */ + public int signum() { + return Integer.signum(numerator); + } + + public Fraction negate() { + return new Fraction(Math.negateExact(this.numerator), this.denominator); + } + + public double doubleValue() { + return (double) this.numerator / (double) this.denominator; + } + + public BigDecimal bigDecimalValue() { + return BigDecimal.valueOf(this.numerator).divide(BigDecimal.valueOf(this.denominator)); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Fraction fraction = (Fraction) o; + return numerator == fraction.numerator && + denominator == fraction.denominator; + } + + @Override + public int hashCode() { + return Objects.hash(numerator, denominator); + } + + @Override + public String toString() { + return new StringJoiner(", ", Fraction.class.getSimpleName() + "[", "]") + .add("numerator=" + numerator) + .add("denominator=" + denominator) + .toString(); + } +} diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/MvnDirectoryIT/hidden_files_only/src/main/java/com/soebes/kata/fraction/MathUtil.java b/itf-examples/src/test/resources-its/com/soebes/itf/examples/MvnDirectoryIT/hidden_files_only/src/main/java/com/soebes/kata/fraction/MathUtil.java new file mode 100644 index 0000000000..25627496bb --- /dev/null +++ b/itf-examples/src/test/resources-its/com/soebes/itf/examples/MvnDirectoryIT/hidden_files_only/src/main/java/com/soebes/kata/fraction/MathUtil.java @@ -0,0 +1,59 @@ +package com.soebes.kata.fraction; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.math.BigInteger; + +/** + * @author Karl Heinz Marbaise + */ +class MathUtil { + + private MathUtil() { + // intentionally empty. + } + + /** + * @param numerator Numerator + * @param denominator Denominator + * @return greatest common divisor. + */ + static int calculateGcd(int numerator, int denominator) { + return BigInteger.valueOf(numerator).gcd(BigInteger.valueOf(denominator)).intValueExact(); + } + + /** + * @param numerator Numerator + * @param denominator Denominator + * @return greatest common divisor. + */ + static long calculateGcd(long numerator, long denominator) { + return BigInteger.valueOf(numerator).gcd(BigInteger.valueOf(denominator)).longValueExact(); + } + + /** + * @param numerator Numerator + * @param denominator Denominator + * @return greatest common divisor. + */ + static BigInteger calculateGcd(BigInteger numerator, BigInteger denominator) { + return numerator.gcd(denominator); + } +} diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/MvnDirectoryIT/hidden_files_only/src/test/java/com/soebes/kata/fraction/FractionTest.java b/itf-examples/src/test/resources-its/com/soebes/itf/examples/MvnDirectoryIT/hidden_files_only/src/test/java/com/soebes/kata/fraction/FractionTest.java new file mode 100644 index 0000000000..e11ee4b664 --- /dev/null +++ b/itf-examples/src/test/resources-its/com/soebes/itf/examples/MvnDirectoryIT/hidden_files_only/src/test/java/com/soebes/kata/fraction/FractionTest.java @@ -0,0 +1,377 @@ +package com.soebes.kata.fraction; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import nl.jqno.equalsverifier.EqualsVerifier; +import org.assertj.core.data.Offset; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import java.math.BigDecimal; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.assertj.core.api.Assertions.assertThatNullPointerException; + +/** + * Test for {@link Fraction}. + */ +class FractionTest { + + @Nested + class BigDecimalValue { + + @Test + void fraction_to_bigdecimal() { + Fraction fraction = new Fraction(1, 1); + assertThat(fraction.bigDecimalValue()).isEqualByComparingTo(BigDecimal.valueOf(1)); + } + } + + @Nested + class DoubleValue { + + @Test + void fraction_to_double() { + Fraction fraction = new Fraction(1, 1); + assertThat(fraction.doubleValue()).isEqualTo(1.0, Offset.offset(1E-6)); + } + } + + @Nested + class Negate { + + @Test + void fraction_negate() { + Fraction fraction = new Fraction(1, 1); + assertThat(fraction.negate()).isEqualByComparingTo(new Fraction(-1, 1)); + } + + @Test + void fraction_negate_max() { + Fraction fraction = new Fraction(Integer.MAX_VALUE, 1); + assertThat(fraction.negate()).isEqualByComparingTo(new Fraction(-Integer.MAX_VALUE, 1)); + } + + @Test + void fraction_negate_min() { + Fraction fraction = new Fraction(Integer.MIN_VALUE, 1); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(fraction::negate) + .withMessage("integer overflow"); + } + } + + @Nested + class Signum { + + @Test + void signum_for_z_pos_n_pos() { + Fraction fraction = new Fraction(1, 2); + assertThat(fraction.signum()).isOne(); + } + + @Test + void signum_for_z_neg_n_pos() { + Fraction fraction = new Fraction(-1, 2); + assertThat(fraction.signum()).isNegative(); + } + + @Test + void signum_for_z_pos_n_neg() { + Fraction fraction = new Fraction(1, -2); + assertThat(fraction.signum()).isNegative(); + } + + @Test + void signum_for_z_neg_n_neg() { + Fraction fraction = new Fraction(-1, -2); + assertThat(fraction.signum()).isPositive(); + } + } + + @Nested + class CompareTo { + + @Test + void fraction_one_identical_to_fraction_two() { + Fraction fractionOne = new Fraction(1, 2); + Fraction fractionTwo = new Fraction(1, 2); + + assertThat(fractionOne).isEqualByComparingTo(fractionTwo); + } + + @Test + void fraction_one_greater_than_fraction_two() { + Fraction fractionOne = new Fraction(1, 1); + Fraction fractionTwo = new Fraction(1, 2); + + assertThat(fractionOne).isGreaterThan(fractionTwo); + } + + @Test + void fraction_one_less_than_fraction_two() { + Fraction fractionOne = new Fraction(1, 3); + Fraction fractionTwo = new Fraction(1, 2); + + assertThat(fractionOne).isLessThan(fractionTwo); + } + + } + + @Nested + class Verification { + + @Test + void hash_code_and_equals() { + EqualsVerifier.forClass(Fraction.class).usingGetClass().verify(); + } + + @Test + void check_to_string() { + Fraction fraction = new Fraction(1, 2); + assertThat(fraction).hasToString("Fraction[numerator=1, denominator=2]"); + } + } + + @Nested + class InvalideValues { + + @Test + void denominator_is_not_allowed_to_be_zero() { + assertThatIllegalArgumentException().isThrownBy(() -> new Fraction(1, 0)) + .withMessage("denominator is not allowed to be zero."); + } + + @Test + void compare_to_null() { + assertThatNullPointerException().isThrownBy(() -> new Fraction(1, 2).compareTo(null)) + .withMessage("compareTo is not allowed to be null."); + } + } + + @Nested + class Normalizing { + + @Test + void normalize_0_x() { + Fraction fraction = new Fraction(0, 6); + + assertThat(fraction.numerator()).isZero(); + assertThat(fraction.denominator()).isEqualTo(1); + } + + @Test + void normalize_improper_fraction() { + Fraction improperFraction = new Fraction(4, 6); + assertThat(improperFraction.numerator()).isEqualTo(2); + assertThat(improperFraction.denominator()).isEqualTo(3); + } + } + + @Nested + class Multiplikation { + + @Test + void multiply_multiplier_by_multiplicand() { + Fraction multiplier = new Fraction(2, 3); + Fraction multiplicand = new Fraction(4, 5); + + Fraction produkt = multiplier.multiply(multiplicand); + + assertThat(produkt).isEqualTo(new Fraction(8, 15)); + } + } + + @Nested + class Divide { + + @Test + void divide_1_2_by_2_5() { + Fraction dividend = new Fraction(1, 2); + Fraction divisor = new Fraction(2, 5); + + Fraction quotient = dividend.divide(divisor); + + assertThat(quotient).isEqualTo(new Fraction(5, 4)); + } + + @Test + void divide_the_same_fraction() { + Fraction dividend = new Fraction(1, 2); + Fraction divisor = new Fraction(1, 2); + + Fraction quotient = dividend.divide(divisor); + + assertThat(quotient).isEqualTo(new Fraction(1, 1)); + } + } + + @Nested + class Subtraction { + + @Test + void subtract_first_minus_second() { + Fraction minuend = new Fraction(2, 3); + Fraction subtrahend = new Fraction(1, 5); + + Fraction difference = minuend.subtract(subtrahend); + + assertThat(difference).isEqualTo(new Fraction(7, 15)); + } + + @Test + void subtract_with_same_denominator() { + Fraction minuend = new Fraction(5, 9); + Fraction subtrahend = new Fraction(2, 9); + + Fraction difference = minuend.subtract(subtrahend); + + assertThat(difference).isEqualTo(new Fraction(3, 9)); + } + + @Test + void subtract_with_improper_faction_result() { + Fraction minuend = new Fraction(21, 7); + Fraction subtrahend = new Fraction(12, 7); + + Fraction difference = minuend.subtract(subtrahend); + + assertThat(difference).isEqualTo(new Fraction(9, 7)); + } + } + + @Nested + class Addition { + + @Test + void chaining_addition_with_improper_fraction_result() { + Fraction summand1 = new Fraction(1, 2); + Fraction summand2 = new Fraction(1, 3); + Fraction summand3 = new Fraction(1, 4); + + Fraction sum = summand1.plus(summand2).plus(summand3); + + assertThat(sum).isEqualTo(new Fraction(26, 24)); + } + + @Test + void chaining_addition_with_proper_fraction_result() { + Fraction summand1 = new Fraction(1, 2); + Fraction summand2 = new Fraction(1, 3); + Fraction summand3 = new Fraction(1, 4); + + Fraction sum = summand1.plus(summand2).plus(summand3); + + assertThat(sum).isEqualTo(new Fraction(13, 12)); + } + + @Test + void addition_with_two_proper_fractions() { + Fraction summand1 = new Fraction(2, 3); + Fraction summand2 = new Fraction(1, 5); + + Fraction sum = summand1.plus(summand2); + + assertThat(sum).isEqualTo(new Fraction(13, 15)); + } + + @Test + void add_1_3_plus_2_3_should_be_1_1() { + Fraction summand1 = new Fraction(1, 3); + Fraction summand2 = new Fraction(2, 3); + + Fraction sum = summand1.plus(summand2); + + assertThat(sum).isEqualTo(new Fraction(3, 3)); + } + + @Test + void add_1_3_plus_2_3_should_be_1_1_reduced() { + Fraction summand1 = new Fraction(1, 3); + Fraction summand2 = new Fraction(2, 3); + + Fraction sum = summand1.plus(summand2); + + assertThat(sum.numerator()).isEqualTo(1); + assertThat(sum.denominator()).isEqualTo(1); + } + + } + + @Nested + class Pow { + + @Test + void power_to_two() { + Fraction fraction = new Fraction(2, 3); + + Fraction produkt = fraction.pow(2); + + assertThat(produkt).isEqualTo(new Fraction(4, 9)); + } + + @Test + void power_to_three() { + Fraction fraction = new Fraction(2, 3); + + Fraction produkt = fraction.pow(3); + + assertThat(produkt).isEqualTo(new Fraction(8, 27)); + } + + @Test + void power_to_ten() { + Fraction fraction = new Fraction(2, 3); + + Fraction produkt = fraction.pow(10); + + assertThat(produkt).isEqualTo(new Fraction(1024, 59049)); + } + } + + @Nested + class Limits { + + @Test + void add_max_value() { + Fraction summand1 = new Fraction(Integer.MAX_VALUE / 2, 1); + Fraction summand2 = new Fraction(Integer.MAX_VALUE / 2, 1); + + Fraction sum = summand1.plus(summand2); + + assertThat(sum.numerator()).isEqualTo(Integer.MAX_VALUE - 1); + assertThat(sum.denominator()).isEqualTo(1); + } + + @Test + void add_min_value() { + Fraction summand1 = new Fraction(Integer.MIN_VALUE / 2, 1); + Fraction summand2 = new Fraction(Integer.MIN_VALUE / 2, 1); + + Fraction sum = summand1.plus(summand2); + + assertThat(sum.numerator()).isEqualTo(Integer.MIN_VALUE); + assertThat(sum.denominator()).isEqualTo(1); + } + + } +} diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/MvnDirectoryIT/non_hidden_files/.mvn/maven.config b/itf-examples/src/test/resources-its/com/soebes/itf/examples/MvnDirectoryIT/non_hidden_files/.mvn/maven.config new file mode 100644 index 0000000000..affad39a42 --- /dev/null +++ b/itf-examples/src/test/resources-its/com/soebes/itf/examples/MvnDirectoryIT/non_hidden_files/.mvn/maven.config @@ -0,0 +1 @@ +-T2 \ No newline at end of file diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/MvnDirectoryIT/non_hidden_files/pom.xml b/itf-examples/src/test/resources-its/com/soebes/itf/examples/MvnDirectoryIT/non_hidden_files/pom.xml new file mode 100644 index 0000000000..42a5ecfdc6 --- /dev/null +++ b/itf-examples/src/test/resources-its/com/soebes/itf/examples/MvnDirectoryIT/non_hidden_files/pom.xml @@ -0,0 +1,111 @@ + + + + + + + 4.0.0 + + + com.soebes.smpp + smpp + 7.0.0 + + + + com.soebes.katas + kata-fraction + 1.0-SNAPSHOT + + + kata-fraction + 8 + + + + + org.junit + junit-bom + 5.10.1 + import + pom + + + nl.jqno.equalsverifier + equalsverifier + 3.15.5 + + + org.assertj + assertj-core + 3.25.0 + + + org.apiguardian + apiguardian-api + 1.1.2 + + + + + + org.apiguardian + apiguardian-api + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.jupiter + junit-jupiter-params + test + + + nl.jqno.equalsverifier + equalsverifier + test + + + org.assertj + assertj-core + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + -Xlint:-options + + + + + + + diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/MvnDirectoryIT/non_hidden_files/src/main/java/com/soebes/kata/fraction/Fraction.java b/itf-examples/src/test/resources-its/com/soebes/itf/examples/MvnDirectoryIT/non_hidden_files/src/main/java/com/soebes/kata/fraction/Fraction.java new file mode 100644 index 0000000000..040bbab4d6 --- /dev/null +++ b/itf-examples/src/test/resources-its/com/soebes/itf/examples/MvnDirectoryIT/non_hidden_files/src/main/java/com/soebes/kata/fraction/Fraction.java @@ -0,0 +1,137 @@ +package com.soebes.kata.fraction; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apiguardian.api.API; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.Objects; +import java.util.StringJoiner; + +import static org.apiguardian.api.API.Status.EXPERIMENTAL; + +/** + * @author Karl Heinz Marbaise + */ +@API(status = EXPERIMENTAL) +public class Fraction implements Comparable { + private final int numerator; + private final int denominator; + + public Fraction(int numerator, int denominator) { + if (denominator == 0) { + throw new IllegalArgumentException("denominator is not allowed to be zero."); + } + int sign = Integer.signum(numerator) * Integer.signum(denominator); + + int gcd = MathUtil.calculateGcd(numerator, denominator); + this.numerator = sign * Math.abs(numerator) / gcd; + this.denominator = Math.abs(denominator) / gcd; + } + + public Fraction plus(Fraction add) { + if (this.denominator == add.denominator) { + return new Fraction(add.numerator + this.numerator, this.denominator); + } else { + return new Fraction(add.numerator * this.denominator + this.numerator * add.denominator, add.denominator * this.denominator); + } + } + + public Fraction subtract(Fraction subtrahend) { + if (this.denominator == subtrahend.denominator) { + return new Fraction(this.numerator - subtrahend.numerator, this.denominator); + } else { + return new Fraction(this.numerator * subtrahend.denominator - this.denominator * subtrahend.numerator, subtrahend.denominator * this.denominator); + } + } + + public Fraction multiply(Fraction factor) { + return new Fraction(this.numerator * factor.numerator, this.denominator * factor.denominator); + } + + public Fraction divide(Fraction divisor) { + return new Fraction(this.numerator * divisor.denominator, this.denominator * divisor.numerator); + } + + public Fraction pow(int power) { + return new Fraction(BigInteger.valueOf(this.numerator).pow(power).intValueExact(), BigInteger.valueOf(this.denominator).pow(power).intValueExact()); + } + + public int numerator() { + return numerator; + } + + public int denominator() { + return denominator; + } + + @Override + public int compareTo(Fraction compareTo) { + if (compareTo == null) { + throw new NullPointerException("compareTo is not allowed to be null."); + } + return this.subtract(compareTo).signum(); + } + + /** + * Returns the signum function of this {@code Fraction}. + * + * @return -1, 0, or 1 as the value of this {@code Fraction} + * is negative, zero, or positive. + */ + public int signum() { + return Integer.signum(numerator); + } + + public Fraction negate() { + return new Fraction(Math.negateExact(this.numerator), this.denominator); + } + + public double doubleValue() { + return (double) this.numerator / (double) this.denominator; + } + + public BigDecimal bigDecimalValue() { + return BigDecimal.valueOf(this.numerator).divide(BigDecimal.valueOf(this.denominator)); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Fraction fraction = (Fraction) o; + return numerator == fraction.numerator && + denominator == fraction.denominator; + } + + @Override + public int hashCode() { + return Objects.hash(numerator, denominator); + } + + @Override + public String toString() { + return new StringJoiner(", ", Fraction.class.getSimpleName() + "[", "]") + .add("numerator=" + numerator) + .add("denominator=" + denominator) + .toString(); + } +} diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/MvnDirectoryIT/non_hidden_files/src/main/java/com/soebes/kata/fraction/MathUtil.java b/itf-examples/src/test/resources-its/com/soebes/itf/examples/MvnDirectoryIT/non_hidden_files/src/main/java/com/soebes/kata/fraction/MathUtil.java new file mode 100644 index 0000000000..25627496bb --- /dev/null +++ b/itf-examples/src/test/resources-its/com/soebes/itf/examples/MvnDirectoryIT/non_hidden_files/src/main/java/com/soebes/kata/fraction/MathUtil.java @@ -0,0 +1,59 @@ +package com.soebes.kata.fraction; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.math.BigInteger; + +/** + * @author Karl Heinz Marbaise + */ +class MathUtil { + + private MathUtil() { + // intentionally empty. + } + + /** + * @param numerator Numerator + * @param denominator Denominator + * @return greatest common divisor. + */ + static int calculateGcd(int numerator, int denominator) { + return BigInteger.valueOf(numerator).gcd(BigInteger.valueOf(denominator)).intValueExact(); + } + + /** + * @param numerator Numerator + * @param denominator Denominator + * @return greatest common divisor. + */ + static long calculateGcd(long numerator, long denominator) { + return BigInteger.valueOf(numerator).gcd(BigInteger.valueOf(denominator)).longValueExact(); + } + + /** + * @param numerator Numerator + * @param denominator Denominator + * @return greatest common divisor. + */ + static BigInteger calculateGcd(BigInteger numerator, BigInteger denominator) { + return numerator.gcd(denominator); + } +} diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/MvnDirectoryIT/non_hidden_files/src/test/java/com/soebes/kata/fraction/FractionTest.java b/itf-examples/src/test/resources-its/com/soebes/itf/examples/MvnDirectoryIT/non_hidden_files/src/test/java/com/soebes/kata/fraction/FractionTest.java new file mode 100644 index 0000000000..e11ee4b664 --- /dev/null +++ b/itf-examples/src/test/resources-its/com/soebes/itf/examples/MvnDirectoryIT/non_hidden_files/src/test/java/com/soebes/kata/fraction/FractionTest.java @@ -0,0 +1,377 @@ +package com.soebes.kata.fraction; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import nl.jqno.equalsverifier.EqualsVerifier; +import org.assertj.core.data.Offset; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import java.math.BigDecimal; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.assertj.core.api.Assertions.assertThatNullPointerException; + +/** + * Test for {@link Fraction}. + */ +class FractionTest { + + @Nested + class BigDecimalValue { + + @Test + void fraction_to_bigdecimal() { + Fraction fraction = new Fraction(1, 1); + assertThat(fraction.bigDecimalValue()).isEqualByComparingTo(BigDecimal.valueOf(1)); + } + } + + @Nested + class DoubleValue { + + @Test + void fraction_to_double() { + Fraction fraction = new Fraction(1, 1); + assertThat(fraction.doubleValue()).isEqualTo(1.0, Offset.offset(1E-6)); + } + } + + @Nested + class Negate { + + @Test + void fraction_negate() { + Fraction fraction = new Fraction(1, 1); + assertThat(fraction.negate()).isEqualByComparingTo(new Fraction(-1, 1)); + } + + @Test + void fraction_negate_max() { + Fraction fraction = new Fraction(Integer.MAX_VALUE, 1); + assertThat(fraction.negate()).isEqualByComparingTo(new Fraction(-Integer.MAX_VALUE, 1)); + } + + @Test + void fraction_negate_min() { + Fraction fraction = new Fraction(Integer.MIN_VALUE, 1); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(fraction::negate) + .withMessage("integer overflow"); + } + } + + @Nested + class Signum { + + @Test + void signum_for_z_pos_n_pos() { + Fraction fraction = new Fraction(1, 2); + assertThat(fraction.signum()).isOne(); + } + + @Test + void signum_for_z_neg_n_pos() { + Fraction fraction = new Fraction(-1, 2); + assertThat(fraction.signum()).isNegative(); + } + + @Test + void signum_for_z_pos_n_neg() { + Fraction fraction = new Fraction(1, -2); + assertThat(fraction.signum()).isNegative(); + } + + @Test + void signum_for_z_neg_n_neg() { + Fraction fraction = new Fraction(-1, -2); + assertThat(fraction.signum()).isPositive(); + } + } + + @Nested + class CompareTo { + + @Test + void fraction_one_identical_to_fraction_two() { + Fraction fractionOne = new Fraction(1, 2); + Fraction fractionTwo = new Fraction(1, 2); + + assertThat(fractionOne).isEqualByComparingTo(fractionTwo); + } + + @Test + void fraction_one_greater_than_fraction_two() { + Fraction fractionOne = new Fraction(1, 1); + Fraction fractionTwo = new Fraction(1, 2); + + assertThat(fractionOne).isGreaterThan(fractionTwo); + } + + @Test + void fraction_one_less_than_fraction_two() { + Fraction fractionOne = new Fraction(1, 3); + Fraction fractionTwo = new Fraction(1, 2); + + assertThat(fractionOne).isLessThan(fractionTwo); + } + + } + + @Nested + class Verification { + + @Test + void hash_code_and_equals() { + EqualsVerifier.forClass(Fraction.class).usingGetClass().verify(); + } + + @Test + void check_to_string() { + Fraction fraction = new Fraction(1, 2); + assertThat(fraction).hasToString("Fraction[numerator=1, denominator=2]"); + } + } + + @Nested + class InvalideValues { + + @Test + void denominator_is_not_allowed_to_be_zero() { + assertThatIllegalArgumentException().isThrownBy(() -> new Fraction(1, 0)) + .withMessage("denominator is not allowed to be zero."); + } + + @Test + void compare_to_null() { + assertThatNullPointerException().isThrownBy(() -> new Fraction(1, 2).compareTo(null)) + .withMessage("compareTo is not allowed to be null."); + } + } + + @Nested + class Normalizing { + + @Test + void normalize_0_x() { + Fraction fraction = new Fraction(0, 6); + + assertThat(fraction.numerator()).isZero(); + assertThat(fraction.denominator()).isEqualTo(1); + } + + @Test + void normalize_improper_fraction() { + Fraction improperFraction = new Fraction(4, 6); + assertThat(improperFraction.numerator()).isEqualTo(2); + assertThat(improperFraction.denominator()).isEqualTo(3); + } + } + + @Nested + class Multiplikation { + + @Test + void multiply_multiplier_by_multiplicand() { + Fraction multiplier = new Fraction(2, 3); + Fraction multiplicand = new Fraction(4, 5); + + Fraction produkt = multiplier.multiply(multiplicand); + + assertThat(produkt).isEqualTo(new Fraction(8, 15)); + } + } + + @Nested + class Divide { + + @Test + void divide_1_2_by_2_5() { + Fraction dividend = new Fraction(1, 2); + Fraction divisor = new Fraction(2, 5); + + Fraction quotient = dividend.divide(divisor); + + assertThat(quotient).isEqualTo(new Fraction(5, 4)); + } + + @Test + void divide_the_same_fraction() { + Fraction dividend = new Fraction(1, 2); + Fraction divisor = new Fraction(1, 2); + + Fraction quotient = dividend.divide(divisor); + + assertThat(quotient).isEqualTo(new Fraction(1, 1)); + } + } + + @Nested + class Subtraction { + + @Test + void subtract_first_minus_second() { + Fraction minuend = new Fraction(2, 3); + Fraction subtrahend = new Fraction(1, 5); + + Fraction difference = minuend.subtract(subtrahend); + + assertThat(difference).isEqualTo(new Fraction(7, 15)); + } + + @Test + void subtract_with_same_denominator() { + Fraction minuend = new Fraction(5, 9); + Fraction subtrahend = new Fraction(2, 9); + + Fraction difference = minuend.subtract(subtrahend); + + assertThat(difference).isEqualTo(new Fraction(3, 9)); + } + + @Test + void subtract_with_improper_faction_result() { + Fraction minuend = new Fraction(21, 7); + Fraction subtrahend = new Fraction(12, 7); + + Fraction difference = minuend.subtract(subtrahend); + + assertThat(difference).isEqualTo(new Fraction(9, 7)); + } + } + + @Nested + class Addition { + + @Test + void chaining_addition_with_improper_fraction_result() { + Fraction summand1 = new Fraction(1, 2); + Fraction summand2 = new Fraction(1, 3); + Fraction summand3 = new Fraction(1, 4); + + Fraction sum = summand1.plus(summand2).plus(summand3); + + assertThat(sum).isEqualTo(new Fraction(26, 24)); + } + + @Test + void chaining_addition_with_proper_fraction_result() { + Fraction summand1 = new Fraction(1, 2); + Fraction summand2 = new Fraction(1, 3); + Fraction summand3 = new Fraction(1, 4); + + Fraction sum = summand1.plus(summand2).plus(summand3); + + assertThat(sum).isEqualTo(new Fraction(13, 12)); + } + + @Test + void addition_with_two_proper_fractions() { + Fraction summand1 = new Fraction(2, 3); + Fraction summand2 = new Fraction(1, 5); + + Fraction sum = summand1.plus(summand2); + + assertThat(sum).isEqualTo(new Fraction(13, 15)); + } + + @Test + void add_1_3_plus_2_3_should_be_1_1() { + Fraction summand1 = new Fraction(1, 3); + Fraction summand2 = new Fraction(2, 3); + + Fraction sum = summand1.plus(summand2); + + assertThat(sum).isEqualTo(new Fraction(3, 3)); + } + + @Test + void add_1_3_plus_2_3_should_be_1_1_reduced() { + Fraction summand1 = new Fraction(1, 3); + Fraction summand2 = new Fraction(2, 3); + + Fraction sum = summand1.plus(summand2); + + assertThat(sum.numerator()).isEqualTo(1); + assertThat(sum.denominator()).isEqualTo(1); + } + + } + + @Nested + class Pow { + + @Test + void power_to_two() { + Fraction fraction = new Fraction(2, 3); + + Fraction produkt = fraction.pow(2); + + assertThat(produkt).isEqualTo(new Fraction(4, 9)); + } + + @Test + void power_to_three() { + Fraction fraction = new Fraction(2, 3); + + Fraction produkt = fraction.pow(3); + + assertThat(produkt).isEqualTo(new Fraction(8, 27)); + } + + @Test + void power_to_ten() { + Fraction fraction = new Fraction(2, 3); + + Fraction produkt = fraction.pow(10); + + assertThat(produkt).isEqualTo(new Fraction(1024, 59049)); + } + } + + @Nested + class Limits { + + @Test + void add_max_value() { + Fraction summand1 = new Fraction(Integer.MAX_VALUE / 2, 1); + Fraction summand2 = new Fraction(Integer.MAX_VALUE / 2, 1); + + Fraction sum = summand1.plus(summand2); + + assertThat(sum.numerator()).isEqualTo(Integer.MAX_VALUE - 1); + assertThat(sum.denominator()).isEqualTo(1); + } + + @Test + void add_min_value() { + Fraction summand1 = new Fraction(Integer.MIN_VALUE / 2, 1); + Fraction summand2 = new Fraction(Integer.MIN_VALUE / 2, 1); + + Fraction sum = summand1.plus(summand2); + + assertThat(sum.numerator()).isEqualTo(Integer.MIN_VALUE); + assertThat(sum.denominator()).isEqualTo(1); + } + + } +} diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/ProjectIT/project_001/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/ProjectIT/project_001/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/ProjectIT/project_002/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/ProjectIT/project_002/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/ProjectSecondIT/project_001/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/ProjectSecondIT/project_001/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/ProjectSecondIT/project_002/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/ProjectSecondIT/project_002/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/SixthIT/basic/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/SixthIT/basic/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/defaults/DefaultsForAllIT/option_debug/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/defaults/DefaultsForAllIT/option_debug/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/goals/GoalsIT/goal_clean/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/goals/GoalsIT/goal_clean/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/goals/GoalsIT/goal_clean/src/test/java/com/soebes/kata/fraction/FractionTest.java b/itf-examples/src/test/resources-its/com/soebes/itf/examples/goals/GoalsIT/goal_clean/src/test/java/com/soebes/kata/fraction/FractionTest.java index 788ffd2bec..1b27d5a948 100644 --- a/itf-examples/src/test/resources-its/com/soebes/itf/examples/goals/GoalsIT/goal_clean/src/test/java/com/soebes/kata/fraction/FractionTest.java +++ b/itf-examples/src/test/resources-its/com/soebes/itf/examples/goals/GoalsIT/goal_clean/src/test/java/com/soebes/kata/fraction/FractionTest.java @@ -26,10 +26,10 @@ import java.math.BigDecimal; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.assertj.core.api.Assertions.assertThatNullPointerException; - /** * Test for {@link Fraction}. */ diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/goals/GoalsIT/goal_clean_compile/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/goals/GoalsIT/goal_clean_compile/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/goals/GoalsIT/no_goals_at_all/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/goals/GoalsIT/no_goals_at_all/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/goals/GoalsOnClassIT/goal_clean/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/goals/GoalsOnClassIT/goal_clean/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/goals/MetaAnnotationGoalIT/clean_verify/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/goals/MetaAnnotationGoalIT/clean_verify/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/mps/xyz/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/mps/xyz/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/mps/xyzp3/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/mps/xyzp3/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/options/OptionsIT/no_options_at_all/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/options/OptionsIT/no_options_at_all/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/options/OptionsIT/option_debug/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/options/OptionsIT/option_debug/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/options/OptionsIT/option_quiet_logfile/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/options/OptionsIT/option_quiet_logfile/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/options/OptionsOnClassIT/option_debug/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/options/OptionsOnClassIT/option_debug/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/profiles/MetaAnnotationProfileIT/profile_1_2_3/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/profiles/MetaAnnotationProfileIT/profile_1_2_3/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/profiles/ProfileIT/UnknownProfile/maven_project/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/profiles/ProfileIT/UnknownProfile/maven_project/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/profiles/ProfileIT/no_profile_at_all/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/profiles/ProfileIT/no_profile_at_all/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/profiles/ProfileIT/profile_1/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/profiles/ProfileIT/profile_1/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/profiles/ProfileIT/profile_1_2/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/profiles/ProfileIT/profile_1_2/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/profiles/ProfileIT/profile_1_2_3/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/profiles/ProfileIT/profile_1_2_3/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/profiles/ProfileOnClassIT/profile_1/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/profiles/ProfileOnClassIT/profile_1/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/profiles/ProfileOnClassIT/profile_1_2_3/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/profiles/ProfileOnClassIT/profile_1_2_3/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/profiles/packagewide/ProfileOnPackageIT/profile_1_2_3/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/profiles/packagewide/ProfileOnPackageIT/profile_1_2_3/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/properties/MetaAnnotationPropertiesIT/property_skiptests/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/properties/MetaAnnotationPropertiesIT/property_skiptests/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/properties/PropertiesIT/property_skiptests/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/properties/PropertiesIT/property_skiptests/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/properties/PropertiesOnClassIT/property_skiptests/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/properties/PropertiesOnClassIT/property_skiptests/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/properties/PropertiesOnNestedClassIT/Level1/property_skiptests/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/properties/PropertiesOnNestedClassIT/Level1/property_skiptests/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/repository/MavenRepositoryNestedIT/NestedIT/repository_in_enclosing_class_directory/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/repository/MavenRepositoryNestedIT/NestedIT/repository_in_enclosing_class_directory/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/repository/MavenRepositoryNestedIT/repository_in_class_directory/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/repository/MavenRepositoryNestedIT/repository_in_class_directory/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/subdir/SubDirClassIT/basic/subdir/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/subdir/SubDirClassIT/basic/subdir/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/subdir/SubDirIT/basic/subdir/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/subdir/SubDirIT/basic/subdir/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/subdir/SubDirNestedIT/DirNested/basic/subdir/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/subdir/SubDirNestedIT/DirNested/basic/subdir/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/itf-examples/src/test/resources-its/com/soebes/itf/examples/subdir/SubDirNestedMultipleIT/DirNested/Level1/Level2/basic/subdir/.mvn/.gitkeep b/itf-examples/src/test/resources-its/com/soebes/itf/examples/subdir/SubDirNestedMultipleIT/DirNested/Level1/Level2/basic/subdir/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2