diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-07-20 08:39:12 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-07-20 08:39:12 +0000 |
commit | 0fbc72f5b4f699164907397fbfdebfd6fcf24130 (patch) | |
tree | 507dc795b1f2a1420947e6b6be193ad0bbd6c496 /test | |
parent | 3e1bf6c9c488dd5c6643a3371d4489d2ce8c9e65 (diff) | |
download | ruby-0fbc72f5b4f699164907397fbfdebfd6fcf24130.tar.gz |
enum.c: Enumerable#uniq
* enum.c (enum_uniq): new method Enumerable#uniq.
[Feature #11090]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55709 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_enum.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/test/ruby/test_enum.rb b/test/ruby/test_enum.rb index df75a80c50..d2403dd1a1 100644 --- a/test/ruby/test_enum.rb +++ b/test/ruby/test_enum.rb @@ -921,4 +921,19 @@ class TestEnumerable < Test::Unit::TestCase assert_int_equal(2, (2..2).sum) assert_int_equal(42, (2...2).sum(42)) end + + def test_uniq + src = [1, 1, 1, 1, 2, 2, 3, 4, 5, 6] + assert_equal([1, 2, 3, 4, 5, 6], src.uniq.to_a) + olimpics = { + 1896 => 'Athens', + 1900 => 'Paris', + 1904 => 'Chikago', + 1906 => 'Athens', + 1908 => 'Rome', + } + assert_equal([[1896, "Athens"], [1900, "Paris"], [1904, "Chikago"], [1908, "Rome"]], + olimpics.uniq{|k,v| v}) + assert_equal([1, 2, 3, 4, 5, 10], (1..100).uniq{|x| (x**2) % 10 }.first(6)) + end end |