Skip to content

Commit

Permalink
Test #maximum and #minimum with empty enumerable
Browse files Browse the repository at this point in the history
Follow-up to #41404.

These tests will prevent regressions if we decide to change the
implementations of `maximum` or `minimum` in the future (for example,
calling `max_by` or `min_by` followed by `send`).
  • Loading branch information
jonathanhefner committed Feb 12, 2021
1 parent 1acde22 commit 5df979d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions activesupport/test/core_ext/enumerable_test.rb
Expand Up @@ -34,11 +34,21 @@ def test_minimum
assert_equal 5, payments.minimum(:price)
end

def test_minimum_with_empty_enumerable
payments = GenericEnumerable.new([])
assert_nil payments.minimum(:price)
end

def test_maximum
payments = GenericEnumerable.new([ Payment.new(5), Payment.new(15), Payment.new(10) ])
assert_equal 15, payments.maximum(:price)
end

def test_maximum_with_empty_enumerable
payments = GenericEnumerable.new([])
assert_nil payments.maximum(:price)
end

def test_sums
enum = GenericEnumerable.new([5, 15, 10])
assert_equal 30, enum.sum
Expand Down

0 comments on commit 5df979d

Please sign in to comment.