1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* enumerator.c (lazy_cycle): add Enumerable::Lazy#cycle.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35028 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
shugo 2012-03-15 02:00:30 +00:00
parent c037f1f616
commit d18dc74698
3 changed files with 57 additions and 3 deletions

View file

@ -184,6 +184,16 @@ class TestLazyEnumerator < Test::Unit::TestCase
assert_equal([4, 5], (1..Float::INFINITY).lazy.drop(3).take(2).to_a)
end
def test_cycle
a = Step.new(1..3)
assert_equal("1", a.cycle(2).map(&:to_s).first)
assert_equal(3, a.current)
assert_equal("1", a.lazy.cycle(2).map(&:to_s).first)
assert_equal(1, a.current)
assert_equal("1", a.lazy.cycle(2, &:to_s).first)
assert_equal(1, a.current)
end
def test_force
assert_equal([1, 2, 3], (1..Float::INFINITY).lazy.take(3).force)
end