aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-03-20 04:27:32 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-03-20 04:27:32 +0000
commit9ce419a45c521d8c41773ad29cb9ccec3be05028 (patch)
tree22a94afde9b375588a2d0d9aef267690e6f2d5b6 /test
parentc9dd4823d98141754842c0b356b141d94ba36604 (diff)
downloadruby-9ce419a45c521d8c41773ad29cb9ccec3be05028.tar.gz
* array.c (rb_ary_uniq_bang): the array is already unique if the
length is zero or one. (rb_ary_uniq): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26987 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_array.rb43
1 files changed, 43 insertions, 0 deletions
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb
index 98acfe9d29..69d3f1d75c 100644
--- a/test/ruby/test_array.rb
+++ b/test/ruby/test_array.rb
@@ -1308,6 +1308,30 @@ class TestArray < Test::Unit::TestCase
end
def test_uniq
+ a = []
+ b = a.uniq
+ assert_equal([], a)
+ assert_equal([], b)
+ assert_not_same(a, b)
+
+ a = [1]
+ b = a.uniq
+ assert_equal([1], a)
+ assert_equal([1], b)
+ assert_not_same(a, b)
+
+ a = [1,1]
+ b = a.uniq
+ assert_equal([1,1], a)
+ assert_equal([1], b)
+ assert_not_same(a, b)
+
+ a = [1,2]
+ b = a.uniq
+ assert_equal([1,2], a)
+ assert_equal([1,2], b)
+ assert_not_same(a, b)
+
a = @cls[ 1, 2, 3, 2, 1, 2, 3, 4, nil ]
b = a.dup
assert_equal(@cls[1, 2, 3, 4, nil], a.uniq)
@@ -1322,6 +1346,25 @@ class TestArray < Test::Unit::TestCase
end
def test_uniq!
+ a = []
+ b = a.uniq!
+ assert_equal(nil, b)
+
+ a = [1]
+ b = a.uniq!
+ assert_equal(nil, b)
+
+ a = [1,1]
+ b = a.uniq!
+ assert_equal([1], a)
+ assert_equal([1], b)
+ assert_same(a, b)
+
+ a = [1,2]
+ b = a.uniq!
+ assert_equal([1,2], a)
+ assert_equal(nil, b)
+
a = @cls[ 1, 2, 3, 2, 1, 2, 3, 4, nil ]
assert_equal(@cls[1, 2, 3, 4, nil], a.uniq!)
assert_equal(@cls[1, 2, 3, 4, nil], a)