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.
Files changed (209) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hamster/groupable.rb +12 -0
  3. data/lib/hamster/hash.rb +32 -12
  4. data/lib/hamster/list.rb +68 -22
  5. data/lib/hamster/queue.rb +5 -6
  6. data/lib/hamster/set.rb +50 -14
  7. data/lib/hamster/stack.rb +2 -0
  8. data/lib/hamster/trie.rb +34 -14
  9. data/lib/hamster/tuple.rb +9 -24
  10. data/lib/hamster/vector.rb +29 -7
  11. data/lib/hamster/version.rb +1 -1
  12. data/spec/hamster/core_ext/array_spec.rb +4 -10
  13. data/spec/hamster/core_ext/enumerable_spec.rb +1 -0
  14. data/spec/hamster/experimental/mutable_set/add_qm_spec.rb +14 -22
  15. data/spec/hamster/experimental/mutable_set/add_spec.rb +20 -34
  16. data/spec/hamster/experimental/mutable_set/delete_qm_spec.rb +15 -24
  17. data/spec/hamster/experimental/mutable_set/delete_spec.rb +15 -25
  18. data/spec/hamster/experimental/mutable_stack/pop_spec.rb +21 -27
  19. data/spec/hamster/experimental/mutable_stack/push_spec.rb +11 -31
  20. data/spec/hamster/hash/all_spec.rb +21 -34
  21. data/spec/hamster/hash/any_spec.rb +0 -15
  22. data/spec/hamster/hash/clear_spec.rb +1 -8
  23. data/spec/hamster/hash/construction_spec.rb +3 -11
  24. data/spec/hamster/hash/copying_spec.rb +1 -8
  25. data/spec/hamster/hash/delete_spec.rb +1 -10
  26. data/spec/hamster/hash/each_spec.rb +1 -12
  27. data/spec/hamster/hash/empty_spec.rb +8 -8
  28. data/spec/hamster/hash/eql_spec.rb +30 -22
  29. data/spec/hamster/hash/except_spec.rb +1 -10
  30. data/spec/hamster/hash/fetch_spec.rb +1 -24
  31. data/spec/hamster/hash/filter_spec.rb +1 -16
  32. data/spec/hamster/hash/find_spec.rb +1 -14
  33. data/spec/hamster/hash/has_key_spec.rb +1 -10
  34. data/spec/hamster/hash/hash_spec.rb +1 -16
  35. data/spec/hamster/hash/immutable_spec.rb +0 -3
  36. data/spec/hamster/hash/inspect_spec.rb +1 -9
  37. data/spec/hamster/hash/keys_spec.rb +4 -5
  38. data/spec/hamster/hash/map_spec.rb +1 -16
  39. data/spec/hamster/hash/merge_spec.rb +5 -11
  40. data/spec/hamster/hash/new_spec.rb +21 -0
  41. data/spec/hamster/hash/put_spec.rb +13 -11
  42. data/spec/hamster/hash/reduce_spec.rb +7 -15
  43. data/spec/hamster/hash/remove_spec.rb +1 -16
  44. data/spec/hamster/hash/uniq_spec.rb +1 -8
  45. data/spec/hamster/hash/values_spec.rb +1 -6
  46. data/spec/hamster/immutable/copying_spec.rb +1 -8
  47. data/spec/hamster/immutable/immutable_spec.rb +1 -14
  48. data/spec/hamster/immutable/memoize_spec.rb +0 -1
  49. data/spec/hamster/list/add_spec.rb +1 -6
  50. data/spec/hamster/list/all_spec.rb +1 -28
  51. data/spec/hamster/list/any_spec.rb +1 -20
  52. data/spec/hamster/list/append_spec.rb +1 -11
  53. data/spec/hamster/list/at_spec.rb +1 -13
  54. data/spec/hamster/list/break_spec.rb +1 -13
  55. data/spec/hamster/list/cadr_spec.rb +1 -9
  56. data/spec/hamster/list/chunk_spec.rb +1 -9
  57. data/spec/hamster/list/clear_spec.rb +1 -9
  58. data/spec/hamster/list/combinations_spec.rb +1 -11
  59. data/spec/hamster/list/compact_spec.rb +1 -9
  60. data/spec/hamster/list/cons_spec.rb +1 -10
  61. data/spec/hamster/list/construction_spec.rb +1 -30
  62. data/spec/hamster/list/copying_spec.rb +1 -9
  63. data/spec/hamster/list/count_spec.rb +1 -15
  64. data/spec/hamster/list/cycle_spec.rb +1 -10
  65. data/spec/hamster/list/drop_spec.rb +1 -9
  66. data/spec/hamster/list/drop_while_spec.rb +1 -13
  67. data/spec/hamster/list/each_slice_spec.rb +1 -17
  68. data/spec/hamster/list/each_spec.rb +1 -17
  69. data/spec/hamster/list/each_with_index_spec.rb +1 -10
  70. data/spec/hamster/list/elem_index_spec.rb +1 -13
  71. data/spec/hamster/list/elem_indices_spec.rb +1 -11
  72. data/spec/hamster/list/empty_spec.rb +1 -13
  73. data/spec/hamster/list/eql_spec.rb +52 -62
  74. data/spec/hamster/list/find_index_spec.rb +1 -13
  75. data/spec/hamster/list/find_indices_spec.rb +1 -11
  76. data/spec/hamster/list/find_spec.rb +1 -17
  77. data/spec/hamster/list/flatten_spec.rb +1 -9
  78. data/spec/hamster/list/grep_spec.rb +1 -16
  79. data/spec/hamster/list/group_by_spec.rb +1 -20
  80. data/spec/hamster/list/head_spec.rb +1 -11
  81. data/spec/hamster/list/include_spec.rb +1 -13
  82. data/spec/hamster/list/init_spec.rb +1 -8
  83. data/spec/hamster/list/inits_spec.rb +1 -9
  84. data/spec/hamster/list/inspect_spec.rb +1 -11
  85. data/spec/hamster/list/intersperse_spec.rb +1 -9
  86. data/spec/hamster/list/join_spec.rb +1 -18
  87. data/spec/hamster/list/last_spec.rb +1 -11
  88. data/spec/hamster/list/map_spec.rb +1 -15
  89. data/spec/hamster/list/maximum_spec.rb +1 -20
  90. data/spec/hamster/list/merge_by_spec.rb +1 -19
  91. data/spec/hamster/list/merge_spec.rb +1 -20
  92. data/spec/hamster/list/minimum_spec.rb +1 -20
  93. data/spec/hamster/list/none_spec.rb +1 -18
  94. data/spec/hamster/list/one_spec.rb +1 -16
  95. data/spec/hamster/list/partition_spec.rb +1 -13
  96. data/spec/hamster/list/product_spec.rb +1 -11
  97. data/spec/hamster/list/reduce_spec.rb +0 -1
  98. data/spec/hamster/list/remove_spec.rb +1 -15
  99. data/spec/hamster/list/reverse_spec.rb +1 -11
  100. data/spec/hamster/list/size_spec.rb +1 -13
  101. data/spec/hamster/list/slice_spec.rb +1 -11
  102. data/spec/hamster/list/sorting_spec.rb +1 -14
  103. data/spec/hamster/list/span_spec.rb +1 -12
  104. data/spec/hamster/list/split_at_spec.rb +1 -9
  105. data/spec/hamster/list/sum_spec.rb +1 -11
  106. data/spec/hamster/list/tail_spec.rb +1 -11
  107. data/spec/hamster/list/tails_spec.rb +1 -9
  108. data/spec/hamster/list/take_spec.rb +1 -9
  109. data/spec/hamster/list/take_while_spec.rb +0 -1
  110. data/spec/hamster/list/to_a_spec.rb +1 -13
  111. data/spec/hamster/list/to_ary_spec.rb +0 -1
  112. data/spec/hamster/list/to_list_spec.rb +1 -9
  113. data/spec/hamster/list/to_set_spec.rb +2 -8
  114. data/spec/hamster/list/union_spec.rb +1 -11
  115. data/spec/hamster/list/uniq_spec.rb +1 -11
  116. data/spec/hamster/queue/clear_spec.rb +1 -9
  117. data/spec/hamster/queue/construction_spec.rb +1 -10
  118. data/spec/hamster/queue/dequeue_spec.rb +1 -11
  119. data/spec/hamster/queue/empty_spec.rb +1 -13
  120. data/spec/hamster/queue/enqueue_spec.rb +1 -11
  121. data/spec/hamster/queue/head_spec.rb +1 -11
  122. data/spec/hamster/queue/inspect_spec.rb +1 -9
  123. data/spec/hamster/queue/size_spec.rb +1 -11
  124. data/spec/hamster/queue/to_a_spec.rb +1 -11
  125. data/spec/hamster/queue/to_list_spec.rb +1 -11
  126. data/spec/hamster/set/add_spec.rb +1 -12
  127. data/spec/hamster/set/all_spec.rb +1 -18
  128. data/spec/hamster/set/any_spec.rb +1 -17
  129. data/spec/hamster/set/clear_spec.rb +9 -8
  130. data/spec/hamster/set/compact_spec.rb +1 -9
  131. data/spec/hamster/set/construction_spec.rb +1 -9
  132. data/spec/hamster/set/copying_spec.rb +1 -8
  133. data/spec/hamster/set/count_spec.rb +1 -13
  134. data/spec/hamster/set/delete_spec.rb +1 -10
  135. data/spec/hamster/set/difference_spec.rb +1 -11
  136. data/spec/hamster/set/empty_spec.rb +1 -11
  137. data/spec/hamster/set/exclusion_spec.rb +1 -11
  138. data/spec/hamster/set/filter_spec.rb +10 -17
  139. data/spec/hamster/set/find_spec.rb +1 -14
  140. data/spec/hamster/set/flatten_spec.rb +8 -10
  141. data/spec/hamster/set/group_by_spec.rb +8 -17
  142. data/spec/hamster/set/head_spec.rb +1 -12
  143. data/spec/hamster/set/immutable_spec.rb +1 -4
  144. data/spec/hamster/set/include_spec.rb +1 -9
  145. data/spec/hamster/set/inspect_spec.rb +1 -9
  146. data/spec/hamster/set/intersection_spec.rb +1 -11
  147. data/spec/hamster/set/join_spec.rb +1 -16
  148. data/spec/hamster/set/map_spec.rb +1 -16
  149. data/spec/hamster/set/marshal_spec.rb +1 -6
  150. data/spec/hamster/set/maximum_spec.rb +1 -18
  151. data/spec/hamster/set/minimum_spec.rb +1 -17
  152. data/spec/hamster/set/new_spec.rb +21 -0
  153. data/spec/hamster/set/none_spec.rb +1 -16
  154. data/spec/hamster/set/one_spec.rb +1 -14
  155. data/spec/hamster/set/partition_spec.rb +1 -13
  156. data/spec/hamster/set/product_spec.rb +1 -9
  157. data/spec/hamster/set/reduce_spec.rb +1 -26
  158. data/spec/hamster/set/remove_spec.rb +1 -16
  159. data/spec/hamster/set/size_spec.rb +1 -9
  160. data/spec/hamster/set/sorting_spec.rb +1 -3
  161. data/spec/hamster/set/subset_spec.rb +1 -9
  162. data/spec/hamster/set/sum_spec.rb +1 -9
  163. data/spec/hamster/set/superset_spec.rb +1 -9
  164. data/spec/hamster/set/to_a_spec.rb +1 -11
  165. data/spec/hamster/set/to_list_spec.rb +1 -11
  166. data/spec/hamster/set/to_set_spec.rb +1 -9
  167. data/spec/hamster/set/union_spec.rb +1 -11
  168. data/spec/hamster/set/uniq_spec.rb +1 -7
  169. data/spec/hamster/sorter/immutable_spec.rb +1 -4
  170. data/spec/hamster/stack/clear_spec.rb +1 -9
  171. data/spec/hamster/stack/construction_spec.rb +1 -10
  172. data/spec/hamster/stack/copying_spec.rb +1 -9
  173. data/spec/hamster/stack/empty_spec.rb +1 -9
  174. data/spec/hamster/stack/eql_spec.rb +1 -13
  175. data/spec/hamster/stack/immutable_spec.rb +1 -4
  176. data/spec/hamster/stack/inspect_spec.rb +1 -9
  177. data/spec/hamster/stack/peek_spec.rb +1 -11
  178. data/spec/hamster/stack/pop_spec.rb +1 -11
  179. data/spec/hamster/stack/push_spec.rb +1 -11
  180. data/spec/hamster/stack/size_spec.rb +1 -11
  181. data/spec/hamster/stack/to_a_spec.rb +1 -11
  182. data/spec/hamster/stack/to_list_spec.rb +1 -9
  183. data/spec/hamster/tuple/construction_spec.rb +30 -0
  184. data/spec/hamster/tuple/copying_spec.rb +1 -8
  185. data/spec/hamster/tuple/eql_spec.rb +57 -40
  186. data/spec/hamster/tuple/first_spec.rb +1 -6
  187. data/spec/hamster/tuple/immutable_spec.rb +1 -4
  188. data/spec/hamster/tuple/inspect_spec.rb +1 -6
  189. data/spec/hamster/tuple/last_spec.rb +1 -6
  190. data/spec/hamster/tuple/to_a_spec.rb +1 -9
  191. data/spec/hamster/tuple/to_ary_spec.rb +0 -1
  192. data/spec/hamster/undefined/erase_spec.rb +1 -12
  193. data/spec/hamster/vector/add_spec.rb +8 -0
  194. data/spec/hamster/vector/clear_spec.rb +1 -8
  195. data/spec/hamster/vector/copying_spec.rb +1 -8
  196. data/spec/hamster/vector/each_spec.rb +1 -11
  197. data/spec/hamster/vector/each_with_index_spec.rb +1 -9
  198. data/spec/hamster/vector/empty_spec.rb +7 -9
  199. data/spec/hamster/vector/eql_spec.rb +1 -12
  200. data/spec/hamster/vector/filter_spec.rb +8 -12
  201. data/spec/hamster/vector/first_spec.rb +1 -11
  202. data/spec/hamster/vector/get_spec.rb +1 -23
  203. data/spec/hamster/vector/include_spec.rb +1 -10
  204. data/spec/hamster/vector/map_spec.rb +8 -14
  205. data/spec/hamster/vector/new_spec.rb +48 -0
  206. data/spec/hamster/vector/reduce_spec.rb +1 -26
  207. data/spec/hamster/vector/set_spec.rb +8 -0
  208. data/spec/spec_helper.rb +0 -5
  209. metadata +35 -68
@@ -1,15 +1,10 @@
1
1
  require "spec_helper"
2
-
3
2
  require "hamster/set"
4
3
 
5
4
  describe Hamster::Set do
6
-
7
5
  [:any?, :exist?, :exists?].each do |method|
8
-
9
6
  describe "##{method}" do
10
-
11
7
  describe "when empty" do
12
-
13
8
  before do
14
9
  @set = Hamster.set
15
10
  end
@@ -21,13 +16,10 @@ describe Hamster::Set do
21
16
  it "with no block returns false" do
22
17
  @set.send(method).should == false
23
18
  end
24
-
25
19
  end
26
20
 
27
21
  describe "when not empty" do
28
-
29
22
  describe "with a block" do
30
-
31
23
  before do
32
24
  @set = Hamster.set("A", "B", "C", nil)
33
25
  end
@@ -37,17 +29,14 @@ describe Hamster::Set do
37
29
  it "returns true if the block ever returns true (#{value.inspect})" do
38
30
  @set.send(method) { |item| item == value }.should == true
39
31
  end
40
-
41
32
  end
42
33
 
43
34
  it "returns false if the block always returns false" do
44
35
  @set.send(method) { |item| item == "D" }.should == false
45
36
  end
46
-
47
37
  end
48
38
 
49
39
  describe "with no block" do
50
-
51
40
  it "returns true if any value is truthy" do
52
41
  Hamster.set(nil, false, true, "A").send(method).should == true
53
42
  end
@@ -55,13 +44,8 @@ describe Hamster::Set do
55
44
  it "returns false if all values are falsey" do
56
45
  Hamster.set(nil, false).send(method).should == false
57
46
  end
58
-
59
47
  end
60
-
61
48
  end
62
-
63
49
  end
64
-
65
50
  end
66
-
67
- end
51
+ end
@@ -1,11 +1,8 @@
1
1
  require "spec_helper"
2
-
3
2
  require "hamster/set"
4
3
 
5
4
  describe Hamster::Set do
6
-
7
5
  describe "#clear" do
8
-
9
6
  [
10
7
  [],
11
8
  ["A"],
@@ -13,7 +10,6 @@ describe Hamster::Set do
13
10
  ].each do |values|
14
11
 
15
12
  describe "on #{values}" do
16
-
17
13
  before do
18
14
  @original = Hamster.set(*values)
19
15
  @result = @original.clear
@@ -26,11 +22,16 @@ describe Hamster::Set do
26
22
  it "returns an empty set" do
27
23
  @result.should equal(Hamster.set)
28
24
  end
29
-
30
25
  end
31
-
32
26
  end
33
27
 
28
+ context "from a subclass" do
29
+ it "returns an empty instance of the subclass" do
30
+ @subclass = Class.new(Hamster::Set)
31
+ @instance = @subclass.new(:a, :b, :c, :d)
32
+ @instance.clear.class.should be(@subclass)
33
+ @instance.clear.should be_empty
34
+ end
35
+ end
34
36
  end
35
-
36
- end
37
+ end
@@ -1,11 +1,8 @@
1
1
  require "spec_helper"
2
-
3
2
  require "hamster/set"
4
3
 
5
4
  describe Hamster::Set do
6
-
7
5
  describe "#compact" do
8
-
9
6
  [
10
7
  [[], []],
11
8
  [["A"], ["A"]],
@@ -19,7 +16,6 @@ describe Hamster::Set do
19
16
  ].each do |values, expected|
20
17
 
21
18
  describe "on #{values.inspect}" do
22
-
23
19
  before do
24
20
  @original = Hamster.set(*values)
25
21
  @result = @original.compact
@@ -32,11 +28,7 @@ describe Hamster::Set do
32
28
  it "returns #{expected.inspect}" do
33
29
  @result.should == Hamster.set(*expected)
34
30
  end
35
-
36
31
  end
37
-
38
32
  end
39
-
40
33
  end
41
-
42
- end
34
+ end
@@ -1,13 +1,9 @@
1
1
  require "spec_helper"
2
-
3
2
  require "hamster/set"
4
3
 
5
4
  describe Hamster::Set do
6
-
7
5
  describe ".set" do
8
-
9
6
  describe "with no values" do
10
-
11
7
  it "returns the empty set" do
12
8
  Hamster.set.should equal(Hamster::EmptySet)
13
9
  end
@@ -15,7 +11,6 @@ describe Hamster::Set do
15
11
  end
16
12
 
17
13
  describe "with a list of values" do
18
-
19
14
  before do
20
15
  @set = Hamster.set("A", "B", "C")
21
16
  end
@@ -23,9 +18,6 @@ describe Hamster::Set do
23
18
  it "is equivalent to repeatedly using #add" do
24
19
  @set.should == Hamster.set.add("A").add("B").add("C")
25
20
  end
26
-
27
21
  end
28
-
29
22
  end
30
-
31
- end
23
+ end
@@ -1,23 +1,16 @@
1
1
  require "spec_helper"
2
-
3
2
  require "hamster/set"
4
3
 
5
4
  describe Hamster::Set do
6
-
7
5
  before do
8
6
  @set = Hamster.set("A", "B", "C")
9
7
  end
10
8
 
11
9
  [:dup, :clone].each do |method|
12
-
13
10
  describe "##{method}" do
14
-
15
11
  it "returns self" do
16
12
  @set.send(method).should equal(@set)
17
13
  end
18
-
19
14
  end
20
-
21
15
  end
22
-
23
- end
16
+ end
@@ -1,11 +1,8 @@
1
1
  require "spec_helper"
2
-
3
2
  require "hamster/set"
4
3
 
5
4
  describe Hamster::Set do
6
-
7
5
  describe "#count" do
8
-
9
6
  [
10
7
  [[], 0],
11
8
  [[1], 1],
@@ -16,13 +13,11 @@ describe Hamster::Set do
16
13
  ].each do |values, expected|
17
14
 
18
15
  describe "on #{values.inspect}" do
19
-
20
16
  before do
21
17
  @original = Hamster.set(*values)
22
18
  end
23
19
 
24
20
  describe "with a block" do
25
-
26
21
  before do
27
22
  @result = @original.count(&:odd?)
28
23
  end
@@ -30,11 +25,9 @@ describe Hamster::Set do
30
25
  it "returns #{expected.inspect}" do
31
26
  @result.should == expected
32
27
  end
33
-
34
28
  end
35
29
 
36
30
  describe "without a block" do
37
-
38
31
  before do
39
32
  @result = @original.count
40
33
  end
@@ -42,13 +35,8 @@ describe Hamster::Set do
42
35
  it "returns length" do
43
36
  @result.should == @original.length
44
37
  end
45
-
46
38
  end
47
-
48
39
  end
49
-
50
40
  end
51
-
52
41
  end
53
-
54
- end
42
+ end
@@ -1,17 +1,13 @@
1
1
  require "spec_helper"
2
-
3
2
  require "hamster/set"
4
3
 
5
4
  describe Hamster::Set do
6
-
7
5
  describe "#delete" do
8
-
9
6
  before do
10
7
  @original = Hamster.set("A", "B", "C")
11
8
  end
12
9
 
13
10
  describe "with an existing value" do
14
-
15
11
  before do
16
12
  @result = @original.delete("B")
17
13
  end
@@ -23,11 +19,9 @@ describe Hamster::Set do
23
19
  it "returns a copy with the remaining of values" do
24
20
  @result.should == Hamster.set("A", "C")
25
21
  end
26
-
27
22
  end
28
23
 
29
24
  describe "with a non-existing value" do
30
-
31
25
  before do
32
26
  @result = @original.delete("D")
33
27
  end
@@ -39,9 +33,6 @@ describe Hamster::Set do
39
33
  it "returns self" do
40
34
  @result.should equal(@original)
41
35
  end
42
-
43
36
  end
44
-
45
37
  end
46
-
47
- end
38
+ end
@@ -1,13 +1,9 @@
1
1
  require "spec_helper"
2
-
3
2
  require "hamster/set"
4
3
 
5
4
  describe Hamster::Set do
6
-
7
5
  [:difference, :diff, :subtract, :-].each do |method|
8
-
9
6
  describe "##{method}" do
10
-
11
7
  [
12
8
  [[], [], []],
13
9
  [["A"], [], ["A"]],
@@ -17,7 +13,6 @@ describe Hamster::Set do
17
13
  ].each do |a, b, expected|
18
14
 
19
15
  describe "for #{a.inspect} and #{b.inspect}" do
20
-
21
16
  before do
22
17
  @result = Hamster.set(*a).send(method, Hamster.set(*b))
23
18
  end
@@ -25,13 +20,8 @@ describe Hamster::Set do
25
20
  it "returns #{expected.inspect}" do
26
21
  @result.should == Hamster.set(*expected)
27
22
  end
28
-
29
23
  end
30
-
31
24
  end
32
-
33
25
  end
34
-
35
26
  end
36
-
37
- end
27
+ end
@@ -1,13 +1,9 @@
1
1
  require "spec_helper"
2
-
3
2
  require "hamster/set"
4
3
 
5
4
  describe Hamster::Set do
6
-
7
5
  [:empty?, :null?].each do |method|
8
-
9
6
  describe "##{method}" do
10
-
11
7
  [
12
8
  [[], true],
13
9
  [["A"], false],
@@ -15,7 +11,6 @@ describe Hamster::Set do
15
11
  ].each do |values, expected|
16
12
 
17
13
  describe "on #{values.inspect}" do
18
-
19
14
  before do
20
15
  @set = Hamster.set(*values)
21
16
  end
@@ -23,13 +18,8 @@ describe Hamster::Set do
23
18
  it "returns #{expected.inspect}" do
24
19
  @set.send(method).should == expected
25
20
  end
26
-
27
21
  end
28
-
29
22
  end
30
-
31
23
  end
32
-
33
24
  end
34
-
35
- end
25
+ end
@@ -1,13 +1,9 @@
1
1
  require "spec_helper"
2
-
3
2
  require "hamster/set"
4
3
 
5
4
  describe Hamster::Set do
6
-
7
5
  [:exclusion, :^].each do |method|
8
-
9
6
  describe "##{method}" do
10
-
11
7
  [
12
8
  [[], [], []],
13
9
  [["A"], [], ["A"]],
@@ -18,7 +14,6 @@ describe Hamster::Set do
18
14
  ].each do |a, b, expected|
19
15
 
20
16
  describe "for #{a.inspect} and #{b.inspect}" do
21
-
22
17
  before do
23
18
  @result = Hamster.set(*a).send(method, Hamster.set(*b))
24
19
  end
@@ -26,13 +21,8 @@ describe Hamster::Set do
26
21
  it "returns #{expected.inspect}" do
27
22
  @result.should == Hamster.set(*expected)
28
23
  end
29
-
30
24
  end
31
-
32
25
  end
33
-
34
26
  end
35
-
36
27
  end
37
-
38
- end
28
+ end
@@ -1,19 +1,14 @@
1
1
  require "spec_helper"
2
-
3
2
  require "hamster/set"
4
3
 
5
4
  describe Hamster::Set do
6
-
7
5
  [:filter, :select, :find_all].each do |method|
8
-
9
6
  describe "##{method}" do
10
-
11
7
  before do
12
8
  @original = Hamster.set("A", "B", "C")
13
9
  end
14
10
 
15
11
  describe "when everything matches" do
16
-
17
12
  before do
18
13
  @result = @original.send(method) { |item| true }
19
14
  end
@@ -21,13 +16,10 @@ describe Hamster::Set do
21
16
  it "returns self" do
22
17
  @result.should equal(@original)
23
18
  end
24
-
25
19
  end
26
20
 
27
21
  describe "when only some things match" do
28
-
29
22
  describe "with a block" do
30
-
31
23
  before do
32
24
  @result = @original.send(method) { |item| item == "A" }
33
25
  end
@@ -39,11 +31,9 @@ describe Hamster::Set do
39
31
  it "returns a set with the matching values" do
40
32
  @result.should == Hamster.set("A")
41
33
  end
42
-
43
34
  end
44
35
 
45
36
  describe "with no block" do
46
-
47
37
  before do
48
38
  @result = @original.send(method)
49
39
  end
@@ -51,13 +41,10 @@ describe Hamster::Set do
51
41
  it "returns self" do
52
42
  @result.should equal(@original)
53
43
  end
54
-
55
44
  end
56
-
57
45
  end
58
46
 
59
47
  describe "when nothing matches" do
60
-
61
48
  before do
62
49
  @result = @original.send(method) { |item| false }
63
50
  end
@@ -69,11 +56,17 @@ describe Hamster::Set do
69
56
  it "returns an empty set" do
70
57
  @result.should equal(Hamster.set)
71
58
  end
72
-
73
59
  end
74
60
 
61
+ context "from a subclass" do
62
+ it "returns an instance of the same class" do
63
+ @subclass = Class.new(Hamster::Set)
64
+ @instance = @subclass.new('A', 'B', 'C')
65
+ @instance.filter { true }.class.should be(@subclass)
66
+ @instance.filter { false }.class.should be(@subclass)
67
+ @instance.filter { rand(2) == 0 }.class.should be(@subclass)
68
+ end
69
+ end
75
70
  end
76
-
77
71
  end
78
-
79
- end
72
+ end