summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-11-05 09:23:14 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-11-05 09:23:14 +0000
commit76977611dd68e384fdce8c546efda5e1931e67a6 (patch)
tree7a5669bc570cc54e8fed7c32b1e11b268af2f043 /test
parentcb3b7fc0e2c1193c45c9c64497e7ff0218f7b54b (diff)
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
Diffstat (limited to 'test')
-rw-r--r--test/test_set.rb19
1 files changed, 19 insertions, 0 deletions
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?('#<Set: {...}>'))
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