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>
|
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.
|
* 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)
|
assert_equal([[1,0],[2,1],[3,2]], @obj.to_enum(:foo, 1, 2, 3).with_index.to_a)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_with_memo
|
def test_with_object
|
||||||
r = 1..10
|
obj = [0, 1]
|
||||||
return unless r.each.respond_to? :with_memo
|
ret = (1..10).each.with_object(obj) {|i, memo|
|
||||||
assert_equal([55, 3628800], (1..10).each.with_memo([0,1]) {|i, memo|
|
|
||||||
memo[0] += i
|
memo[0] += i
|
||||||
memo[1] *= 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 = [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)
|
if seen.key?(i)
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
|
@ -113,6 +115,7 @@ class TestEnumerator < Test::Unit::TestCase
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
assert_same(obj, ret)
|
||||||
assert_equal([2, 5, 1, 3, 4, 0], a)
|
assert_equal([2, 5, 1, 3, 4, 0], a)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue