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

add tests.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26988 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2010-03-20 05:17:19 +00:00
parent 9ce419a45c
commit 4b6a7a46e8

View file

@ -1345,6 +1345,26 @@ class TestArray < Test::Unit::TestCase
assert_equal(@cls[1, 2, 3], @cls[1, 2, 3].uniq)
end
def test_uniq_with_block
a = []
b = a.uniq {|v| v.even? }
assert_equal([], a)
assert_equal([], b)
assert_not_same(a, b)
a = [1]
b = a.uniq {|v| v.even? }
assert_equal([1], a)
assert_equal([1], b)
assert_not_same(a, b)
a = [1,3]
b = a.uniq {|v| v.even? }
assert_equal([1,3], a)
assert_equal([1], b)
assert_not_same(a, b)
end
def test_uniq!
a = []
b = a.uniq!
@ -1385,6 +1405,27 @@ class TestArray < Test::Unit::TestCase
assert_raise(RuntimeError) { f.uniq! }
end
def test_uniq_bang_with_block
a = []
b = a.uniq! {|v| v.even? }
assert_equal(nil, b)
a = [1]
b = a.uniq! {|v| v.even? }
assert_equal(nil, b)
a = [1,3]
b = a.uniq! {|v| v.even? }
assert_equal([1], a)
assert_equal([1], b)
assert_same(a, b)
a = [1,2]
b = a.uniq! {|v| v.even? }
assert_equal([1,2], a)
assert_equal(nil, b)
end
def test_unshift
a = @cls[]
assert_equal(@cls['cat'], a.unshift('cat'))