Test #maximum and #minimum with empty enumerable

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`).
This commit is contained in:
Jonathan Hefner 2021-02-12 15:58:20 -06:00
parent 1acde22bf2
commit 5df979dd35
1 changed files with 10 additions and 0 deletions

View File

@ -34,11 +34,21 @@ class EnumerableTests < ActiveSupport::TestCase
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