* 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:
parent
6954ba398a
commit
d29143b99e
@ -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>
|
Sat Sep 7 19:23:56 2002 Akinori MUSHA <knu@iDaemons.org>
|
||||||
|
|
||||||
* lib/set.rb: Fix a bug in flatten()'s recursive set detection.
|
* lib/set.rb: Fix a bug in flatten()'s recursive set detection.
|
||||||
|
37
lib/set.rb
37
lib/set.rb
@ -188,10 +188,10 @@ class Set
|
|||||||
def initialize(enum = nil)
|
def initialize(enum = nil)
|
||||||
@hash = {}
|
@hash = {}
|
||||||
|
|
||||||
if enum
|
enum.nil? and return
|
||||||
enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable"
|
|
||||||
enum.each { |o| @hash[o] = true }
|
enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable"
|
||||||
end
|
enum.each { |o| @hash[o] = true }
|
||||||
end
|
end
|
||||||
|
|
||||||
def dup
|
def dup
|
||||||
@ -464,6 +464,9 @@ class TC_Set < Test::Unit::TestCase
|
|||||||
Set.new('a'..'c')
|
Set.new('a'..'c')
|
||||||
Set.new('XYZ')
|
Set.new('XYZ')
|
||||||
}
|
}
|
||||||
|
assert_raises(ArgumentError) {
|
||||||
|
Set.new(false)
|
||||||
|
}
|
||||||
assert_raises(ArgumentError) {
|
assert_raises(ArgumentError) {
|
||||||
Set.new(1)
|
Set.new(1)
|
||||||
}
|
}
|
||||||
@ -577,6 +580,23 @@ class TC_Set < Test::Unit::TestCase
|
|||||||
assert_raises(ArgumentError) {
|
assert_raises(ArgumentError) {
|
||||||
set1.flatten!
|
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
|
end
|
||||||
|
|
||||||
def test_include?
|
def test_include?
|
||||||
@ -726,6 +746,15 @@ class TC_Set < Test::Unit::TestCase
|
|||||||
assert_equal(set1, set1)
|
assert_equal(set1, set1)
|
||||||
assert_equal(set1, set2)
|
assert_equal(set1, set2)
|
||||||
assert_not_equal(Set[1], [1])
|
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
|
end
|
||||||
|
|
||||||
# def test_hash
|
# def test_hash
|
||||||
|
Loading…
x
Reference in New Issue
Block a user