red-arrow 0.4.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -26,4 +26,10 @@ class ArrayTest < Test::Unit::TestCase
26
26
  assert_equal([true, false, nil, true],
27
27
  array.to_a)
28
28
  end
29
+
30
+ test("#[]") do
31
+ array = Arrow::BooleanArray.new([true, false, nil, true])
32
+ assert_equal([true, false, nil, true],
33
+ [array[0], array[1], array[2], array[3]])
34
+ end
29
35
  end
@@ -14,11 +14,11 @@
14
14
 
15
15
  class ColumnTest < Test::Unit::TestCase
16
16
  test("#each") do
17
- arrayes = [
17
+ arrays = [
18
18
  Arrow::BooleanArray.new([true, false]),
19
19
  Arrow::BooleanArray.new([nil, true]),
20
20
  ]
21
- chunked_array = Arrow::ChunkedArray.new(arrayes)
21
+ chunked_array = Arrow::ChunkedArray.new(arrays)
22
22
  column = Arrow::Column.new(Arrow::Field.new("visible", :boolean),
23
23
  chunked_array)
24
24
  assert_equal([true, false, nil, true],
@@ -0,0 +1,90 @@
1
+ # Copyright 2017-2018 Kouhei Sutou <kou@clear-code.com>
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ class CSVReaderTest < Test::Unit::TestCase
16
+ include Helper::Fixture
17
+
18
+ sub_test_case(".read") do
19
+ test("String: data: with header") do
20
+ data = fixture_path("with-header.csv").read
21
+ assert_equal(<<-TABLE, Arrow::CSVReader.read(data).to_s)
22
+ name score
23
+ 0 alice 10
24
+ 1 bob 29
25
+ 2 chris -1
26
+ TABLE
27
+ end
28
+
29
+ test("String: data: without header") do
30
+ data = fixture_path("without-header.csv").read
31
+ assert_equal(<<-TABLE, Arrow::CSVReader.read(data).to_s)
32
+ 0 1
33
+ 0 alice 10
34
+ 1 bob 29
35
+ 2 chris -1
36
+ TABLE
37
+ end
38
+
39
+ test("String: path: with header") do
40
+ path = fixture_path("with-header.csv").to_s
41
+ assert_equal(<<-TABLE, Arrow::CSVReader.read(path).to_s)
42
+ name score
43
+ 0 alice 10
44
+ 1 bob 29
45
+ 2 chris -1
46
+ TABLE
47
+ end
48
+
49
+ test("String: path: without header") do
50
+ path = fixture_path("without-header.csv").to_s
51
+ assert_equal(<<-TABLE, Arrow::CSVReader.read(path).to_s)
52
+ 0 1
53
+ 0 alice 10
54
+ 1 bob 29
55
+ 2 chris -1
56
+ TABLE
57
+ end
58
+
59
+ test("Pathname: with header") do
60
+ path = fixture_path("with-header.csv")
61
+ assert_equal(<<-TABLE, Arrow::CSVReader.read(path).to_s)
62
+ name score
63
+ 0 alice 10
64
+ 1 bob 29
65
+ 2 chris -1
66
+ TABLE
67
+ end
68
+
69
+ test("Pathname: without header") do
70
+ path = fixture_path("without-header.csv")
71
+ assert_equal(<<-TABLE, Arrow::CSVReader.read(path).to_s)
72
+ 0 1
73
+ 0 alice 10
74
+ 1 bob 29
75
+ 2 chris -1
76
+ TABLE
77
+ end
78
+
79
+ test("CSV") do
80
+ CSV.open(fixture_path("with-header.csv").to_s, headers: true) do |csv|
81
+ assert_equal(<<-TABLE, Arrow::CSVReader.read(csv).to_s)
82
+ name score
83
+ 0 alice 10
84
+ 1 bob 29
85
+ 2 chris -1
86
+ TABLE
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,401 @@
1
+ # Copyright 2017-2018 Kouhei Sutou <kou@clear-code.com>
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ class SlicerTest < Test::Unit::TestCase
16
+ def setup
17
+ @count_field = Arrow::Field.new("count", :uint32)
18
+ @visible_field = Arrow::Field.new("visible", :boolean)
19
+ schema = Arrow::Schema.new([@count_field, @visible_field])
20
+ count_arrays = [
21
+ Arrow::UInt32Array.new([0, 1, 2]),
22
+ Arrow::UInt32Array.new([4, 8, 16]),
23
+ Arrow::UInt32Array.new([32, 64, nil]),
24
+ Arrow::UInt32Array.new([256]),
25
+ ]
26
+ visible_arrays = [
27
+ Arrow::BooleanArray.new([nil, true, false, nil]),
28
+ Arrow::BooleanArray.new([true]),
29
+ Arrow::BooleanArray.new([true, false]),
30
+ Arrow::BooleanArray.new([nil]),
31
+ Arrow::BooleanArray.new([nil]),
32
+ Arrow::BooleanArray.new([true]),
33
+ ]
34
+ @count_array = Arrow::ChunkedArray.new(count_arrays)
35
+ @visible_array = Arrow::ChunkedArray.new(visible_arrays)
36
+ @count_column = Arrow::Column.new(@count_field, @count_array)
37
+ @visible_column = Arrow::Column.new(@visible_field, @visible_array)
38
+ @table = Arrow::Table.new(schema, [@count_column, @visible_column])
39
+ end
40
+
41
+ sub_test_case("column") do
42
+ test("BooleanArray") do
43
+ sliced_table = @table.slice do |slicer|
44
+ slicer.visible
45
+ end
46
+ assert_equal(<<-TABLE, sliced_table.to_s)
47
+ count visible
48
+ 0 1 true
49
+ 1 8 true
50
+ 2 16 true
51
+ 3 256 true
52
+ TABLE
53
+ end
54
+
55
+ test("not BooleanArray") do
56
+ sliced_table = @table.slice do |slicer|
57
+ slicer.count
58
+ end
59
+ assert_equal(<<-TABLE, sliced_table.to_s)
60
+ count visible
61
+ 0 1 true
62
+ 1 2 false
63
+ 2 4
64
+ 3 8 true
65
+ 4 16 true
66
+ 5 32 false
67
+ 6 64
68
+ 7 256 true
69
+ TABLE
70
+ end
71
+ end
72
+
73
+ sub_test_case("!column") do
74
+ test("BooleanArray") do
75
+ sliced_table = @table.slice do |slicer|
76
+ !slicer.visible
77
+ end
78
+ assert_equal(<<-TABLE, sliced_table.to_s)
79
+ count visible
80
+ 0 2 false
81
+ 1 32 false
82
+ TABLE
83
+ end
84
+
85
+ test("not BooleanArray") do
86
+ sliced_table = @table.slice do |slicer|
87
+ !slicer.count
88
+ end
89
+ assert_equal(<<-TABLE, sliced_table.to_s)
90
+ count visible
91
+ 0 0
92
+ TABLE
93
+ end
94
+ end
95
+
96
+ test("column.null?") do
97
+ sliced_table = @table.slice do |slicer|
98
+ slicer.visible.null?
99
+ end
100
+ assert_equal(<<-TABLE, sliced_table.to_s)
101
+ count visible
102
+ 0 0
103
+ 1 4
104
+ 2 64
105
+ 3
106
+ TABLE
107
+ end
108
+
109
+ sub_test_case("column ==") do
110
+ test("nil") do
111
+ sliced_table = @table.slice do |slicer|
112
+ slicer.visible == nil
113
+ end
114
+ assert_equal(<<-TABLE, sliced_table.to_s)
115
+ count visible
116
+ 0 0
117
+ 1 4
118
+ 2 64
119
+ 3
120
+ TABLE
121
+ end
122
+
123
+ test("value") do
124
+ sliced_table = @table.slice do |slicer|
125
+ slicer.visible == true
126
+ end
127
+ assert_equal(<<-TABLE, sliced_table.to_s)
128
+ count visible
129
+ 0 1 true
130
+ 1 8 true
131
+ 2 16 true
132
+ 3 256 true
133
+ TABLE
134
+ end
135
+ end
136
+
137
+ sub_test_case("!(column ==)") do
138
+ test("nil") do
139
+ sliced_table = @table.slice do |slicer|
140
+ !(slicer.visible == nil)
141
+ end
142
+ assert_equal(<<-TABLE, sliced_table.to_s)
143
+ count visible
144
+ 0 1 true
145
+ 1 2 false
146
+ 2 8 true
147
+ 3 16 true
148
+ 4 32 false
149
+ 5 256 true
150
+ TABLE
151
+ end
152
+
153
+ test("value") do
154
+ sliced_table = @table.slice do |slicer|
155
+ !(slicer.visible == true)
156
+ end
157
+ assert_equal(<<-TABLE, sliced_table.to_s)
158
+ count visible
159
+ 0 2 false
160
+ 1 32 false
161
+ TABLE
162
+ end
163
+ end
164
+
165
+ sub_test_case("column !=") do
166
+ test("nil") do
167
+ sliced_table = @table.slice do |slicer|
168
+ slicer.visible != nil
169
+ end
170
+ assert_equal(<<-TABLE, sliced_table.to_s)
171
+ count visible
172
+ 0 1 true
173
+ 1 2 false
174
+ 2 8 true
175
+ 3 16 true
176
+ 4 32 false
177
+ 5 256 true
178
+ TABLE
179
+ end
180
+
181
+ test("value") do
182
+ sliced_table = @table.slice do |slicer|
183
+ slicer.visible != true
184
+ end
185
+ assert_equal(<<-TABLE, sliced_table.to_s)
186
+ count visible
187
+ 0 2 false
188
+ 1 32 false
189
+ TABLE
190
+ end
191
+ end
192
+
193
+ test("column < value") do
194
+ sliced_table = @table.slice do |slicer|
195
+ slicer.count < 16
196
+ end
197
+ assert_equal(<<-TABLE, sliced_table.to_s)
198
+ count visible
199
+ 0 0
200
+ 1 1 true
201
+ 2 2 false
202
+ 3 4
203
+ 4 8 true
204
+ TABLE
205
+ end
206
+
207
+ test("!(column < value)") do
208
+ sliced_table = @table.slice do |slicer|
209
+ !(slicer.count < 16)
210
+ end
211
+ assert_equal(<<-TABLE, sliced_table.to_s)
212
+ count visible
213
+ 0 16 true
214
+ 1 32 false
215
+ 2 64
216
+ 3 256 true
217
+ TABLE
218
+ end
219
+
220
+ test("column <= value") do
221
+ sliced_table = @table.slice do |slicer|
222
+ slicer.count <= 16
223
+ end
224
+ assert_equal(<<-TABLE, sliced_table.to_s)
225
+ count visible
226
+ 0 0
227
+ 1 1 true
228
+ 2 2 false
229
+ 3 4
230
+ 4 8 true
231
+ 5 16 true
232
+ TABLE
233
+ end
234
+
235
+ test("!(column <= value)") do
236
+ sliced_table = @table.slice do |slicer|
237
+ !(slicer.count <= 16)
238
+ end
239
+ assert_equal(<<-TABLE, sliced_table.to_s)
240
+ count visible
241
+ 0 32 false
242
+ 1 64
243
+ 2 256 true
244
+ TABLE
245
+ end
246
+
247
+ test("column > value") do
248
+ sliced_table = @table.slice do |slicer|
249
+ slicer.count > 16
250
+ end
251
+ assert_equal(<<-TABLE, sliced_table.to_s)
252
+ count visible
253
+ 0 32 false
254
+ 1 64
255
+ 2 256 true
256
+ TABLE
257
+ end
258
+
259
+ test("!(column > value)") do
260
+ sliced_table = @table.slice do |slicer|
261
+ !(slicer.count > 16)
262
+ end
263
+ assert_equal(<<-TABLE, sliced_table.to_s)
264
+ count visible
265
+ 0 0
266
+ 1 1 true
267
+ 2 2 false
268
+ 3 4
269
+ 4 8 true
270
+ 5 16 true
271
+ TABLE
272
+ end
273
+
274
+ test("column >= value") do
275
+ sliced_table = @table.slice do |slicer|
276
+ slicer.count >= 16
277
+ end
278
+ assert_equal(<<-TABLE, sliced_table.to_s)
279
+ count visible
280
+ 0 16 true
281
+ 1 32 false
282
+ 2 64
283
+ 3 256 true
284
+ TABLE
285
+ end
286
+
287
+ test("!(column >= value)") do
288
+ sliced_table = @table.slice do |slicer|
289
+ !(slicer.count >= 16)
290
+ end
291
+ assert_equal(<<-TABLE, sliced_table.to_s)
292
+ count visible
293
+ 0 0
294
+ 1 1 true
295
+ 2 2 false
296
+ 3 4
297
+ 4 8 true
298
+ TABLE
299
+ end
300
+
301
+ test("condition & condition") do
302
+ sliced_table = @table.slice do |slicer|
303
+ slicer.visible & (slicer.count >= 16)
304
+ end
305
+ assert_equal(<<-TABLE, sliced_table.to_s)
306
+ count visible
307
+ 0 16 true
308
+ 1 256 true
309
+ TABLE
310
+ end
311
+
312
+ test("condition | condition") do
313
+ sliced_table = @table.slice do |slicer|
314
+ slicer.visible | (slicer.count >= 16)
315
+ end
316
+ assert_equal(<<-TABLE, sliced_table.to_s)
317
+ count visible
318
+ 0 1 true
319
+ 1 8 true
320
+ 2 16 true
321
+ 3 32 false
322
+ 4 256 true
323
+ TABLE
324
+ end
325
+
326
+ test("condition ^ condition") do
327
+ sliced_table = @table.slice do |slicer|
328
+ slicer.visible ^ (slicer.count >= 16)
329
+ end
330
+ assert_equal(<<-TABLE, sliced_table.to_s)
331
+ count visible
332
+ 0 1 true
333
+ 1 8 true
334
+ 2 32 false
335
+ TABLE
336
+ end
337
+
338
+ test("select") do
339
+ sliced_table = @table.slice do |slicer|
340
+ slicer.visible.select do |value|
341
+ value.nil? or value
342
+ end
343
+ end
344
+ assert_equal(<<-TABLE, sliced_table.to_s)
345
+ count visible
346
+ 0 0
347
+ 1 1 true
348
+ 2 4
349
+ 3 8 true
350
+ 4 16 true
351
+ 5 64
352
+ 6
353
+ 7 256 true
354
+ TABLE
355
+ end
356
+
357
+ test("!select") do
358
+ sliced_table = @table.slice do |slicer|
359
+ !slicer.visible.select do |value|
360
+ value.nil? or value
361
+ end
362
+ end
363
+ assert_equal(<<-TABLE, sliced_table.to_s)
364
+ count visible
365
+ 0 2 false
366
+ 1 32 false
367
+ TABLE
368
+ end
369
+
370
+ test("reject") do
371
+ sliced_table = @table.slice do |slicer|
372
+ slicer.visible.reject do |value|
373
+ value.nil? or value
374
+ end
375
+ end
376
+ assert_equal(<<-TABLE, sliced_table.to_s)
377
+ count visible
378
+ 0 2 false
379
+ 1 32 false
380
+ TABLE
381
+ end
382
+
383
+ test("!reject") do
384
+ sliced_table = @table.slice do |slicer|
385
+ !slicer.visible.reject do |value|
386
+ value.nil? or value
387
+ end
388
+ end
389
+ assert_equal(<<-TABLE, sliced_table.to_s)
390
+ count visible
391
+ 0 0
392
+ 1 1 true
393
+ 2 4
394
+ 3 8 true
395
+ 4 16 true
396
+ 5 64
397
+ 6
398
+ 7 256 true
399
+ TABLE
400
+ end
401
+ end