aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_set.rb
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2016-02-14 23:47:39 +0900
committerKazuki Yamaguchi <k@rhe.jp>2016-03-18 14:53:55 +0900
commitf2ece415562cf8525241464c6ff50e3dff6b1c80 (patch)
tree952935685e54075962e9f6f4ad52f61ae6bae15f /test/test_set.rb
parent7e81ca14feaff4db75feaa1556dff64cbe30d7df (diff)
downloadruby-fix/set-sortedset-comparison.tar.gz
set: fix SortedSet#superset? with rbtreefix/set-sortedset-comparison
* lib/set.rb (Set#{<,<=,>,>=}): check if the internal @hash has <,<=,>,>= operators. In SortedSet, @hash may be a RBTree, which doesn't have them.
Diffstat (limited to 'test/test_set.rb')
-rw-r--r--test/test_set.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/test_set.rb b/test/test_set.rb
index 15c5a13d21..2adbadddcf 100644
--- a/test/test_set.rb
+++ b/test/test_set.rb
@@ -708,6 +708,26 @@ class TC_SortedSet < Test::Unit::TestCase
set << 42
assert_equal(7, e.size)
end
+
+ def test_superset
+ set = SortedSet.new([1,2,3])
+
+ assert_equal(false, set.superset?(Set.new([1,2,3,4])))
+ assert_equal(true, set >= SortedSet.new([1,2,3]))
+
+ assert_equal(false, set.proper_superset?(Set.new([1,2,3,4])))
+ assert_equal(false, set > SortedSet.new([1,2,3]))
+ end
+
+ def test_subset
+ set = SortedSet.new([1,2,3])
+
+ assert_equal(true, set.subset?(Set.new([1,2,3,4])))
+ assert_equal(true, set <= SortedSet.new([1,2,3]))
+
+ assert_equal(true, set.proper_subset?(Set.new([1,2,3,4])))
+ assert_equal(false, set < SortedSet.new([1,2,3]))
+ end
end
class TC_Enumerable < Test::Unit::TestCase