Skip to content
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

Sync tests for practice exercise series #2641

Merged
merged 2 commits into from
Jan 14, 2024
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 @@ -10,16 +10,20 @@ class Series {
private List<String> digits;

Series(String string) {
if (string.length() == 0) {
throw new IllegalArgumentException("series cannot be empty");
}

this.digits = Arrays.stream(string.split("")).collect(Collectors.toList());
this.digitsSize = string.isEmpty() ? 0 : this.digits.size();
}

List<String> slices(int num) {
if (num <= 0) {
throw new IllegalArgumentException("Slice size is too small.");
throw new IllegalArgumentException("slice length cannot be negative or zero");
}
if (num > this.digitsSize) {
throw new IllegalArgumentException("Slice size is too big.");
throw new IllegalArgumentException("slice length cannot be greater than series length");
}
final int limit = this.digitsSize - num + 1;
List<String> result = new ArrayList<>(limit);
Expand Down
16 changes: 13 additions & 3 deletions exercises/practice/series/.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.

[7ae7a46a-d992-4c2a-9c15-a112d125ebad]
description = "slices of one from one"
Expand All @@ -23,6 +30,9 @@ description = "slices of a long series"
[6d235d85-46cf-4fae-9955-14b6efef27cd]
description = "slice length is too large"

[d7957455-346d-4e47-8e4b-87ed1564c6d7]
description = "slice length is way too large"

[d34004ad-8765-4c09-8ba1-ada8ce776806]
description = "slice length cannot be zero"

Expand Down
21 changes: 15 additions & 6 deletions exercises/practice/series/src/test/java/SeriesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,17 @@ public void sliceLengthIsToolarge() {

assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> series.slices(6))
.withMessage("Slice size is too big.");
.withMessage("slice length cannot be greater than series length");
}

@Ignore("Remove to run test")
@Test
public void sliceLengthIsWayToolarge() {
Series series = new Series("12345");

assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> series.slices(42))
.withMessage("slice length cannot be greater than series length");
}

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

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

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

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

@Ignore("Remove to run test")
@Test
public void emptySeries() {
Series series = new Series("");

assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> series.slices(1))
.withMessage("Slice size is too big.");
.isThrownBy(() -> new Series(""))
.withMessage("series cannot be empty");
}

}