mirror of
https://github.com/ruby/ruby.git
synced 2025-08-25 22:14:37 +02:00
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> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62731 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3438cfa729
commit
0faf018624
4 changed files with 61 additions and 9 deletions
|
@ -657,8 +657,13 @@ 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)
|
||||
|
||||
u = (1..Float::INFINITY).lazy.uniq{|x| (x**2) % 10 }
|
||||
assert_equal([1, 2, 3, 4, 5, 10], u.first(6))
|
||||
assert_equal([1, 2, 3, 4, 5, 10], u.first(6))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue