]> git.proxmox.com Git - ceph.git/blame - ceph/src/arrow/ruby/red-arrow/test/test-struct-array.rb
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / ruby / red-arrow / test / test-struct-array.rb
CommitLineData
1d09f67e
TL
1# Licensed to the Apache Software Foundation (ASF) under one
2# or more contributor license agreements. See the NOTICE file
3# distributed with this work for additional information
4# regarding copyright ownership. The ASF licenses this file
5# to you under the Apache License, Version 2.0 (the
6# "License"); you may not use this file except in compliance
7# with the License. You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing,
12# software distributed under the License is distributed on an
13# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14# KIND, either express or implied. See the License for the
15# specific language governing permissions and limitations
16# under the License.
17
18class StructArrayTest < Test::Unit::TestCase
19 sub_test_case(".new") do
20 test("build") do
21 data_type = Arrow::StructDataType.new(visible: :boolean,
22 count: :uint64)
23 values = [
24 [true, 1],
25 nil,
26 [false, 2],
27 ]
28 array = Arrow::StructArray.new(data_type, values)
29 assert_equal([
30 [true, false, false],
31 [1, 0, 2],
32 ],
33 [
34 array.find_field(0).to_a,
35 array.find_field(1).to_a,
36 ])
37 end
38 end
39
40 sub_test_case("instance methods") do
41 def setup
42 @data_type = Arrow::StructDataType.new(visible: {type: :boolean},
43 count: {type: :uint64})
44 @values = [
45 [true, 1],
46 [false, 2],
47 ]
48 @array = Arrow::StructArray.new(@data_type, @values)
49 end
50
51 test("#[]") do
52 assert_equal([
53 {"visible" => true, "count" => 1},
54 {"visible" => false, "count" => 2},
55 ],
56 @array.to_a)
57 end
58
59 test("#get_value") do
60 assert_equal([
61 {"visible" => true, "count" => 1},
62 {"visible" => false, "count" => 2},
63 ],
64 [
65 @array.get_value(0),
66 @array.get_value(1),
67 ])
68 end
69
70 sub_test_case("#find_field") do
71 test("Integer") do
72 assert_equal([
73 [true, false],
74 [1, 2],
75 ],
76 [
77 @array.find_field(0).to_a,
78 @array.find_field(1).to_a,
79 ])
80 end
81
82 test("String, Symbol") do
83 assert_equal([
84 [true, false],
85 [1, 2],
86 ],
87 [
88 @array.find_field("visible").to_a,
89 @array.find_field(:count).to_a,
90 ])
91 end
92 end
93 end
94end