Project

General

Profile

Bug #12072 ยป 0001-set-fix-SortedSet-superset-with-rbtree.patch

rhenium (Kazuki Yamaguchi), 02/14/2016 03:13 PM

View differences:

lib/set.rb
# Returns true if the set is a superset of the given set.
def superset?(set)
case
when set.instance_of?(self.class)
when set.instance_of?(self.class) && @hash.respond_to?(:>=)
@hash >= set.instance_variable_get(:@hash)
when set.is_a?(Set)
size >= set.size && set.all? { |o| include?(o) }
......
# Returns true if the set is a proper superset of the given set.
def proper_superset?(set)
case
when set.instance_of?(self.class)
when set.instance_of?(self.class) && @hash.respond_to?(:>)
@hash > set.instance_variable_get(:@hash)
when set.is_a?(Set)
size > set.size && set.all? { |o| include?(o) }
......
# Returns true if the set is a subset of the given set.
def subset?(set)
case
when set.instance_of?(self.class)
when set.instance_of?(self.class) && @hash.respond_to?(:<=)
@hash <= set.instance_variable_get(:@hash)
when set.is_a?(Set)
size <= set.size && all? { |o| set.include?(o) }
......
# Returns true if the set is a proper subset of the given set.
def proper_subset?(set)
case
when set.instance_of?(self.class)
when set.instance_of?(self.class) && @hash.respond_to?(:<)
@hash < set.instance_variable_get(:@hash)
when set.is_a?(Set)
size < set.size && all? { |o| set.include?(o) }
test/test_set.rb
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
    (1-1/1)