]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/ruby/red-arrow/test/test-map-array-builder.rb
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / ruby / red-arrow / test / test-map-array-builder.rb
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
18 class MapArrayBuilderTest < Test::Unit::TestCase
19 def setup
20 key_type = Arrow::StringDataType.new
21 item_type = Arrow::Int16DataType.new
22 data_type = Arrow::MapDataType.new(key_type, item_type)
23 @builder = Arrow::MapArrayBuilder.new(data_type)
24 end
25
26 sub_test_case("#append_value") do
27 test("nil") do
28 @builder.append_value(nil)
29 array = @builder.finish
30 assert_equal([nil], array.collect {|value| value})
31 end
32
33 test("Hash") do
34 @builder.append_value({"a" => 0, "b" => 1})
35 @builder.append_value({"c" => 0, "d" => 1})
36 array = @builder.finish
37 assert_equal([
38 {"a" => 0, "b" => 1},
39 {"c" => 0, "d" => 1}
40 ],
41 array.collect {|value| value})
42 end
43
44 test("#each") do
45 @builder.append_value([["a", 0], ["b", 1]])
46 @builder.append_value([["c", 0], ["d", 1]])
47 array = @builder.finish
48 assert_equal([
49 {"a" => 0, "b" => 1},
50 {"c" => 0, "d" => 1}
51 ],
52 array.collect {|value| value})
53 end
54 end
55
56 sub_test_case("#append_values") do
57 test("[nil]") do
58 @builder.append_values([nil])
59 array = @builder.finish
60 assert_equal([nil], array.collect {|value| value})
61 end
62
63 test("[Hash]") do
64 @builder.append_values([{"a" => 0, "b" => 1}, {"c" => 0, "d" => 1}])
65 array = @builder.finish
66 assert_equal([
67 {"a" => 0, "b" => 1},
68 {"c" => 0, "d" => 1}
69 ],
70 array.collect {|value| value})
71 end
72
73 test("[#each]") do
74 @builder.append_values([[["a", 0], ["b", 1]], [["c", 0], ["d", 1]]])
75 array = @builder.finish
76 assert_equal([
77 {"a" => 0, "b" => 1},
78 {"c" => 0, "d" => 1}
79 ],
80 array.collect {|value| value})
81 end
82
83 test("[nil, Hash, #each]") do
84 @builder.append_values([nil, {"a" => 0, "b" => 1}, [["c", 0], ["d", 1]]])
85 array = @builder.finish
86 assert_equal([
87 nil,
88 {"a" => 0, "b" => 1},
89 {"c" => 0, "d" => 1}
90 ],
91 array.collect {|value| value})
92 end
93
94 test("is_valids") do
95 @builder.append_values([
96 {"a" => 0, "b" => 1},
97 {"c" => 0, "d" => 1},
98 {"e" => 0, "f" => 1}
99 ],
100 [true, false, true])
101 array = @builder.finish
102 assert_equal([
103 {"a" => 0, "b" => 1},
104 nil,
105 {"e" => 0, "f" => 1}
106 ],
107 array.collect {|value| value})
108 end
109 end
110 end