scaruby 0.0.5 → 0.0.6

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.
@@ -1,288 +1,288 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- require 'scaruby/core_ext'
4
-
5
- describe Enumerable do
6
-
7
- one_to_five = 1.upto 5
8
- one_to_five_shuffled = one_to_five.sort_by {rand}
9
-
10
- it 'has #to_a' do
11
- one_to_five.to_a.should eq([1,2,3,4,5])
12
- end
13
- it 'has #corresponds' do
14
- [1,2,3].corresponds([1,2,3]) {|a,b| a == b }.should eq(true)
15
- [1,2,3].corresponds([3,1,2]) {|a,b| a == b }.should eq(false)
16
- end
17
- it 'has #count' do
18
- one_to_five.count {|i| i > 2 }.should eq(3)
19
- end
20
- it 'has #diff' do
21
- [1,2,3].diff([2,3,4]).to_a.should eq([1])
22
- end
23
- it 'has #distinct' do
24
- [1,2,4,1,3,3,3,2,4,1].distinct.to_a.should eq([1,2,4,3])
25
- end
26
- it 'has #drop' do
27
- one_to_five.drop(3).to_a.should eq([4,5])
28
- one_to_five.drop(7).to_a.should eq([])
29
- end
30
- it 'has #drop_right' do
31
- one_to_five.drop_right(3).to_a.should eq([1,2])
32
- one_to_five.drop_right(7).to_a.should eq([])
33
- end
34
- it 'has #drop_while' do
35
- [5,3,2,4,1].drop_while {|e| e > 2 }.to_a.should eq([2,4,1])
36
- end
37
- it 'has #ends_with' do
38
- [1,2,3].ends_with([1,2]).should eq(false)
39
- [1,2,3].ends_with([1,2,3]).should eq(true)
40
- [1,2,3].ends_with([1,1,2,3]).should eq(false)
41
- [1,2,3].ends_with([2,3]).should eq(true)
42
- [1,2,3].ends_with([3]).should eq(true)
43
- end
44
- it 'has #exists' do
45
- [1,2,3].exists {|i| i < 2 }.should eq(true)
46
- [1,2,3].exists {|i| i < 4 }.should eq(true)
47
- [2,3,4].exists {|i| i > 4 }.should eq(false)
48
- end
49
- it 'has #filter' do
50
- one_to_five.filter {|i| i > 3 }.to_a.should eq([4,5])
51
- one_to_five.filter {|i| i > 10 }.to_a.should eq([])
52
- end
53
- it 'has #filter_not' do
54
- one_to_five.filter_not {|i| i > 3 }.to_a.should eq([1,2,3])
55
- one_to_five.filter_not {|i| i > 10 }.to_a.should eq([1,2,3,4,5])
56
- end
57
- it 'has #find' do
58
- some = one_to_five.find {|i| i < 3 }
59
- # the already defined method is called
60
- #some.get.should eq(1)
61
- some.should eq(1)
62
- none = one_to_five.find {|i| i > 10 }
63
- # the already defined method is called
64
- #none.is_defined.should eq(false)
65
- none.should eq(nil)
66
- end
67
- it 'has #flat_map and it works with nested arrays' do
68
- [[1,2],[3,4],[5]].flat_map {|i| i }.to_a.should eq([1,2,3,4,5])
69
- end
70
- it 'has #flat_map and it works with Option elements' do
71
- # the already defined method is called
72
- #([1,2,nil,3]).flat_map {|i| Option.new(i) }.to_a.should eq([1,2,3])
73
- [1,2,nil,3].flat_map {|i| Option.new(i) }.to_a do |opt|
74
- opt.is_a?(Option).should eq(true)
75
- end
76
- end
77
- it 'has #fold_left' do
78
- input = [1,2,3]
79
- expected = [1,2,3]
80
- idx = 0
81
- input.fold_left(0) {|z,x|
82
- x.should eq(expected[idx])
83
- idx += 1
84
- z + x
85
- }.should eq(6)
86
- end
87
- it 'has #fold_right' do
88
- input = [1,2,3]
89
- expected = [3,2,1]
90
- idx = 0
91
- input.fold_right(0) {|z,x|
92
- x.should eq(expected[idx])
93
- idx += 1
94
- z + x
95
- }.should eq(6)
96
- end
97
- it 'has #flatten' do
98
- [[1,2],[3,4],[5]].flatten.to_a.should eq([1,2,3,4,5])
99
- [Option.new(1),
100
- Option.new(2),
101
- Option.new(nil),
102
- Option.new(3)].flatten.to_a.each do |opt|
103
- opt.is_a?(Option).should eq(true)
104
- end
105
- end
106
- it 'has #forall' do
107
- [1,2,3].forall {|i| i > 0 }.should eq(true)
108
- [1,2,3].forall {|i| i > 1 }.should eq(false)
109
- end
110
- it 'has #foreach' do
111
- count = 0
112
- returned = ([1,2,3]).foreach do |i|
113
- count += 1
114
- end
115
- count.should eq(3)
116
- returned.should eq(nil)
117
- end
118
- it 'has #group_by' do
119
- expected = {3=>[3,3,3], 1=>[1,1,1], 2=>[2,2]}
120
- [1,1,1,2,3,2,3,3].group_by {|i| i }.to_hash.should eq(expected)
121
- end
122
- it 'has #head' do
123
- one_to_five.head.should eq(1)
124
- end
125
- it 'has #head_option and it works with Some' do
126
- some = one_to_five.head_option
127
- some.get_or_else(999).should eq(1)
128
- end
129
- it 'has #head_option and it works with None' do
130
- none = ([]).head_option
131
- none.get_or_else(999).should eq(999)
132
- end
133
- it 'has #indices' do
134
- [1,2,3].indices.to_a.should eq([0,1,2])
135
- end
136
- it 'has #init' do
137
- [1,2,3].init.to_a.should eq([1,2])
138
- end
139
- it 'has #intersect' do
140
- [1,2,3].intersect([2,3,4]).to_a.should eq([2,3])
141
- end
142
- it 'has #is_empty' do
143
- [1,2,3].is_empty.should eq(false)
144
- [nil].is_empty.should eq(false)
145
- [].is_empty.should eq(true)
146
- end
147
- it 'has #last' do
148
- [1,2,3].last.should eq(3)
149
- end
150
- it 'has #last_option' do
151
- some = [1,2,3].last_option
152
- some.get.should eq(3)
153
- none = ([]).last_option
154
- none.is_defined.should eq(false)
155
- end
156
- it 'has #lift' do
157
- seq_lift = [1,2,3].lift
158
- seq_lift.apply(0).get.should eq(1)
159
- seq_lift.apply(1).get.should eq(2)
160
- seq_lift.apply(2).get.should eq(3)
161
- seq_lift.apply(3).is_defined.should eq(false)
162
- seq_lift.call(0).get.should eq(1)
163
- seq_lift.call(1).get.should eq(2)
164
- seq_lift.call(2).get.should eq(3)
165
- seq_lift.call(3).is_defined.should eq(false)
166
- end
167
- it 'has #map' do
168
- [1,2,3].map {|i| i + i }.to_a.should eq([2,4,6])
169
- end
170
- it 'has #max' do
171
- one_to_five_shuffled.max.should eq(5)
172
- end
173
- it 'has #min' do
174
- one_to_five_shuffled.min.should eq(1)
175
- end
176
- it 'has #mk_string' do
177
- one_to_five.mk_string.should eq('12345')
178
- one_to_five.mk_string(',').should eq('1,2,3,4,5')
179
- one_to_five.mk_string('^',',','$').should eq('^1,2,3,4,5$')
180
- begin
181
- one_to_five.mk_string('a','b').should eq(nil)
182
- rescue ArgumentError
183
- end
184
- one_to_five.mk_string('^',',','$','zzz').should eq('^1,2,3,4,5$')
185
- end
186
- it 'has #non_empty' do
187
- one_to_five.non_empty.should eq(true)
188
- [].non_empty.should eq(false)
189
- end
190
- it 'has #partition' do
191
- [5,2,3,1,4,2,3].partition {|i| i < 3 }.to_a.should eq([[2,1,2],[5,3,4,3]])
192
- end
193
- it 'has #patch' do
194
- [5,2,3,1,4,2,3].patch(3,[111,222],3).to_a.should eq([5,2,3,111,222,3])
195
- end
196
- it 'has #reverse' do
197
- [1,2,3].reverse.to_a.should eq([3,2,1])
198
- end
199
- it 'has #reverse_map' do
200
- [1,2,3].reverse_map {|i| i + i }.to_a.should eq([6,4,2])
201
- end
202
- it 'has #same_elements' do
203
- [1,2,3].same_elements([1,2,3]).should eq(true)
204
- [1,2,3].same_elements([1,3,2]).should eq(false)
205
- [1,2,3].same_elements([1,2]).should eq(false)
206
- end
207
- it 'has #scan_left' do
208
- [1,2,3].scan_left(1) {|a,b| a + b }.to_a.should eq([1,2,4,7])
209
- end
210
- it 'has #scan_right' do
211
- [1,2,3].scan_right(1) {|a,b| a + b }.to_a.should eq([7,6,4,1])
212
- end
213
- it 'has #slice' do
214
- # the already defined method is called
215
- #[1,2,3,4,5].slice(1,1).to_a.should eq([])
216
- #[1,2,3,4,5].slice(1,2).to_a.should eq([2])
217
- #[1,2,3,4,5].slice(1,3).to_a.should eq([2,3])
218
- #[1,2,3,4,5].slice(1,4).to_a.should eq([2,3,4])
219
- [1,2,3,4,5].slice(1,1).should eq([2])
220
- [1,2,3,4,5].slice(1,2).should eq([2,3])
221
- [1,2,3,4,5].slice(1,3).should eq([2,3,4])
222
- [1,2,3,4,5].slice(1,4).should eq([2,3,4,5])
223
- end
224
- it 'has #sliding' do
225
- [1,2,3,4,5].sliding(2).to_a.should eq([[1,2],[2,3],[3,4],[4,5]])
226
- end
227
- it 'has #sort_with' do
228
- [1,3,2,4,5].sort_with {|a,b| b <=> a }.to_a.should eq([5,4,3,2,1])
229
- end
230
- it 'has #span' do
231
- [1,2,3,2,1].span {|i| i < 3 }.to_a.should eq([[1,2],[3,2,1]])
232
- end
233
- it 'has #split_at' do
234
- [1,2,3,2,1].split_at(3).to_a.should eq([[1,2,3],[2,1]])
235
- end
236
- it 'has #starts_with' do
237
- [1,2,3].starts_with([1]).should eq(true)
238
- [1,2,3].starts_with([1,2]).should eq(true)
239
- [1,2,3].starts_with([1,2,3]).should eq(true)
240
- [1,2,3].starts_with([1,2,3,4]).should eq(false)
241
- [1,2,3].starts_with([2,3]).should eq(false)
242
- [1,2,3].starts_with([4,1,2,3]).should eq(false)
243
- end
244
- it 'has #sum' do
245
- [1,2,3].sum.should eq(6)
246
- end
247
- it 'has #tail' do
248
- [1,2,3].tail.to_a.should eq([2,3])
249
- [].tail.to_a.should eq([])
250
- end
251
- it 'has #take' do
252
- [1,2,3].take(0).to_a.should eq([])
253
- [1,2,3].take(1).to_a.should eq([1])
254
- [1,2,3].take(2).to_a.should eq([1,2])
255
- [1,2,3].take(3).to_a.should eq([1,2,3])
256
- [1,2,3].take(4).to_a.should eq([1,2,3])
257
- end
258
- it 'has #take_right' do
259
- [1,2,3].take_right(0).to_a.should eq([])
260
- [1,2,3].take_right(1).to_a.should eq([3])
261
- [1,2,3].take_right(2).to_a.should eq([2,3])
262
- [1,2,3].take_right(3).to_a.should eq([1,2,3])
263
- [1,2,3].take_right(4).to_a.should eq([1,2,3])
264
- end
265
- it 'has #take_while' do
266
- [5,3,2,4,1].take_while {|e| e > 2 }.to_a.should eq([5,3])
267
- end
268
- it 'has #union' do
269
- [1,2,3].union([2,3,4]).to_a.should eq([1,2,3,2,3,4])
270
- end
271
- it 'has #updated' do
272
- [1,2,3].updated(1,999).to_a.should eq([1,999,3])
273
- end
274
- it 'has #zip' do
275
- # the already defined method is called
276
- #[1,2,3].zip([2,3]).to_a.should eq([[1,2],[2,3]])
277
- #[1,2,3].zip([2,3,4]).to_a.should eq([[1,2],[2,3],[3,4]])
278
- #[1,2,3].zip([2,3,4,5]).to_a.should eq([[1,2],[2,3],[3,4]])
279
- [1,2,3].zip([2,3]).should eq([[1,2],[2,3],[3,nil]])
280
- [1,2,3].zip([2,3,4]).should eq([[1,2],[2,3],[3,4]])
281
- [1,2,3].zip([2,3,4,5]).should eq([[1,2],[2,3],[3,4]])
282
- end
283
- it 'has #zip_with_index' do
284
- [].zip_with_index.to_a.should eq([])
285
- [1,2,3].zip_with_index.to_a.should eq([[1,0],[2,1],[3,2]])
286
- end
287
-
288
- end
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'scaruby/core_ext'
4
+
5
+ describe Enumerable do
6
+
7
+ one_to_five = 1.upto 5
8
+ one_to_five_shuffled = one_to_five.sort_by { rand }
9
+
10
+ it 'has #to_a' do
11
+ one_to_five.to_a.should eq([1, 2, 3, 4, 5])
12
+ end
13
+ it 'has #corresponds' do
14
+ [1, 2, 3].corresponds([1, 2, 3]) { |a, b| a == b }.should eq(true)
15
+ [1, 2, 3].corresponds([3, 1, 2]) { |a, b| a == b }.should eq(false)
16
+ end
17
+ it 'has #count' do
18
+ one_to_five.count { |i| i > 2 }.should eq(3)
19
+ end
20
+ it 'has #diff' do
21
+ [1, 2, 3].diff([2, 3, 4]).to_a.should eq([1])
22
+ end
23
+ it 'has #distinct' do
24
+ [1, 2, 4, 1, 3, 3, 3, 2, 4, 1].distinct.to_a.should eq([1, 2, 4, 3])
25
+ end
26
+ it 'has #drop' do
27
+ one_to_five.drop(3).to_a.should eq([4, 5])
28
+ one_to_five.drop(7).to_a.should eq([])
29
+ end
30
+ it 'has #drop_right' do
31
+ one_to_five.drop_right(3).to_a.should eq([1, 2])
32
+ one_to_five.drop_right(7).to_a.should eq([])
33
+ end
34
+ it 'has #drop_while' do
35
+ [5, 3, 2, 4, 1].drop_while { |e| e > 2 }.to_a.should eq([2, 4, 1])
36
+ end
37
+ it 'has #ends_with' do
38
+ [1, 2, 3].ends_with([1, 2]).should eq(false)
39
+ [1, 2, 3].ends_with([1, 2, 3]).should eq(true)
40
+ [1, 2, 3].ends_with([1, 1, 2, 3]).should eq(false)
41
+ [1, 2, 3].ends_with([2, 3]).should eq(true)
42
+ [1, 2, 3].ends_with([3]).should eq(true)
43
+ end
44
+ it 'has #exists' do
45
+ [1, 2, 3].exists { |i| i < 2 }.should eq(true)
46
+ [1, 2, 3].exists { |i| i < 4 }.should eq(true)
47
+ [2, 3, 4].exists { |i| i > 4 }.should eq(false)
48
+ end
49
+ it 'has #filter' do
50
+ one_to_five.filter { |i| i > 3 }.to_a.should eq([4, 5])
51
+ one_to_five.filter { |i| i > 10 }.to_a.should eq([])
52
+ end
53
+ it 'has #filter_not' do
54
+ one_to_five.filter_not { |i| i > 3 }.to_a.should eq([1, 2, 3])
55
+ one_to_five.filter_not { |i| i > 10 }.to_a.should eq([1, 2, 3, 4, 5])
56
+ end
57
+ it 'has #find' do
58
+ some = one_to_five.find { |i| i < 3 }
59
+ # the already defined method is called
60
+ #some.get.should eq(1)
61
+ some.should eq(1)
62
+ none = one_to_five.find { |i| i > 10 }
63
+ # the already defined method is called
64
+ #none.is_defined.should eq(false)
65
+ none.should eq(nil)
66
+ end
67
+ it 'has #flat_map and it works with nested arrays' do
68
+ [[1, 2], [3, 4], [5]].flat_map { |i| i }.to_a.should eq([1, 2, 3, 4, 5])
69
+ end
70
+ it 'has #flat_map and it works with Option elements' do
71
+ # the already defined method is called
72
+ #([1,2,nil,3]).flat_map {|i| Option.new(i) }.to_a.should eq([1,2,3])
73
+ [1, 2, nil, 3].flat_map { |i| Option.new(i) }.to_a do |opt|
74
+ opt.is_a?(Option).should eq(true)
75
+ end
76
+ end
77
+ it 'has #fold_left' do
78
+ input = [1, 2, 3]
79
+ expected = [1, 2, 3]
80
+ idx = 0
81
+ input.fold_left(0) { |z, x|
82
+ x.should eq(expected[idx])
83
+ idx += 1
84
+ z + x
85
+ }.should eq(6)
86
+ end
87
+ it 'has #fold_right' do
88
+ input = [1, 2, 3]
89
+ expected = [3, 2, 1]
90
+ idx = 0
91
+ input.fold_right(0) { |z, x|
92
+ x.should eq(expected[idx])
93
+ idx += 1
94
+ z + x
95
+ }.should eq(6)
96
+ end
97
+ it 'has #flatten' do
98
+ [[1, 2], [3, 4], [5]].flatten.to_a.should eq([1, 2, 3, 4, 5])
99
+ [Option.new(1),
100
+ Option.new(2),
101
+ Option.new(nil),
102
+ Option.new(3)].flatten.to_a.each do |opt|
103
+ opt.is_a?(Option).should eq(true)
104
+ end
105
+ end
106
+ it 'has #forall' do
107
+ [1, 2, 3].forall { |i| i > 0 }.should eq(true)
108
+ [1, 2, 3].forall { |i| i > 1 }.should eq(false)
109
+ end
110
+ it 'has #foreach' do
111
+ count = 0
112
+ returned = ([1, 2, 3]).foreach do |i|
113
+ count += 1
114
+ end
115
+ count.should eq(3)
116
+ returned.should eq(nil)
117
+ end
118
+ it 'has #group_by' do
119
+ expected = {3 => [3, 3, 3], 1 => [1, 1, 1], 2 => [2, 2]}
120
+ [1, 1, 1, 2, 3, 2, 3, 3].group_by { |i| i }.to_hash.should eq(expected)
121
+ end
122
+ it 'has #head' do
123
+ one_to_five.head.should eq(1)
124
+ end
125
+ it 'has #head_option and it works with Some' do
126
+ some = one_to_five.head_option
127
+ some.get_or_else(999).should eq(1)
128
+ end
129
+ it 'has #head_option and it works with None' do
130
+ none = ([]).head_option
131
+ none.get_or_else(999).should eq(999)
132
+ end
133
+ it 'has #indices' do
134
+ [1, 2, 3].indices.to_a.should eq([0, 1, 2])
135
+ end
136
+ it 'has #init' do
137
+ [1, 2, 3].init.to_a.should eq([1, 2])
138
+ end
139
+ it 'has #intersect' do
140
+ [1, 2, 3].intersect([2, 3, 4]).to_a.should eq([2, 3])
141
+ end
142
+ it 'has #is_empty' do
143
+ [1, 2, 3].is_empty.should eq(false)
144
+ [nil].is_empty.should eq(false)
145
+ [].is_empty.should eq(true)
146
+ end
147
+ it 'has #last' do
148
+ [1, 2, 3].last.should eq(3)
149
+ end
150
+ it 'has #last_option' do
151
+ some = [1, 2, 3].last_option
152
+ some.get.should eq(3)
153
+ none = ([]).last_option
154
+ none.is_defined.should eq(false)
155
+ end
156
+ it 'has #lift' do
157
+ seq_lift = [1, 2, 3].lift
158
+ seq_lift.apply(0).get.should eq(1)
159
+ seq_lift.apply(1).get.should eq(2)
160
+ seq_lift.apply(2).get.should eq(3)
161
+ seq_lift.apply(3).is_defined.should eq(false)
162
+ seq_lift.call(0).get.should eq(1)
163
+ seq_lift.call(1).get.should eq(2)
164
+ seq_lift.call(2).get.should eq(3)
165
+ seq_lift.call(3).is_defined.should eq(false)
166
+ end
167
+ it 'has #map' do
168
+ [1, 2, 3].map { |i| i + i }.to_a.should eq([2, 4, 6])
169
+ end
170
+ it 'has #max' do
171
+ one_to_five_shuffled.max.should eq(5)
172
+ end
173
+ it 'has #min' do
174
+ one_to_five_shuffled.min.should eq(1)
175
+ end
176
+ it 'has #mk_string' do
177
+ one_to_five.mk_string.should eq('12345')
178
+ one_to_five.mk_string(',').should eq('1,2,3,4,5')
179
+ one_to_five.mk_string('^', ',', '$').should eq('^1,2,3,4,5$')
180
+ begin
181
+ one_to_five.mk_string('a', 'b').should eq(nil)
182
+ rescue ArgumentError
183
+ end
184
+ one_to_five.mk_string('^', ',', '$', 'zzz').should eq('^1,2,3,4,5$')
185
+ end
186
+ it 'has #non_empty' do
187
+ one_to_five.non_empty.should eq(true)
188
+ [].non_empty.should eq(false)
189
+ end
190
+ it 'has #partition' do
191
+ [5, 2, 3, 1, 4, 2, 3].partition { |i| i < 3 }.to_a.should eq([[2, 1, 2], [5, 3, 4, 3]])
192
+ end
193
+ it 'has #patch' do
194
+ [5, 2, 3, 1, 4, 2, 3].patch(3, [111, 222], 3).to_a.should eq([5, 2, 3, 111, 222, 3])
195
+ end
196
+ it 'has #reverse' do
197
+ [1, 2, 3].reverse.to_a.should eq([3, 2, 1])
198
+ end
199
+ it 'has #reverse_map' do
200
+ [1, 2, 3].reverse_map { |i| i + i }.to_a.should eq([6, 4, 2])
201
+ end
202
+ it 'has #same_elements' do
203
+ [1, 2, 3].same_elements([1, 2, 3]).should eq(true)
204
+ [1, 2, 3].same_elements([1, 3, 2]).should eq(false)
205
+ [1, 2, 3].same_elements([1, 2]).should eq(false)
206
+ end
207
+ it 'has #scan_left' do
208
+ [1, 2, 3].scan_left(1) { |a, b| a + b }.to_a.should eq([1, 2, 4, 7])
209
+ end
210
+ it 'has #scan_right' do
211
+ [1, 2, 3].scan_right(1) { |a, b| a + b }.to_a.should eq([7, 6, 4, 1])
212
+ end
213
+ it 'has #slice' do
214
+ # the already defined method is called
215
+ #[1,2,3,4,5].slice(1,1).to_a.should eq([])
216
+ #[1,2,3,4,5].slice(1,2).to_a.should eq([2])
217
+ #[1,2,3,4,5].slice(1,3).to_a.should eq([2,3])
218
+ #[1,2,3,4,5].slice(1,4).to_a.should eq([2,3,4])
219
+ [1, 2, 3, 4, 5].slice(1, 1).should eq([2])
220
+ [1, 2, 3, 4, 5].slice(1, 2).should eq([2, 3])
221
+ [1, 2, 3, 4, 5].slice(1, 3).should eq([2, 3, 4])
222
+ [1, 2, 3, 4, 5].slice(1, 4).should eq([2, 3, 4, 5])
223
+ end
224
+ it 'has #sliding' do
225
+ [1, 2, 3, 4, 5].sliding(2).to_a.should eq([[1, 2], [2, 3], [3, 4], [4, 5]])
226
+ end
227
+ it 'has #sort_with' do
228
+ [1, 3, 2, 4, 5].sort_with { |a, b| b <=> a }.to_a.should eq([5, 4, 3, 2, 1])
229
+ end
230
+ it 'has #span' do
231
+ [1, 2, 3, 2, 1].span { |i| i < 3 }.to_a.should eq([[1, 2], [3, 2, 1]])
232
+ end
233
+ it 'has #split_at' do
234
+ [1, 2, 3, 2, 1].split_at(3).to_a.should eq([[1, 2, 3], [2, 1]])
235
+ end
236
+ it 'has #starts_with' do
237
+ [1, 2, 3].starts_with([1]).should eq(true)
238
+ [1, 2, 3].starts_with([1, 2]).should eq(true)
239
+ [1, 2, 3].starts_with([1, 2, 3]).should eq(true)
240
+ [1, 2, 3].starts_with([1, 2, 3, 4]).should eq(false)
241
+ [1, 2, 3].starts_with([2, 3]).should eq(false)
242
+ [1, 2, 3].starts_with([4, 1, 2, 3]).should eq(false)
243
+ end
244
+ it 'has #sum' do
245
+ [1, 2, 3].sum.should eq(6)
246
+ end
247
+ it 'has #tail' do
248
+ [1, 2, 3].tail.to_a.should eq([2, 3])
249
+ [].tail.to_a.should eq([])
250
+ end
251
+ it 'has #take' do
252
+ [1, 2, 3].take(0).to_a.should eq([])
253
+ [1, 2, 3].take(1).to_a.should eq([1])
254
+ [1, 2, 3].take(2).to_a.should eq([1, 2])
255
+ [1, 2, 3].take(3).to_a.should eq([1, 2, 3])
256
+ [1, 2, 3].take(4).to_a.should eq([1, 2, 3])
257
+ end
258
+ it 'has #take_right' do
259
+ [1, 2, 3].take_right(0).to_a.should eq([])
260
+ [1, 2, 3].take_right(1).to_a.should eq([3])
261
+ [1, 2, 3].take_right(2).to_a.should eq([2, 3])
262
+ [1, 2, 3].take_right(3).to_a.should eq([1, 2, 3])
263
+ [1, 2, 3].take_right(4).to_a.should eq([1, 2, 3])
264
+ end
265
+ it 'has #take_while' do
266
+ [5, 3, 2, 4, 1].take_while { |e| e > 2 }.to_a.should eq([5, 3])
267
+ end
268
+ it 'has #union' do
269
+ [1, 2, 3].union([2, 3, 4]).to_a.should eq([1, 2, 3, 2, 3, 4])
270
+ end
271
+ it 'has #updated' do
272
+ [1, 2, 3].updated(1, 999).to_a.should eq([1, 999, 3])
273
+ end
274
+ it 'has #zip' do
275
+ # the already defined method is called
276
+ #[1,2,3].zip([2,3]).to_a.should eq([[1,2],[2,3]])
277
+ #[1,2,3].zip([2,3,4]).to_a.should eq([[1,2],[2,3],[3,4]])
278
+ #[1,2,3].zip([2,3,4,5]).to_a.should eq([[1,2],[2,3],[3,4]])
279
+ [1, 2, 3].zip([2, 3]).should eq([[1, 2], [2, 3], [3, nil]])
280
+ [1, 2, 3].zip([2, 3, 4]).should eq([[1, 2], [2, 3], [3, 4]])
281
+ [1, 2, 3].zip([2, 3, 4, 5]).should eq([[1, 2], [2, 3], [3, 4]])
282
+ end
283
+ it 'has #zip_with_index' do
284
+ [].zip_with_index.to_a.should eq([])
285
+ [1, 2, 3].zip_with_index.to_a.should eq([[1, 0], [2, 1], [3, 2]])
286
+ end
287
+
288
+ end