1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/set.rb: Disallow Set.new(false). Add even more tests.

[Submitted by: "Christoph" <chr_news@gmx.net>]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2814 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
knu 2002-09-07 10:48:14 +00:00
parent 6954ba398a
commit d29143b99e
2 changed files with 38 additions and 4 deletions

View file

@ -1,3 +1,8 @@
Sat Sep 7 19:46:57 2002 Akinori MUSHA <knu@iDaemons.org>
* lib/set.rb: Disallow Set.new(false). Add even more tests.
[Submitted by: "Christoph" <chr_news@gmx.net>]
Sat Sep 7 19:23:56 2002 Akinori MUSHA <knu@iDaemons.org>
* lib/set.rb: Fix a bug in flatten()'s recursive set detection.

View file

@ -188,10 +188,10 @@ class Set
def initialize(enum = nil)
@hash = {}
if enum
enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable"
enum.each { |o| @hash[o] = true }
end
enum.nil? and return
enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable"
enum.each { |o| @hash[o] = true }
end
def dup
@ -464,6 +464,9 @@ class TC_Set < Test::Unit::TestCase
Set.new('a'..'c')
Set.new('XYZ')
}
assert_raises(ArgumentError) {
Set.new(false)
}
assert_raises(ArgumentError) {
Set.new(1)
}
@ -577,6 +580,23 @@ class TC_Set < Test::Unit::TestCase
assert_raises(ArgumentError) {
set1.flatten!
}
# test5; miscellaneus
empty = Set[]
set = Set[Set[empty, "a"],Set[empty, "b"]]
assert_nothing_raised {
set.flatten
}
set1 = empty.merge(Set["no_more", set])
assert_nil(Set.new(0..31).flatten!)
x = Set[Set[],Set[1,2]].flatten!
y = Set[1,2]
assert_equal(x, y)
end
def test_include?
@ -726,6 +746,15 @@ class TC_Set < Test::Unit::TestCase
assert_equal(set1, set1)
assert_equal(set1, set2)
assert_not_equal(Set[1], [1])
set1 = Class.new(Set)["a", "b"]
set2 = Set["a", "b", set1]
set1 = set1.add(set1.clone)
assert_equal(set1, set2)
assert_equal(set2, set1)
assert_equal(set2, set2.clone)
assert_equal(set1.clone, set1)
end
# def test_hash