diff options
Diffstat (limited to 'test/ruby/test_enumerator.rb')
-rw-r--r-- | test/ruby/test_enumerator.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/test/ruby/test_enumerator.rb b/test/ruby/test_enumerator.rb index b2ef8e5c25..4757855533 100644 --- a/test/ruby/test_enumerator.rb +++ b/test/ruby/test_enumerator.rb @@ -10,6 +10,10 @@ class TestEnumerator < Test::Unit::TestCase a.each {|x| yield x } end end + @sized = @obj.clone + def @sized.size + 42 + end end def enum_test obj @@ -429,6 +433,16 @@ class TestEnumerator < Test::Unit::TestCase end end + def test_size_for_enum_created_from_enumerable + %i[find_all reject map flat_map partition group_by sort_by min_by max_by + minmax_by each_with_index reverse_each each_entry].each do |method| + assert_equal nil, @obj.send(method).size + assert_equal 42, @sized.send(method).size + end + assert_equal nil, @obj.each_with_object(nil).size + assert_equal 42, @sized.each_with_object(nil).size + end + def check_consistency_for_combinatorics(method) [ [], [:a, :b, :c, :d, :e] ].product([-2, 0, 2, 5, 6]) do |array, arg| assert_equal array.send(method, arg).to_a.size, array.send(method, arg).size, |