aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_set.rb
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-06-15 05:37:38 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-06-15 05:37:38 +0000
commit9f2e41b7e0be219e1db219dbc31f4a0a8c892809 (patch)
tree345eba1b0bf5645074c92ab18619aaf526fea516 /test/test_set.rb
parentbab5bf0c79ba310eb2606c079315de417a3cccc9 (diff)
downloadruby-9f2e41b7e0be219e1db219dbc31f4a0a8c892809.tar.gz
* lib/set.rb: Make Set#each and SortedSet#each generate a sized
enumerator. [GH-931] by kachick (Kenichi Kamiya) * test/test_set.rb: Import tests from Set into SortedSet. [GH-931] by kachick (Kenichi Kamiya) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50908 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/test_set.rb')
-rw-r--r--test/test_set.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/test_set.rb b/test/test_set.rb
index e9867dd923..854bcc637b 100644
--- a/test/test_set.rb
+++ b/test/test_set.rb
@@ -364,6 +364,10 @@ class TC_Set < Test::Unit::TestCase
ary.empty? or raise "forgotten elements: #{ary.join(', ')}"
}
+
+ assert_equal(6, e.size)
+ set << 42
+ assert_equal(7, e.size)
end
def test_add
@@ -669,6 +673,29 @@ class TC_SortedSet < Test::Unit::TestCase
assert_equal(['four', 'one', 'three', 'two'], s.to_a)
assert_equal(['four', 'one', 'three', 'two'], a)
end
+
+ def test_each
+ ary = [1,3,5,7,10,20]
+ set = SortedSet.new(ary)
+
+ ret = set.each { |o| }
+ assert_same(set, ret)
+
+ e = set.each
+ assert_instance_of(Enumerator, e)
+
+ assert_nothing_raised {
+ set.each { |o|
+ ary.delete(o) or raise "unexpected element: #{o}"
+ }
+
+ ary.empty? or raise "forgotten elements: #{ary.join(', ')}"
+ }
+
+ assert_equal(6, e.size)
+ set << 42
+ assert_equal(7, e.size)
+ end
end
class TC_Enumerable < Test::Unit::TestCase