Skip to content

Commit

Permalink
Series: Test is not testing for zero length series
Browse files Browse the repository at this point in the history
This test now raises if the series is 0 instead of of the slice slice
size being larger than the series.

This allows one to raise on normalization of user input, the series
given, rather than incidentally having the slice size of 1 be larger
than the series size from a zero length string.

The example solution is updated to raise specifically for a zero length
series, rather than the incidental raising when slices are asked for.
  • Loading branch information
kotp committed Oct 31, 2024
1 parent 149839f commit e986d31
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
1 change: 1 addition & 0 deletions exercises/practice/series/.meta/example.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Series
def initialize(series)
raise ArgumentError if series.length.zero?
@series = series
end
def slices(n)
Expand Down
3 changes: 1 addition & 2 deletions exercises/practice/series/series_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ def test_slice_length_cannot_be_negative
def test_empty_series_is_invalid
skip
slice_string = ""
series = Series.new(slice_string)
assert_raises ArgumentError do
series.slices(1)
Series.new(slice_string)
end
end
end

0 comments on commit e986d31

Please sign in to comment.