From 76977611dd68e384fdce8c546efda5e1931e67a6 Mon Sep 17 00:00:00 2001 From: knu Date: Sat, 5 Nov 2016 09:23:14 +0000 Subject: Add Set#compare_by_identity and Set#compare_by_identity? * lib/set.rb (Set#compare_by_identity, Set#compare_by_identity?): New methods. [Feature #12210] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56589 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/test_set.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test/test_set.rb') diff --git a/test/test_set.rb b/test/test_set.rb index 9439974fea..07c404ab79 100644 --- a/test/test_set.rb +++ b/test/test_set.rb @@ -715,6 +715,25 @@ class TC_Set < Test::Unit::TestCase set1.add(set2) assert_equal(true, set1.inspect.include?('#')) end + + def test_compare_by_identity + a1, a2 = "a", "a" + b1, b2 = "b", "b" + c = "c" + array = [a1, b1, c, a2, b2] + + iset = Set.new.compare_by_identity + assert_send([iset, :compare_by_identity?]) + iset.merge(array) + assert_equal(5, iset.size) + assert_equal(array.map(&:object_id).sort, iset.map(&:object_id).sort) + + set = Set.new + assert_not_send([set, :compare_by_identity?]) + set.merge(array) + assert_equal(3, set.size) + assert_equal(array.uniq.sort, set.sort) + end end class TC_SortedSet < Test::Unit::TestCase -- cgit v1.2.3