hamster 0.1.23 → 0.2.0
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 +26 -0
- data/README.rdoc +1 -1
- data/lib/hamster.rb +1 -1
- data/lib/hamster/core_ext/io.rb +7 -5
- data/lib/hamster/hash.rb +31 -29
- data/lib/hamster/list.rb +203 -128
- data/lib/hamster/set.rb +39 -25
- data/lib/hamster/stack.rb +9 -5
- data/lib/hamster/trie.rb +5 -1
- data/lib/hamster/version.rb +1 -1
- data/spec/hamster/hash/all_spec.rb +29 -25
- data/spec/hamster/hash/reduce_spec.rb +1 -1
- data/spec/hamster/hash/uniq_spec.rb +23 -0
- data/spec/hamster/list/all_spec.rb +55 -55
- data/spec/hamster/list/any_spec.rb +4 -8
- data/spec/hamster/list/append_spec.rb +2 -20
- data/spec/hamster/list/break_spec.rb +22 -121
- data/spec/hamster/list/cadr_spec.rb +4 -0
- data/spec/hamster/list/chunk_spec.rb +6 -0
- data/spec/hamster/list/combinations_spec.rb +51 -0
- data/spec/hamster/list/count_spec.rb +4 -8
- data/spec/hamster/list/cycle_spec.rb +5 -24
- data/spec/hamster/list/drop_spec.rb +2 -14
- data/spec/hamster/list/drop_while_spec.rb +2 -14
- data/spec/hamster/list/each_spec.rb +4 -8
- data/spec/hamster/list/eql_spec.rb +9 -10
- data/spec/hamster/list/filter_spec.rb +2 -20
- data/spec/hamster/list/find_spec.rb +4 -8
- data/spec/hamster/list/grep_spec.rb +2 -20
- data/spec/hamster/list/include_spec.rb +4 -8
- data/spec/hamster/list/init_spec.rb +4 -0
- data/spec/hamster/list/inits_spec.rb +42 -0
- data/spec/hamster/list/inspect_spec.rb +4 -8
- data/spec/hamster/list/intersperse_spec.rb +2 -14
- data/spec/hamster/list/join_spec.rb +4 -8
- data/spec/hamster/list/last_spec.rb +4 -8
- data/spec/hamster/list/map_spec.rb +2 -14
- data/spec/hamster/list/maximum_spec.rb +4 -8
- data/spec/hamster/list/minimum_spec.rb +4 -8
- data/spec/hamster/list/none_spec.rb +4 -8
- data/spec/hamster/list/one_spec.rb +4 -8
- data/spec/hamster/list/partition_spec.rb +12 -111
- data/spec/hamster/list/product_spec.rb +4 -8
- data/spec/hamster/list/reduce_spec.rb +4 -8
- data/spec/hamster/list/remove_spec.rb +2 -14
- data/spec/hamster/list/reverse_spec.rb +4 -8
- data/spec/hamster/list/size_spec.rb +4 -8
- data/spec/hamster/list/sorting_spec.rb +2 -14
- data/spec/hamster/list/span_spec.rb +22 -121
- data/spec/hamster/list/split_at_spec.rb +2 -65
- data/spec/hamster/list/sum_spec.rb +4 -8
- data/spec/hamster/list/tails_spec.rb +42 -0
- data/spec/hamster/list/take_spec.rb +2 -14
- data/spec/hamster/list/take_while_spec.rb +2 -14
- data/spec/hamster/list/to_a_spec.rb +4 -8
- data/spec/hamster/list/to_ary_spec.rb +4 -8
- data/spec/hamster/list/union_spec.rb +1 -21
- data/spec/hamster/list/uniq_spec.rb +3 -15
- data/spec/hamster/list/zip_spec.rb +1 -21
- data/spec/hamster/set/all_spec.rb +33 -29
- data/spec/hamster/set/product_spec.rb +32 -0
- data/spec/hamster/set/sum_spec.rb +32 -0
- data/spec/hamster/set/uniq_spec.rb +1 -1
- data/spec/spec.opts +0 -1
- metadata +8 -2
@@ -6,20 +6,8 @@ describe Hamster::List do
|
|
6
6
|
|
7
7
|
describe "#take_while" do
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
it "stream" do
|
12
|
-
@list = Hamster.interval(0, STACK_OVERFLOW_DEPTH)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "list" do
|
16
|
-
@list = (0...STACK_OVERFLOW_DEPTH).reduce(Hamster.list) { |list, i| list.cons(i) }
|
17
|
-
end
|
18
|
-
|
19
|
-
after do
|
20
|
-
@list.take_while { true }
|
21
|
-
end
|
22
|
-
|
9
|
+
it "is lazy" do
|
10
|
+
lambda { Hamster.stream { fail }.take_while { false } }.should_not raise_error
|
23
11
|
end
|
24
12
|
|
25
13
|
[
|
@@ -8,18 +8,14 @@ describe Hamster::List do
|
|
8
8
|
|
9
9
|
describe "##{method}" do
|
10
10
|
|
11
|
-
describe "
|
11
|
+
describe "on a really big list" do
|
12
12
|
|
13
|
-
|
13
|
+
before do
|
14
14
|
@list = Hamster.interval(0, STACK_OVERFLOW_DEPTH)
|
15
15
|
end
|
16
16
|
|
17
|
-
it "
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
after do
|
22
|
-
@list.send(method)
|
17
|
+
it "doesn't run out of stack" do
|
18
|
+
lambda { @list.to_a }.should_not raise_error
|
23
19
|
end
|
24
20
|
|
25
21
|
end
|
@@ -6,18 +6,14 @@ describe Hamster::List do
|
|
6
6
|
|
7
7
|
describe "#to_ary" do
|
8
8
|
|
9
|
-
describe "
|
9
|
+
describe "on a really big list" do
|
10
10
|
|
11
|
-
|
11
|
+
before do
|
12
12
|
@list = Hamster.interval(0, STACK_OVERFLOW_DEPTH)
|
13
13
|
end
|
14
14
|
|
15
|
-
it "
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
after do
|
20
|
-
@list.to_ary
|
15
|
+
it "doesn't run out of stack" do
|
16
|
+
lambda { @list.to_ary }.should_not raise_error
|
21
17
|
end
|
22
18
|
|
23
19
|
end
|
@@ -8,28 +8,8 @@ describe Hamster::List do
|
|
8
8
|
|
9
9
|
describe "#union" do
|
10
10
|
|
11
|
-
describe "doesn't run out of stack space on a really big" do
|
12
|
-
|
13
|
-
it "stream" do
|
14
|
-
@a = @b = Hamster.interval(0, STACK_OVERFLOW_DEPTH)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "list" do
|
18
|
-
@a = @b = (0...STACK_OVERFLOW_DEPTH).reduce(Hamster.list) { |list, i| list.cons(i) }
|
19
|
-
end
|
20
|
-
|
21
|
-
after do
|
22
|
-
@a.send(method, @b)
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
11
|
it "is lazy" do
|
28
|
-
|
29
|
-
a = Hamster.stream { count += 1 }
|
30
|
-
b = Hamster.stream { count += 1 }
|
31
|
-
result = a.send(method, b)
|
32
|
-
count.should <= 2
|
12
|
+
lambda { Hamster.stream { fail }.union(Hamster.stream { fail }) }.should_not raise_error
|
33
13
|
end
|
34
14
|
|
35
15
|
[
|
@@ -4,24 +4,12 @@ require 'hamster/list'
|
|
4
4
|
|
5
5
|
describe Hamster::List do
|
6
6
|
|
7
|
-
[:uniq, :nub].each do |method|
|
7
|
+
[:uniq, :nub, :remove_duplicates].each do |method|
|
8
8
|
|
9
9
|
describe "##{method}" do
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
it "stream" do
|
14
|
-
@list = Hamster.replicate(STACK_OVERFLOW_DEPTH, 0)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "list" do
|
18
|
-
@list = (0...STACK_OVERFLOW_DEPTH).reduce(Hamster.list) { |list, i| list.cons(0) }
|
19
|
-
end
|
20
|
-
|
21
|
-
after do
|
22
|
-
@list.send(method).each {}
|
23
|
-
end
|
24
|
-
|
11
|
+
it "is lazy" do
|
12
|
+
lambda { Hamster.stream { fail }.uniq }.should_not raise_error
|
25
13
|
end
|
26
14
|
|
27
15
|
[
|
@@ -6,28 +6,8 @@ describe Hamster::List do
|
|
6
6
|
|
7
7
|
describe "#zip" do
|
8
8
|
|
9
|
-
describe "doesn't run out of stack space on a really big" do
|
10
|
-
|
11
|
-
it "stream" do
|
12
|
-
@left = @right = Hamster.interval(0, STACK_OVERFLOW_DEPTH)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "list" do
|
16
|
-
@left = @right = (0...STACK_OVERFLOW_DEPTH).reduce(Hamster.list) { |list, i| list.cons(i) }
|
17
|
-
end
|
18
|
-
|
19
|
-
after do
|
20
|
-
@left.zip(@right)
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
9
|
it "is lazy" do
|
26
|
-
|
27
|
-
left = Hamster.stream { count += 1 }
|
28
|
-
right = Hamster.stream { count += 1 }
|
29
|
-
result = left.zip(right)
|
30
|
-
count.should <= 2
|
10
|
+
lambda { Hamster.stream { fail }.zip(Hamster.stream { fail }) }.should_not raise_error
|
31
11
|
end
|
32
12
|
|
33
13
|
[
|
@@ -4,52 +4,56 @@ require 'hamster/set'
|
|
4
4
|
|
5
5
|
describe Hamster::Set do
|
6
6
|
|
7
|
-
|
7
|
+
[:all?, :forall?].each do |method|
|
8
8
|
|
9
|
-
describe "
|
9
|
+
describe "##{method}" do
|
10
10
|
|
11
|
-
|
12
|
-
@set = Hamster.set
|
13
|
-
end
|
11
|
+
describe "when empty" do
|
14
12
|
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
before do
|
14
|
+
@set = Hamster.set
|
15
|
+
end
|
16
|
+
|
17
|
+
it "with a block returns true" do
|
18
|
+
@set.send(method) {}.should == true
|
19
|
+
end
|
20
|
+
|
21
|
+
it "with no block returns true" do
|
22
|
+
@set.send(method).should == true
|
23
|
+
end
|
18
24
|
|
19
|
-
it "with no block returns true" do
|
20
|
-
@set.all?.should == true
|
21
25
|
end
|
22
26
|
|
23
|
-
|
27
|
+
describe "when not empty" do
|
24
28
|
|
25
|
-
|
29
|
+
describe "with a block" do
|
26
30
|
|
27
|
-
|
31
|
+
before do
|
32
|
+
@set = Hamster.set("A", "B", "C")
|
33
|
+
end
|
28
34
|
|
29
|
-
|
30
|
-
|
31
|
-
|
35
|
+
it "returns true if the block always returns true" do
|
36
|
+
@set.send(method) { |item| true }.should == true
|
37
|
+
end
|
32
38
|
|
33
|
-
|
34
|
-
|
35
|
-
|
39
|
+
it "returns false if the block ever returns false" do
|
40
|
+
@set.send(method) { |item| item == "D" }.should == false
|
41
|
+
end
|
36
42
|
|
37
|
-
it "returns false if the block ever returns false" do
|
38
|
-
@set.all? { |item| item == "D" }.should == false
|
39
43
|
end
|
40
44
|
|
41
|
-
|
45
|
+
describe "with no block" do
|
42
46
|
|
43
|
-
|
47
|
+
it "returns true if all values are truthy" do
|
48
|
+
Hamster.set(true, "A").send(method).should == true
|
49
|
+
end
|
44
50
|
|
45
|
-
|
46
|
-
Hamster.set(true, "A").all?.should == true
|
47
|
-
end
|
51
|
+
[nil, false].each do |value|
|
48
52
|
|
49
|
-
|
53
|
+
it "returns false if any value is #{value.inspect}" do
|
54
|
+
Hamster.set(value, true, "A").send(method).should == false
|
55
|
+
end
|
50
56
|
|
51
|
-
it "returns false if any value is #{value.inspect}" do
|
52
|
-
Hamster.set(value, true, "A").all?.should == false
|
53
57
|
end
|
54
58
|
|
55
59
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
require 'hamster/set'
|
4
|
+
|
5
|
+
describe Hamster::Set do
|
6
|
+
|
7
|
+
describe "#product" do
|
8
|
+
|
9
|
+
[
|
10
|
+
[[], 1],
|
11
|
+
[[2], 2],
|
12
|
+
[[1, 3, 5, 7, 11], 1155],
|
13
|
+
].each do |values, expected|
|
14
|
+
|
15
|
+
describe "on #{values.inspect}" do
|
16
|
+
|
17
|
+
before do
|
18
|
+
original = Hamster.set(*values)
|
19
|
+
@result = original.product
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns #{expected.inspect}" do
|
23
|
+
@result.should == expected
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
require 'hamster/set'
|
4
|
+
|
5
|
+
describe Hamster::Set do
|
6
|
+
|
7
|
+
describe "#sum" do
|
8
|
+
|
9
|
+
[
|
10
|
+
[[], 0],
|
11
|
+
[[2], 2],
|
12
|
+
[[1, 3, 5, 7, 11], 27],
|
13
|
+
].each do |values, expected|
|
14
|
+
|
15
|
+
describe "on #{values.inspect}" do
|
16
|
+
|
17
|
+
before do
|
18
|
+
original = Hamster.set(*values)
|
19
|
+
@result = original.sum
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns #{expected.inspect}" do
|
23
|
+
@result.should == expected
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
data/spec/spec.opts
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hamster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Harris
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-14 00:00:00 +11:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- spec/hamster/hash/reduce_spec.rb
|
64
64
|
- spec/hamster/hash/remove_spec.rb
|
65
65
|
- spec/hamster/hash/size_spec.rb
|
66
|
+
- spec/hamster/hash/uniq_spec.rb
|
66
67
|
- spec/hamster/list/all_spec.rb
|
67
68
|
- spec/hamster/list/any_spec.rb
|
68
69
|
- spec/hamster/list/append_spec.rb
|
@@ -70,6 +71,7 @@ files:
|
|
70
71
|
- spec/hamster/list/cadr_spec.rb
|
71
72
|
- spec/hamster/list/chunk_spec.rb
|
72
73
|
- spec/hamster/list/clear_spec.rb
|
74
|
+
- spec/hamster/list/combinations_spec.rb
|
73
75
|
- spec/hamster/list/cons_spec.rb
|
74
76
|
- spec/hamster/list/construction_spec.rb
|
75
77
|
- spec/hamster/list/copying_spec.rb
|
@@ -86,6 +88,7 @@ files:
|
|
86
88
|
- spec/hamster/list/head_spec.rb
|
87
89
|
- spec/hamster/list/include_spec.rb
|
88
90
|
- spec/hamster/list/init_spec.rb
|
91
|
+
- spec/hamster/list/inits_spec.rb
|
89
92
|
- spec/hamster/list/inspect_spec.rb
|
90
93
|
- spec/hamster/list/intersperse_spec.rb
|
91
94
|
- spec/hamster/list/join_spec.rb
|
@@ -106,6 +109,7 @@ files:
|
|
106
109
|
- spec/hamster/list/split_at_spec.rb
|
107
110
|
- spec/hamster/list/sum_spec.rb
|
108
111
|
- spec/hamster/list/tail_spec.rb
|
112
|
+
- spec/hamster/list/tails_spec.rb
|
109
113
|
- spec/hamster/list/take_spec.rb
|
110
114
|
- spec/hamster/list/take_while_spec.rb
|
111
115
|
- spec/hamster/list/to_a_spec.rb
|
@@ -136,10 +140,12 @@ files:
|
|
136
140
|
- spec/hamster/set/minimum_spec.rb
|
137
141
|
- spec/hamster/set/none_spec.rb
|
138
142
|
- spec/hamster/set/partition_spec.rb
|
143
|
+
- spec/hamster/set/product_spec.rb
|
139
144
|
- spec/hamster/set/reduce_spec.rb
|
140
145
|
- spec/hamster/set/remove_spec.rb
|
141
146
|
- spec/hamster/set/size_spec.rb
|
142
147
|
- spec/hamster/set/sorting_spec.rb
|
148
|
+
- spec/hamster/set/sum_spec.rb
|
143
149
|
- spec/hamster/set/to_a_spec.rb
|
144
150
|
- spec/hamster/set/to_list_spec.rb
|
145
151
|
- spec/hamster/set/to_set_spec.rb
|