hamster 1.0.1.pre.rc.1 → 1.0.1.pre.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hamster/groupable.rb +12 -0
- data/lib/hamster/hash.rb +32 -12
- data/lib/hamster/list.rb +68 -22
- data/lib/hamster/queue.rb +5 -6
- data/lib/hamster/set.rb +50 -14
- data/lib/hamster/stack.rb +2 -0
- data/lib/hamster/trie.rb +34 -14
- data/lib/hamster/tuple.rb +9 -24
- data/lib/hamster/vector.rb +29 -7
- data/lib/hamster/version.rb +1 -1
- data/spec/hamster/core_ext/array_spec.rb +4 -10
- data/spec/hamster/core_ext/enumerable_spec.rb +1 -0
- data/spec/hamster/experimental/mutable_set/add_qm_spec.rb +14 -22
- data/spec/hamster/experimental/mutable_set/add_spec.rb +20 -34
- data/spec/hamster/experimental/mutable_set/delete_qm_spec.rb +15 -24
- data/spec/hamster/experimental/mutable_set/delete_spec.rb +15 -25
- data/spec/hamster/experimental/mutable_stack/pop_spec.rb +21 -27
- data/spec/hamster/experimental/mutable_stack/push_spec.rb +11 -31
- data/spec/hamster/hash/all_spec.rb +21 -34
- data/spec/hamster/hash/any_spec.rb +0 -15
- data/spec/hamster/hash/clear_spec.rb +1 -8
- data/spec/hamster/hash/construction_spec.rb +3 -11
- data/spec/hamster/hash/copying_spec.rb +1 -8
- data/spec/hamster/hash/delete_spec.rb +1 -10
- data/spec/hamster/hash/each_spec.rb +1 -12
- data/spec/hamster/hash/empty_spec.rb +8 -8
- data/spec/hamster/hash/eql_spec.rb +30 -22
- data/spec/hamster/hash/except_spec.rb +1 -10
- data/spec/hamster/hash/fetch_spec.rb +1 -24
- data/spec/hamster/hash/filter_spec.rb +1 -16
- data/spec/hamster/hash/find_spec.rb +1 -14
- data/spec/hamster/hash/has_key_spec.rb +1 -10
- data/spec/hamster/hash/hash_spec.rb +1 -16
- data/spec/hamster/hash/immutable_spec.rb +0 -3
- data/spec/hamster/hash/inspect_spec.rb +1 -9
- data/spec/hamster/hash/keys_spec.rb +4 -5
- data/spec/hamster/hash/map_spec.rb +1 -16
- data/spec/hamster/hash/merge_spec.rb +5 -11
- data/spec/hamster/hash/new_spec.rb +21 -0
- data/spec/hamster/hash/put_spec.rb +13 -11
- data/spec/hamster/hash/reduce_spec.rb +7 -15
- data/spec/hamster/hash/remove_spec.rb +1 -16
- data/spec/hamster/hash/uniq_spec.rb +1 -8
- data/spec/hamster/hash/values_spec.rb +1 -6
- data/spec/hamster/immutable/copying_spec.rb +1 -8
- data/spec/hamster/immutable/immutable_spec.rb +1 -14
- data/spec/hamster/immutable/memoize_spec.rb +0 -1
- data/spec/hamster/list/add_spec.rb +1 -6
- data/spec/hamster/list/all_spec.rb +1 -28
- data/spec/hamster/list/any_spec.rb +1 -20
- data/spec/hamster/list/append_spec.rb +1 -11
- data/spec/hamster/list/at_spec.rb +1 -13
- data/spec/hamster/list/break_spec.rb +1 -13
- data/spec/hamster/list/cadr_spec.rb +1 -9
- data/spec/hamster/list/chunk_spec.rb +1 -9
- data/spec/hamster/list/clear_spec.rb +1 -9
- data/spec/hamster/list/combinations_spec.rb +1 -11
- data/spec/hamster/list/compact_spec.rb +1 -9
- data/spec/hamster/list/cons_spec.rb +1 -10
- data/spec/hamster/list/construction_spec.rb +1 -30
- data/spec/hamster/list/copying_spec.rb +1 -9
- data/spec/hamster/list/count_spec.rb +1 -15
- data/spec/hamster/list/cycle_spec.rb +1 -10
- data/spec/hamster/list/drop_spec.rb +1 -9
- data/spec/hamster/list/drop_while_spec.rb +1 -13
- data/spec/hamster/list/each_slice_spec.rb +1 -17
- data/spec/hamster/list/each_spec.rb +1 -17
- data/spec/hamster/list/each_with_index_spec.rb +1 -10
- data/spec/hamster/list/elem_index_spec.rb +1 -13
- data/spec/hamster/list/elem_indices_spec.rb +1 -11
- data/spec/hamster/list/empty_spec.rb +1 -13
- data/spec/hamster/list/eql_spec.rb +52 -62
- data/spec/hamster/list/find_index_spec.rb +1 -13
- data/spec/hamster/list/find_indices_spec.rb +1 -11
- data/spec/hamster/list/find_spec.rb +1 -17
- data/spec/hamster/list/flatten_spec.rb +1 -9
- data/spec/hamster/list/grep_spec.rb +1 -16
- data/spec/hamster/list/group_by_spec.rb +1 -20
- data/spec/hamster/list/head_spec.rb +1 -11
- data/spec/hamster/list/include_spec.rb +1 -13
- data/spec/hamster/list/init_spec.rb +1 -8
- data/spec/hamster/list/inits_spec.rb +1 -9
- data/spec/hamster/list/inspect_spec.rb +1 -11
- data/spec/hamster/list/intersperse_spec.rb +1 -9
- data/spec/hamster/list/join_spec.rb +1 -18
- data/spec/hamster/list/last_spec.rb +1 -11
- data/spec/hamster/list/map_spec.rb +1 -15
- data/spec/hamster/list/maximum_spec.rb +1 -20
- data/spec/hamster/list/merge_by_spec.rb +1 -19
- data/spec/hamster/list/merge_spec.rb +1 -20
- data/spec/hamster/list/minimum_spec.rb +1 -20
- data/spec/hamster/list/none_spec.rb +1 -18
- data/spec/hamster/list/one_spec.rb +1 -16
- data/spec/hamster/list/partition_spec.rb +1 -13
- data/spec/hamster/list/product_spec.rb +1 -11
- data/spec/hamster/list/reduce_spec.rb +0 -1
- data/spec/hamster/list/remove_spec.rb +1 -15
- data/spec/hamster/list/reverse_spec.rb +1 -11
- data/spec/hamster/list/size_spec.rb +1 -13
- data/spec/hamster/list/slice_spec.rb +1 -11
- data/spec/hamster/list/sorting_spec.rb +1 -14
- data/spec/hamster/list/span_spec.rb +1 -12
- data/spec/hamster/list/split_at_spec.rb +1 -9
- data/spec/hamster/list/sum_spec.rb +1 -11
- data/spec/hamster/list/tail_spec.rb +1 -11
- data/spec/hamster/list/tails_spec.rb +1 -9
- data/spec/hamster/list/take_spec.rb +1 -9
- data/spec/hamster/list/take_while_spec.rb +0 -1
- data/spec/hamster/list/to_a_spec.rb +1 -13
- data/spec/hamster/list/to_ary_spec.rb +0 -1
- data/spec/hamster/list/to_list_spec.rb +1 -9
- data/spec/hamster/list/to_set_spec.rb +2 -8
- data/spec/hamster/list/union_spec.rb +1 -11
- data/spec/hamster/list/uniq_spec.rb +1 -11
- data/spec/hamster/queue/clear_spec.rb +1 -9
- data/spec/hamster/queue/construction_spec.rb +1 -10
- data/spec/hamster/queue/dequeue_spec.rb +1 -11
- data/spec/hamster/queue/empty_spec.rb +1 -13
- data/spec/hamster/queue/enqueue_spec.rb +1 -11
- data/spec/hamster/queue/head_spec.rb +1 -11
- data/spec/hamster/queue/inspect_spec.rb +1 -9
- data/spec/hamster/queue/size_spec.rb +1 -11
- data/spec/hamster/queue/to_a_spec.rb +1 -11
- data/spec/hamster/queue/to_list_spec.rb +1 -11
- data/spec/hamster/set/add_spec.rb +1 -12
- data/spec/hamster/set/all_spec.rb +1 -18
- data/spec/hamster/set/any_spec.rb +1 -17
- data/spec/hamster/set/clear_spec.rb +9 -8
- data/spec/hamster/set/compact_spec.rb +1 -9
- data/spec/hamster/set/construction_spec.rb +1 -9
- data/spec/hamster/set/copying_spec.rb +1 -8
- data/spec/hamster/set/count_spec.rb +1 -13
- data/spec/hamster/set/delete_spec.rb +1 -10
- data/spec/hamster/set/difference_spec.rb +1 -11
- data/spec/hamster/set/empty_spec.rb +1 -11
- data/spec/hamster/set/exclusion_spec.rb +1 -11
- data/spec/hamster/set/filter_spec.rb +10 -17
- data/spec/hamster/set/find_spec.rb +1 -14
- data/spec/hamster/set/flatten_spec.rb +8 -10
- data/spec/hamster/set/group_by_spec.rb +8 -17
- data/spec/hamster/set/head_spec.rb +1 -12
- data/spec/hamster/set/immutable_spec.rb +1 -4
- data/spec/hamster/set/include_spec.rb +1 -9
- data/spec/hamster/set/inspect_spec.rb +1 -9
- data/spec/hamster/set/intersection_spec.rb +1 -11
- data/spec/hamster/set/join_spec.rb +1 -16
- data/spec/hamster/set/map_spec.rb +1 -16
- data/spec/hamster/set/marshal_spec.rb +1 -6
- data/spec/hamster/set/maximum_spec.rb +1 -18
- data/spec/hamster/set/minimum_spec.rb +1 -17
- data/spec/hamster/set/new_spec.rb +21 -0
- data/spec/hamster/set/none_spec.rb +1 -16
- data/spec/hamster/set/one_spec.rb +1 -14
- data/spec/hamster/set/partition_spec.rb +1 -13
- data/spec/hamster/set/product_spec.rb +1 -9
- data/spec/hamster/set/reduce_spec.rb +1 -26
- data/spec/hamster/set/remove_spec.rb +1 -16
- data/spec/hamster/set/size_spec.rb +1 -9
- data/spec/hamster/set/sorting_spec.rb +1 -3
- data/spec/hamster/set/subset_spec.rb +1 -9
- data/spec/hamster/set/sum_spec.rb +1 -9
- data/spec/hamster/set/superset_spec.rb +1 -9
- data/spec/hamster/set/to_a_spec.rb +1 -11
- data/spec/hamster/set/to_list_spec.rb +1 -11
- data/spec/hamster/set/to_set_spec.rb +1 -9
- data/spec/hamster/set/union_spec.rb +1 -11
- data/spec/hamster/set/uniq_spec.rb +1 -7
- data/spec/hamster/sorter/immutable_spec.rb +1 -4
- data/spec/hamster/stack/clear_spec.rb +1 -9
- data/spec/hamster/stack/construction_spec.rb +1 -10
- data/spec/hamster/stack/copying_spec.rb +1 -9
- data/spec/hamster/stack/empty_spec.rb +1 -9
- data/spec/hamster/stack/eql_spec.rb +1 -13
- data/spec/hamster/stack/immutable_spec.rb +1 -4
- data/spec/hamster/stack/inspect_spec.rb +1 -9
- data/spec/hamster/stack/peek_spec.rb +1 -11
- data/spec/hamster/stack/pop_spec.rb +1 -11
- data/spec/hamster/stack/push_spec.rb +1 -11
- data/spec/hamster/stack/size_spec.rb +1 -11
- data/spec/hamster/stack/to_a_spec.rb +1 -11
- data/spec/hamster/stack/to_list_spec.rb +1 -9
- data/spec/hamster/tuple/construction_spec.rb +30 -0
- data/spec/hamster/tuple/copying_spec.rb +1 -8
- data/spec/hamster/tuple/eql_spec.rb +57 -40
- data/spec/hamster/tuple/first_spec.rb +1 -6
- data/spec/hamster/tuple/immutable_spec.rb +1 -4
- data/spec/hamster/tuple/inspect_spec.rb +1 -6
- data/spec/hamster/tuple/last_spec.rb +1 -6
- data/spec/hamster/tuple/to_a_spec.rb +1 -9
- data/spec/hamster/tuple/to_ary_spec.rb +0 -1
- data/spec/hamster/undefined/erase_spec.rb +1 -12
- data/spec/hamster/vector/add_spec.rb +8 -0
- data/spec/hamster/vector/clear_spec.rb +1 -8
- data/spec/hamster/vector/copying_spec.rb +1 -8
- data/spec/hamster/vector/each_spec.rb +1 -11
- data/spec/hamster/vector/each_with_index_spec.rb +1 -9
- data/spec/hamster/vector/empty_spec.rb +7 -9
- data/spec/hamster/vector/eql_spec.rb +1 -12
- data/spec/hamster/vector/filter_spec.rb +8 -12
- data/spec/hamster/vector/first_spec.rb +1 -11
- data/spec/hamster/vector/get_spec.rb +1 -23
- data/spec/hamster/vector/include_spec.rb +1 -10
- data/spec/hamster/vector/map_spec.rb +8 -14
- data/spec/hamster/vector/new_spec.rb +48 -0
- data/spec/hamster/vector/reduce_spec.rb +1 -26
- data/spec/hamster/vector/set_spec.rb +8 -0
- data/spec/spec_helper.rb +0 -5
- metadata +35 -68
@@ -1,15 +1,10 @@
|
|
1
1
|
require "spec_helper"
|
2
|
-
|
3
2
|
require "hamster/set"
|
4
3
|
|
5
4
|
describe Hamster::Set do
|
6
|
-
|
7
5
|
[:maximum, :max].each do |method|
|
8
|
-
|
9
6
|
describe "##{method}" do
|
10
|
-
|
11
7
|
describe "with a block" do
|
12
|
-
|
13
8
|
[
|
14
9
|
[[], nil],
|
15
10
|
[["A"], "A"],
|
@@ -17,7 +12,6 @@ describe Hamster::Set do
|
|
17
12
|
].each do |values, expected|
|
18
13
|
|
19
14
|
describe "on #{values.inspect}" do
|
20
|
-
|
21
15
|
before do
|
22
16
|
original = Hamster.set(*values)
|
23
17
|
@result = original.send(method) { |maximum, item| item.length <=> maximum.length }
|
@@ -26,15 +20,11 @@ describe Hamster::Set do
|
|
26
20
|
it "returns #{expected.inspect}" do
|
27
21
|
@result.should == expected
|
28
22
|
end
|
29
|
-
|
30
23
|
end
|
31
|
-
|
32
24
|
end
|
33
|
-
|
34
25
|
end
|
35
26
|
|
36
27
|
describe "without a block" do
|
37
|
-
|
38
28
|
[
|
39
29
|
[[], nil],
|
40
30
|
[["A"], "A"],
|
@@ -42,7 +32,6 @@ describe Hamster::Set do
|
|
42
32
|
].each do |values, expected|
|
43
33
|
|
44
34
|
describe "on #{values.inspect}" do
|
45
|
-
|
46
35
|
before do
|
47
36
|
original = Hamster.set(*values)
|
48
37
|
@result = original.send(method)
|
@@ -51,15 +40,9 @@ describe Hamster::Set do
|
|
51
40
|
it "returns #{expected.inspect}" do
|
52
41
|
@result.should == expected
|
53
42
|
end
|
54
|
-
|
55
43
|
end
|
56
|
-
|
57
44
|
end
|
58
|
-
|
59
45
|
end
|
60
|
-
|
61
46
|
end
|
62
|
-
|
63
47
|
end
|
64
|
-
|
65
|
-
end
|
48
|
+
end
|
@@ -1,13 +1,9 @@
|
|
1
1
|
require "spec_helper"
|
2
|
-
|
3
2
|
require "hamster/set"
|
4
3
|
|
5
4
|
describe Hamster::Set do
|
6
|
-
|
7
5
|
[:minimum, :min].each do |method|
|
8
|
-
|
9
6
|
describe "##{method}" do
|
10
|
-
|
11
7
|
describe "with a block" do
|
12
8
|
|
13
9
|
[
|
@@ -17,7 +13,6 @@ describe Hamster::Set do
|
|
17
13
|
].each do |values, expected|
|
18
14
|
|
19
15
|
describe "on #{values.inspect}" do
|
20
|
-
|
21
16
|
before do
|
22
17
|
original = Hamster.set(*values)
|
23
18
|
@result = original.send(method) { |minimum, item| item.length <=> minimum.length }
|
@@ -26,15 +21,11 @@ describe Hamster::Set do
|
|
26
21
|
it "returns #{expected.inspect}" do
|
27
22
|
@result.should == expected
|
28
23
|
end
|
29
|
-
|
30
24
|
end
|
31
|
-
|
32
25
|
end
|
33
|
-
|
34
26
|
end
|
35
27
|
|
36
28
|
describe "without a block" do
|
37
|
-
|
38
29
|
[
|
39
30
|
[[], nil],
|
40
31
|
[["A"], "A"],
|
@@ -42,7 +33,6 @@ describe Hamster::Set do
|
|
42
33
|
].each do |values, expected|
|
43
34
|
|
44
35
|
describe "on #{values.inspect}" do
|
45
|
-
|
46
36
|
before do
|
47
37
|
original = Hamster.set(*values)
|
48
38
|
@result = original.send(method)
|
@@ -51,15 +41,9 @@ describe Hamster::Set do
|
|
51
41
|
it "returns #{expected.inspect}" do
|
52
42
|
@result.should == expected
|
53
43
|
end
|
54
|
-
|
55
44
|
end
|
56
|
-
|
57
45
|
end
|
58
|
-
|
59
46
|
end
|
60
|
-
|
61
47
|
end
|
62
|
-
|
63
48
|
end
|
64
|
-
|
65
|
-
end
|
49
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "hamster/set"
|
3
|
+
|
4
|
+
describe Hamster::Set do
|
5
|
+
describe "new" do
|
6
|
+
describe "from a subclass" do
|
7
|
+
before do
|
8
|
+
@subclass = Class.new(Hamster::Set)
|
9
|
+
@instance = @subclass.new("some", "values")
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should return an instance of the subclass" do
|
13
|
+
@instance.class.should be @subclass
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should return a frozen instance" do
|
17
|
+
@instance.frozen?.should be true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,13 +1,9 @@
|
|
1
1
|
require "spec_helper"
|
2
|
-
|
3
2
|
require "hamster/set"
|
4
3
|
|
5
4
|
describe Hamster::Set do
|
6
|
-
|
7
5
|
describe "#none?" do
|
8
|
-
|
9
6
|
describe "when empty" do
|
10
|
-
|
11
7
|
before do
|
12
8
|
@set = Hamster.set
|
13
9
|
end
|
@@ -19,33 +15,26 @@ describe Hamster::Set do
|
|
19
15
|
it "with no block returns true" do
|
20
16
|
@set.none?.should == true
|
21
17
|
end
|
22
|
-
|
23
18
|
end
|
24
19
|
|
25
20
|
describe "when not empty" do
|
26
|
-
|
27
21
|
describe "with a block" do
|
28
|
-
|
29
22
|
before do
|
30
23
|
@set = Hamster.set("A", "B", "C", nil)
|
31
24
|
end
|
32
25
|
|
33
26
|
["A", "B", "C", nil].each do |value|
|
34
|
-
|
35
27
|
it "returns false if the block ever returns true (#{value.inspect})" do
|
36
28
|
@set.none? { |item| item == value }.should == false
|
37
29
|
end
|
38
|
-
|
39
30
|
end
|
40
31
|
|
41
32
|
it "returns true if the block always returns false" do
|
42
33
|
@set.none? { |item| item == "D" }.should == true
|
43
34
|
end
|
44
|
-
|
45
35
|
end
|
46
36
|
|
47
37
|
describe "with no block" do
|
48
|
-
|
49
38
|
it "returns false if any value is truthy" do
|
50
39
|
Hamster.set(nil, false, true, "A").none?.should == false
|
51
40
|
end
|
@@ -53,11 +42,7 @@ describe Hamster::Set do
|
|
53
42
|
it "returns true if all values are falsey" do
|
54
43
|
Hamster.set(nil, false).none?.should == true
|
55
44
|
end
|
56
|
-
|
57
45
|
end
|
58
|
-
|
59
46
|
end
|
60
|
-
|
61
47
|
end
|
62
|
-
|
63
|
-
end
|
48
|
+
end
|
@@ -1,13 +1,9 @@
|
|
1
1
|
require "spec_helper"
|
2
|
-
|
3
2
|
require "hamster/set"
|
4
3
|
|
5
4
|
describe Hamster::Set do
|
6
|
-
|
7
5
|
describe "#one?" do
|
8
|
-
|
9
6
|
describe "when empty" do
|
10
|
-
|
11
7
|
before do
|
12
8
|
@set = Hamster.set
|
13
9
|
end
|
@@ -19,13 +15,10 @@ describe Hamster::Set do
|
|
19
15
|
it "with no block returns false" do
|
20
16
|
@set.one?.should == false
|
21
17
|
end
|
22
|
-
|
23
18
|
end
|
24
19
|
|
25
20
|
describe "when not empty" do
|
26
|
-
|
27
21
|
describe "with a block" do
|
28
|
-
|
29
22
|
before do
|
30
23
|
@set = Hamster.set("A", "B", "C")
|
31
24
|
end
|
@@ -41,11 +34,9 @@ describe Hamster::Set do
|
|
41
34
|
it "returns true if the block only returns true once" do
|
42
35
|
@set.one? { |item| item == "A" }.should == true
|
43
36
|
end
|
44
|
-
|
45
37
|
end
|
46
38
|
|
47
39
|
describe "with no block" do
|
48
|
-
|
49
40
|
it "returns false if more than one value is truthy" do
|
50
41
|
Hamster.set(nil, true, "A").one?.should == false
|
51
42
|
end
|
@@ -53,11 +44,7 @@ describe Hamster::Set do
|
|
53
44
|
it "returns true if only one value is truthy" do
|
54
45
|
Hamster.set(nil, true, false).one?.should == true
|
55
46
|
end
|
56
|
-
|
57
47
|
end
|
58
|
-
|
59
48
|
end
|
60
|
-
|
61
49
|
end
|
62
|
-
|
63
|
-
end
|
50
|
+
end
|
@@ -1,12 +1,9 @@
|
|
1
1
|
require "spec_helper"
|
2
|
-
|
3
2
|
require "hamster/tuple"
|
4
3
|
require "hamster/set"
|
5
4
|
|
6
5
|
describe Hamster::Set do
|
7
|
-
|
8
6
|
describe "#partition" do
|
9
|
-
|
10
7
|
[
|
11
8
|
[[], [], []],
|
12
9
|
[[1], [1], []],
|
@@ -19,13 +16,11 @@ describe Hamster::Set do
|
|
19
16
|
].each do |values, expected_matches, expected_remainder|
|
20
17
|
|
21
18
|
describe "on #{values.inspect}" do
|
22
|
-
|
23
19
|
before do
|
24
20
|
@original = Hamster.set(*values)
|
25
21
|
end
|
26
22
|
|
27
23
|
describe "with a block" do
|
28
|
-
|
29
24
|
before do
|
30
25
|
@result = @original.partition(&:odd?)
|
31
26
|
@matches = @result.first
|
@@ -47,11 +42,9 @@ describe Hamster::Set do
|
|
47
42
|
it "correctly identifies the remainder" do
|
48
43
|
@remainder.should == Hamster.set(*expected_remainder)
|
49
44
|
end
|
50
|
-
|
51
45
|
end
|
52
46
|
|
53
47
|
describe "without a block" do
|
54
|
-
|
55
48
|
before do
|
56
49
|
@result = @original.partition
|
57
50
|
end
|
@@ -59,13 +52,8 @@ describe Hamster::Set do
|
|
59
52
|
it "returns self" do
|
60
53
|
@result.should equal(@original)
|
61
54
|
end
|
62
|
-
|
63
55
|
end
|
64
|
-
|
65
56
|
end
|
66
|
-
|
67
57
|
end
|
68
|
-
|
69
58
|
end
|
70
|
-
|
71
|
-
end
|
59
|
+
end
|
@@ -1,11 +1,8 @@
|
|
1
1
|
require "spec_helper"
|
2
|
-
|
3
2
|
require "hamster/set"
|
4
3
|
|
5
4
|
describe Hamster::Set do
|
6
|
-
|
7
5
|
describe "#product" do
|
8
|
-
|
9
6
|
[
|
10
7
|
[[], 1],
|
11
8
|
[[2], 2],
|
@@ -13,7 +10,6 @@ describe Hamster::Set do
|
|
13
10
|
].each do |values, expected|
|
14
11
|
|
15
12
|
describe "on #{values.inspect}" do
|
16
|
-
|
17
13
|
before do
|
18
14
|
original = Hamster.set(*values)
|
19
15
|
@result = original.product
|
@@ -22,11 +18,7 @@ describe Hamster::Set do
|
|
22
18
|
it "returns #{expected.inspect}" do
|
23
19
|
@result.should == expected
|
24
20
|
end
|
25
|
-
|
26
21
|
end
|
27
|
-
|
28
22
|
end
|
29
|
-
|
30
23
|
end
|
31
|
-
|
32
|
-
end
|
24
|
+
end
|
@@ -1,13 +1,9 @@
|
|
1
1
|
require "spec_helper"
|
2
|
-
|
3
2
|
require "hamster/set"
|
4
3
|
|
5
4
|
describe Hamster::Set do
|
6
|
-
|
7
5
|
[:reduce, :inject, :fold, :foldr].each do |method|
|
8
|
-
|
9
6
|
describe "##{method}" do
|
10
|
-
|
11
7
|
[
|
12
8
|
[[], 10, 10],
|
13
9
|
[[1], 10, 9],
|
@@ -15,33 +11,24 @@ describe Hamster::Set do
|
|
15
11
|
].each do |values, initial, expected|
|
16
12
|
|
17
13
|
describe "on #{values.inspect}" do
|
18
|
-
|
19
14
|
before do
|
20
15
|
@set = Hamster.set(*values)
|
21
16
|
end
|
22
17
|
|
23
18
|
describe "with an initial value of #{initial}" do
|
24
|
-
|
25
19
|
describe "and a block" do
|
26
|
-
|
27
20
|
it "returns #{expected.inspect}" do
|
28
21
|
@set.send(method, initial) { |memo, item| memo - item }.should == expected
|
29
22
|
end
|
30
|
-
|
31
23
|
end
|
32
24
|
|
33
25
|
describe "and no block" do
|
34
|
-
|
35
26
|
it "returns the memo" do
|
36
27
|
@set.send(method, initial).should == initial
|
37
28
|
end
|
38
|
-
|
39
29
|
end
|
40
|
-
|
41
30
|
end
|
42
|
-
|
43
31
|
end
|
44
|
-
|
45
32
|
end
|
46
33
|
|
47
34
|
[
|
@@ -51,37 +38,25 @@ describe Hamster::Set do
|
|
51
38
|
].each do |values, expected|
|
52
39
|
|
53
40
|
describe "on #{values.inspect}" do
|
54
|
-
|
55
41
|
before do
|
56
42
|
@set = Hamster.set(*values)
|
57
43
|
end
|
58
44
|
|
59
45
|
describe "with no initial value" do
|
60
|
-
|
61
46
|
describe "and a block" do
|
62
|
-
|
63
47
|
it "returns #{expected.inspect}" do
|
64
48
|
@set.send(method) { |memo, item| memo + item }.should == expected
|
65
49
|
end
|
66
|
-
|
67
50
|
end
|
68
51
|
|
69
52
|
describe "and no block" do
|
70
|
-
|
71
53
|
it "returns nil" do
|
72
54
|
@set.send(method).should be_nil
|
73
55
|
end
|
74
|
-
|
75
56
|
end
|
76
|
-
|
77
57
|
end
|
78
|
-
|
79
58
|
end
|
80
|
-
|
81
59
|
end
|
82
|
-
|
83
60
|
end
|
84
|
-
|
85
61
|
end
|
86
|
-
|
87
|
-
end
|
62
|
+
end
|
@@ -1,19 +1,14 @@
|
|
1
1
|
require "spec_helper"
|
2
|
-
|
3
2
|
require "hamster/set"
|
4
3
|
|
5
4
|
describe Hamster::Set do
|
6
|
-
|
7
5
|
[:remove, :reject, :delete_if].each do |method|
|
8
|
-
|
9
6
|
describe "##{method}" do
|
10
|
-
|
11
7
|
before do
|
12
8
|
@original = Hamster.set("A", "B", "C")
|
13
9
|
end
|
14
10
|
|
15
11
|
describe "when nothing matches" do
|
16
|
-
|
17
12
|
before do
|
18
13
|
@result = @original.send(method) { |item| false }
|
19
14
|
end
|
@@ -21,13 +16,10 @@ describe Hamster::Set do
|
|
21
16
|
it "returns self" do
|
22
17
|
@result.should equal(@original)
|
23
18
|
end
|
24
|
-
|
25
19
|
end
|
26
20
|
|
27
21
|
describe "when only some things match" do
|
28
|
-
|
29
22
|
describe "with a block" do
|
30
|
-
|
31
23
|
before do
|
32
24
|
@result = @original.send(method) { |item| item == "A" }
|
33
25
|
end
|
@@ -39,11 +31,9 @@ describe Hamster::Set do
|
|
39
31
|
it "returns a set with the matching values" do
|
40
32
|
@result.should == Hamster.set("B", "C")
|
41
33
|
end
|
42
|
-
|
43
34
|
end
|
44
35
|
|
45
36
|
describe "with no block" do
|
46
|
-
|
47
37
|
before do
|
48
38
|
@result = @original.send(method)
|
49
39
|
end
|
@@ -51,13 +41,8 @@ describe Hamster::Set do
|
|
51
41
|
it "returns self" do
|
52
42
|
@result.should equal(@original)
|
53
43
|
end
|
54
|
-
|
55
44
|
end
|
56
|
-
|
57
45
|
end
|
58
|
-
|
59
46
|
end
|
60
|
-
|
61
47
|
end
|
62
|
-
|
63
|
-
end
|
48
|
+
end
|