mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* test/ruby/test_enumerator.rb (TestEnumerator#test_with_object):
Add (back) the test for Enumerable#with_object. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18867 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
990ffbb96a
commit
0924bcf835
2 changed files with 16 additions and 8 deletions
|
@ -1,3 +1,8 @@
|
|||
Tue Aug 26 19:25:44 2008 Akinori MUSHA <knu@iDaemons.org>
|
||||
|
||||
* test/ruby/test_enumerator.rb (TestEnumerator#test_with_object):
|
||||
Add (back) the test for Enumerable#with_object.
|
||||
|
||||
Tue Aug 26 16:16:43 2008 NARUSE, Yui <naruse@ruby-lang.org>
|
||||
|
||||
* test/cgi/test_cgi_tag_helper.rb: add more tests for html3.
|
||||
|
|
|
@ -96,16 +96,18 @@ class TestEnumerator < Test::Unit::TestCase
|
|||
assert_equal([[1,0],[2,1],[3,2]], @obj.to_enum(:foo, 1, 2, 3).with_index.to_a)
|
||||
end
|
||||
|
||||
def test_with_memo
|
||||
r = 1..10
|
||||
return unless r.each.respond_to? :with_memo
|
||||
assert_equal([55, 3628800], (1..10).each.with_memo([0,1]) {|i, memo|
|
||||
memo[0] += i
|
||||
memo[1] *= i
|
||||
})
|
||||
def test_with_object
|
||||
obj = [0, 1]
|
||||
ret = (1..10).each.with_object(obj) {|i, memo|
|
||||
memo[0] += i
|
||||
memo[1] *= i
|
||||
}
|
||||
assert_same(obj, ret)
|
||||
assert_equal([55, 3628800], ret)
|
||||
|
||||
a = [2,5,2,1,5,3,4,2,1,0]
|
||||
a.delete_if.with_memo({}) {|i, seen|
|
||||
obj = {}
|
||||
ret = a.delete_if.with_object(obj) {|i, seen|
|
||||
if seen.key?(i)
|
||||
true
|
||||
else
|
||||
|
@ -113,6 +115,7 @@ class TestEnumerator < Test::Unit::TestCase
|
|||
false
|
||||
end
|
||||
}
|
||||
assert_same(obj, ret)
|
||||
assert_equal([2, 5, 1, 3, 4, 0], a)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue