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,11 +1,8 @@
|
|
1
1
|
require "spec_helper"
|
2
|
-
|
3
2
|
require "hamster/list"
|
4
3
|
|
5
4
|
describe Hamster::List do
|
6
|
-
|
7
5
|
describe "#intersperse" do
|
8
|
-
|
9
6
|
it "is lazy" do
|
10
7
|
-> { Hamster.stream { fail }.intersperse("") }.should_not raise_error
|
11
8
|
end
|
@@ -17,7 +14,6 @@ describe Hamster::List do
|
|
17
14
|
].each do |values, expected|
|
18
15
|
|
19
16
|
describe "on #{values.inspect}" do
|
20
|
-
|
21
17
|
before do
|
22
18
|
@original = Hamster.list(*values)
|
23
19
|
@result = @original.intersperse("|")
|
@@ -30,11 +26,7 @@ describe Hamster::List do
|
|
30
26
|
it "returns #{expected.inspect}" do
|
31
27
|
@result.should == Hamster.list(*expected)
|
32
28
|
end
|
33
|
-
|
34
29
|
end
|
35
|
-
|
36
30
|
end
|
37
|
-
|
38
31
|
end
|
39
|
-
|
40
|
-
end
|
32
|
+
end
|
@@ -1,13 +1,9 @@
|
|
1
1
|
require "spec_helper"
|
2
|
-
|
3
2
|
require "hamster/list"
|
4
3
|
|
5
4
|
describe Hamster::List do
|
6
|
-
|
7
5
|
describe "#join" do
|
8
|
-
|
9
6
|
describe "on a really big list" do
|
10
|
-
|
11
7
|
before do
|
12
8
|
@list = Hamster.interval(0, STACK_OVERFLOW_DEPTH)
|
13
9
|
end
|
@@ -15,11 +11,9 @@ describe Hamster::List do
|
|
15
11
|
it "doesn't run out of stack" do
|
16
12
|
-> { @list.join }.should_not raise_error
|
17
13
|
end
|
18
|
-
|
19
14
|
end
|
20
15
|
|
21
16
|
describe "with a separator" do
|
22
|
-
|
23
17
|
[
|
24
18
|
[[], ""],
|
25
19
|
[["A"], "A"],
|
@@ -27,7 +21,6 @@ describe Hamster::List do
|
|
27
21
|
].each do |values, expected|
|
28
22
|
|
29
23
|
describe "on #{values.inspect}" do
|
30
|
-
|
31
24
|
before do
|
32
25
|
@original = Hamster.list(*values)
|
33
26
|
@result = @original.join("|")
|
@@ -40,15 +33,11 @@ describe Hamster::List do
|
|
40
33
|
it "returns #{expected.inspect}" do
|
41
34
|
@result.should == expected
|
42
35
|
end
|
43
|
-
|
44
36
|
end
|
45
|
-
|
46
37
|
end
|
47
|
-
|
48
38
|
end
|
49
39
|
|
50
40
|
describe "without a separator" do
|
51
|
-
|
52
41
|
[
|
53
42
|
[[], ""],
|
54
43
|
[["A"], "A"],
|
@@ -56,7 +45,6 @@ describe Hamster::List do
|
|
56
45
|
].each do |values, expected|
|
57
46
|
|
58
47
|
describe "on #{values.inspect}" do
|
59
|
-
|
60
48
|
before do
|
61
49
|
@original = Hamster.list(*values)
|
62
50
|
@result = @original.join
|
@@ -69,13 +57,8 @@ describe Hamster::List do
|
|
69
57
|
it "returns #{expected.inspect}" do
|
70
58
|
@result.should == expected
|
71
59
|
end
|
72
|
-
|
73
60
|
end
|
74
|
-
|
75
61
|
end
|
76
|
-
|
77
62
|
end
|
78
|
-
|
79
63
|
end
|
80
|
-
|
81
|
-
end
|
64
|
+
end
|
@@ -1,13 +1,9 @@
|
|
1
1
|
require "spec_helper"
|
2
|
-
|
3
2
|
require "hamster/list"
|
4
3
|
|
5
4
|
describe Hamster::List do
|
6
|
-
|
7
5
|
describe "#last" do
|
8
|
-
|
9
6
|
describe "on a really big list" do
|
10
|
-
|
11
7
|
before do
|
12
8
|
@list = Hamster.interval(0, STACK_OVERFLOW_DEPTH)
|
13
9
|
end
|
@@ -15,7 +11,6 @@ describe Hamster::List do
|
|
15
11
|
it "doesn't run out of stack" do
|
16
12
|
-> { @list.last }.should_not raise_error
|
17
13
|
end
|
18
|
-
|
19
14
|
end
|
20
15
|
|
21
16
|
[
|
@@ -25,7 +20,6 @@ describe Hamster::List do
|
|
25
20
|
].each do |values, expected|
|
26
21
|
|
27
22
|
describe "on #{values.inspect}" do
|
28
|
-
|
29
23
|
before do
|
30
24
|
original = Hamster.list(*values)
|
31
25
|
@result = original.last
|
@@ -34,11 +28,7 @@ describe Hamster::List do
|
|
34
28
|
it "returns #{expected.inspect}" do
|
35
29
|
@result.should == expected
|
36
30
|
end
|
37
|
-
|
38
31
|
end
|
39
|
-
|
40
32
|
end
|
41
|
-
|
42
33
|
end
|
43
|
-
|
44
|
-
end
|
34
|
+
end
|
@@ -1,13 +1,9 @@
|
|
1
1
|
require "spec_helper"
|
2
|
-
|
3
2
|
require "hamster/list"
|
4
3
|
|
5
4
|
describe Hamster::List do
|
6
|
-
|
7
5
|
[:map, :collect].each do |method|
|
8
|
-
|
9
6
|
describe "##{method}" do
|
10
|
-
|
11
7
|
it "is lazy" do
|
12
8
|
-> { Hamster.stream { fail }.map { |item| item } }.should_not raise_error
|
13
9
|
end
|
@@ -19,13 +15,11 @@ describe Hamster::List do
|
|
19
15
|
].each do |values, expected|
|
20
16
|
|
21
17
|
describe "on #{values.inspect}" do
|
22
|
-
|
23
18
|
before do
|
24
19
|
@original = Hamster.list(*values)
|
25
20
|
end
|
26
21
|
|
27
22
|
describe "with a block" do
|
28
|
-
|
29
23
|
before do
|
30
24
|
@result = @original.send(method, &:downcase)
|
31
25
|
end
|
@@ -43,11 +37,9 @@ describe Hamster::List do
|
|
43
37
|
@original.send(method) { |item| count += 1 }
|
44
38
|
count.should <= 1
|
45
39
|
end
|
46
|
-
|
47
40
|
end
|
48
41
|
|
49
42
|
describe "without a block" do
|
50
|
-
|
51
43
|
before do
|
52
44
|
@result = @original.send(method)
|
53
45
|
end
|
@@ -55,15 +47,9 @@ describe Hamster::List do
|
|
55
47
|
it "returns self" do
|
56
48
|
@result.should equal(@original)
|
57
49
|
end
|
58
|
-
|
59
50
|
end
|
60
|
-
|
61
51
|
end
|
62
|
-
|
63
52
|
end
|
64
|
-
|
65
53
|
end
|
66
|
-
|
67
54
|
end
|
68
|
-
|
69
|
-
end
|
55
|
+
end
|
@@ -1,15 +1,10 @@
|
|
1
1
|
require "spec_helper"
|
2
|
-
|
3
2
|
require "hamster/list"
|
4
3
|
|
5
4
|
describe Hamster::List do
|
6
|
-
|
7
5
|
[:maximum, :max].each do |method|
|
8
|
-
|
9
6
|
describe "##{method}" do
|
10
|
-
|
11
7
|
describe "on a really big list" do
|
12
|
-
|
13
8
|
before do
|
14
9
|
@list = Hamster.interval(0, STACK_OVERFLOW_DEPTH)
|
15
10
|
end
|
@@ -17,11 +12,9 @@ describe Hamster::List do
|
|
17
12
|
it "doesn't run out of stack" do
|
18
13
|
-> { @list.send(method) }.should_not raise_error
|
19
14
|
end
|
20
|
-
|
21
15
|
end
|
22
16
|
|
23
17
|
describe "with a block" do
|
24
|
-
|
25
18
|
[
|
26
19
|
[[], nil],
|
27
20
|
[["A"], "A"],
|
@@ -29,7 +22,6 @@ describe Hamster::List do
|
|
29
22
|
].each do |values, expected|
|
30
23
|
|
31
24
|
describe "on #{values.inspect}" do
|
32
|
-
|
33
25
|
before do
|
34
26
|
original = Hamster.list(*values)
|
35
27
|
@result = original.send(method) { |maximum, item| item.length <=> maximum.length }
|
@@ -38,15 +30,11 @@ describe Hamster::List do
|
|
38
30
|
it "returns #{expected.inspect}" do
|
39
31
|
@result.should == expected
|
40
32
|
end
|
41
|
-
|
42
33
|
end
|
43
|
-
|
44
34
|
end
|
45
|
-
|
46
35
|
end
|
47
36
|
|
48
37
|
describe "without a block" do
|
49
|
-
|
50
38
|
[
|
51
39
|
[[], nil],
|
52
40
|
[["A"], "A"],
|
@@ -54,7 +42,6 @@ describe Hamster::List do
|
|
54
42
|
].each do |values, expected|
|
55
43
|
|
56
44
|
describe "on #{values.inspect}" do
|
57
|
-
|
58
45
|
before do
|
59
46
|
original = Hamster.list(*values)
|
60
47
|
@result = original.send(method)
|
@@ -63,15 +50,9 @@ describe Hamster::List do
|
|
63
50
|
it "returns #{expected.inspect}" do
|
64
51
|
@result.should == expected
|
65
52
|
end
|
66
|
-
|
67
53
|
end
|
68
|
-
|
69
54
|
end
|
70
|
-
|
71
55
|
end
|
72
|
-
|
73
56
|
end
|
74
|
-
|
75
57
|
end
|
76
|
-
|
77
|
-
end
|
58
|
+
end
|
@@ -1,23 +1,17 @@
|
|
1
1
|
require "spec_helper"
|
2
|
-
|
3
2
|
require "hamster/list"
|
4
3
|
|
5
4
|
describe Hamster::List do
|
6
|
-
|
7
5
|
context "without a comparator" do
|
8
|
-
|
9
6
|
context "on an empty list" do
|
10
|
-
|
11
7
|
subject { Hamster.list }
|
12
8
|
|
13
9
|
it "returns an empty list" do
|
14
10
|
subject.merge_by.should be_empty
|
15
11
|
end
|
16
|
-
|
17
12
|
end
|
18
13
|
|
19
14
|
context "on a single list" do
|
20
|
-
|
21
15
|
let(:list) { Hamster.list(1, 2, 3) }
|
22
16
|
|
23
17
|
subject { Hamster.list(list) }
|
@@ -25,11 +19,9 @@ describe Hamster::List do
|
|
25
19
|
it "returns the list" do
|
26
20
|
subject.merge_by.should == list
|
27
21
|
end
|
28
|
-
|
29
22
|
end
|
30
23
|
|
31
24
|
context "with multiple lists" do
|
32
|
-
|
33
25
|
subject { Hamster.list(Hamster.list(3, 6, 7, 8), Hamster.list(1, 2, 4, 5, 9)) }
|
34
26
|
|
35
27
|
it "merges the lists based on natural sort order" do
|
@@ -37,23 +29,18 @@ describe Hamster::List do
|
|
37
29
|
end
|
38
30
|
|
39
31
|
end
|
40
|
-
|
41
32
|
end
|
42
33
|
|
43
34
|
context "with a comparator" do
|
44
|
-
|
45
35
|
context "on an empty list" do
|
46
|
-
|
47
36
|
subject { Hamster.list }
|
48
37
|
|
49
38
|
it "returns an empty list" do
|
50
39
|
subject.merge_by { |item| fail("should never be called") }.should be_empty
|
51
40
|
end
|
52
|
-
|
53
41
|
end
|
54
42
|
|
55
43
|
context "on a single list" do
|
56
|
-
|
57
44
|
let(:list) { Hamster.list(1, 2, 3) }
|
58
45
|
|
59
46
|
subject { Hamster.list(list) }
|
@@ -61,19 +48,14 @@ describe Hamster::List do
|
|
61
48
|
it "returns the list" do
|
62
49
|
subject.merge_by { |item| -item }.should == Hamster.list(1, 2, 3)
|
63
50
|
end
|
64
|
-
|
65
51
|
end
|
66
52
|
|
67
53
|
context "with multiple lists" do
|
68
|
-
|
69
54
|
subject { Hamster.list(Hamster.list(8, 7, 6, 3), Hamster.list(9, 5, 4, 2, 1)) }
|
70
55
|
|
71
56
|
it "merges the lists based on the specified transformer" do
|
72
57
|
subject.merge_by { |item| -item }.should == Hamster.list(9, 8, 7, 6, 5, 4, 3, 2, 1)
|
73
58
|
end
|
74
|
-
|
75
59
|
end
|
76
|
-
|
77
60
|
end
|
78
|
-
|
79
|
-
end
|
61
|
+
end
|
@@ -1,23 +1,17 @@
|
|
1
1
|
require "spec_helper"
|
2
|
-
|
3
2
|
require "hamster/list"
|
4
3
|
|
5
4
|
describe Hamster::List do
|
6
|
-
|
7
5
|
context "without a comparator" do
|
8
|
-
|
9
6
|
context "on an empty list" do
|
10
|
-
|
11
7
|
subject { Hamster.list }
|
12
8
|
|
13
9
|
it "returns an empty list" do
|
14
10
|
subject.merge.should be_empty
|
15
11
|
end
|
16
|
-
|
17
12
|
end
|
18
13
|
|
19
14
|
context "on a single list" do
|
20
|
-
|
21
15
|
let(:list) { Hamster.list(1, 2, 3) }
|
22
16
|
|
23
17
|
subject { Hamster.list(list) }
|
@@ -25,35 +19,27 @@ describe Hamster::List do
|
|
25
19
|
it "returns the list" do
|
26
20
|
subject.merge.should == list
|
27
21
|
end
|
28
|
-
|
29
22
|
end
|
30
23
|
|
31
24
|
context "with multiple lists" do
|
32
|
-
|
33
25
|
subject { Hamster.list(Hamster.list(3, 6, 7, 8), Hamster.list(1, 2, 4, 5, 9)) }
|
34
26
|
|
35
27
|
it "merges the lists based on natural sort order" do
|
36
28
|
subject.merge.should == Hamster.list(1, 2, 3, 4, 5, 6, 7, 8, 9)
|
37
29
|
end
|
38
|
-
|
39
30
|
end
|
40
|
-
|
41
31
|
end
|
42
32
|
|
43
33
|
context "with a comparator" do
|
44
|
-
|
45
34
|
context "on an empty list" do
|
46
|
-
|
47
35
|
subject { Hamster.list }
|
48
36
|
|
49
37
|
it "returns an empty list" do
|
50
38
|
subject.merge { |a, b| fail("should never be called") }.should be_empty
|
51
39
|
end
|
52
|
-
|
53
40
|
end
|
54
41
|
|
55
42
|
context "on a single list" do
|
56
|
-
|
57
43
|
let(:list) { Hamster.list(1, 2, 3) }
|
58
44
|
|
59
45
|
subject { Hamster.list(list) }
|
@@ -61,19 +47,14 @@ describe Hamster::List do
|
|
61
47
|
it "returns the list" do
|
62
48
|
subject.merge { |a, b| fail("should never be called") }.should == list
|
63
49
|
end
|
64
|
-
|
65
50
|
end
|
66
51
|
|
67
52
|
context "with multiple lists" do
|
68
|
-
|
69
53
|
subject { Hamster.list(Hamster.list(8, 7, 6, 3), Hamster.list(9, 5, 4, 2, 1)) }
|
70
54
|
|
71
55
|
it "merges the lists based on the specified comparator" do
|
72
56
|
subject.merge { |a, b| b <=> a }.should == Hamster.list(9, 8, 7, 6, 5, 4, 3, 2, 1)
|
73
57
|
end
|
74
|
-
|
75
58
|
end
|
76
|
-
|
77
59
|
end
|
78
|
-
|
79
|
-
end
|
60
|
+
end
|
@@ -1,15 +1,10 @@
|
|
1
1
|
require "spec_helper"
|
2
|
-
|
3
2
|
require "hamster/list"
|
4
3
|
|
5
4
|
describe Hamster::List do
|
6
|
-
|
7
5
|
[:minimum, :min].each do |method|
|
8
|
-
|
9
6
|
describe "##{method}" do
|
10
|
-
|
11
7
|
describe "on a really big list" do
|
12
|
-
|
13
8
|
before do
|
14
9
|
@list = Hamster.interval(0, STACK_OVERFLOW_DEPTH)
|
15
10
|
end
|
@@ -17,11 +12,9 @@ describe Hamster::List do
|
|
17
12
|
it "doesn't run out of stack" do
|
18
13
|
-> { @list.send(method) }.should_not raise_error
|
19
14
|
end
|
20
|
-
|
21
15
|
end
|
22
16
|
|
23
17
|
describe "with a block" do
|
24
|
-
|
25
18
|
[
|
26
19
|
[[], nil],
|
27
20
|
[["A"], "A"],
|
@@ -29,7 +22,6 @@ describe Hamster::List do
|
|
29
22
|
].each do |values, expected|
|
30
23
|
|
31
24
|
describe "on #{values.inspect}" do
|
32
|
-
|
33
25
|
before do
|
34
26
|
original = Hamster.list(*values)
|
35
27
|
@result = original.send(method) { |minimum, item| item.length <=> minimum.length }
|
@@ -38,15 +30,11 @@ describe Hamster::List do
|
|
38
30
|
it "returns #{expected.inspect}" do
|
39
31
|
@result.should == expected
|
40
32
|
end
|
41
|
-
|
42
33
|
end
|
43
|
-
|
44
34
|
end
|
45
|
-
|
46
35
|
end
|
47
36
|
|
48
37
|
describe "without a block" do
|
49
|
-
|
50
38
|
[
|
51
39
|
[[], nil],
|
52
40
|
[["A"], "A"],
|
@@ -54,7 +42,6 @@ describe Hamster::List do
|
|
54
42
|
].each do |values, expected|
|
55
43
|
|
56
44
|
describe "on #{values.inspect}" do
|
57
|
-
|
58
45
|
before do
|
59
46
|
original = Hamster.list(*values)
|
60
47
|
@result = original.send(method)
|
@@ -63,15 +50,9 @@ describe Hamster::List do
|
|
63
50
|
it "returns #{expected.inspect}" do
|
64
51
|
@result.should == expected
|
65
52
|
end
|
66
|
-
|
67
53
|
end
|
68
|
-
|
69
54
|
end
|
70
|
-
|
71
55
|
end
|
72
|
-
|
73
56
|
end
|
74
|
-
|
75
57
|
end
|
76
|
-
|
77
|
-
end
|
58
|
+
end
|