Skip to content

Sync tests for practice exercise collatz-conjecture #2529

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class CollatzCalculator {

int computeStepCount(int start) {
if (start < 1) {
throw new IllegalArgumentException("Only natural numbers are allowed");
throw new IllegalArgumentException("Only positive integers are allowed");
}

int steps = 0;
Expand Down Expand Up @@ -40,7 +40,7 @@ class CollatzCalculator {

long computeStepCount(int start) {
if (start < 1) {
throw new IllegalArgumentException("Only natural numbers are allowed");
throw new IllegalArgumentException("Only positive integers are allowed");
}

return IntStream.iterate(start, num -> num != 1, num -> (num & 1) == 1 ? 3 * num + 1 : num >> 1).count();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class CollatzCalculator {

long computeStepCount(int start) {
if (start < 1) {
throw new IllegalArgumentException("Only natural numbers are allowed");
throw new IllegalArgumentException("Only positive integers are allowed");
}

return IntStream.iterate(start, num -> num != 1, num -> (num & 1) == 1 ? 3 * num + 1 : num >> 1).count();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
long computeStepCount(int start) {
if (start < 1) {
throw new IllegalArgumentException("Only natural numbers are allowed");
throw new IllegalArgumentException("Only positive integers are allowed");
}

return IntStream.iterate(start, num -> num != 1, num -> (num & 1) == 1 ? 3 * num + 1 : num >> 1).count();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class CollatzCalculator {

int computeStepCount(int start) {
if (start < 1) {
throw new IllegalArgumentException("Only natural numbers are allowed");
throw new IllegalArgumentException("Only positive integers are allowed");
}

int steps = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class CollatzCalculator {

int computeStepCount(final int start) {
if (start <= 0) {
throw new IllegalArgumentException("Only natural numbers are allowed");
throw new IllegalArgumentException("Only positive integers are allowed");
}
if (start == 1) {
return 0;
Expand Down
23 changes: 20 additions & 3 deletions exercises/practice/collatz-conjecture/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# This is an auto-generated file. Regular comments will be removed when this
# file is regenerated. Regenerating will not touch any manually added keys,
# so comments can be added in a "comment" key.
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

[540a3d51-e7a6-47a5-92a3-4ad1838f0bfd]
description = "zero steps for one"
Expand All @@ -16,6 +23,16 @@ description = "large number of even and odd steps"

[7d4750e6-def9-4b86-aec7-9f7eb44f95a3]
description = "zero is an error"
include = false

[2187673d-77d6-4543-975e-66df6c50e2da]
description = "zero is an error"
reimplements = "7d4750e6-def9-4b86-aec7-9f7eb44f95a3"

[c6c795bf-a288-45e9-86a1-841359ad426d]
description = "negative value is an error"
include = false

[ec11f479-56bc-47fd-a434-bcd7a31a7a2e]
description = "negative value is an error"
reimplements = "c6c795bf-a288-45e9-86a1-841359ad426d"
1 change: 0 additions & 1 deletion exercises/practice/collatz-conjecture/.meta/version

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ public void testAVeryLargeInput() {
public void testZeroIsConsideredInvalidInput() {
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> collatzCalculator.computeStepCount(0))
.withMessage("Only natural numbers are allowed");
.withMessage("Only positive integers are allowed");
}

@Ignore("Remove to run test")
@Test
public void testNegativeIntegerIsConsideredInvalidInput() {
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> collatzCalculator.computeStepCount(-15))
.withMessage("Only natural numbers are allowed");
.withMessage("Only positive integers are allowed");
}

}