ruby icon indicating copy to clipboard operation
ruby copied to clipboard

strain: More test cases.

Open Insti opened this issue 7 years ago • 7 comments

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?

Insti avatar Jul 29 '16 09:07 Insti

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

Insti avatar Jul 29 '16 10:07 Insti

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".

kotp avatar Jul 29 '16 20:07 kotp

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.

Cohen-Carlisle avatar Aug 22 '16 19:08 Cohen-Carlisle

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.

stale[bot] avatar Apr 29 '17 20:04 stale[bot]

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.

stale[bot] avatar Jun 30 '17 09:06 stale[bot]

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.

stale[bot] avatar Aug 29 '17 19:08 stale[bot]

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.

stale[bot] avatar Oct 31 '17 10:10 stale[bot]

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.

kytrinyx avatar Oct 13 '22 08:10 kytrinyx