Skip to content

Commit 477240a

Browse files
Sync tests for practice exercise collatz-conjecture (#2529)
* Sync tests for practice exercise `collatz-conjecture` * Update reference implementation * Update approaches
1 parent c326013 commit 477240a

File tree

8 files changed

+28
-12
lines changed

8 files changed

+28
-12
lines changed

exercises/practice/collatz-conjecture/.approaches/introduction.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class CollatzCalculator {
1111

1212
int computeStepCount(int start) {
1313
if (start < 1) {
14-
throw new IllegalArgumentException("Only natural numbers are allowed");
14+
throw new IllegalArgumentException("Only positive integers are allowed");
1515
}
1616

1717
int steps = 0;
@@ -40,7 +40,7 @@ class CollatzCalculator {
4040

4141
long computeStepCount(int start) {
4242
if (start < 1) {
43-
throw new IllegalArgumentException("Only natural numbers are allowed");
43+
throw new IllegalArgumentException("Only positive integers are allowed");
4444
}
4545

4646
return IntStream.iterate(start, num -> num != 1, num -> (num & 1) == 1 ? 3 * num + 1 : num >> 1).count();

exercises/practice/collatz-conjecture/.approaches/intstream-iterate/content.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class CollatzCalculator {
77

88
long computeStepCount(int start) {
99
if (start < 1) {
10-
throw new IllegalArgumentException("Only natural numbers are allowed");
10+
throw new IllegalArgumentException("Only positive integers are allowed");
1111
}
1212

1313
return IntStream.iterate(start, num -> num != 1, num -> (num & 1) == 1 ? 3 * num + 1 : num >> 1).count();

exercises/practice/collatz-conjecture/.approaches/intstream-iterate/snippet.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
long computeStepCount(int start) {
22
if (start < 1) {
3-
throw new IllegalArgumentException("Only natural numbers are allowed");
3+
throw new IllegalArgumentException("Only positive integers are allowed");
44
}
55

66
return IntStream.iterate(start, num -> num != 1, num -> (num & 1) == 1 ? 3 * num + 1 : num >> 1).count();

exercises/practice/collatz-conjecture/.approaches/while-loop/content.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class CollatzCalculator {
55

66
int computeStepCount(int start) {
77
if (start < 1) {
8-
throw new IllegalArgumentException("Only natural numbers are allowed");
8+
throw new IllegalArgumentException("Only positive integers are allowed");
99
}
1010

1111
int steps = 0;

exercises/practice/collatz-conjecture/.meta/src/reference/java/CollatzCalculator.java

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

33
int computeStepCount(final int start) {
44
if (start <= 0) {
5-
throw new IllegalArgumentException("Only natural numbers are allowed");
5+
throw new IllegalArgumentException("Only positive integers are allowed");
66
}
77
if (start == 1) {
88
return 0;

exercises/practice/collatz-conjecture/.meta/tests.toml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
# This is an auto-generated file. Regular comments will be removed when this
2-
# file is regenerated. Regenerating will not touch any manually added keys,
3-
# so comments can be added in a "comment" key.
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
411

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

1724
[7d4750e6-def9-4b86-aec7-9f7eb44f95a3]
1825
description = "zero is an error"
26+
include = false
27+
28+
[2187673d-77d6-4543-975e-66df6c50e2da]
29+
description = "zero is an error"
30+
reimplements = "7d4750e6-def9-4b86-aec7-9f7eb44f95a3"
1931

2032
[c6c795bf-a288-45e9-86a1-841359ad426d]
2133
description = "negative value is an error"
34+
include = false
35+
36+
[ec11f479-56bc-47fd-a434-bcd7a31a7a2e]
37+
description = "negative value is an error"
38+
reimplements = "c6c795bf-a288-45e9-86a1-841359ad426d"

exercises/practice/collatz-conjecture/.meta/version

Lines changed: 0 additions & 1 deletion
This file was deleted.

exercises/practice/collatz-conjecture/src/test/java/CollatzCalculatorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ public void testAVeryLargeInput() {
3636
public void testZeroIsConsideredInvalidInput() {
3737
assertThatExceptionOfType(IllegalArgumentException.class)
3838
.isThrownBy(() -> collatzCalculator.computeStepCount(0))
39-
.withMessage("Only natural numbers are allowed");
39+
.withMessage("Only positive integers are allowed");
4040
}
4141

4242
@Ignore("Remove to run test")
4343
@Test
4444
public void testNegativeIntegerIsConsideredInvalidInput() {
4545
assertThatExceptionOfType(IllegalArgumentException.class)
4646
.isThrownBy(() -> collatzCalculator.computeStepCount(-15))
47-
.withMessage("Only natural numbers are allowed");
47+
.withMessage("Only positive integers are allowed");
4848
}
4949

5050
}

0 commit comments

Comments
 (0)