1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/spec/ruby/library/set/flatten_spec.rb
eregon 1d15d5f080 Move spec/rubyspec to spec/ruby for consistency
* Other ruby implementations use the spec/ruby directory.
  [Misc #13792] [ruby-core:82287]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-20 20:18:52 +00:00

40 lines
1.1 KiB
Ruby

require File.expand_path('../../../spec_helper', __FILE__)
require 'set'
describe "Set#flatten" do
it "returns a copy of self with each included Set flattened" do
set = Set[1, 2, Set[3, 4, Set[5, 6, Set[7, 8]]], 9, 10]
flattened_set = set.flatten
flattened_set.should_not equal(set)
flattened_set.should == Set[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
end
it "raises an ArgumentError when self is recursive" do
(set = Set[]) << set
lambda { set.flatten }.should raise_error(ArgumentError)
end
end
describe "Set#flatten!" do
it "flattens self" do
set = Set[1, 2, Set[3, 4, Set[5, 6, Set[7, 8]]], 9, 10]
set.flatten!
set.should == Set[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
end
it "returns self when self was modified" do
set = Set[1, 2, Set[3, 4]]
set.flatten!.should equal(set)
end
it "returns nil when self was not modified" do
set = Set[1, 2, 3, 4]
set.flatten!.should be_nil
end
it "raises an ArgumentError when self is recursive" do
(set = Set[]) << set
lambda { set.flatten! }.should raise_error(ArgumentError)
end
end