Skip to content

Commit 50e3f75

Browse files
authored
GH-48437: [Ruby] Add tests for large list array (#48438)
### Rationale for this change They should have been included in #48411. ### What changes are included in this PR? Add missing tests. ### Are these changes tested? Yes. ### Are there any user-facing changes? No. * GitHub Issue: #48437 Authored-by: Sutou Kouhei <[email protected]> Signed-off-by: Sutou Kouhei <[email protected]>
1 parent 09f1561 commit 50e3f75

File tree

3 files changed

+190
-0
lines changed

3 files changed

+190
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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 LargeListArrayBuilderTest < Test::Unit::TestCase
19+
def setup
20+
@data_type = Arrow::LargeListDataType.new(name: "visible", type: :boolean)
21+
@builder = Arrow::LargeListArrayBuilder.new(@data_type)
22+
end
23+
24+
sub_test_case("#append_value") do
25+
test("nil") do
26+
@builder.append_value(nil)
27+
array = @builder.finish
28+
assert_equal(nil, array[0])
29+
end
30+
31+
test("Array") do
32+
@builder.append_value([true, false, true])
33+
array = @builder.finish
34+
assert_equal([true, false, true], array[0].to_a)
35+
end
36+
37+
test("Struct[]") do
38+
item_type = Arrow::StructDataType.new([{name: "visible", type: :boolean}])
39+
data_type = Arrow::LargeListDataType.new(name: "struct",
40+
data_type: item_type)
41+
builder = Arrow::LargeListArrayBuilder.new(data_type)
42+
builder.append_value([])
43+
array = builder.finish
44+
assert_equal([[]], array.to_a)
45+
end
46+
end
47+
48+
sub_test_case("#append_values") do
49+
test("[nil, Array]") do
50+
@builder.append_values([[false], nil, [true, false, true]])
51+
array = @builder.finish
52+
assert_equal([
53+
[false],
54+
nil,
55+
[true, false, true],
56+
],
57+
array.collect {|list| list ? list.to_a : nil})
58+
end
59+
60+
test("is_valids") do
61+
@builder.append_values([[false], [true, true], [true, false, true]],
62+
[true, false, true])
63+
array = @builder.finish
64+
assert_equal([
65+
[false],
66+
nil,
67+
[true, false, true],
68+
],
69+
array.collect {|list| list ? list.to_a : nil})
70+
end
71+
end
72+
73+
sub_test_case("#append") do
74+
test("backward compatibility") do
75+
@builder.append
76+
@builder.value_builder.append(true)
77+
@builder.value_builder.append(false)
78+
@builder.append
79+
@builder.value_builder.append(true)
80+
array = @builder.finish
81+
82+
assert_equal([
83+
[true, false],
84+
[true],
85+
],
86+
array.collect(&:to_a))
87+
end
88+
end
89+
end
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 LargeListArrayTest < Test::Unit::TestCase
19+
sub_test_case(".new") do
20+
test("build") do
21+
data_type = Arrow::LargeListDataType.new(name: "visible", type: :boolean)
22+
values = [
23+
[true, false],
24+
nil,
25+
[false, true, false],
26+
]
27+
array = Arrow::LargeListArray.new(data_type, values)
28+
assert_equal(values,
29+
array.collect {|value| value ? value.to_a : nil})
30+
end
31+
end
32+
end
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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 LargeListDataTypeTest < Test::Unit::TestCase
19+
sub_test_case(".new") do
20+
test("Arrow::Field") do
21+
field = Arrow::Field.new(:tag, :string)
22+
assert_equal("large_list<tag: string>",
23+
Arrow::LargeListDataType.new(field).to_s)
24+
end
25+
26+
test("name: String") do
27+
assert_equal("large_list<tag: string>",
28+
Arrow::LargeListDataType.new(name: "tag", type: :string).to_s)
29+
end
30+
31+
test("field: Arrow::Field") do
32+
field = Arrow::Field.new(:tag, :string)
33+
assert_equal("large_list<tag: string>",
34+
Arrow::LargeListDataType.new(field: field).to_s)
35+
end
36+
37+
test("field: Hash") do
38+
field_description = {name: "tag", type: :string}
39+
assert_equal("large_list<tag: string>",
40+
Arrow::LargeListDataType.new(field: field_description).to_s)
41+
end
42+
43+
test("Arrow::DataType") do
44+
data_type = Arrow::BooleanDataType.new
45+
assert_equal("large_list<item: bool>",
46+
Arrow::LargeListDataType.new(data_type).to_s)
47+
end
48+
49+
test("String") do
50+
assert_equal("large_list<item: bool>",
51+
Arrow::LargeListDataType.new("boolean").to_s)
52+
end
53+
54+
test("Symbol") do
55+
assert_equal("large_list<item: bool>",
56+
Arrow::LargeListDataType.new(:boolean).to_s)
57+
end
58+
59+
test("[data type name, additional information]") do
60+
assert_equal("large_list<item: time32[ms]>",
61+
Arrow::LargeListDataType.new([:time32, :milli]).to_s)
62+
end
63+
64+
test("type: Symbol") do
65+
assert_equal("large_list<item: bool>",
66+
Arrow::LargeListDataType.new(type: :boolean).to_s)
67+
end
68+
end
69+
end

0 commit comments

Comments
 (0)