mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* test/ruby/test_enum.rb: add some tests.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22826 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
835513a234
commit
f725819666
2 changed files with 13 additions and 0 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
Mon Mar 9 01:38:00 2009 Yusuke Endoh <mame@tsg.ne.jp>
|
||||||
|
|
||||||
|
* test/ruby/test_enum.rb: add some tests.
|
||||||
|
|
||||||
Mon Mar 9 01:12:37 2009 Yusuke Endoh <mame@tsg.ne.jp>
|
Mon Mar 9 01:12:37 2009 Yusuke Endoh <mame@tsg.ne.jp>
|
||||||
|
|
||||||
* test/ruby/test_object.rb: add a test for Object#method_missing.
|
* test/ruby/test_object.rb: add a test for Object#method_missing.
|
||||||
|
|
|
@ -48,6 +48,7 @@ class TestEnumerable < Test::Unit::TestCase
|
||||||
assert_equal(1, @obj.find_index {|x| x % 2 == 0 })
|
assert_equal(1, @obj.find_index {|x| x % 2 == 0 })
|
||||||
assert_equal(nil, @obj.find_index {|x| false })
|
assert_equal(nil, @obj.find_index {|x| false })
|
||||||
assert_raise(ArgumentError) { @obj.find_index(0, 1) }
|
assert_raise(ArgumentError) { @obj.find_index(0, 1) }
|
||||||
|
assert_equal(1, @obj.find_index(2) {|x| x == 1 })
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_find_all
|
def test_find_all
|
||||||
|
@ -212,6 +213,10 @@ class TestEnumerable < Test::Unit::TestCase
|
||||||
@obj.zip([:a, :b, :c]) {|x,y| a << [x, y] }
|
@obj.zip([:a, :b, :c]) {|x,y| a << [x, y] }
|
||||||
assert_equal([[1,:a],[2,:b],[3,:c],[1,nil],[2,nil]], a)
|
assert_equal([[1,:a],[2,:b],[3,:c],[1,nil],[2,nil]], a)
|
||||||
|
|
||||||
|
a = []
|
||||||
|
@obj.zip({a: "A", b: "B", c: "C"}) {|x,y| a << [x, y] }
|
||||||
|
assert_equal([[1,[:a,"A"]],[2,[:b,"B"]],[3,[:c,"C"]],[1,nil],[2,nil]], a)
|
||||||
|
|
||||||
ary = Object.new
|
ary = Object.new
|
||||||
def ary.to_a; [1, 2]; end
|
def ary.to_a; [1, 2]; end
|
||||||
assert_raise(NoMethodError){ %w(a b).zip(ary) }
|
assert_raise(NoMethodError){ %w(a b).zip(ary) }
|
||||||
|
@ -274,4 +279,8 @@ class TestEnumerable < Test::Unit::TestCase
|
||||||
c.call
|
c.call
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_reverse_each
|
||||||
|
assert_equal([2,1,3,2,1], @obj.reverse_each.to_a)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue