ruby
ruby copied to clipboard
strain: More test cases.
Many of the solutions submitted would fail this test:
def test_array_with_nils
assert_equal [nil, nil, nil], [1,nil,2,nil,3,nil].keep(&:nil?)
end
Should we include it in the tests?
Here are 6 new tests that most solutions fail at least one of:
def test_keep_with_nils
# skip
assert_equal [nil, nil, nil], [1,nil,2,nil,3,nil].keep(&:nil?)
end
def test_discard_with_nils
# skip
assert_equal [nil, nil, nil], [1,nil,2,nil,3,nil].discard { |e| !e.nil? }
end
def test_keep_with_duplicate_elements
# skip
count = 0
first_five = proc { (count += 1) <= 5 }
assert_equal [1,2,3,1,2], [1,2,3,1,2,3,1,2,3].keep(&first_five)
end
def test_discard_with_duplicate_elements
# skip
count = 0
first_four = proc { (count += 1) <= 4 }
assert_equal [2,3,1,2,3], [1,2,3,1,2,3,1,2,3].discard(&first_four)
end
# Either return a sensible value OR raise an error.
def test_keep_called_without_block
# skip
assert_equal [1,2,3], [1,2,3].keep
rescue LocalJumpError
assert true
end
# Either return a sensible value OR raise an error.
def test_discard_called_without_block
# skip
assert_equal [], [1,2,3].discard
rescue LocalJumpError
assert true
end
The readme is very clear that the list doesn't need to be numbers. Perhaps one test included that demonstrates keep and discard on a list of words, with the criteria being "stop words".
It seems to me like strain
is a subset of list-ops
. Perhaps strain
should be deprecated and cases like this added to list-ops
, if necessary.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I agree that the right move here is to deprecate strain
in favor of list-ops
, as we have implemented both.
These test cases could be proposed in https://github.com/exercism/problem-specifications as an addition to the list-ops exercise. If they are proposed there they will need to have a scenario
that indicates that they mix input types, since some languages will not allow having nils
where another type is expected.
If someone feels strongly that these cases should be added, please open the issue in problem-specifications, and then come back to the Ruby track to sync the tests.toml and implement the additional tests.
I am going to close this issue.