Skip to content

Commit fd5f986

Browse files
authored
Sync tests for practice exercise series (exercism#2641)
1 parent 00b1de3 commit fd5f986

3 files changed

Lines changed: 34 additions & 11 deletions

File tree

exercises/practice/series/.meta/src/reference/java/Series.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,20 @@ class Series {
1010
private List<String> digits;
1111

1212
Series(String string) {
13+
if (string.length() == 0) {
14+
throw new IllegalArgumentException("series cannot be empty");
15+
}
16+
1317
this.digits = Arrays.stream(string.split("")).collect(Collectors.toList());
1418
this.digitsSize = string.isEmpty() ? 0 : this.digits.size();
1519
}
1620

1721
List<String> slices(int num) {
1822
if (num <= 0) {
19-
throw new IllegalArgumentException("Slice size is too small.");
23+
throw new IllegalArgumentException("slice length cannot be negative or zero");
2024
}
2125
if (num > this.digitsSize) {
22-
throw new IllegalArgumentException("Slice size is too big.");
26+
throw new IllegalArgumentException("slice length cannot be greater than series length");
2327
}
2428
final int limit = this.digitsSize - num + 1;
2529
List<String> result = new ArrayList<>(limit);

exercises/practice/series/.meta/tests.toml

Lines changed: 13 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
[7ae7a46a-d992-4c2a-9c15-a112d125ebad]
613
description = "slices of one from one"
@@ -23,6 +30,9 @@ description = "slices of a long series"
2330
[6d235d85-46cf-4fae-9955-14b6efef27cd]
2431
description = "slice length is too large"
2532

33+
[d7957455-346d-4e47-8e4b-87ed1564c6d7]
34+
description = "slice length is way too large"
35+
2636
[d34004ad-8765-4c09-8ba1-ada8ce776806]
2737
description = "slice length cannot be zero"
2838

exercises/practice/series/src/test/java/SeriesTest.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,17 @@ public void sliceLengthIsToolarge() {
8484

8585
assertThatExceptionOfType(IllegalArgumentException.class)
8686
.isThrownBy(() -> series.slices(6))
87-
.withMessage("Slice size is too big.");
87+
.withMessage("slice length cannot be greater than series length");
88+
}
89+
90+
@Ignore("Remove to run test")
91+
@Test
92+
public void sliceLengthIsWayToolarge() {
93+
Series series = new Series("12345");
94+
95+
assertThatExceptionOfType(IllegalArgumentException.class)
96+
.isThrownBy(() -> series.slices(42))
97+
.withMessage("slice length cannot be greater than series length");
8898
}
8999

90100
@Ignore("Remove to run test")
@@ -94,7 +104,7 @@ public void sliceLengthZero() {
94104

95105
assertThatExceptionOfType(IllegalArgumentException.class)
96106
.isThrownBy(() -> series.slices(0))
97-
.withMessage("Slice size is too small.");
107+
.withMessage("slice length cannot be negative or zero");
98108
}
99109

100110
@Ignore("Remove to run test")
@@ -104,17 +114,16 @@ public void sliceLengthNegative() {
104114

105115
assertThatExceptionOfType(IllegalArgumentException.class)
106116
.isThrownBy(() -> series.slices(-1))
107-
.withMessage("Slice size is too small.");
117+
.withMessage("slice length cannot be negative or zero");
108118
}
109119

110120
@Ignore("Remove to run test")
111121
@Test
112122
public void emptySeries() {
113-
Series series = new Series("");
114123

115124
assertThatExceptionOfType(IllegalArgumentException.class)
116-
.isThrownBy(() -> series.slices(1))
117-
.withMessage("Slice size is too big.");
125+
.isThrownBy(() -> new Series(""))
126+
.withMessage("series cannot be empty");
118127
}
119128

120129
}

0 commit comments

Comments
 (0)