diff options
author | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-07-02 08:30:36 +0000 |
---|---|---|
committer | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-07-02 08:30:36 +0000 |
commit | bb8532946030cb2e4337bd4f1f462e19ee507fa1 (patch) | |
tree | 8d60b3acf837bc51a22cb21c829cfbbeab72212c /test | |
parent | 905189b2e3a7d746af91cdea254ed041a5fc111f (diff) |
merge revision(s) 62731,62735: [Backport #14495]
Bug Fix Enumerator::Lazy#uniq state for multiple call
* enumerator.c (lazy_uniq_i): create new hash for each calls.
[Fix GH-1820]
Currently
2.5.0-preview1 :001 > arr = (0..100).lazy.uniq{|i| i % 10}
=> #<Enumerator::Lazy: #<Enumerator::Lazy: 0..100>:uniq>
2.5.0-preview1 :002 > arr.to_a
=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
2.5.0-preview1 :003 > arr.to_a
=> []
Expected
arr.to_a to always return same output
From: Anmol Chopra <anmolchopra@rocketbox.in>
test_enumerator.rb: duplicate assertions
* test/ruby/test_enumerator.rb (test_uniq): remove assertions
which ared duplicate of lazy enumerator tests in
test_lazy_enumerator.rb.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_5@63824 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_enumerator.rb | 5 | ||||
-rw-r--r-- | test/ruby/test_lazy_enumerator.rb | 9 |
2 files changed, 12 insertions, 2 deletions
diff --git a/test/ruby/test_enumerator.rb b/test/ruby/test_enumerator.rb index 235dfbfc9b..66a45cc14e 100644 --- a/test/ruby/test_enumerator.rb +++ b/test/ruby/test_enumerator.rb @@ -657,8 +657,9 @@ class TestEnumerator < Test::Unit::TestCase end def test_uniq - assert_equal([1, 2, 3, 4, 5, 10], - (1..Float::INFINITY).lazy.uniq{|x| (x**2) % 10 }.first(6)) + u = [0, 1, 0, 1].to_enum.lazy.uniq + assert_equal([0, 1], u.force) + assert_equal([0, 1], u.force) end end diff --git a/test/ruby/test_lazy_enumerator.rb b/test/ruby/test_lazy_enumerator.rb index 22028283ce..03371c912a 100644 --- a/test/ruby/test_lazy_enumerator.rb +++ b/test/ruby/test_lazy_enumerator.rb @@ -569,4 +569,13 @@ EOS [1, 2, 3].lazy.map(&:undefined).map(&:to_s).force end end + + def test_uniq + u = (1..Float::INFINITY).lazy.uniq do |x| + raise "too big" if x > 10000 + (x**2) % 10 + end + assert_equal([1, 2, 3, 4, 5, 10], u.first(6)) + assert_equal([1, 2, 3, 4, 5, 10], u.first(6)) + end end |