hamster 0.1.13 → 0.1.14
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +14 -0
- data/README.rdoc +2 -2
- data/lib/hamster/hash.rb +10 -9
- data/lib/hamster/list.rb +96 -64
- data/lib/hamster/set.rb +12 -5
- data/lib/hamster/version.rb +1 -1
- data/spec/hamster/hash/all_spec.rb +1 -1
- data/spec/hamster/hash/eql_spec.rb +42 -13
- data/spec/hamster/hash/filter_spec.rb +1 -1
- data/spec/hamster/hash/reduce_spec.rb +1 -1
- data/spec/hamster/hash/reject_spec.rb +31 -27
- data/spec/hamster/list/all_spec.rb +73 -0
- data/spec/hamster/list/any_spec.rb +77 -0
- data/spec/hamster/list/cadr_spec.rb +4 -2
- data/spec/hamster/list/cons_spec.rb +6 -4
- data/spec/hamster/list/copying_spec.rb +4 -2
- data/spec/hamster/list/drop_spec.rb +16 -2
- data/spec/hamster/list/drop_while_spec.rb +17 -3
- data/spec/hamster/list/each_spec.rb +18 -4
- data/spec/hamster/list/empty_spec.rb +4 -2
- data/spec/hamster/list/eql_spec.rb +41 -7
- data/spec/hamster/list/filter_spec.rb +20 -6
- data/spec/hamster/list/find_spec.rb +63 -0
- data/spec/hamster/list/head_spec.rb +4 -2
- data/spec/hamster/list/include_spec.rb +16 -2
- data/spec/hamster/list/inspect_spec.rb +16 -2
- data/spec/hamster/list/map_spec.rb +18 -4
- data/spec/hamster/list/none_spec.rb +73 -0
- data/spec/hamster/list/reduce_spec.rb +66 -12
- data/spec/hamster/list/reject_spec.rb +39 -21
- data/spec/hamster/list/size_spec.rb +16 -2
- data/spec/hamster/list/tail_spec.rb +4 -2
- data/spec/hamster/list/take_spec.rb +16 -2
- data/spec/hamster/list/take_while_spec.rb +18 -4
- data/spec/hamster/list/to_a_spec.rb +16 -2
- data/spec/hamster/list/to_ary_spec.rb +42 -0
- data/spec/hamster/set/eql_spec.rb +35 -5
- data/spec/hamster/set/filter_spec.rb +1 -1
- data/spec/hamster/set/reduce_spec.rb +1 -1
- data/spec/hamster/set/reject_spec.rb +31 -27
- data/spec/hamster/set/to_a_spec.rb +29 -0
- data/spec/hamster/stack/copying_spec.rb +4 -2
- data/spec/hamster/stack/empty_spec.rb +4 -2
- data/spec/hamster/stack/eql_spec.rb +27 -7
- data/spec/hamster/stack/inspect_spec.rb +4 -2
- data/spec/hamster/stack/pop_spec.rb +12 -8
- data/spec/hamster/stack/push_spec.rb +6 -4
- data/spec/hamster/stack/size_spec.rb +4 -2
- data/spec/hamster/stack/top_spec.rb +6 -4
- metadata +8 -2
@@ -2,50 +2,54 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
|
2
2
|
|
3
3
|
describe Hamster::Hash do
|
4
4
|
|
5
|
-
|
5
|
+
[:reject, :delete_if].each do |method|
|
6
6
|
|
7
|
-
|
8
|
-
@original = Hamster.hash("A" => "aye", "B" => "bee", "C" => "see")
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "when nothing matches" do
|
7
|
+
describe "##{method}" do
|
12
8
|
|
13
9
|
before do
|
14
|
-
@
|
10
|
+
@original = Hamster.hash("A" => "aye", "B" => "bee", "C" => "see")
|
15
11
|
end
|
16
12
|
|
17
|
-
|
18
|
-
|
13
|
+
describe "when nothing matches" do
|
14
|
+
|
15
|
+
before do
|
16
|
+
@result = @original.send(method) { |key, value| false }
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns self" do
|
20
|
+
@result.should equal(@original)
|
21
|
+
end
|
22
|
+
|
19
23
|
end
|
20
24
|
|
21
|
-
|
25
|
+
describe "when only some things match" do
|
22
26
|
|
23
|
-
|
27
|
+
describe "with a block" do
|
24
28
|
|
25
|
-
|
29
|
+
before do
|
30
|
+
@result = @original.send(method) { |key, value| key == "A" && value == "aye" }
|
31
|
+
end
|
26
32
|
|
27
|
-
|
28
|
-
|
29
|
-
|
33
|
+
it "preserves the original" do
|
34
|
+
@original.should == Hamster.hash("A" => "aye", "B" => "bee", "C" => "see")
|
35
|
+
end
|
30
36
|
|
31
|
-
|
32
|
-
|
33
|
-
|
37
|
+
it "returns a set with the matching values" do
|
38
|
+
@result.should == Hamster.hash("B" => "bee", "C" => "see")
|
39
|
+
end
|
34
40
|
|
35
|
-
it "returns a set with the matching values" do
|
36
|
-
@result.should == Hamster.hash("B" => "bee", "C" => "see")
|
37
41
|
end
|
38
42
|
|
39
|
-
|
43
|
+
describe "with no block" do
|
40
44
|
|
41
|
-
|
45
|
+
before do
|
46
|
+
@result = @original.send(method)
|
47
|
+
end
|
42
48
|
|
43
|
-
|
44
|
-
|
45
|
-
|
49
|
+
it "returns self" do
|
50
|
+
@result.should equal(@original)
|
51
|
+
end
|
46
52
|
|
47
|
-
it "returns self" do
|
48
|
-
@result.should equal(@original)
|
49
53
|
end
|
50
54
|
|
51
55
|
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe Hamster::List do
|
4
|
+
|
5
|
+
describe "#all?" do
|
6
|
+
|
7
|
+
describe "on a really big list" do
|
8
|
+
|
9
|
+
before do
|
10
|
+
@list = Hamster.interval(0, 10000)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "doesn't run out of stack space" do
|
14
|
+
@list.all? { true }
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "when empty" do
|
20
|
+
|
21
|
+
before do
|
22
|
+
@list = Hamster.list
|
23
|
+
end
|
24
|
+
|
25
|
+
it "with a block returns true" do
|
26
|
+
@list.all? {}.should be_true
|
27
|
+
end
|
28
|
+
|
29
|
+
it "with no block returns true" do
|
30
|
+
@list.all?.should be_true
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "when not empty" do
|
36
|
+
|
37
|
+
describe "with a block" do
|
38
|
+
|
39
|
+
before do
|
40
|
+
@list = Hamster.list("A", "B", "C")
|
41
|
+
end
|
42
|
+
|
43
|
+
it "returns true if the block always returns true" do
|
44
|
+
@list.all? { |item| true }.should be_true
|
45
|
+
end
|
46
|
+
|
47
|
+
it "returns false if the block ever returns false" do
|
48
|
+
@list.all? { |item| item == "D" }.should be_false
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "with no block" do
|
54
|
+
|
55
|
+
it "returns true if all values are truthy" do
|
56
|
+
Hamster.list(true, "A").all?.should be_true
|
57
|
+
end
|
58
|
+
|
59
|
+
[nil, false].each do |value|
|
60
|
+
|
61
|
+
it "returns false if any value is #{value.inspect}" do
|
62
|
+
Hamster.list(value, true, "A").all?.should be_false
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe Hamster::List do
|
4
|
+
|
5
|
+
[:any?, :exist?, :exists?].each do |method|
|
6
|
+
|
7
|
+
describe "##{method}" do
|
8
|
+
|
9
|
+
describe "on a really big list" do
|
10
|
+
|
11
|
+
before do
|
12
|
+
@list = Hamster.interval(0, 10000)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "doesn't run out of stack space" do
|
16
|
+
@list.any? { false }
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "when empty" do
|
22
|
+
|
23
|
+
before do
|
24
|
+
@list = Hamster.list
|
25
|
+
end
|
26
|
+
|
27
|
+
it "with a block returns false" do
|
28
|
+
@list.send(method) {}.should be_false
|
29
|
+
end
|
30
|
+
|
31
|
+
it "with no block returns false" do
|
32
|
+
@list.send(method).should be_false
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "when not empty" do
|
38
|
+
|
39
|
+
describe "with a block" do
|
40
|
+
|
41
|
+
before do
|
42
|
+
@list = Hamster.list("A", "B", "C", nil)
|
43
|
+
end
|
44
|
+
|
45
|
+
["A", "B", "C", nil].each do |value|
|
46
|
+
|
47
|
+
it "returns true if the block ever returns true (#{value.inspect})" do
|
48
|
+
@list.send(method) { |item| item == value }.should be_true
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
it "returns false if the block always returns false" do
|
54
|
+
@list.send(method) { |item| item == "D" }.should be_false
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "with no block" do
|
60
|
+
|
61
|
+
it "returns true if any value is truthy" do
|
62
|
+
Hamster.list(nil, false, true, "A").send(method).should be_true
|
63
|
+
end
|
64
|
+
|
65
|
+
it "returns false if all values are falsey" do
|
66
|
+
Hamster.list(nil, false).send(method).should be_false
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
@@ -22,10 +22,12 @@ describe Hamster::List do
|
|
22
22
|
|
23
23
|
describe "on #{values.inspect}" do
|
24
24
|
|
25
|
-
|
25
|
+
before do
|
26
|
+
@list = Hamster.list(*values)
|
27
|
+
end
|
26
28
|
|
27
29
|
it "returns #{expected}" do
|
28
|
-
list.send(method).should == expected
|
30
|
+
@list.send(method).should == expected
|
29
31
|
end
|
30
32
|
|
31
33
|
end
|
@@ -15,15 +15,17 @@ describe Hamster::List do
|
|
15
15
|
|
16
16
|
describe "on #{values.inspect} with #{new_value.inspect}" do
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
before do
|
19
|
+
@original = Hamster.list(*values)
|
20
|
+
@result = @original.send(method, new_value)
|
21
|
+
end
|
20
22
|
|
21
23
|
it "preserves the original" do
|
22
|
-
original.should == Hamster.list(*values)
|
24
|
+
@original.should == Hamster.list(*values)
|
23
25
|
end
|
24
26
|
|
25
27
|
it "returns #{expected.inspect}" do
|
26
|
-
result.should == Hamster.list(*expected)
|
28
|
+
@result.should == Hamster.list(*expected)
|
27
29
|
end
|
28
30
|
|
29
31
|
end
|
@@ -12,10 +12,12 @@ describe Hamster::List do
|
|
12
12
|
|
13
13
|
describe "on #{values.inspect}" do
|
14
14
|
|
15
|
-
|
15
|
+
before do
|
16
|
+
@list = Hamster.list(*values)
|
17
|
+
end
|
16
18
|
|
17
19
|
it "returns self" do
|
18
|
-
list.send(method).should equal(list)
|
20
|
+
@list.send(method).should equal(@list)
|
19
21
|
end
|
20
22
|
|
21
23
|
end
|
@@ -4,6 +4,18 @@ describe Hamster::List do
|
|
4
4
|
|
5
5
|
describe "#drop" do
|
6
6
|
|
7
|
+
describe "on a really big list" do
|
8
|
+
|
9
|
+
before do
|
10
|
+
@list = Hamster.interval(0, 10000)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "doesn't run out of stack space" do
|
14
|
+
@list.drop(10000)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
7
19
|
[
|
8
20
|
[[], 10, []],
|
9
21
|
[["A"], 10, []],
|
@@ -14,10 +26,12 @@ describe Hamster::List do
|
|
14
26
|
|
15
27
|
describe "#{number} from #{values.inspect}" do
|
16
28
|
|
17
|
-
|
29
|
+
before do
|
30
|
+
@list = Hamster.list(*values)
|
31
|
+
end
|
18
32
|
|
19
33
|
it "returns #{expected}" do
|
20
|
-
list.drop(number).should == Hamster.list(*expected)
|
34
|
+
@list.drop(number).should == Hamster.list(*expected)
|
21
35
|
end
|
22
36
|
|
23
37
|
end
|
@@ -4,6 +4,18 @@ describe Hamster::List do
|
|
4
4
|
|
5
5
|
describe "#drop_while" do
|
6
6
|
|
7
|
+
describe "on a really big list" do
|
8
|
+
|
9
|
+
before do
|
10
|
+
@list = Hamster.interval(0, 10000)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "doesn't run out of stack space" do
|
14
|
+
@list.drop_while { true }
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
7
19
|
[
|
8
20
|
[[], []],
|
9
21
|
[["A"], []],
|
@@ -12,12 +24,14 @@ describe Hamster::List do
|
|
12
24
|
|
13
25
|
describe "on #{values.inspect}" do
|
14
26
|
|
15
|
-
|
27
|
+
before do
|
28
|
+
@list = Hamster.list(*values)
|
29
|
+
end
|
16
30
|
|
17
31
|
describe "with a block" do
|
18
32
|
|
19
33
|
it "returns #{expected}" do
|
20
|
-
list.drop_while { |item| item < "C" }.should == Hamster.list(*expected)
|
34
|
+
@list.drop_while { |item| item < "C" }.should == Hamster.list(*expected)
|
21
35
|
end
|
22
36
|
|
23
37
|
end
|
@@ -25,7 +39,7 @@ describe Hamster::List do
|
|
25
39
|
describe "without a block" do
|
26
40
|
|
27
41
|
it "returns self" do
|
28
|
-
list.drop_while.should
|
42
|
+
@list.drop_while.should equal(@list)
|
29
43
|
end
|
30
44
|
|
31
45
|
end
|
@@ -4,6 +4,18 @@ describe Hamster::List do
|
|
4
4
|
|
5
5
|
describe "#each" do
|
6
6
|
|
7
|
+
describe "on a really big list" do
|
8
|
+
|
9
|
+
before do
|
10
|
+
@list = Hamster.interval(0, 10000)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "doesn't run out of stack space" do
|
14
|
+
@list.each {}
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
7
19
|
[
|
8
20
|
[],
|
9
21
|
["A"],
|
@@ -12,18 +24,20 @@ describe Hamster::List do
|
|
12
24
|
|
13
25
|
describe "on #{values.inspect}" do
|
14
26
|
|
15
|
-
|
27
|
+
before do
|
28
|
+
@list = Hamster.list(*values)
|
29
|
+
end
|
16
30
|
|
17
31
|
describe "with a block" do
|
18
32
|
|
19
33
|
it "iterates over the items in order" do
|
20
34
|
items = []
|
21
|
-
list.each { |value| items << value }
|
35
|
+
@list.each { |value| items << value }
|
22
36
|
items.should == values
|
23
37
|
end
|
24
38
|
|
25
39
|
it "returns nil" do
|
26
|
-
list.each {}.should be_nil
|
40
|
+
@list.each {}.should be_nil
|
27
41
|
end
|
28
42
|
|
29
43
|
end
|
@@ -31,7 +45,7 @@ describe Hamster::List do
|
|
31
45
|
describe "without a block" do
|
32
46
|
|
33
47
|
it "returns self" do
|
34
|
-
list.each.should
|
48
|
+
@list.each.should equal(@list)
|
35
49
|
end
|
36
50
|
|
37
51
|
end
|
@@ -12,10 +12,12 @@ describe Hamster::List do
|
|
12
12
|
|
13
13
|
describe "on #{values.inspect}" do
|
14
14
|
|
15
|
-
|
15
|
+
before do
|
16
|
+
@list = Hamster.list(*values)
|
17
|
+
end
|
16
18
|
|
17
19
|
it "returns #{expected}" do
|
18
|
-
list.empty?.should == expected
|
20
|
+
@list.empty?.should == expected
|
19
21
|
end
|
20
22
|
|
21
23
|
end
|