Add tests for write! edge cases in Circular Buffer#124
Add tests for write! edge cases in Circular Buffer#124kytrinyx merged 1 commit intoexercism:masterfrom julianandrews:add-edge-case-tests-to-circular-buffer
Conversation
Tests for "CircularBuffer.write!" with "nil" argument and on non-full buffers. Fixes #123.
There was a problem hiding this comment.
This is actually an interesting question overall... it seems odd to me now that a nil would be treated differently than any another value, but I see that we're already doing this for the write with a nil.
Let's do this for now, but also be open to having the discussion about what nil actually means in the context of a circular buffer.
There was a problem hiding this comment.
I had the a similar thought. It's notable that all of the test cases only use strings as values for the buffer. If the intent is a circular buffer for strings only, then probably instead of silently failing on a nil write, the buffer should throw an exception on any non-string value.
If instead the intent is a buffer that can accept arbitrary objects, then nil should be a valid thing to write. Of course, that would make the exercise a notch more difficult since the simple approach of using a nil filled array wouldn't work anymore, but it would also be more general an correct.
Since the buffer is suppose to raise an error if you try to read from it empty, there's no scenario where nil is used to represent an empty value or anything like that.
There was a problem hiding this comment.
Agreed, I like the idea of making this a circular string buffer, and to have any non-string values raise errors. We could have several tests to that effect (nil, fixnum, Object.new, whatever), or one test with several different types of things.
There was a problem hiding this comment.
I could write a fix to replace the nil write tests with tests that check a representative set of non-string values all throw an ArgumentError (or some custom exception). In that case it might also make sense to have some of the tests test longer strings (not just single character strings) just to make it clear that any strings (but only strings) are valid inputs.
There was a problem hiding this comment.
Yes, longer strings would help clarify.
|
Thanks! |
…cular-buffer Add tests for write! edge cases in Circular Buffer
meetup common test data
Tests for "CircularBuffer.write!" with "nil" argument and on non-full
buffers. Fixes #123.