rubysl-set 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +0 -1
- data/.travis.yml +8 -0
- data/README.md +2 -2
- data/Rakefile +0 -1
- data/lib/rubysl/set.rb +2 -0
- data/lib/rubysl/set/set.rb +1237 -0
- data/lib/{rubysl-set → rubysl/set}/version.rb +1 -1
- data/lib/set.rb +1 -0
- data/rubysl-set.gemspec +19 -18
- data/spec/add_spec.rb +26 -0
- data/spec/append_spec.rb +6 -0
- data/spec/classify_spec.rb +34 -0
- data/spec/clear_spec.rb +16 -0
- data/spec/collect_spec.rb +6 -0
- data/spec/constructor_spec.rb +14 -0
- data/spec/delete_if_spec.rb +45 -0
- data/spec/delete_spec.rb +36 -0
- data/spec/difference_spec.rb +6 -0
- data/spec/divide_spec.rb +33 -0
- data/spec/each_spec.rb +33 -0
- data/spec/empty_spec.rb +9 -0
- data/spec/enumerable/to_set_spec.rb +18 -0
- data/spec/eql_spec.rb +16 -0
- data/spec/equal_value_spec.rb +37 -0
- data/spec/exclusion_spec.rb +17 -0
- data/spec/flatten_merge_spec.rb +22 -0
- data/spec/flatten_spec.rb +39 -0
- data/spec/hash_spec.rb +14 -0
- data/spec/include_spec.rb +6 -0
- data/spec/initialize_copy_spec.rb +17 -0
- data/spec/initialize_spec.rb +23 -0
- data/spec/inspect_spec.rb +17 -0
- data/spec/intersection_spec.rb +10 -0
- data/spec/keep_if_spec.rb +39 -0
- data/spec/length_spec.rb +6 -0
- data/spec/map_spec.rb +6 -0
- data/spec/member_spec.rb +6 -0
- data/spec/merge_spec.rb +18 -0
- data/spec/minus_spec.rb +6 -0
- data/spec/plus_spec.rb +6 -0
- data/spec/pretty_print_cycle_spec.rb +9 -0
- data/spec/pretty_print_spec.rb +16 -0
- data/spec/proper_subset_spec.rb +33 -0
- data/spec/proper_superset_spec.rb +33 -0
- data/spec/reject_spec.rb +49 -0
- data/spec/replace_spec.rb +16 -0
- data/spec/select_spec.rb +43 -0
- data/spec/shared/add.rb +14 -0
- data/spec/shared/collect.rb +20 -0
- data/spec/shared/difference.rb +15 -0
- data/spec/shared/include.rb +7 -0
- data/spec/shared/intersection.rb +15 -0
- data/spec/shared/length.rb +6 -0
- data/spec/shared/union.rb +15 -0
- data/spec/size_spec.rb +6 -0
- data/spec/sortedset/add_spec.rb +34 -0
- data/spec/sortedset/append_spec.rb +6 -0
- data/spec/sortedset/classify_spec.rb +34 -0
- data/spec/sortedset/clear_spec.rb +16 -0
- data/spec/sortedset/collect_spec.rb +6 -0
- data/spec/sortedset/constructor_spec.rb +14 -0
- data/spec/sortedset/delete_if_spec.rb +47 -0
- data/spec/sortedset/delete_spec.rb +36 -0
- data/spec/sortedset/difference_spec.rb +6 -0
- data/spec/sortedset/divide_spec.rb +33 -0
- data/spec/sortedset/each_spec.rb +35 -0
- data/spec/sortedset/empty_spec.rb +9 -0
- data/spec/sortedset/eql_spec.rb +17 -0
- data/spec/sortedset/equal_value_spec.rb +12 -0
- data/spec/sortedset/exclusion_spec.rb +17 -0
- data/spec/sortedset/flatten_merge_spec.rb +7 -0
- data/spec/sortedset/flatten_spec.rb +47 -0
- data/spec/sortedset/hash_spec.rb +14 -0
- data/spec/sortedset/include_spec.rb +6 -0
- data/spec/sortedset/initialize_copy_spec.rb +17 -0
- data/spec/sortedset/initialize_spec.rb +31 -0
- data/spec/sortedset/inspect_spec.rb +9 -0
- data/spec/sortedset/intersection_spec.rb +10 -0
- data/spec/sortedset/keep_if_spec.rb +32 -0
- data/spec/sortedset/length_spec.rb +6 -0
- data/spec/sortedset/map_spec.rb +6 -0
- data/spec/sortedset/member_spec.rb +6 -0
- data/spec/sortedset/merge_spec.rb +18 -0
- data/spec/sortedset/minus_spec.rb +6 -0
- data/spec/sortedset/plus_spec.rb +6 -0
- data/spec/sortedset/pretty_print_cycle_spec.rb +9 -0
- data/spec/sortedset/pretty_print_spec.rb +16 -0
- data/spec/sortedset/proper_subset_spec.rb +32 -0
- data/spec/sortedset/proper_superset_spec.rb +32 -0
- data/spec/sortedset/reject_spec.rb +51 -0
- data/spec/sortedset/replace_spec.rb +16 -0
- data/spec/sortedset/select_spec.rb +36 -0
- data/spec/sortedset/shared/add.rb +14 -0
- data/spec/sortedset/shared/collect.rb +20 -0
- data/spec/sortedset/shared/difference.rb +15 -0
- data/spec/sortedset/shared/include.rb +7 -0
- data/spec/sortedset/shared/intersection.rb +15 -0
- data/spec/sortedset/shared/length.rb +6 -0
- data/spec/sortedset/shared/union.rb +15 -0
- data/spec/sortedset/size_spec.rb +6 -0
- data/spec/sortedset/subset_spec.rb +32 -0
- data/spec/sortedset/subtract_spec.rb +16 -0
- data/spec/sortedset/superset_spec.rb +32 -0
- data/spec/sortedset/to_a_spec.rb +7 -0
- data/spec/sortedset/union_spec.rb +10 -0
- data/spec/subset_spec.rb +33 -0
- data/spec/subtract_spec.rb +16 -0
- data/spec/superset_spec.rb +33 -0
- data/spec/to_a_spec.rb +7 -0
- data/spec/union_spec.rb +10 -0
- metadata +282 -86
- data/lib/rubysl-set.rb +0 -7
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
3
|
+
describe "SortedSet#^" do
|
4
|
+
before :each do
|
5
|
+
@set = SortedSet[1, 2, 3, 4]
|
6
|
+
end
|
7
|
+
|
8
|
+
it "returns a new SortedSet containing elements that are not in both self and the passed Enumberable" do
|
9
|
+
(@set ^ SortedSet[3, 4, 5]).should == SortedSet[1, 2, 5]
|
10
|
+
(@set ^ [3, 4, 5]).should == SortedSet[1, 2, 5]
|
11
|
+
end
|
12
|
+
|
13
|
+
it "raises an ArgumentError when passed a non-Enumerable" do
|
14
|
+
lambda { @set ^ 3 }.should raise_error(ArgumentError)
|
15
|
+
lambda { @set ^ Object.new }.should raise_error(ArgumentError)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
3
|
+
# Note: Flatten make little sens on sorted sets, because SortedSets are not (by default)
|
4
|
+
# comparable. For a SortedSet to be both valid and nested, we need to define a comparison operator:
|
5
|
+
module SortedSet_FlattenSpecs
|
6
|
+
class ComparableSortedSet < SortedSet
|
7
|
+
def <=>(other)
|
8
|
+
return puts "#{other} vs #{self}" unless other.is_a?(ComparableSortedSet)
|
9
|
+
to_a <=> other.to_a
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "SortedSet#flatten" do
|
15
|
+
ruby_bug "http://redmine.ruby-lang.org/projects/ruby-18/issues/show?id=117", "1.8.7" do
|
16
|
+
it "returns a copy of self with each included SortedSet flattened" do
|
17
|
+
klass = SortedSet_FlattenSpecs::ComparableSortedSet
|
18
|
+
set = klass[klass[1,2], klass[3,4], klass[5,6,7], klass[8]]
|
19
|
+
flattened_set = set.flatten
|
20
|
+
|
21
|
+
flattened_set.should_not equal(set)
|
22
|
+
flattened_set.should == klass[1, 2, 3, 4, 5, 6, 7, 8]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "SortedSet#flatten!" do
|
28
|
+
ruby_bug "http://redmine.ruby-lang.org/projects/ruby-18/issues/show?id=117", "1.8.7" do
|
29
|
+
it "flattens self" do
|
30
|
+
klass = SortedSet_FlattenSpecs::ComparableSortedSet
|
31
|
+
set = klass[klass[1,2], klass[3,4], klass[5,6,7], klass[8]]
|
32
|
+
set.flatten!
|
33
|
+
set.should == klass[1, 2, 3, 4, 5, 6, 7, 8]
|
34
|
+
end
|
35
|
+
|
36
|
+
it "returns self when self was modified" do
|
37
|
+
klass = SortedSet_FlattenSpecs::ComparableSortedSet
|
38
|
+
set = klass[klass[1,2], klass[3,4]]
|
39
|
+
set.flatten!.should equal(set)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it "returns nil when self was not modified" do
|
44
|
+
set = SortedSet[1, 2, 3, 4]
|
45
|
+
set.flatten!.should be_nil
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
3
|
+
ruby_version_is "1.8.7" do
|
4
|
+
describe "SortedSet#hash" do
|
5
|
+
it "is static" do
|
6
|
+
SortedSet[].hash.should == SortedSet[].hash
|
7
|
+
SortedSet[1, 2, 3].hash.should == SortedSet[1, 2, 3].hash
|
8
|
+
SortedSet["a", "b", "c"].hash.should == SortedSet["c", "b", "a"].hash
|
9
|
+
|
10
|
+
SortedSet[].hash.should_not == SortedSet[1, 2, 3].hash
|
11
|
+
SortedSet[1, 2, 3].hash.should_not == SortedSet["a", "b", "c"].hash
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
3
|
+
describe "SortedSet#initialize_copy" do
|
4
|
+
before(:each) do
|
5
|
+
@set = SortedSet[1, 2, 3]
|
6
|
+
end
|
7
|
+
|
8
|
+
it "is private" do
|
9
|
+
Set.should have_private_instance_method(:initialize_copy)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "replaces all elements of self with the elements of the passed SortedSet" do
|
13
|
+
other = SortedSet["1", "2", "3"]
|
14
|
+
@set.send(:initialize_copy, other)
|
15
|
+
@set.should == SortedSet["1", "2", "3"]
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
3
|
+
describe "SortedSet#initialize" do
|
4
|
+
it "is private" do
|
5
|
+
SortedSet.should have_private_instance_method("initialize")
|
6
|
+
end
|
7
|
+
|
8
|
+
it "adds all elements of the passed Enumerable to self" do
|
9
|
+
s = SortedSet.new([1, 2, 3])
|
10
|
+
s.size.should eql(3)
|
11
|
+
s.should include(1)
|
12
|
+
s.should include(2)
|
13
|
+
s.should include(3)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "preprocesses all elements by a passed block before adding to self" do
|
17
|
+
s = SortedSet.new([1, 2, 3]) { |x| x * x }
|
18
|
+
s.size.should eql(3)
|
19
|
+
s.should include(1)
|
20
|
+
s.should include(4)
|
21
|
+
s.should include(9)
|
22
|
+
end
|
23
|
+
|
24
|
+
ruby_version_is ""..."1.9" do
|
25
|
+
ruby_bug "redmine #118", "1.8.7" do
|
26
|
+
it "takes only values which respond to <=>" do
|
27
|
+
lambda { SortedSet[3, 4, SortedSet[5, 6]] }.should raise_error(ArgumentError)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
3
|
+
describe "SortedSet#inspect" do
|
4
|
+
it "returns a String representation of self" do
|
5
|
+
SortedSet[].inspect.should be_kind_of(String)
|
6
|
+
SortedSet[1, 2, 3].inspect.should be_kind_of(String)
|
7
|
+
SortedSet["1", "2", "3"].inspect.should be_kind_of(String)
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require File.expand_path('../shared/intersection', __FILE__)
|
2
|
+
require 'set'
|
3
|
+
|
4
|
+
describe "SortedSet#intersection" do
|
5
|
+
it_behaves_like :sorted_set_intersection, :intersection
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "SortedSet#&" do
|
9
|
+
it_behaves_like :sorted_set_intersection, :&
|
10
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
3
|
+
ruby_version_is "1.9" do
|
4
|
+
describe "SortedSet#keep_if" do
|
5
|
+
before(:each) do
|
6
|
+
@set = SortedSet["one", "two", "three"]
|
7
|
+
end
|
8
|
+
|
9
|
+
it "yields each Object in self in sorted order" do
|
10
|
+
ret = []
|
11
|
+
@set.keep_if { |x| ret << x }
|
12
|
+
ret.should == ["one", "two", "three"].sort
|
13
|
+
end
|
14
|
+
|
15
|
+
it "keeps every element from self for which the passed block returns true" do
|
16
|
+
@set.keep_if { |x| x.size != 3 }
|
17
|
+
@set.to_a.should == ["three"]
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns self" do
|
21
|
+
@set.keep_if {}.should equal(@set)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns an Enumerator when passed no block" do
|
25
|
+
enum = @set.keep_if
|
26
|
+
enum.should be_an_instance_of(enumerator_class)
|
27
|
+
|
28
|
+
enum.each { |x| x.size != 3 }
|
29
|
+
@set.to_a.should == ["three"]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
3
|
+
describe "SortedSet#merge" do
|
4
|
+
it "adds the elements of the passed Enumerable to self" do
|
5
|
+
SortedSet["a", "b"].merge(SortedSet["b", "c", "d"]).should == SortedSet["a", "b", "c", "d"]
|
6
|
+
SortedSet[1, 2].merge([3, 4]).should == SortedSet[1, 2, 3, 4]
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns self" do
|
10
|
+
set = SortedSet[1, 2]
|
11
|
+
set.merge([3, 4]).should equal(set)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "raises an ArgumentError when passed a non-Enumerable" do
|
15
|
+
lambda { SortedSet[1, 2].merge(1) }.should raise_error(ArgumentError)
|
16
|
+
lambda { SortedSet[1, 2].merge(Object.new) }.should raise_error(ArgumentError)
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
3
|
+
describe "SortedSet#pretty_print_cycle" do
|
4
|
+
it "passes the 'pretty print' representation of a self-referencing SortedSet to the pretty print writer" do
|
5
|
+
pp = mock("PrettyPrint")
|
6
|
+
pp.should_receive(:text).with("#<SortedSet: {...}>")
|
7
|
+
SortedSet[1, 2, 3].pretty_print_cycle(pp)
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
3
|
+
describe "SortedSet#pretty_print" do
|
4
|
+
it "passes the 'pretty print' representation of self to the pretty print writer" do
|
5
|
+
pp = mock("PrettyPrint")
|
6
|
+
set = SortedSet[1, 2, 3]
|
7
|
+
|
8
|
+
pp.should_receive(:text).with("#<SortedSet: {")
|
9
|
+
pp.should_receive(:text).with("}>")
|
10
|
+
|
11
|
+
pp.should_receive(:nest).with(1).and_yield
|
12
|
+
pp.should_receive(:seplist).with(set)
|
13
|
+
|
14
|
+
set.pretty_print(pp)
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
3
|
+
describe "SortedSet#proper_subset?" do
|
4
|
+
before(:each) do
|
5
|
+
@set = SortedSet[1, 2, 3, 4]
|
6
|
+
end
|
7
|
+
|
8
|
+
it "returns true if passed a SortedSet that self is a proper subset of" do
|
9
|
+
SortedSet[].proper_subset?(@set).should be_true
|
10
|
+
SortedSet[].proper_subset?(SortedSet[1, 2, 3]).should be_true
|
11
|
+
SortedSet[].proper_subset?(SortedSet["a", "b", "c"]).should be_true
|
12
|
+
|
13
|
+
SortedSet[1, 2, 3].proper_subset?(@set).should be_true
|
14
|
+
SortedSet[1, 3].proper_subset?(@set).should be_true
|
15
|
+
SortedSet[1, 2].proper_subset?(@set).should be_true
|
16
|
+
SortedSet[1].proper_subset?(@set).should be_true
|
17
|
+
|
18
|
+
SortedSet[5].proper_subset?(@set).should be_false
|
19
|
+
SortedSet[1, 5].proper_subset?(@set).should be_false
|
20
|
+
SortedSet["test"].proper_subset?(@set).should be_false
|
21
|
+
|
22
|
+
@set.proper_subset?(@set).should be_false
|
23
|
+
SortedSet[].proper_subset?(SortedSet[]).should be_false
|
24
|
+
end
|
25
|
+
|
26
|
+
it "raises an ArgumentError when passed a non-SortedSet" do
|
27
|
+
lambda { SortedSet[].proper_subset?([]) }.should raise_error(ArgumentError)
|
28
|
+
lambda { SortedSet[].proper_subset?(1) }.should raise_error(ArgumentError)
|
29
|
+
lambda { SortedSet[].proper_subset?("test") }.should raise_error(ArgumentError)
|
30
|
+
lambda { SortedSet[].proper_subset?(Object.new) }.should raise_error(ArgumentError)
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
3
|
+
describe "SortedSet#proper_superset?" do
|
4
|
+
before(:each) do
|
5
|
+
@set = SortedSet[1, 2, 3, 4]
|
6
|
+
end
|
7
|
+
|
8
|
+
it "returns true if passed a SortedSet that self is a proper superset of" do
|
9
|
+
@set.proper_superset?(SortedSet[]).should be_true
|
10
|
+
SortedSet[1, 2, 3].proper_superset?(SortedSet[]).should be_true
|
11
|
+
SortedSet["a", "b", "c"].proper_superset?(SortedSet[]).should be_true
|
12
|
+
|
13
|
+
@set.proper_superset?(SortedSet[1, 2, 3]).should be_true
|
14
|
+
@set.proper_superset?(SortedSet[1, 3]).should be_true
|
15
|
+
@set.proper_superset?(SortedSet[1, 2]).should be_true
|
16
|
+
@set.proper_superset?(SortedSet[1]).should be_true
|
17
|
+
|
18
|
+
@set.proper_superset?(SortedSet[5]).should be_false
|
19
|
+
@set.proper_superset?(SortedSet[1, 5]).should be_false
|
20
|
+
@set.proper_superset?(SortedSet["test"]).should be_false
|
21
|
+
|
22
|
+
@set.proper_superset?(@set).should be_false
|
23
|
+
SortedSet[].proper_superset?(SortedSet[]).should be_false
|
24
|
+
end
|
25
|
+
|
26
|
+
it "raises an ArgumentError when passed a non-SortedSet" do
|
27
|
+
lambda { SortedSet[].proper_superset?([]) }.should raise_error(ArgumentError)
|
28
|
+
lambda { SortedSet[].proper_superset?(1) }.should raise_error(ArgumentError)
|
29
|
+
lambda { SortedSet[].proper_superset?("test") }.should raise_error(ArgumentError)
|
30
|
+
lambda { SortedSet[].proper_superset?(Object.new) }.should raise_error(ArgumentError)
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
3
|
+
describe "SortedSet#reject!" do
|
4
|
+
before(:each) do
|
5
|
+
@set = SortedSet["one", "two", "three"]
|
6
|
+
end
|
7
|
+
|
8
|
+
ruby_bug "http://redmine.ruby-lang.org/issues/show/115", "1.8.7.7" do
|
9
|
+
it "yields each Object in self in sorted order" do
|
10
|
+
res = []
|
11
|
+
@set.reject! { |x| res << x }
|
12
|
+
res.should == ["one", "two", "three"].sort
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it "deletes every element from self for which the passed block returns true" do
|
17
|
+
@set.reject! { |x| x.size == 3 }
|
18
|
+
@set.size.should eql(1)
|
19
|
+
|
20
|
+
@set.should_not include("one")
|
21
|
+
@set.should_not include("two")
|
22
|
+
@set.should include("three")
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns self when self was modified" do
|
26
|
+
@set.reject! { |x| true }.should equal(@set)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns nil when self was not modified" do
|
30
|
+
@set.reject! { |x| false }.should be_nil
|
31
|
+
end
|
32
|
+
|
33
|
+
ruby_version_is "" ... "1.8.8" do
|
34
|
+
it "raises a LocalJumpError when passed no block" do
|
35
|
+
lambda { @set.reject! }.should raise_error(LocalJumpError)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
ruby_version_is "1.8.8" do
|
40
|
+
it "returns an Enumerator when passed no block" do
|
41
|
+
enum = @set.reject!
|
42
|
+
enum.should be_an_instance_of(enumerator_class)
|
43
|
+
|
44
|
+
enum.each { |x| x.size == 3 }
|
45
|
+
|
46
|
+
@set.should_not include("one")
|
47
|
+
@set.should_not include("two")
|
48
|
+
@set.should include("three")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
3
|
+
describe "SortedSet#replace" do
|
4
|
+
before :each do
|
5
|
+
@set = SortedSet["a", "b", "c"]
|
6
|
+
end
|
7
|
+
|
8
|
+
it "replaces the contents with other and returns self" do
|
9
|
+
@set.replace(SortedSet[1, 2, 3]).should == @set
|
10
|
+
@set.should == SortedSet[1, 2, 3]
|
11
|
+
end
|
12
|
+
|
13
|
+
it "accepts any enumerable as other" do
|
14
|
+
@set.replace([1, 2, 3]).should == SortedSet[1, 2, 3]
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
3
|
+
ruby_version_is "1.9" do
|
4
|
+
describe "SortedSet#select!" do
|
5
|
+
before(:each) do
|
6
|
+
@set = SortedSet["one", "two", "three"]
|
7
|
+
end
|
8
|
+
|
9
|
+
it "yields each Object in self in sorted order" do
|
10
|
+
res = []
|
11
|
+
@set.select! { |x| res << x }
|
12
|
+
res.should == ["one", "two", "three"].sort
|
13
|
+
end
|
14
|
+
|
15
|
+
it "keeps every element from self for which the passed block returns true" do
|
16
|
+
@set.select! { |x| x.size != 3 }
|
17
|
+
@set.to_a.should == ["three"]
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns self when self was modified" do
|
21
|
+
@set.select! { false }.should equal(@set)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns nil when self was not modified" do
|
25
|
+
@set.select! { true }.should be_nil
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns an Enumerator when passed no block" do
|
29
|
+
enum = @set.select!
|
30
|
+
enum.should be_an_instance_of(enumerator_class)
|
31
|
+
|
32
|
+
enum.each { |x| x.size != 3 }
|
33
|
+
@set.to_a.should == ["three"]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|