hamster 0.1.19 → 0.1.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.rdoc +10 -0
- data/README.rdoc +1 -1
- data/lib/hamster/list.rb +19 -1
- data/lib/hamster/stack.rb +4 -0
- data/lib/hamster/version.rb +1 -1
- data/spec/hamster/hash/all_spec.rb +5 -5
- data/spec/hamster/hash/any_spec.rb +5 -5
- data/spec/hamster/hash/eql_spec.rb +2 -2
- data/spec/hamster/hash/has_key_spec.rb +2 -2
- data/spec/hamster/hash/none_spec.rb +5 -5
- data/spec/hamster/list/all_spec.rb +44 -12
- data/spec/hamster/list/any_spec.rb +8 -8
- data/spec/hamster/list/append_spec.rb +2 -2
- data/spec/hamster/list/break_spec.rb +183 -0
- data/spec/hamster/list/cadr_spec.rb +7 -2
- data/spec/hamster/list/clear_spec.rb +36 -0
- data/spec/hamster/list/copying_spec.rb +3 -2
- data/spec/hamster/list/cycle_spec.rb +20 -7
- data/spec/hamster/list/drop_spec.rb +10 -5
- data/spec/hamster/list/drop_while_spec.rb +17 -5
- data/spec/hamster/list/each_spec.rb +15 -8
- data/spec/hamster/list/empty_spec.rb +2 -2
- data/spec/hamster/list/eql_spec.rb +6 -6
- data/spec/hamster/list/filter_spec.rb +14 -6
- data/spec/hamster/list/find_spec.rb +2 -2
- data/spec/hamster/list/grep_spec.rb +10 -5
- data/spec/hamster/list/head_spec.rb +16 -12
- data/spec/hamster/list/include_spec.rb +2 -2
- data/spec/hamster/list/inspect_spec.rb +2 -2
- data/spec/hamster/list/map_spec.rb +18 -6
- data/spec/hamster/list/maximum_spec.rb +2 -2
- data/spec/hamster/list/minimum_spec.rb +2 -2
- data/spec/hamster/list/none_spec.rb +8 -8
- data/spec/hamster/list/one_spec.rb +9 -9
- data/spec/hamster/list/partition_spec.rb +87 -39
- data/spec/hamster/list/reduce_spec.rb +2 -2
- data/spec/hamster/list/reject_spec.rb +14 -6
- data/spec/hamster/list/reverse_spec.rb +9 -4
- data/spec/hamster/list/size_spec.rb +2 -2
- data/spec/hamster/list/span_spec.rb +183 -0
- data/spec/hamster/list/split_at_spec.rb +68 -17
- data/spec/hamster/list/tail_spec.rb +2 -2
- data/spec/hamster/list/take_spec.rb +10 -5
- data/spec/hamster/list/take_while_spec.rb +15 -6
- data/spec/hamster/list/to_a_spec.rb +2 -2
- data/spec/hamster/list/to_ary_spec.rb +3 -3
- data/spec/hamster/list/to_list_spec.rb +3 -2
- data/spec/hamster/list/zip_spec.rb +16 -7
- data/spec/hamster/set/all_spec.rb +6 -6
- data/spec/hamster/set/any_spec.rb +6 -6
- data/spec/hamster/set/eql_spec.rb +2 -2
- data/spec/hamster/set/include_spec.rb +2 -2
- data/spec/hamster/set/none_spec.rb +6 -6
- data/spec/hamster/set/to_list.rb +1 -1
- data/spec/hamster/stack/clear_spec.rb +36 -0
- data/spec/hamster/stack/eql_spec.rb +2 -2
- data/spec/hamster/stack/pop_spec.rb +2 -2
- data/spec/hamster/trie/remove_spec.rb +3 -3
- data/spec/spec_helper.rb +2 -0
- metadata +9 -89
- data/lib/hamster/core_ext/enumerable.rbc +0 -481
- data/lib/hamster/core_ext/io.rbc +0 -604
- data/lib/hamster/hash.rbc +0 -3117
- data/lib/hamster/list.rbc +0 -7274
- data/lib/hamster/set.rbc +0 -3152
- data/lib/hamster/stack.rbc +0 -1358
- data/lib/hamster/trie.rbc +0 -3416
- data/spec/hamster/core_ext/enumerable_spec.rbc +0 -747
- data/spec/hamster/core_ext/io_spec.rbc +0 -409
- data/spec/hamster/hash/all_spec.rbc +0 -1214
- data/spec/hamster/hash/any_spec.rbc +0 -1495
- data/spec/hamster/hash/construction_spec.rbc +0 -742
- data/spec/hamster/hash/copying_spec.rbc +0 -519
- data/spec/hamster/hash/each_spec.rbc +0 -908
- data/spec/hamster/hash/empty_spec.rbc +0 -517
- data/spec/hamster/hash/eql_spec.rbc +0 -1702
- data/spec/hamster/hash/filter_spec.rbc +0 -1433
- data/spec/hamster/hash/get_spec.rbc +0 -791
- data/spec/hamster/hash/has_key_spec.rbc +0 -719
- data/spec/hamster/hash/map_spec.rbc +0 -1454
- data/spec/hamster/hash/none_spec.rbc +0 -1399
- data/spec/hamster/hash/put_spec.rbc +0 -1334
- data/spec/hamster/hash/reduce_spec.rbc +0 -1234
- data/spec/hamster/hash/reject_spec.rbc +0 -1445
- data/spec/hamster/hash/remove_spec.rbc +0 -1135
- data/spec/hamster/hash/size_spec.rbc +0 -596
- data/spec/hamster/list/all_spec.rbc +0 -1760
- data/spec/hamster/list/any_spec.rbc +0 -1888
- data/spec/hamster/list/append_spec.rbc +0 -1555
- data/spec/hamster/list/cadr_spec.rbc +0 -855
- data/spec/hamster/list/cons_spec.rbc +0 -848
- data/spec/hamster/list/construction_spec.rbc +0 -1732
- data/spec/hamster/list/copying_spec.rbc +0 -555
- data/spec/hamster/list/drop_spec.rbc +0 -1081
- data/spec/hamster/list/drop_while_spec.rbc +0 -1286
- data/spec/hamster/list/each_spec.rbc +0 -1365
- data/spec/hamster/list/empty_spec.rbc +0 -571
- data/spec/hamster/list/eql_spec.rbc +0 -1819
- data/spec/hamster/list/filter_spec.rbc +0 -1595
- data/spec/hamster/list/find_spec.rbc +0 -1456
- data/spec/hamster/list/head_spec.rbc +0 -575
- data/spec/hamster/list/include_spec.rbc +0 -1173
- data/spec/hamster/list/inspect_spec.rbc +0 -995
- data/spec/hamster/list/map_spec.rbc +0 -1545
- data/spec/hamster/list/none_spec.rbc +0 -1788
- data/spec/hamster/list/partition_spec.rbc +0 -2715
- data/spec/hamster/list/reduce_spec.rbc +0 -2081
- data/spec/hamster/list/reject_spec.rbc +0 -1590
- data/spec/hamster/list/reverse_spec.rbc +0 -1061
- data/spec/hamster/list/size_spec.rbc +0 -1063
- data/spec/hamster/list/tail_spec.rbc +0 -595
- data/spec/hamster/list/take_spec.rbc +0 -1075
- data/spec/hamster/list/take_while_spec.rbc +0 -1446
- data/spec/hamster/list/to_a_spec.rbc +0 -961
- data/spec/hamster/list/to_ary_spec.rbc +0 -1080
- data/spec/hamster/set/add_spec.rbc +0 -1039
- data/spec/hamster/set/all_spec.rbc +0 -1316
- data/spec/hamster/set/any_spec.rbc +0 -1444
- data/spec/hamster/set/construction_spec.rbc +0 -422
- data/spec/hamster/set/copying_spec.rbc +0 -469
- data/spec/hamster/set/each_spec.rbc +0 -820
- data/spec/hamster/set/empty_spec.rbc +0 -452
- data/spec/hamster/set/eql_spec.rbc +0 -1309
- data/spec/hamster/set/filter_spec.rbc +0 -1272
- data/spec/hamster/set/include_spec.rbc +0 -657
- data/spec/hamster/set/map_spec.rbc +0 -1285
- data/spec/hamster/set/none_spec.rbc +0 -1344
- data/spec/hamster/set/reduce_spec.rbc +0 -1177
- data/spec/hamster/set/reject_spec.rbc +0 -1273
- data/spec/hamster/set/remove_spec.rbc +0 -947
- data/spec/hamster/set/size_spec.rbc +0 -531
- data/spec/hamster/set/to_a_spec.rbc +0 -559
- data/spec/hamster/stack/construction_spec.rbc +0 -862
- data/spec/hamster/stack/copying_spec.rbc +0 -555
- data/spec/hamster/stack/empty_spec.rbc +0 -571
- data/spec/hamster/stack/eql_spec.rbc +0 -1281
- data/spec/hamster/stack/inspect_spec.rbc +0 -586
- data/spec/hamster/stack/pop_spec.rbc +0 -1099
- data/spec/hamster/stack/push_spec.rbc +0 -848
- data/spec/hamster/stack/size_spec.rbc +0 -650
- data/spec/hamster/stack/top_spec.rbc +0 -676
- data/spec/hamster/trie/remove_spec.rbc +0 -40
- data/spec/spec_helper.rbc +0 -163
- data/tasks/spec.rbc +0 -201
@@ -11,11 +11,11 @@ describe Hamster::List do
|
|
11
11
|
describe "doesn't run out of stack space on a really big" do
|
12
12
|
|
13
13
|
it "stream" do
|
14
|
-
@list = Hamster.interval(0,
|
14
|
+
@list = Hamster.interval(0, STACK_OVERFLOW_DEPTH)
|
15
15
|
end
|
16
16
|
|
17
17
|
it "list" do
|
18
|
-
@list = (0
|
18
|
+
@list = (0...STACK_OVERFLOW_DEPTH).reduce(Hamster.list) { |list, i| list.cons(i) }
|
19
19
|
end
|
20
20
|
|
21
21
|
after do
|
@@ -9,11 +9,11 @@ describe Hamster::List do
|
|
9
9
|
describe "doesn't run out of stack space on a really big" do
|
10
10
|
|
11
11
|
it "stream" do
|
12
|
-
@list = Hamster.interval(0,
|
12
|
+
@list = Hamster.interval(0, STACK_OVERFLOW_DEPTH)
|
13
13
|
end
|
14
14
|
|
15
15
|
it "list" do
|
16
|
-
@list = (0
|
16
|
+
@list = (0...STACK_OVERFLOW_DEPTH).reduce(Hamster.list) { |list, i| list.cons(i) }
|
17
17
|
end
|
18
18
|
|
19
19
|
after do
|
@@ -11,11 +11,11 @@ describe Hamster::List do
|
|
11
11
|
describe "doesn't run out of stack space on a really big" do
|
12
12
|
|
13
13
|
it "stream" do
|
14
|
-
@list = Hamster.interval(0,
|
14
|
+
@list = Hamster.interval(0, STACK_OVERFLOW_DEPTH)
|
15
15
|
end
|
16
16
|
|
17
17
|
it "list" do
|
18
|
-
@list = (0
|
18
|
+
@list = (0...STACK_OVERFLOW_DEPTH).reduce(Hamster.list) { |list, i| list.cons(i) }
|
19
19
|
end
|
20
20
|
|
21
21
|
after do
|
@@ -33,18 +33,26 @@ describe Hamster::List do
|
|
33
33
|
describe "on #{values.inspect}" do
|
34
34
|
|
35
35
|
before do
|
36
|
-
@
|
36
|
+
@original = Hamster.list(*values)
|
37
37
|
end
|
38
38
|
|
39
39
|
describe "with a block" do
|
40
40
|
|
41
|
+
before do
|
42
|
+
@result = @original.send(method) { |item| item.downcase }
|
43
|
+
end
|
44
|
+
|
45
|
+
it "preserves the original" do
|
46
|
+
@original.should == Hamster.list(*values)
|
47
|
+
end
|
48
|
+
|
41
49
|
it "returns #{expected.inspect}" do
|
42
|
-
@
|
50
|
+
@result.should == Hamster.list(*expected)
|
43
51
|
end
|
44
52
|
|
45
53
|
it "is lazy" do
|
46
54
|
count = 0
|
47
|
-
@
|
55
|
+
@original.send(method) { |item| count += 1 }
|
48
56
|
count.should <= 1
|
49
57
|
end
|
50
58
|
|
@@ -52,8 +60,12 @@ describe Hamster::List do
|
|
52
60
|
|
53
61
|
describe "without a block" do
|
54
62
|
|
63
|
+
before do
|
64
|
+
@result = @original.send(method)
|
65
|
+
end
|
66
|
+
|
55
67
|
it "returns self" do
|
56
|
-
@
|
68
|
+
@result.should equal(@original)
|
57
69
|
end
|
58
70
|
|
59
71
|
end
|
@@ -11,11 +11,11 @@ describe Hamster::List do
|
|
11
11
|
describe "doesn't run out of stack space on a really big" do
|
12
12
|
|
13
13
|
it "stream" do
|
14
|
-
@list = Hamster.interval(0,
|
14
|
+
@list = Hamster.interval(0, STACK_OVERFLOW_DEPTH)
|
15
15
|
end
|
16
16
|
|
17
17
|
it "list" do
|
18
|
-
@list = (0
|
18
|
+
@list = (0...STACK_OVERFLOW_DEPTH).reduce(Hamster.list) { |list, i| list.cons(i) }
|
19
19
|
end
|
20
20
|
|
21
21
|
after do
|
@@ -11,11 +11,11 @@ describe Hamster::List do
|
|
11
11
|
describe "doesn't run out of stack space on a really big" do
|
12
12
|
|
13
13
|
it "stream" do
|
14
|
-
@list = Hamster.interval(0,
|
14
|
+
@list = Hamster.interval(0, STACK_OVERFLOW_DEPTH)
|
15
15
|
end
|
16
16
|
|
17
17
|
it "list" do
|
18
|
-
@list = (0
|
18
|
+
@list = (0...STACK_OVERFLOW_DEPTH).reduce(Hamster.list) { |list, i| list.cons(i) }
|
19
19
|
end
|
20
20
|
|
21
21
|
after do
|
@@ -9,11 +9,11 @@ describe Hamster::List do
|
|
9
9
|
describe "doesn't run out of stack space on a really big" do
|
10
10
|
|
11
11
|
it "stream" do
|
12
|
-
@list = Hamster.interval(0,
|
12
|
+
@list = Hamster.interval(0, STACK_OVERFLOW_DEPTH)
|
13
13
|
end
|
14
14
|
|
15
15
|
it "list" do
|
16
|
-
@list = (0
|
16
|
+
@list = (0...STACK_OVERFLOW_DEPTH).reduce(Hamster.list) { |list, i| list.cons(i) }
|
17
17
|
end
|
18
18
|
|
19
19
|
after do
|
@@ -29,11 +29,11 @@ describe Hamster::List do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
it "with a block returns true" do
|
32
|
-
@list.none? {}.should
|
32
|
+
@list.none? {}.should == true
|
33
33
|
end
|
34
34
|
|
35
35
|
it "with no block returns true" do
|
36
|
-
@list.none?.should
|
36
|
+
@list.none?.should == true
|
37
37
|
end
|
38
38
|
|
39
39
|
end
|
@@ -49,13 +49,13 @@ describe Hamster::List do
|
|
49
49
|
["A", "B", "C", nil].each do |value|
|
50
50
|
|
51
51
|
it "returns false if the block ever returns true (#{value.inspect})" do
|
52
|
-
@list.none? { |item| item == value }.should
|
52
|
+
@list.none? { |item| item == value }.should == false
|
53
53
|
end
|
54
54
|
|
55
55
|
end
|
56
56
|
|
57
57
|
it "returns true if the block always returns false" do
|
58
|
-
@list.none? { |item| item == "D" }.should
|
58
|
+
@list.none? { |item| item == "D" }.should == true
|
59
59
|
end
|
60
60
|
|
61
61
|
end
|
@@ -63,11 +63,11 @@ describe Hamster::List do
|
|
63
63
|
describe "with no block" do
|
64
64
|
|
65
65
|
it "returns false if any value is truthy" do
|
66
|
-
Hamster.list(nil, false, true, "A").none?.should
|
66
|
+
Hamster.list(nil, false, true, "A").none?.should == false
|
67
67
|
end
|
68
68
|
|
69
69
|
it "returns true if all values are falsey" do
|
70
|
-
Hamster.list(nil, false).none?.should
|
70
|
+
Hamster.list(nil, false).none?.should == true
|
71
71
|
end
|
72
72
|
|
73
73
|
end
|
@@ -9,11 +9,11 @@ describe Hamster::List do
|
|
9
9
|
describe "doesn't run out of stack space on a really big" do
|
10
10
|
|
11
11
|
it "stream" do
|
12
|
-
@list = Hamster.interval(0,
|
12
|
+
@list = Hamster.interval(0, STACK_OVERFLOW_DEPTH)
|
13
13
|
end
|
14
14
|
|
15
15
|
it "list" do
|
16
|
-
@list = (0
|
16
|
+
@list = (0...STACK_OVERFLOW_DEPTH).reduce(Hamster.list) { |list, i| list.cons(i) }
|
17
17
|
end
|
18
18
|
|
19
19
|
after do
|
@@ -29,11 +29,11 @@ describe Hamster::List do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
it "with a block returns false" do
|
32
|
-
@list.one? {}.should
|
32
|
+
@list.one? {}.should == false
|
33
33
|
end
|
34
34
|
|
35
35
|
it "with no block returns false" do
|
36
|
-
@list.one?.should
|
36
|
+
@list.one?.should == false
|
37
37
|
end
|
38
38
|
|
39
39
|
end
|
@@ -47,15 +47,15 @@ describe Hamster::List do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
it "returns false if the block returns true more than once" do
|
50
|
-
@list.one? { |item| true }.should
|
50
|
+
@list.one? { |item| true }.should == false
|
51
51
|
end
|
52
52
|
|
53
53
|
it "returns fale if the block never returns true" do
|
54
|
-
@list.one? { |item| false }.should
|
54
|
+
@list.one? { |item| false }.should == false
|
55
55
|
end
|
56
56
|
|
57
57
|
it "returns true if the block only returns true once" do
|
58
|
-
@list.one? { |item| item == "A" }.should
|
58
|
+
@list.one? { |item| item == "A" }.should == true
|
59
59
|
end
|
60
60
|
|
61
61
|
end
|
@@ -63,11 +63,11 @@ describe Hamster::List do
|
|
63
63
|
describe "with no block" do
|
64
64
|
|
65
65
|
it "returns false if more than one value is truthy" do
|
66
|
-
Hamster.list(nil, true, "A").one?.should
|
66
|
+
Hamster.list(nil, true, "A").one?.should == false
|
67
67
|
end
|
68
68
|
|
69
69
|
it "returns true if only one value is truthy" do
|
70
|
-
Hamster.list(nil, true, false).one?.should
|
70
|
+
Hamster.list(nil, true, false).one?.should == true
|
71
71
|
end
|
72
72
|
|
73
73
|
end
|
@@ -4,16 +4,42 @@ require 'hamster/list'
|
|
4
4
|
|
5
5
|
describe Hamster::List do
|
6
6
|
|
7
|
+
shared_examples_for "#partition without a block" do
|
8
|
+
|
9
|
+
describe "without a block" do
|
10
|
+
|
11
|
+
before do
|
12
|
+
@result = @original.partition
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns self" do
|
16
|
+
@result.should equal(@original)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
shared_examples_for "#partition is lazy" do
|
24
|
+
|
25
|
+
it "is lazy" do
|
26
|
+
count = 0
|
27
|
+
@original.partition { |item| count += 1; true }
|
28
|
+
count.should <= 1
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
7
33
|
describe "#partition" do
|
8
34
|
|
9
35
|
describe "doesn't run out of stack space on a really big" do
|
10
36
|
|
11
37
|
it "stream" do
|
12
|
-
@list = Hamster.interval(0,
|
38
|
+
@list = Hamster.interval(0, STACK_OVERFLOW_DEPTH)
|
13
39
|
end
|
14
40
|
|
15
41
|
it "list" do
|
16
|
-
@list = (0
|
42
|
+
@list = (0...STACK_OVERFLOW_DEPTH).reduce(Hamster.list) { |list, i| list.cons(i) }
|
17
43
|
end
|
18
44
|
|
19
45
|
after do
|
@@ -26,20 +52,35 @@ describe Hamster::List do
|
|
26
52
|
|
27
53
|
before do
|
28
54
|
count = 0
|
29
|
-
|
30
|
-
partitions = counter.partition { |item| item %2 != 0 }
|
31
|
-
@matches = partitions.car
|
32
|
-
@remainder = partitions.cadr
|
55
|
+
@original = Hamster.stream { count += 1 }
|
33
56
|
end
|
34
57
|
|
35
|
-
|
36
|
-
|
37
|
-
|
58
|
+
describe "with a block" do
|
59
|
+
|
60
|
+
before do
|
61
|
+
@result = @original.partition { |item| (item %2) != 0 }
|
62
|
+
@matches = @result.car
|
63
|
+
@remainder = @result.cadr
|
64
|
+
end
|
65
|
+
|
66
|
+
it "returns a list with two items" do
|
67
|
+
@result.size.should == 2
|
68
|
+
end
|
69
|
+
|
70
|
+
it "correctly identifies the matches" do
|
71
|
+
@matches.take(5).should == Hamster.list(1, 3, 5, 7, 9)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "correctly identifies the remainder" do
|
75
|
+
@remainder.take(5).should == Hamster.list(2, 4, 6, 8, 10)
|
76
|
+
end
|
38
77
|
|
39
|
-
it "correctly identifies the remainder" do
|
40
|
-
@remainder.take(5).should == Hamster.list(2, 4, 6, 8, 10)
|
41
78
|
end
|
42
79
|
|
80
|
+
it_should_behave_like "#partition without a block"
|
81
|
+
|
82
|
+
it_should_behave_like "#partition is lazy"
|
83
|
+
|
43
84
|
end
|
44
85
|
|
45
86
|
describe "on an interval" do
|
@@ -51,13 +92,17 @@ describe Hamster::List do
|
|
51
92
|
describe "with a block" do
|
52
93
|
|
53
94
|
before do
|
54
|
-
result = @original.partition { |item| (item % 2) != 0 }
|
55
|
-
@
|
56
|
-
@remainder = result.cadr
|
95
|
+
@result = @original.partition { |item| (item % 2) != 0 }
|
96
|
+
@matches = @result.car
|
97
|
+
@remainder = @result.cadr
|
98
|
+
end
|
99
|
+
|
100
|
+
it "returns a list with two items" do
|
101
|
+
@result.size.should == 2
|
57
102
|
end
|
58
103
|
|
59
104
|
it "correctly identifies the matches" do
|
60
|
-
@
|
105
|
+
@matches.should == Hamster.list(1, 3, 5, 7, 9)
|
61
106
|
end
|
62
107
|
|
63
108
|
it "correctly identifies the remainder" do
|
@@ -66,17 +111,9 @@ describe Hamster::List do
|
|
66
111
|
|
67
112
|
end
|
68
113
|
|
69
|
-
|
70
|
-
|
71
|
-
before do
|
72
|
-
@result = @original.partition
|
73
|
-
end
|
74
|
-
|
75
|
-
it "returns self" do
|
76
|
-
@result.should equal(@original)
|
77
|
-
end
|
114
|
+
it_should_behave_like "#partition without a block"
|
78
115
|
|
79
|
-
|
116
|
+
it_should_behave_like "#partition is lazy"
|
80
117
|
|
81
118
|
end
|
82
119
|
|
@@ -95,27 +132,38 @@ describe Hamster::List do
|
|
95
132
|
|
96
133
|
before do
|
97
134
|
@original = Hamster.list(*values)
|
98
|
-
@partitions = @original.partition { |item| (item % 2) != 0 }
|
99
|
-
@matches = @partitions.car
|
100
|
-
@remainder = @partitions.cadr
|
101
135
|
end
|
102
136
|
|
103
|
-
|
104
|
-
@original.should == Hamster.list(*values)
|
105
|
-
end
|
137
|
+
describe "with a block" do
|
106
138
|
|
107
|
-
|
108
|
-
|
109
|
-
|
139
|
+
before do
|
140
|
+
@result = @original.partition { |item| (item % 2) != 0 }
|
141
|
+
@matches = @result.car
|
142
|
+
@remainder = @result.cadr
|
143
|
+
end
|
110
144
|
|
111
|
-
|
112
|
-
|
113
|
-
|
145
|
+
it "preserves the original" do
|
146
|
+
@original.should == Hamster.list(*values)
|
147
|
+
end
|
148
|
+
|
149
|
+
it "returns a list with two items" do
|
150
|
+
@result.size.should == 2
|
151
|
+
end
|
152
|
+
|
153
|
+
it "correctly identifies the matches" do
|
154
|
+
@matches.should == Hamster.list(*expected_matches)
|
155
|
+
end
|
156
|
+
|
157
|
+
it "correctly identifies the remainder" do
|
158
|
+
@remainder.should == Hamster.list(*expected_remainder)
|
159
|
+
end
|
114
160
|
|
115
|
-
it "correctly identifies the remainder" do
|
116
|
-
@remainder.should == Hamster.list(*expected_remainder)
|
117
161
|
end
|
118
162
|
|
163
|
+
it_should_behave_like "#partition without a block"
|
164
|
+
|
165
|
+
it_should_behave_like "#partition is lazy"
|
166
|
+
|
119
167
|
end
|
120
168
|
|
121
169
|
end
|
@@ -11,11 +11,11 @@ describe Hamster::List do
|
|
11
11
|
describe "doesn't run out of stack space on a really big" do
|
12
12
|
|
13
13
|
it "stream" do
|
14
|
-
@list = Hamster.interval(0,
|
14
|
+
@list = Hamster.interval(0, STACK_OVERFLOW_DEPTH)
|
15
15
|
end
|
16
16
|
|
17
17
|
it "list" do
|
18
|
-
@list = (0
|
18
|
+
@list = (0...STACK_OVERFLOW_DEPTH).reduce(Hamster.list) { |list, i| list.cons(i) }
|
19
19
|
end
|
20
20
|
|
21
21
|
after do
|
@@ -11,11 +11,11 @@ describe Hamster::List do
|
|
11
11
|
describe "doesn't run out of stack space on a really big" do
|
12
12
|
|
13
13
|
it "stream" do
|
14
|
-
@list = Hamster.interval(0,
|
14
|
+
@list = Hamster.interval(0, STACK_OVERFLOW_DEPTH)
|
15
15
|
end
|
16
16
|
|
17
17
|
it "list" do
|
18
|
-
@list = (0
|
18
|
+
@list = (0...STACK_OVERFLOW_DEPTH).reduce(Hamster.list) { |list, i| list.cons(i) }
|
19
19
|
end
|
20
20
|
|
21
21
|
after do
|
@@ -35,18 +35,22 @@ describe Hamster::List do
|
|
35
35
|
describe "on #{values.inspect}" do
|
36
36
|
|
37
37
|
before do
|
38
|
-
@
|
38
|
+
@original = Hamster.list(*values)
|
39
39
|
end
|
40
40
|
|
41
41
|
describe "with a block" do
|
42
42
|
|
43
|
+
before do
|
44
|
+
@result = @original.send(method) { |item| item == item.downcase }
|
45
|
+
end
|
46
|
+
|
43
47
|
it "returns #{expected.inspect}" do
|
44
|
-
@
|
48
|
+
@result.should == Hamster.list(*expected)
|
45
49
|
end
|
46
50
|
|
47
51
|
it "is lazy" do
|
48
52
|
count = 0
|
49
|
-
@
|
53
|
+
@original.send(method) { |item| count += 1; false }
|
50
54
|
count.should <= 1
|
51
55
|
end
|
52
56
|
|
@@ -54,8 +58,12 @@ describe Hamster::List do
|
|
54
58
|
|
55
59
|
describe "without a block" do
|
56
60
|
|
61
|
+
before do
|
62
|
+
@result = @original.send(method)
|
63
|
+
end
|
64
|
+
|
57
65
|
it "returns self" do
|
58
|
-
@
|
66
|
+
@result.should equal(@original)
|
59
67
|
end
|
60
68
|
|
61
69
|
end
|