tbpgr_utils 0.0.21 → 0.0.22
Sign up to get free protection for your applications and to get access to all the features.
- data/.rubocop.yml +2 -0
- data/README.md +31 -0
- data/lib/open_classes/array.rb +33 -0
- data/lib/tbpgr_utils/version.rb +1 -1
- data/spec/open_classes/array_spec.rb +590 -491
- metadata +13 -12
data/.rubocop.yml
ADDED
data/README.md
CHANGED
@@ -23,6 +23,8 @@ Or install it yourself as:
|
|
23
23
|
|[TbpgrUtils Array#together](#arraytogether) |loop all arrays by block |
|
24
24
|
|[TbpgrUtils Array#together_at](#arraytogether_at) |together version of Array#at. together_at has alias :tat |
|
25
25
|
|[TbpgrUtils Array#together_clear](#arraytogether_clear) |together version of Array#clear. together_clear has alias :tclear |
|
26
|
+
|[TbpgrUtils Array#together_compact](#arraytogether_compact) |together version of Array#compact. together_compact has alias :tcompact. this is immutable. |
|
27
|
+
|[TbpgrUtils Array#together_compact!](#arraytogether_compact!) |together version of Array#compact!. together_compact! has alias :tcompact! this is mutable. |
|
26
28
|
|[TbpgrUtils Array#together_concat](#arraytogether_concat) |together version of Array#concat. together_concat has alias :tconcat |
|
27
29
|
|[TbpgrUtils Array#together_map](#arraytogether_mapor-tmap-together_collect-tcollect) |together version of Enumerable#map. together_map has aliases [:tmap, :together_collect, :tcollect] |
|
28
30
|
|[TbpgrUtils Array#together_reduce](#arraytogether_reduceor-treduce-together_inject-tinject) |together version of Enumerable#reduce. together_reduce has aliases [:treduce, :together_inject, :tinject] |
|
@@ -89,6 +91,34 @@ numbers = %w{1 2 3}
|
|
89
91
|
|
90
92
|
[back to list](#list)
|
91
93
|
|
94
|
+
### Array#together_compact
|
95
|
+
~~~ruby
|
96
|
+
require 'tbpgr_utils'
|
97
|
+
|
98
|
+
alpha = ['a','b','c', nil,'d']
|
99
|
+
numbers = [1, 2, nil, 3]
|
100
|
+
lists = [alpha, numbers]
|
101
|
+
ret = lists.together_compact
|
102
|
+
print lists # => output [['a','b','c', nil,'d'], [1, 2, nil, 3]]
|
103
|
+
print ret # => output [['a','b','c','d'], [1, 2, 3]]
|
104
|
+
~~~
|
105
|
+
|
106
|
+
[back to list](#list)
|
107
|
+
|
108
|
+
### Array#together_compact!
|
109
|
+
~~~ruby
|
110
|
+
require 'tbpgr_utils'
|
111
|
+
|
112
|
+
alpha = ['a','b','c', nil,'d']
|
113
|
+
numbers = [1, 2, nil, 3]
|
114
|
+
lists = [alpha, numbers]
|
115
|
+
ret = lists.together_compact!
|
116
|
+
print lists # => output [['a','b','c','d'], [1, 2, 3]]
|
117
|
+
print ret # => output [['a','b','c','d'], [1, 2, 3]]
|
118
|
+
~~~
|
119
|
+
|
120
|
+
[back to list](#list)
|
121
|
+
|
92
122
|
### Array#together_concat
|
93
123
|
~~~ruby
|
94
124
|
require 'tbpgr_utils'
|
@@ -796,6 +826,7 @@ if you are Sublime Text2 user, you can use snippet for TbpgrUtils.
|
|
796
826
|
https://github.com/tbpgr/tbpgr_utils_snippets
|
797
827
|
|
798
828
|
## History
|
829
|
+
* version 0.0.22 : add Array#together_compact. together_compact has alias :tcompact. Array#together_compact!. together_compact! has alias :tcompact!.
|
799
830
|
* version 0.0.21 : add Array#together_clear. together_clear has alias :tclear
|
800
831
|
* version 0.0.20 : add Array#together_at. together_at has alias :tat
|
801
832
|
* version 0.0.19 : add AttributesHashable module.
|
data/lib/open_classes/array.rb
CHANGED
@@ -176,6 +176,37 @@ class Array
|
|
176
176
|
each { |list|list.clear }
|
177
177
|
end
|
178
178
|
|
179
|
+
# Arrays bulk compact.(immutable)
|
180
|
+
#
|
181
|
+
# together_compact has alias :tcompact
|
182
|
+
#
|
183
|
+
# same elements size case
|
184
|
+
# alpha = ['a','b','c', nil,'d']
|
185
|
+
# numbers = [1, 2, nil, 3]
|
186
|
+
# lists = [alpha, numbers]
|
187
|
+
# ret = lists.together_compact
|
188
|
+
# print lists # => output [['a','b','c', nil,'d'], [1, 2, nil, 3]]
|
189
|
+
# print ret # => output [['a','b','c','d'], [1, 2, 3]]
|
190
|
+
def together_compact
|
191
|
+
if_not_contain_array_rails_type_error
|
192
|
+
reduce([]) { |ret, list|ret << list.compact }
|
193
|
+
end
|
194
|
+
|
195
|
+
# Arrays bulk compact!.(mutable)
|
196
|
+
#
|
197
|
+
# together_compact! has alias :tcompact!
|
198
|
+
#
|
199
|
+
# same elements size case
|
200
|
+
# alpha = ['a','b','c', nil,'d']
|
201
|
+
# numbers = [1, 2, nil, 3]
|
202
|
+
# ret = lists.together_compact!
|
203
|
+
# print lists # => output [['a','b','c','d'], [1, 2, 3]]
|
204
|
+
# print ret # => output [['a','b','c','d'], [1, 2, 3]]
|
205
|
+
def together_compact!
|
206
|
+
if_not_contain_array_rails_type_error
|
207
|
+
each { |list|list.compact! }
|
208
|
+
end
|
209
|
+
|
179
210
|
private
|
180
211
|
|
181
212
|
def if_not_contain_array_rails_type_error
|
@@ -226,6 +257,8 @@ class Array
|
|
226
257
|
alias_method :tconcat, :together_concat
|
227
258
|
alias_method :tat, :together_at
|
228
259
|
alias_method :tclear, :together_clear
|
260
|
+
alias_method :tcompact, :together_compact
|
261
|
+
alias_method :tcompact!, :together_compact!
|
229
262
|
alias_methods [:together_collect, :tmap, :tcollect], :together_map
|
230
263
|
alias_methods [:together_find_all, :tselect, :tfindall], :together_select
|
231
264
|
alias_methods [:together_inject, :treduce, :tinject], :together_reduce
|
data/lib/tbpgr_utils/version.rb
CHANGED
@@ -1,491 +1,590 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'spec_helper'
|
3
|
-
require 'tbpgr_utils'
|
4
|
-
|
5
|
-
describe Array do
|
6
|
-
context :together do
|
7
|
-
cases = [
|
8
|
-
{
|
9
|
-
case_no: 1,
|
10
|
-
case_title: 'valid case',
|
11
|
-
inputs: [[1, 2, 3], %w{one two three}],
|
12
|
-
expected: ['1:one', '2:two', '3:three'],
|
13
|
-
},
|
14
|
-
{
|
15
|
-
case_no: 2,
|
16
|
-
case_title: 'contain nil case',
|
17
|
-
inputs: [[1, 2, 3], %w{one two}],
|
18
|
-
expected: ['1:one', '2:two', '3:'],
|
19
|
-
},
|
20
|
-
]
|
21
|
-
|
22
|
-
cases.each do |c|
|
23
|
-
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
24
|
-
begin
|
25
|
-
case_before c
|
26
|
-
|
27
|
-
# -- given --
|
28
|
-
# nothing
|
29
|
-
|
30
|
-
# -- when/then --
|
31
|
-
actual = []
|
32
|
-
c[:inputs].together do |first, second|
|
33
|
-
actual << "#{first}:#{second}"
|
34
|
-
end
|
35
|
-
|
36
|
-
expect(actual).to eq(c[:expected])
|
37
|
-
ensure
|
38
|
-
case_after c
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def case_before(c)
|
43
|
-
# implement each case before
|
44
|
-
end
|
45
|
-
|
46
|
-
def case_after(c)
|
47
|
-
# implement each case after
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
context :together_with_index do
|
53
|
-
cases = [
|
54
|
-
{
|
55
|
-
case_no: 1,
|
56
|
-
case_title: 'valid case',
|
57
|
-
inputs: [[1, 2, 3], %w{one two three}],
|
58
|
-
expected: ['0:1:one', '1:2:two', '2:3:three'],
|
59
|
-
},
|
60
|
-
{
|
61
|
-
case_no: 2,
|
62
|
-
case_title: 'contain nil case',
|
63
|
-
inputs: [[1, 2, 3], %w{one two}],
|
64
|
-
expected: ['0:1:one', '1:2:two', '2:3:'],
|
65
|
-
},
|
66
|
-
]
|
67
|
-
|
68
|
-
cases.each do |c|
|
69
|
-
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
70
|
-
begin
|
71
|
-
case_before c
|
72
|
-
|
73
|
-
# -- given --
|
74
|
-
# nothing
|
75
|
-
|
76
|
-
# -- when/then --
|
77
|
-
actual = []
|
78
|
-
c[:inputs].together_with_index do |first, second, index|
|
79
|
-
actual << "#{index.to_s}:#{first}:#{second}"
|
80
|
-
end
|
81
|
-
|
82
|
-
expect(actual).to eq(c[:expected])
|
83
|
-
ensure
|
84
|
-
case_after c
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def case_before(c)
|
89
|
-
# implement each case before
|
90
|
-
end
|
91
|
-
|
92
|
-
def case_after(c)
|
93
|
-
# implement each case after
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
context :together_map do
|
99
|
-
cases = [
|
100
|
-
{
|
101
|
-
case_no: 1,
|
102
|
-
case_title: 'valid case',
|
103
|
-
method_name: :together_map,
|
104
|
-
inputs: [[1, 2, 3], %w{one two three}],
|
105
|
-
expected: ['1:one', '2:two', '3:three'],
|
106
|
-
},
|
107
|
-
{
|
108
|
-
case_no: 2,
|
109
|
-
case_title: 'contain nil case',
|
110
|
-
method_name: :together_map,
|
111
|
-
inputs: [[1, 2, 3], %w{one two}],
|
112
|
-
expected: ['1:one', '2:two', '3:'],
|
113
|
-
},
|
114
|
-
{
|
115
|
-
case_no: 3,
|
116
|
-
case_title: 'valid case',
|
117
|
-
method_name: :together_map,
|
118
|
-
inputs: [[1, 2, 3], %w{one two three}],
|
119
|
-
expected: [['1:one', '2:two', '3:three'], ['one:1', 'two:2', 'three:3']],
|
120
|
-
is_multi: true,
|
121
|
-
},
|
122
|
-
{
|
123
|
-
case_no: 4,
|
124
|
-
case_title: 'valid case(alias together_collect)',
|
125
|
-
method_name: :together_collect,
|
126
|
-
inputs: [[1, 2, 3], %w{one two three}],
|
127
|
-
expected: ['1:one', '2:two', '3:three'],
|
128
|
-
},
|
129
|
-
{
|
130
|
-
case_no: 5,
|
131
|
-
case_title: 'valid case(alias tmap)',
|
132
|
-
method_name: :tmap,
|
133
|
-
inputs: [[1, 2, 3], %w{one two three}],
|
134
|
-
expected: ['1:one', '2:two', '3:three'],
|
135
|
-
},
|
136
|
-
{
|
137
|
-
case_no: 6,
|
138
|
-
case_title: 'valid case(alias tcollect)',
|
139
|
-
method_name: :tcollect,
|
140
|
-
inputs: [[1, 2, 3], %w{one two three}],
|
141
|
-
expected: ['1:one', '2:two', '3:three'],
|
142
|
-
},
|
143
|
-
]
|
144
|
-
|
145
|
-
cases.each do |c|
|
146
|
-
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
147
|
-
begin
|
148
|
-
case_before c
|
149
|
-
|
150
|
-
# -- given --
|
151
|
-
# nothing
|
152
|
-
|
153
|
-
# -- when/then --
|
154
|
-
if c[:is_multi]
|
155
|
-
actual = c[:inputs].method(c[:method_name]).call { |first, second|["#{first}:#{second}", "#{second}:#{first}"] }
|
156
|
-
else
|
157
|
-
actual = c[:inputs].method(c[:method_name]).call { |first, second|"#{first}:#{second}" }
|
158
|
-
end
|
159
|
-
|
160
|
-
expect(actual).to eq(c[:expected])
|
161
|
-
ensure
|
162
|
-
case_after c
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
def case_before(c)
|
167
|
-
# implement each case before
|
168
|
-
end
|
169
|
-
|
170
|
-
def case_after(c)
|
171
|
-
# implement each case after
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
context :together_select do
|
177
|
-
cases = [
|
178
|
-
{
|
179
|
-
case_no: 1,
|
180
|
-
case_title: 'single valid case',
|
181
|
-
inputs: [[1, 2, 3, 4], [4, 2, 3, 1]],
|
182
|
-
condition: 'first == second',
|
183
|
-
method_name: :together_select,
|
184
|
-
expected: [[2, 3], [2, 3]],
|
185
|
-
},
|
186
|
-
{
|
187
|
-
case_no: 2,
|
188
|
-
case_title: 'multi valid case',
|
189
|
-
inputs: [[1, 2, 3, 4], [4, 2, 3, 1]],
|
190
|
-
condition: '[first.odd?, second.even?]',
|
191
|
-
expected: [[1, 3], [4, 2]],
|
192
|
-
method_name: :together_select,
|
193
|
-
},
|
194
|
-
{
|
195
|
-
case_no: 3,
|
196
|
-
case_title: 'multi valid case',
|
197
|
-
inputs: [[1, 2, 3, 4], [4, 2, 3, 1]],
|
198
|
-
condition: '[first.odd?, second.even?]',
|
199
|
-
expected: [[1, 3], [4, 2]],
|
200
|
-
method_name: :tselect,
|
201
|
-
},
|
202
|
-
{
|
203
|
-
case_no: 4,
|
204
|
-
case_title: 'multi valid case',
|
205
|
-
inputs: [[1, 2, 3, 4], [4, 2, 3, 1]],
|
206
|
-
condition: '[first.odd?, second.even?]',
|
207
|
-
expected: [[1, 3], [4, 2]],
|
208
|
-
method_name: :together_find_all,
|
209
|
-
},
|
210
|
-
{
|
211
|
-
case_no: 5,
|
212
|
-
case_title: 'multi valid case',
|
213
|
-
inputs: [[1, 2, 3, 4], [4, 2, 3, 1]],
|
214
|
-
condition: '[first.odd?, second.even?]',
|
215
|
-
expected: [[1, 3], [4, 2]],
|
216
|
-
method_name: :tfindall,
|
217
|
-
},
|
218
|
-
]
|
219
|
-
|
220
|
-
cases.each do |c|
|
221
|
-
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
222
|
-
begin
|
223
|
-
case_before c
|
224
|
-
|
225
|
-
# -- given --
|
226
|
-
# nothing
|
227
|
-
|
228
|
-
# -- when/then --
|
229
|
-
actual = c[:inputs].method(c[:method_name]).call { |first, second| eval c[:condition], binding }
|
230
|
-
|
231
|
-
expect(actual).to eq(c[:expected])
|
232
|
-
ensure
|
233
|
-
case_after c
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
def case_before(c)
|
238
|
-
# implement each case before
|
239
|
-
end
|
240
|
-
|
241
|
-
def case_after(c)
|
242
|
-
# implement each case after
|
243
|
-
end
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
context :together_reduce do
|
248
|
-
cases = [
|
249
|
-
{
|
250
|
-
case_no: 1,
|
251
|
-
case_title: 'single valid case',
|
252
|
-
inputs: [[1, 2, 3, 4], [4, 2, 3, 1]],
|
253
|
-
init: nil,
|
254
|
-
logic: 'memo + first + second',
|
255
|
-
method_name: :together_reduce,
|
256
|
-
expected: 20,
|
257
|
-
},
|
258
|
-
{
|
259
|
-
case_no: 2,
|
260
|
-
case_title: 'single with init valid case',
|
261
|
-
inputs: [[1, 2, 3, 4], [4, 2, 3, 1]],
|
262
|
-
init: 10,
|
263
|
-
logic: 'memo + first + second',
|
264
|
-
method_name: :together_reduce,
|
265
|
-
expected: 30,
|
266
|
-
},
|
267
|
-
{
|
268
|
-
case_no: 5,
|
269
|
-
case_title: 'single valid case',
|
270
|
-
inputs: [[1, 2, 3, 4], [4, 2, 3, 1]],
|
271
|
-
logic: 'memo + first + second',
|
272
|
-
expected: 20,
|
273
|
-
method_name: :treduce,
|
274
|
-
},
|
275
|
-
{
|
276
|
-
case_no: 6,
|
277
|
-
case_title: 'single valid case',
|
278
|
-
inputs: [[1, 2, 3, 4], [4, 2, 3, 1]],
|
279
|
-
logic: 'memo + first + second',
|
280
|
-
expected: 20,
|
281
|
-
method_name: :together_inject,
|
282
|
-
},
|
283
|
-
{
|
284
|
-
case_no: 7,
|
285
|
-
case_title: 'multi valid case',
|
286
|
-
inputs: [[1, 2, 3, 4], [4, 2, 3, 1]],
|
287
|
-
logic: 'memo + first + second',
|
288
|
-
expected: 20,
|
289
|
-
method_name: :tinject,
|
290
|
-
},
|
291
|
-
{
|
292
|
-
case_no: 8,
|
293
|
-
case_title: 'single with init valid array case',
|
294
|
-
inputs: [[1, 2, 3, 4], [4, 2, 3, 1]],
|
295
|
-
init: [],
|
296
|
-
logic: 'memo << first + second',
|
297
|
-
method_name: :together_reduce,
|
298
|
-
expected: [5, 4, 6, 5],
|
299
|
-
},
|
300
|
-
{
|
301
|
-
case_no: 9,
|
302
|
-
case_title: 'single with init valid array case',
|
303
|
-
inputs: [[1, 2, 3, 4], [4, 2, 3, 1]],
|
304
|
-
init: {},
|
305
|
-
logic: 'memo[first] = second; memo',
|
306
|
-
method_name: :together_reduce,
|
307
|
-
expected: { 1 => 4, 2 => 2, 3 => 3, 4 => 1 },
|
308
|
-
},
|
309
|
-
]
|
310
|
-
|
311
|
-
cases.each do |c|
|
312
|
-
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
313
|
-
begin
|
314
|
-
case_before c
|
315
|
-
|
316
|
-
# -- given --
|
317
|
-
# nothing
|
318
|
-
|
319
|
-
# -- when/then --
|
320
|
-
if c[:init]
|
321
|
-
actual = c[:inputs].method(c[:method_name]).call(c[:init]) { |memo, first, second| eval c[:logic], binding }
|
322
|
-
else
|
323
|
-
actual = c[:inputs].method(c[:method_name]).call { |memo, first, second| eval c[:logic], binding }
|
324
|
-
end
|
325
|
-
|
326
|
-
expect(actual).to eq(c[:expected])
|
327
|
-
ensure
|
328
|
-
case_after c
|
329
|
-
end
|
330
|
-
end
|
331
|
-
|
332
|
-
def case_before(c)
|
333
|
-
# implement each case before
|
334
|
-
end
|
335
|
-
|
336
|
-
def case_after(c)
|
337
|
-
# implement each case after
|
338
|
-
end
|
339
|
-
end
|
340
|
-
end
|
341
|
-
|
342
|
-
context :together_concat do
|
343
|
-
cases = [
|
344
|
-
{
|
345
|
-
case_no: 1,
|
346
|
-
case_title: 'valid case',
|
347
|
-
inputs: [[1, 2, 3], %w{one two three}],
|
348
|
-
add_list: [4, 5, 6],
|
349
|
-
method_name: :together_concat,
|
350
|
-
expected: [[1, 2, 3, 4, 5, 6], ['one', 'two', 'three', 4, 5, 6]],
|
351
|
-
},
|
352
|
-
{
|
353
|
-
case_no: 2,
|
354
|
-
case_title: 'valid case',
|
355
|
-
inputs: [[1, 2, 3], %w{one two three}],
|
356
|
-
add_list: [4, 5, 6],
|
357
|
-
method_name: :tconcat,
|
358
|
-
expected: [[1, 2, 3, 4, 5, 6], ['one', 'two', 'three', 4, 5, 6]],
|
359
|
-
},
|
360
|
-
]
|
361
|
-
|
362
|
-
cases.each do |c|
|
363
|
-
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
364
|
-
begin
|
365
|
-
case_before c
|
366
|
-
|
367
|
-
# -- given --
|
368
|
-
# nothing
|
369
|
-
|
370
|
-
# -- when --
|
371
|
-
c[:inputs].send c[:method_name], c[:add_list]
|
372
|
-
|
373
|
-
# -- then --
|
374
|
-
expect(c[:inputs]).to eq(c[:expected])
|
375
|
-
ensure
|
376
|
-
case_after c
|
377
|
-
end
|
378
|
-
end
|
379
|
-
|
380
|
-
def case_before(c)
|
381
|
-
# implement each case before
|
382
|
-
end
|
383
|
-
|
384
|
-
def case_after(c)
|
385
|
-
# implement each case after
|
386
|
-
end
|
387
|
-
end
|
388
|
-
end
|
389
|
-
|
390
|
-
context :together_at do
|
391
|
-
cases = [
|
392
|
-
{
|
393
|
-
case_no: 1,
|
394
|
-
case_title: 'valid case',
|
395
|
-
inputs: [[1, 2, 3], %w{one two three}],
|
396
|
-
index: 2,
|
397
|
-
method_name: :together_at,
|
398
|
-
expected: [3, 'three'],
|
399
|
-
},
|
400
|
-
{
|
401
|
-
case_no: 2,
|
402
|
-
case_title: 'contain nil case',
|
403
|
-
inputs: [[1, 2, 3], %w{one two}],
|
404
|
-
index: 2,
|
405
|
-
method_name: :together_at,
|
406
|
-
expected: [3, nil],
|
407
|
-
},
|
408
|
-
{
|
409
|
-
case_no: 3,
|
410
|
-
case_title: 'valid case',
|
411
|
-
inputs: [[1, 2, 3], %w{one two three}],
|
412
|
-
index: 2,
|
413
|
-
method_name: :tat,
|
414
|
-
expected: [3, 'three'],
|
415
|
-
},
|
416
|
-
]
|
417
|
-
|
418
|
-
cases.each do |c|
|
419
|
-
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
420
|
-
begin
|
421
|
-
case_before c
|
422
|
-
|
423
|
-
# -- given --
|
424
|
-
# nothing
|
425
|
-
|
426
|
-
# -- when --
|
427
|
-
actual = c[:inputs].send c[:method_name], c[:index]
|
428
|
-
|
429
|
-
# -- then --
|
430
|
-
expect(actual).to eq(c[:expected])
|
431
|
-
ensure
|
432
|
-
case_after c
|
433
|
-
end
|
434
|
-
end
|
435
|
-
|
436
|
-
def case_before(c)
|
437
|
-
# implement each case before
|
438
|
-
end
|
439
|
-
|
440
|
-
def case_after(c)
|
441
|
-
# implement each case after
|
442
|
-
end
|
443
|
-
end
|
444
|
-
end
|
445
|
-
|
446
|
-
context :together_clear do
|
447
|
-
cases = [
|
448
|
-
{
|
449
|
-
case_no: 1,
|
450
|
-
case_title: 'valid case',
|
451
|
-
inputs: [[1, 2, 3], %w{one two three}],
|
452
|
-
method_name: :together_clear,
|
453
|
-
expected: [[], []],
|
454
|
-
},
|
455
|
-
{
|
456
|
-
case_no: 2,
|
457
|
-
case_title: 'valid case',
|
458
|
-
inputs: [[1, 2, 3], %w{one two three}],
|
459
|
-
method_name: :tclear,
|
460
|
-
expected: [[], []],
|
461
|
-
},
|
462
|
-
]
|
463
|
-
|
464
|
-
cases.each do |c|
|
465
|
-
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
466
|
-
begin
|
467
|
-
case_before c
|
468
|
-
|
469
|
-
# -- given --
|
470
|
-
# nothing
|
471
|
-
|
472
|
-
# -- when --
|
473
|
-
actual = c[:inputs].send c[:method_name]
|
474
|
-
|
475
|
-
# -- then --
|
476
|
-
expect(actual).to eq(c[:expected])
|
477
|
-
ensure
|
478
|
-
case_after c
|
479
|
-
end
|
480
|
-
end
|
481
|
-
|
482
|
-
def case_before(c)
|
483
|
-
# implement each case before
|
484
|
-
end
|
485
|
-
|
486
|
-
def case_after(c)
|
487
|
-
# implement each case after
|
488
|
-
end
|
489
|
-
end
|
490
|
-
end
|
491
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'tbpgr_utils'
|
4
|
+
|
5
|
+
describe Array do
|
6
|
+
context :together do
|
7
|
+
cases = [
|
8
|
+
{
|
9
|
+
case_no: 1,
|
10
|
+
case_title: 'valid case',
|
11
|
+
inputs: [[1, 2, 3], %w{one two three}],
|
12
|
+
expected: ['1:one', '2:two', '3:three'],
|
13
|
+
},
|
14
|
+
{
|
15
|
+
case_no: 2,
|
16
|
+
case_title: 'contain nil case',
|
17
|
+
inputs: [[1, 2, 3], %w{one two}],
|
18
|
+
expected: ['1:one', '2:two', '3:'],
|
19
|
+
},
|
20
|
+
]
|
21
|
+
|
22
|
+
cases.each do |c|
|
23
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
24
|
+
begin
|
25
|
+
case_before c
|
26
|
+
|
27
|
+
# -- given --
|
28
|
+
# nothing
|
29
|
+
|
30
|
+
# -- when/then --
|
31
|
+
actual = []
|
32
|
+
c[:inputs].together do |first, second|
|
33
|
+
actual << "#{first}:#{second}"
|
34
|
+
end
|
35
|
+
|
36
|
+
expect(actual).to eq(c[:expected])
|
37
|
+
ensure
|
38
|
+
case_after c
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def case_before(c)
|
43
|
+
# implement each case before
|
44
|
+
end
|
45
|
+
|
46
|
+
def case_after(c)
|
47
|
+
# implement each case after
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context :together_with_index do
|
53
|
+
cases = [
|
54
|
+
{
|
55
|
+
case_no: 1,
|
56
|
+
case_title: 'valid case',
|
57
|
+
inputs: [[1, 2, 3], %w{one two three}],
|
58
|
+
expected: ['0:1:one', '1:2:two', '2:3:three'],
|
59
|
+
},
|
60
|
+
{
|
61
|
+
case_no: 2,
|
62
|
+
case_title: 'contain nil case',
|
63
|
+
inputs: [[1, 2, 3], %w{one two}],
|
64
|
+
expected: ['0:1:one', '1:2:two', '2:3:'],
|
65
|
+
},
|
66
|
+
]
|
67
|
+
|
68
|
+
cases.each do |c|
|
69
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
70
|
+
begin
|
71
|
+
case_before c
|
72
|
+
|
73
|
+
# -- given --
|
74
|
+
# nothing
|
75
|
+
|
76
|
+
# -- when/then --
|
77
|
+
actual = []
|
78
|
+
c[:inputs].together_with_index do |first, second, index|
|
79
|
+
actual << "#{index.to_s}:#{first}:#{second}"
|
80
|
+
end
|
81
|
+
|
82
|
+
expect(actual).to eq(c[:expected])
|
83
|
+
ensure
|
84
|
+
case_after c
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def case_before(c)
|
89
|
+
# implement each case before
|
90
|
+
end
|
91
|
+
|
92
|
+
def case_after(c)
|
93
|
+
# implement each case after
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context :together_map do
|
99
|
+
cases = [
|
100
|
+
{
|
101
|
+
case_no: 1,
|
102
|
+
case_title: 'valid case',
|
103
|
+
method_name: :together_map,
|
104
|
+
inputs: [[1, 2, 3], %w{one two three}],
|
105
|
+
expected: ['1:one', '2:two', '3:three'],
|
106
|
+
},
|
107
|
+
{
|
108
|
+
case_no: 2,
|
109
|
+
case_title: 'contain nil case',
|
110
|
+
method_name: :together_map,
|
111
|
+
inputs: [[1, 2, 3], %w{one two}],
|
112
|
+
expected: ['1:one', '2:two', '3:'],
|
113
|
+
},
|
114
|
+
{
|
115
|
+
case_no: 3,
|
116
|
+
case_title: 'valid case',
|
117
|
+
method_name: :together_map,
|
118
|
+
inputs: [[1, 2, 3], %w{one two three}],
|
119
|
+
expected: [['1:one', '2:two', '3:three'], ['one:1', 'two:2', 'three:3']],
|
120
|
+
is_multi: true,
|
121
|
+
},
|
122
|
+
{
|
123
|
+
case_no: 4,
|
124
|
+
case_title: 'valid case(alias together_collect)',
|
125
|
+
method_name: :together_collect,
|
126
|
+
inputs: [[1, 2, 3], %w{one two three}],
|
127
|
+
expected: ['1:one', '2:two', '3:three'],
|
128
|
+
},
|
129
|
+
{
|
130
|
+
case_no: 5,
|
131
|
+
case_title: 'valid case(alias tmap)',
|
132
|
+
method_name: :tmap,
|
133
|
+
inputs: [[1, 2, 3], %w{one two three}],
|
134
|
+
expected: ['1:one', '2:two', '3:three'],
|
135
|
+
},
|
136
|
+
{
|
137
|
+
case_no: 6,
|
138
|
+
case_title: 'valid case(alias tcollect)',
|
139
|
+
method_name: :tcollect,
|
140
|
+
inputs: [[1, 2, 3], %w{one two three}],
|
141
|
+
expected: ['1:one', '2:two', '3:three'],
|
142
|
+
},
|
143
|
+
]
|
144
|
+
|
145
|
+
cases.each do |c|
|
146
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
147
|
+
begin
|
148
|
+
case_before c
|
149
|
+
|
150
|
+
# -- given --
|
151
|
+
# nothing
|
152
|
+
|
153
|
+
# -- when/then --
|
154
|
+
if c[:is_multi]
|
155
|
+
actual = c[:inputs].method(c[:method_name]).call { |first, second|["#{first}:#{second}", "#{second}:#{first}"] }
|
156
|
+
else
|
157
|
+
actual = c[:inputs].method(c[:method_name]).call { |first, second|"#{first}:#{second}" }
|
158
|
+
end
|
159
|
+
|
160
|
+
expect(actual).to eq(c[:expected])
|
161
|
+
ensure
|
162
|
+
case_after c
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def case_before(c)
|
167
|
+
# implement each case before
|
168
|
+
end
|
169
|
+
|
170
|
+
def case_after(c)
|
171
|
+
# implement each case after
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
context :together_select do
|
177
|
+
cases = [
|
178
|
+
{
|
179
|
+
case_no: 1,
|
180
|
+
case_title: 'single valid case',
|
181
|
+
inputs: [[1, 2, 3, 4], [4, 2, 3, 1]],
|
182
|
+
condition: 'first == second',
|
183
|
+
method_name: :together_select,
|
184
|
+
expected: [[2, 3], [2, 3]],
|
185
|
+
},
|
186
|
+
{
|
187
|
+
case_no: 2,
|
188
|
+
case_title: 'multi valid case',
|
189
|
+
inputs: [[1, 2, 3, 4], [4, 2, 3, 1]],
|
190
|
+
condition: '[first.odd?, second.even?]',
|
191
|
+
expected: [[1, 3], [4, 2]],
|
192
|
+
method_name: :together_select,
|
193
|
+
},
|
194
|
+
{
|
195
|
+
case_no: 3,
|
196
|
+
case_title: 'multi valid case',
|
197
|
+
inputs: [[1, 2, 3, 4], [4, 2, 3, 1]],
|
198
|
+
condition: '[first.odd?, second.even?]',
|
199
|
+
expected: [[1, 3], [4, 2]],
|
200
|
+
method_name: :tselect,
|
201
|
+
},
|
202
|
+
{
|
203
|
+
case_no: 4,
|
204
|
+
case_title: 'multi valid case',
|
205
|
+
inputs: [[1, 2, 3, 4], [4, 2, 3, 1]],
|
206
|
+
condition: '[first.odd?, second.even?]',
|
207
|
+
expected: [[1, 3], [4, 2]],
|
208
|
+
method_name: :together_find_all,
|
209
|
+
},
|
210
|
+
{
|
211
|
+
case_no: 5,
|
212
|
+
case_title: 'multi valid case',
|
213
|
+
inputs: [[1, 2, 3, 4], [4, 2, 3, 1]],
|
214
|
+
condition: '[first.odd?, second.even?]',
|
215
|
+
expected: [[1, 3], [4, 2]],
|
216
|
+
method_name: :tfindall,
|
217
|
+
},
|
218
|
+
]
|
219
|
+
|
220
|
+
cases.each do |c|
|
221
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
222
|
+
begin
|
223
|
+
case_before c
|
224
|
+
|
225
|
+
# -- given --
|
226
|
+
# nothing
|
227
|
+
|
228
|
+
# -- when/then --
|
229
|
+
actual = c[:inputs].method(c[:method_name]).call { |first, second| eval c[:condition], binding }
|
230
|
+
|
231
|
+
expect(actual).to eq(c[:expected])
|
232
|
+
ensure
|
233
|
+
case_after c
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
def case_before(c)
|
238
|
+
# implement each case before
|
239
|
+
end
|
240
|
+
|
241
|
+
def case_after(c)
|
242
|
+
# implement each case after
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
context :together_reduce do
|
248
|
+
cases = [
|
249
|
+
{
|
250
|
+
case_no: 1,
|
251
|
+
case_title: 'single valid case',
|
252
|
+
inputs: [[1, 2, 3, 4], [4, 2, 3, 1]],
|
253
|
+
init: nil,
|
254
|
+
logic: 'memo + first + second',
|
255
|
+
method_name: :together_reduce,
|
256
|
+
expected: 20,
|
257
|
+
},
|
258
|
+
{
|
259
|
+
case_no: 2,
|
260
|
+
case_title: 'single with init valid case',
|
261
|
+
inputs: [[1, 2, 3, 4], [4, 2, 3, 1]],
|
262
|
+
init: 10,
|
263
|
+
logic: 'memo + first + second',
|
264
|
+
method_name: :together_reduce,
|
265
|
+
expected: 30,
|
266
|
+
},
|
267
|
+
{
|
268
|
+
case_no: 5,
|
269
|
+
case_title: 'single valid case',
|
270
|
+
inputs: [[1, 2, 3, 4], [4, 2, 3, 1]],
|
271
|
+
logic: 'memo + first + second',
|
272
|
+
expected: 20,
|
273
|
+
method_name: :treduce,
|
274
|
+
},
|
275
|
+
{
|
276
|
+
case_no: 6,
|
277
|
+
case_title: 'single valid case',
|
278
|
+
inputs: [[1, 2, 3, 4], [4, 2, 3, 1]],
|
279
|
+
logic: 'memo + first + second',
|
280
|
+
expected: 20,
|
281
|
+
method_name: :together_inject,
|
282
|
+
},
|
283
|
+
{
|
284
|
+
case_no: 7,
|
285
|
+
case_title: 'multi valid case',
|
286
|
+
inputs: [[1, 2, 3, 4], [4, 2, 3, 1]],
|
287
|
+
logic: 'memo + first + second',
|
288
|
+
expected: 20,
|
289
|
+
method_name: :tinject,
|
290
|
+
},
|
291
|
+
{
|
292
|
+
case_no: 8,
|
293
|
+
case_title: 'single with init valid array case',
|
294
|
+
inputs: [[1, 2, 3, 4], [4, 2, 3, 1]],
|
295
|
+
init: [],
|
296
|
+
logic: 'memo << first + second',
|
297
|
+
method_name: :together_reduce,
|
298
|
+
expected: [5, 4, 6, 5],
|
299
|
+
},
|
300
|
+
{
|
301
|
+
case_no: 9,
|
302
|
+
case_title: 'single with init valid array case',
|
303
|
+
inputs: [[1, 2, 3, 4], [4, 2, 3, 1]],
|
304
|
+
init: {},
|
305
|
+
logic: 'memo[first] = second; memo',
|
306
|
+
method_name: :together_reduce,
|
307
|
+
expected: { 1 => 4, 2 => 2, 3 => 3, 4 => 1 },
|
308
|
+
},
|
309
|
+
]
|
310
|
+
|
311
|
+
cases.each do |c|
|
312
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
313
|
+
begin
|
314
|
+
case_before c
|
315
|
+
|
316
|
+
# -- given --
|
317
|
+
# nothing
|
318
|
+
|
319
|
+
# -- when/then --
|
320
|
+
if c[:init]
|
321
|
+
actual = c[:inputs].method(c[:method_name]).call(c[:init]) { |memo, first, second| eval c[:logic], binding }
|
322
|
+
else
|
323
|
+
actual = c[:inputs].method(c[:method_name]).call { |memo, first, second| eval c[:logic], binding }
|
324
|
+
end
|
325
|
+
|
326
|
+
expect(actual).to eq(c[:expected])
|
327
|
+
ensure
|
328
|
+
case_after c
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
332
|
+
def case_before(c)
|
333
|
+
# implement each case before
|
334
|
+
end
|
335
|
+
|
336
|
+
def case_after(c)
|
337
|
+
# implement each case after
|
338
|
+
end
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
context :together_concat do
|
343
|
+
cases = [
|
344
|
+
{
|
345
|
+
case_no: 1,
|
346
|
+
case_title: 'valid case',
|
347
|
+
inputs: [[1, 2, 3], %w{one two three}],
|
348
|
+
add_list: [4, 5, 6],
|
349
|
+
method_name: :together_concat,
|
350
|
+
expected: [[1, 2, 3, 4, 5, 6], ['one', 'two', 'three', 4, 5, 6]],
|
351
|
+
},
|
352
|
+
{
|
353
|
+
case_no: 2,
|
354
|
+
case_title: 'valid case',
|
355
|
+
inputs: [[1, 2, 3], %w{one two three}],
|
356
|
+
add_list: [4, 5, 6],
|
357
|
+
method_name: :tconcat,
|
358
|
+
expected: [[1, 2, 3, 4, 5, 6], ['one', 'two', 'three', 4, 5, 6]],
|
359
|
+
},
|
360
|
+
]
|
361
|
+
|
362
|
+
cases.each do |c|
|
363
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
364
|
+
begin
|
365
|
+
case_before c
|
366
|
+
|
367
|
+
# -- given --
|
368
|
+
# nothing
|
369
|
+
|
370
|
+
# -- when --
|
371
|
+
c[:inputs].send c[:method_name], c[:add_list]
|
372
|
+
|
373
|
+
# -- then --
|
374
|
+
expect(c[:inputs]).to eq(c[:expected])
|
375
|
+
ensure
|
376
|
+
case_after c
|
377
|
+
end
|
378
|
+
end
|
379
|
+
|
380
|
+
def case_before(c)
|
381
|
+
# implement each case before
|
382
|
+
end
|
383
|
+
|
384
|
+
def case_after(c)
|
385
|
+
# implement each case after
|
386
|
+
end
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
390
|
+
context :together_at do
|
391
|
+
cases = [
|
392
|
+
{
|
393
|
+
case_no: 1,
|
394
|
+
case_title: 'valid case',
|
395
|
+
inputs: [[1, 2, 3], %w{one two three}],
|
396
|
+
index: 2,
|
397
|
+
method_name: :together_at,
|
398
|
+
expected: [3, 'three'],
|
399
|
+
},
|
400
|
+
{
|
401
|
+
case_no: 2,
|
402
|
+
case_title: 'contain nil case',
|
403
|
+
inputs: [[1, 2, 3], %w{one two}],
|
404
|
+
index: 2,
|
405
|
+
method_name: :together_at,
|
406
|
+
expected: [3, nil],
|
407
|
+
},
|
408
|
+
{
|
409
|
+
case_no: 3,
|
410
|
+
case_title: 'valid case',
|
411
|
+
inputs: [[1, 2, 3], %w{one two three}],
|
412
|
+
index: 2,
|
413
|
+
method_name: :tat,
|
414
|
+
expected: [3, 'three'],
|
415
|
+
},
|
416
|
+
]
|
417
|
+
|
418
|
+
cases.each do |c|
|
419
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
420
|
+
begin
|
421
|
+
case_before c
|
422
|
+
|
423
|
+
# -- given --
|
424
|
+
# nothing
|
425
|
+
|
426
|
+
# -- when --
|
427
|
+
actual = c[:inputs].send c[:method_name], c[:index]
|
428
|
+
|
429
|
+
# -- then --
|
430
|
+
expect(actual).to eq(c[:expected])
|
431
|
+
ensure
|
432
|
+
case_after c
|
433
|
+
end
|
434
|
+
end
|
435
|
+
|
436
|
+
def case_before(c)
|
437
|
+
# implement each case before
|
438
|
+
end
|
439
|
+
|
440
|
+
def case_after(c)
|
441
|
+
# implement each case after
|
442
|
+
end
|
443
|
+
end
|
444
|
+
end
|
445
|
+
|
446
|
+
context :together_clear do
|
447
|
+
cases = [
|
448
|
+
{
|
449
|
+
case_no: 1,
|
450
|
+
case_title: 'valid case',
|
451
|
+
inputs: [[1, 2, 3], %w{one two three}],
|
452
|
+
method_name: :together_clear,
|
453
|
+
expected: [[], []],
|
454
|
+
},
|
455
|
+
{
|
456
|
+
case_no: 2,
|
457
|
+
case_title: 'valid case',
|
458
|
+
inputs: [[1, 2, 3], %w{one two three}],
|
459
|
+
method_name: :tclear,
|
460
|
+
expected: [[], []],
|
461
|
+
},
|
462
|
+
]
|
463
|
+
|
464
|
+
cases.each do |c|
|
465
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
466
|
+
begin
|
467
|
+
case_before c
|
468
|
+
|
469
|
+
# -- given --
|
470
|
+
# nothing
|
471
|
+
|
472
|
+
# -- when --
|
473
|
+
actual = c[:inputs].send c[:method_name]
|
474
|
+
|
475
|
+
# -- then --
|
476
|
+
expect(actual).to eq(c[:expected])
|
477
|
+
ensure
|
478
|
+
case_after c
|
479
|
+
end
|
480
|
+
end
|
481
|
+
|
482
|
+
def case_before(c)
|
483
|
+
# implement each case before
|
484
|
+
end
|
485
|
+
|
486
|
+
def case_after(c)
|
487
|
+
# implement each case after
|
488
|
+
end
|
489
|
+
end
|
490
|
+
end
|
491
|
+
|
492
|
+
context :together_compact do
|
493
|
+
cases = [
|
494
|
+
{
|
495
|
+
case_no: 1,
|
496
|
+
case_title: 'valid case',
|
497
|
+
inputs: [[1, 2, nil, 3], ['a', 'b', 'c', nil, 'd']],
|
498
|
+
method_name: :together_compact,
|
499
|
+
expected_self: [[1, 2, nil, 3], ['a', 'b', 'c', nil, 'd']],
|
500
|
+
expected_ret: [[1, 2, 3], ['a', 'b', 'c', 'd']],
|
501
|
+
},
|
502
|
+
{
|
503
|
+
case_no: 2,
|
504
|
+
case_title: 'valid case(use alias tcompact)',
|
505
|
+
inputs: [[1, 2, nil, 3], ['a', 'b', 'c', nil, 'd']],
|
506
|
+
method_name: :tcompact,
|
507
|
+
expected_self: [[1, 2, nil, 3], ['a', 'b', 'c', nil, 'd']],
|
508
|
+
expected_ret: [[1, 2, 3], ['a', 'b', 'c', 'd']],
|
509
|
+
},
|
510
|
+
]
|
511
|
+
|
512
|
+
cases.each do |c|
|
513
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
514
|
+
begin
|
515
|
+
case_before c
|
516
|
+
|
517
|
+
# -- given --
|
518
|
+
# nothing
|
519
|
+
|
520
|
+
# -- when --
|
521
|
+
actual = c[:inputs].send c[:method_name]
|
522
|
+
|
523
|
+
# -- then --
|
524
|
+
expect(c[:inputs]).to eq(c[:expected_self])
|
525
|
+
expect(actual).to eq(c[:expected_ret])
|
526
|
+
ensure
|
527
|
+
case_after c
|
528
|
+
end
|
529
|
+
end
|
530
|
+
|
531
|
+
def case_before(c)
|
532
|
+
# implement each case before
|
533
|
+
end
|
534
|
+
|
535
|
+
def case_after(c)
|
536
|
+
# implement each case after
|
537
|
+
end
|
538
|
+
end
|
539
|
+
end
|
540
|
+
|
541
|
+
|
542
|
+
context :together_compact! do
|
543
|
+
cases = [
|
544
|
+
{
|
545
|
+
case_no: 1,
|
546
|
+
case_title: 'valid case',
|
547
|
+
inputs: [[1, 2, nil, 3], ['a', 'b', 'c', nil, 'd']],
|
548
|
+
method_name: :together_compact!,
|
549
|
+
expected_self: [[1, 2, 3], ['a', 'b', 'c', 'd']],
|
550
|
+
expected_ret: [[1, 2, 3], ['a', 'b', 'c', 'd']],
|
551
|
+
},
|
552
|
+
{
|
553
|
+
case_no: 2,
|
554
|
+
case_title: 'valid case(use alias tcompact)',
|
555
|
+
inputs: [[1, 2, nil, 3], ['a', 'b', 'c', nil, 'd']],
|
556
|
+
method_name: :tcompact!,
|
557
|
+
expected_self: [[1, 2, 3], ['a', 'b', 'c', 'd']],
|
558
|
+
expected_ret: [[1, 2, 3], ['a', 'b', 'c', 'd']],
|
559
|
+
},
|
560
|
+
]
|
561
|
+
|
562
|
+
cases.each do |c|
|
563
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
564
|
+
begin
|
565
|
+
case_before c
|
566
|
+
|
567
|
+
# -- given --
|
568
|
+
# nothing
|
569
|
+
|
570
|
+
# -- when --
|
571
|
+
actual = c[:inputs].send c[:method_name]
|
572
|
+
|
573
|
+
# -- then --
|
574
|
+
expect(c[:inputs]).to eq(c[:expected_self])
|
575
|
+
expect(actual).to eq(c[:expected_ret])
|
576
|
+
ensure
|
577
|
+
case_after c
|
578
|
+
end
|
579
|
+
end
|
580
|
+
|
581
|
+
def case_before(c)
|
582
|
+
# implement each case before
|
583
|
+
end
|
584
|
+
|
585
|
+
def case_after(c)
|
586
|
+
# implement each case after
|
587
|
+
end
|
588
|
+
end
|
589
|
+
end
|
590
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tbpgr_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.22
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-01-
|
12
|
+
date: 2014-01-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement: &
|
16
|
+
requirement: &23038980 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 4.0.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *23038980
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bundler
|
27
|
-
requirement: &
|
27
|
+
requirement: &23038680 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '1.3'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *23038680
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &23038452 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *23038452
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &23038116 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 2.14.1
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *23038116
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: simplecov
|
60
|
-
requirement: &
|
60
|
+
requirement: &23037816 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: 0.8.2
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *23037816
|
69
69
|
description: Utilities
|
70
70
|
email:
|
71
71
|
- tbpgr@tbpgr.jp
|
@@ -75,6 +75,7 @@ extra_rdoc_files: []
|
|
75
75
|
files:
|
76
76
|
- .gitignore
|
77
77
|
- .rspec
|
78
|
+
- .rubocop.yml
|
78
79
|
- Gemfile
|
79
80
|
- LICENSE.txt
|
80
81
|
- README.md
|