hamster 0.1.13 → 0.1.14
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 +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,38 +2,56 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
|
2
2
|
|
3
3
|
describe Hamster::List do
|
4
4
|
|
5
|
-
|
5
|
+
[:reject, :delete_if].each do |method|
|
6
6
|
|
7
|
-
|
8
|
-
[[], []],
|
9
|
-
[["A"], ["A"]],
|
10
|
-
[["A", "B", "C"], ["A", "B", "C"]],
|
11
|
-
[["A", "b", "C"], ["A", "C"]],
|
12
|
-
[["a", "b", "c"], []],
|
13
|
-
].each do |values, expected|
|
7
|
+
describe "##{method}" do
|
14
8
|
|
15
|
-
describe "on
|
9
|
+
describe "on a really big list" do
|
16
10
|
|
17
|
-
|
11
|
+
before do
|
12
|
+
@list = Hamster.interval(0, 10000)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "doesn't run out of stack space" do
|
16
|
+
@list.send(method) { true }
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
18
20
|
|
19
|
-
|
21
|
+
[
|
22
|
+
[[], []],
|
23
|
+
[["A"], ["A"]],
|
24
|
+
[["A", "B", "C"], ["A", "B", "C"]],
|
25
|
+
[["A", "b", "C"], ["A", "C"]],
|
26
|
+
[["a", "b", "c"], []],
|
27
|
+
].each do |values, expected|
|
20
28
|
|
21
|
-
|
22
|
-
|
29
|
+
describe "on #{values.inspect}" do
|
30
|
+
|
31
|
+
before do
|
32
|
+
@list = Hamster.list(*values)
|
23
33
|
end
|
24
34
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
35
|
+
describe "with a block" do
|
36
|
+
|
37
|
+
it "returns #{expected}" do
|
38
|
+
@list.send(method) { |item| item == item.downcase }.should == Hamster.list(*expected)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "is lazy" do
|
42
|
+
count = 0
|
43
|
+
@list.send(method) { |item| count += 1; false }
|
44
|
+
count.should <= 1
|
45
|
+
end
|
46
|
+
|
29
47
|
end
|
30
48
|
|
31
|
-
|
49
|
+
describe "without a block" do
|
32
50
|
|
33
|
-
|
51
|
+
it "returns self" do
|
52
|
+
@list.send(method).should equal(@list)
|
53
|
+
end
|
34
54
|
|
35
|
-
it "returns self" do
|
36
|
-
list.reject.should == list
|
37
55
|
end
|
38
56
|
|
39
57
|
end
|
@@ -6,6 +6,18 @@ describe Hamster::List do
|
|
6
6
|
|
7
7
|
describe "##{method}" do
|
8
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.size
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
9
21
|
[
|
10
22
|
[[], 0],
|
11
23
|
[["A"], 1],
|
@@ -14,10 +26,12 @@ describe Hamster::List do
|
|
14
26
|
|
15
27
|
describe "on #{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.send(method).should == expected
|
34
|
+
@list.send(method).should == expected
|
21
35
|
end
|
22
36
|
|
23
37
|
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.tail.should == Hamster.list(*expected)
|
20
|
+
@list.tail.should == Hamster.list(*expected)
|
19
21
|
end
|
20
22
|
|
21
23
|
end
|
@@ -4,6 +4,18 @@ describe Hamster::List do
|
|
4
4
|
|
5
5
|
describe "#take" 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.take(10000)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
7
19
|
[
|
8
20
|
[[], 10, []],
|
9
21
|
[["A"], 10, ["A"]],
|
@@ -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.take(number).should == Hamster.list(*expected)
|
34
|
+
@list.take(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 "#take_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.take_while { true }
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
7
19
|
[
|
8
20
|
[[], []],
|
9
21
|
[["A"], ["A"]],
|
@@ -12,17 +24,19 @@ 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.take_while { |item| item < "C" }.should == Hamster.list(*expected)
|
34
|
+
@list.take_while { |item| item < "C" }.should == Hamster.list(*expected)
|
21
35
|
end
|
22
36
|
|
23
37
|
it "is lazy" do
|
24
38
|
count = 0
|
25
|
-
list.take_while { |item| count += 1; true }
|
39
|
+
@list.take_while { |item| count += 1; true }
|
26
40
|
count.should <= 1
|
27
41
|
end
|
28
42
|
|
@@ -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.take_while.should
|
48
|
+
@list.take_while.should equal(@list)
|
35
49
|
end
|
36
50
|
|
37
51
|
end
|
@@ -4,6 +4,18 @@ describe Hamster::List do
|
|
4
4
|
|
5
5
|
describe "#to_a" 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.to_a
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
7
19
|
[
|
8
20
|
[],
|
9
21
|
["A"],
|
@@ -12,10 +24,12 @@ 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
|
it "returns #{values.inspect}" do
|
18
|
-
list.to_a.should == values
|
32
|
+
@list.to_a.should == values
|
19
33
|
end
|
20
34
|
|
21
35
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe Hamster::List do
|
4
|
+
|
5
|
+
describe "#to_ary" 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.to_ary
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "enables explicit conversion to" do
|
20
|
+
|
21
|
+
before do
|
22
|
+
@list = Hamster.list("A", "B", "C")
|
23
|
+
end
|
24
|
+
|
25
|
+
it "arrays" do
|
26
|
+
array = *@list
|
27
|
+
array.should == ["A", "B", "C"]
|
28
|
+
end
|
29
|
+
|
30
|
+
it "call parameters" do
|
31
|
+
[@list].each do |a, b, c|
|
32
|
+
a.should == "A"
|
33
|
+
b.should == "B"
|
34
|
+
c.should == "C"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -1,25 +1,55 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
2
|
|
3
|
+
require 'set'
|
4
|
+
|
3
5
|
describe Hamster::Set do
|
4
6
|
|
5
7
|
[:eql?, :==].each do |method|
|
6
8
|
|
7
9
|
describe "##{method}" do
|
8
10
|
|
11
|
+
describe "returns false when comparing with" do
|
12
|
+
|
13
|
+
before do
|
14
|
+
@set = Hamster.set("A", "B", "C")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "a standard set" do
|
18
|
+
@set.send(method, Set["A", "B", "C"]).should be_false
|
19
|
+
end
|
20
|
+
|
21
|
+
it "an aribtrary object" do
|
22
|
+
@set.send(method, Object.new).should be_false
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
9
27
|
[
|
10
28
|
[[], [], true],
|
29
|
+
[[], [nil], false],
|
11
30
|
[["A"], [], false],
|
12
|
-
[[], ["A"], false],
|
13
31
|
[["A"], ["A"], true],
|
14
32
|
[["A"], ["B"], false],
|
15
33
|
[["A", "B"], ["A"], false],
|
16
|
-
[["A"], ["A", "B"], false],
|
17
34
|
[["A", "B", "C"], ["A", "B", "C"], true],
|
18
35
|
[["C", "A", "B"], ["A", "B", "C"], true],
|
19
|
-
].each do |a, b,
|
36
|
+
].each do |a, b, expected|
|
37
|
+
|
38
|
+
describe "returns #{expected}" do
|
39
|
+
|
40
|
+
before do
|
41
|
+
@a = Hamster.set(*a)
|
42
|
+
@b = Hamster.set(*b)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "for #{a.inspect} and #{b.inspect}" do
|
46
|
+
@a.send(method, @b).should == expected
|
47
|
+
end
|
48
|
+
|
49
|
+
it "for #{b.inspect} and #{a.inspect}" do
|
50
|
+
@b.send(method, @a).should == expected
|
51
|
+
end
|
20
52
|
|
21
|
-
it "returns #{result} for #{a.inspect} and #{b.inspect}" do
|
22
|
-
Hamster.set(*a).send(method, Hamster.set(*b)).should == result
|
23
53
|
end
|
24
54
|
|
25
55
|
end
|
@@ -2,50 +2,54 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
|
2
2
|
|
3
3
|
describe Hamster::Set do
|
4
4
|
|
5
|
-
|
5
|
+
[:reject, :delete_if].each do |method|
|
6
6
|
|
7
|
-
|
8
|
-
@original = Hamster.set("A", "B", "C")
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "when nothing matches" do
|
7
|
+
describe "##{method}" do
|
12
8
|
|
13
9
|
before do
|
14
|
-
@
|
10
|
+
@original = Hamster.set("A", "B", "C")
|
15
11
|
end
|
16
12
|
|
17
|
-
|
18
|
-
|
13
|
+
describe "when nothing matches" do
|
14
|
+
|
15
|
+
before do
|
16
|
+
@result = @original.send(method) { |item| 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) { |item| item == "A" }
|
31
|
+
end
|
26
32
|
|
27
|
-
|
28
|
-
|
29
|
-
|
33
|
+
it "preserves the original" do
|
34
|
+
@original.should == Hamster.set("A", "B", "C")
|
35
|
+
end
|
30
36
|
|
31
|
-
|
32
|
-
|
33
|
-
|
37
|
+
it "returns a set with the matching values" do
|
38
|
+
@result.should == Hamster.set("B", "C")
|
39
|
+
end
|
34
40
|
|
35
|
-
it "returns a set with the matching values" do
|
36
|
-
@result.should == Hamster.set("B", "C")
|
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
|