kou commented on code in PR #48369:
URL: https://github.com/apache/arrow/pull/48369#discussion_r2594182257


##########
c_glib/test/test-fixed-size-list-array-builder.rb:
##########
@@ -0,0 +1,93 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class TestFixedSizeListArrayBuilder < Test::Unit::TestCase
+  include Helper::Buildable
+  include Helper::Omittable
+
+  def setup
+    require_gi_bindings(3, 1, 9)
+  end
+
+  def test_new
+    field = Arrow::Field.new("value", Arrow::Int8DataType.new)
+    data_type = Arrow::FixedSizeListDataType.new(field, 2)
+    builder = Arrow::FixedSizeListArrayBuilder.new(data_type)
+    assert_equal(data_type, builder.value_data_type)
+  end
+
+  def test_append_value
+    field = Arrow::Field.new("value", Arrow::Int8DataType.new)
+    data_type = Arrow::FixedSizeListDataType.new(field, 2)
+    builder = Arrow::FixedSizeListArrayBuilder.new(data_type)
+    value_builder = builder.value_builder
+
+    # Append first list: [1, 2]
+    builder.append_value
+    value_builder.append_value(1)
+    value_builder.append_value(2)
+
+    # Append second list: [3, 4]
+    builder.append_value
+    value_builder.append_value(3)
+    value_builder.append_value(4)
+
+    array = builder.finish
+    assert_equal(2, array.length)
+    assert_equal([1, 2], array.get_value(0).length.times.collect {|i|
+ array.get_value(0).get_value(i)})
+    assert_equal([3, 4], array.get_value(1).length.times.collect {|i|
+ array.get_value(1).get_value(i)})

Review Comment:
   ```suggestion
       assert_equal([1, 2], get_value(array, 0))
       assert_equal([3, 4], get_value(array, 1))
   ```



##########
c_glib/test/test-fixed-size-list-array-builder.rb:
##########
@@ -0,0 +1,93 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class TestFixedSizeListArrayBuilder < Test::Unit::TestCase
+  include Helper::Buildable
+  include Helper::Omittable
+
+  def setup
+    require_gi_bindings(3, 1, 9)
+  end
+
+  def test_new
+    field = Arrow::Field.new("value", Arrow::Int8DataType.new)
+    data_type = Arrow::FixedSizeListDataType.new(field, 2)
+    builder = Arrow::FixedSizeListArrayBuilder.new(data_type)
+    assert_equal(data_type, builder.value_data_type)
+  end
+
+  def test_append_value
+    field = Arrow::Field.new("value", Arrow::Int8DataType.new)
+    data_type = Arrow::FixedSizeListDataType.new(field, 2)
+    builder = Arrow::FixedSizeListArrayBuilder.new(data_type)
+    value_builder = builder.value_builder
+
+    # Append first list: [1, 2]
+    builder.append_value
+    value_builder.append_value(1)
+    value_builder.append_value(2)
+
+    # Append second list: [3, 4]
+    builder.append_value
+    value_builder.append_value(3)
+    value_builder.append_value(4)
+
+    array = builder.finish
+    assert_equal(2, array.length)
+    assert_equal([1, 2], array.get_value(0).length.times.collect {|i|
+ array.get_value(0).get_value(i)})
+    assert_equal([3, 4], array.get_value(1).length.times.collect {|i|
+ array.get_value(1).get_value(i)})
+  end
+
+  def test_append_null
+    field = Arrow::Field.new("value", Arrow::Int8DataType.new)
+    data_type = Arrow::FixedSizeListDataType.new(field, 2)
+    builder = Arrow::FixedSizeListArrayBuilder.new(data_type)
+    value_builder = builder.value_builder
+
+    # Append first list: [1, 2]
+    builder.append_value
+    value_builder.append_value(1)
+    value_builder.append_value(2)
+
+    # Append null list
+    builder.append_null
+
+    # Append third list: [5, 6]
+    builder.append_value
+    value_builder.append_value(5)
+    value_builder.append_value(6)
+
+    array = builder.finish
+    assert_equal(3, array.length)
+    assert_equal([1, 2], array.get_value(0).length.times.collect {|i|
+ array.get_value(0).get_value(i)})
+    assert_equal(true, array.null?(1))
+    assert_equal([5, 6], array.get_value(2).length.times.collect {|i|
+ array.get_value(2).get_value(i)})

Review Comment:
   ```suggestion
       assert_equal([5, 6], get_value(array, 2))
   ```



##########
c_glib/test/test-fixed-size-list-array-builder.rb:
##########
@@ -0,0 +1,93 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class TestFixedSizeListArrayBuilder < Test::Unit::TestCase
+  include Helper::Buildable
+  include Helper::Omittable
+
+  def setup
+    require_gi_bindings(3, 1, 9)
+  end
+

Review Comment:
   Could you define a helper method that gets the i-th value to shorten test 
code?
   
   ```suggestion
   
     def get_value(array, i)
       value = array.get_value(i)
       value.length.times.collect do |j|
         value.get_value(j)
       end
     end
   
   ```



##########
c_glib/test/test-fixed-size-list-array-builder.rb:
##########
@@ -0,0 +1,93 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class TestFixedSizeListArrayBuilder < Test::Unit::TestCase
+  include Helper::Buildable
+  include Helper::Omittable
+
+  def setup
+    require_gi_bindings(3, 1, 9)
+  end
+
+  def test_new
+    field = Arrow::Field.new("value", Arrow::Int8DataType.new)
+    data_type = Arrow::FixedSizeListDataType.new(field, 2)
+    builder = Arrow::FixedSizeListArrayBuilder.new(data_type)
+    assert_equal(data_type, builder.value_data_type)
+  end
+
+  def test_append_value
+    field = Arrow::Field.new("value", Arrow::Int8DataType.new)
+    data_type = Arrow::FixedSizeListDataType.new(field, 2)
+    builder = Arrow::FixedSizeListArrayBuilder.new(data_type)
+    value_builder = builder.value_builder
+
+    # Append first list: [1, 2]
+    builder.append_value
+    value_builder.append_value(1)
+    value_builder.append_value(2)
+
+    # Append second list: [3, 4]
+    builder.append_value
+    value_builder.append_value(3)
+    value_builder.append_value(4)
+
+    array = builder.finish
+    assert_equal(2, array.length)
+    assert_equal([1, 2], array.get_value(0).length.times.collect {|i|
+ array.get_value(0).get_value(i)})
+    assert_equal([3, 4], array.get_value(1).length.times.collect {|i|
+ array.get_value(1).get_value(i)})
+  end
+
+  def test_append_null
+    field = Arrow::Field.new("value", Arrow::Int8DataType.new)
+    data_type = Arrow::FixedSizeListDataType.new(field, 2)
+    builder = Arrow::FixedSizeListArrayBuilder.new(data_type)
+    value_builder = builder.value_builder
+
+    # Append first list: [1, 2]
+    builder.append_value
+    value_builder.append_value(1)
+    value_builder.append_value(2)
+
+    # Append null list
+    builder.append_null
+
+    # Append third list: [5, 6]
+    builder.append_value
+    value_builder.append_value(5)
+    value_builder.append_value(6)
+
+    array = builder.finish
+    assert_equal(3, array.length)
+    assert_equal([1, 2], array.get_value(0).length.times.collect {|i|
+ array.get_value(0).get_value(i)})
+    assert_equal(true, array.null?(1))

Review Comment:
   Could you use `assert` with block for predicate? It shows more useful 
information on failure.
   
   ```suggestion
       assert do
         array.null?(1)
       end
   ```



##########
c_glib/test/test-fixed-size-list-array-builder.rb:
##########
@@ -0,0 +1,93 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class TestFixedSizeListArrayBuilder < Test::Unit::TestCase
+  include Helper::Buildable
+  include Helper::Omittable
+
+  def setup
+    require_gi_bindings(3, 1, 9)
+  end
+
+  def test_new
+    field = Arrow::Field.new("value", Arrow::Int8DataType.new)
+    data_type = Arrow::FixedSizeListDataType.new(field, 2)
+    builder = Arrow::FixedSizeListArrayBuilder.new(data_type)
+    assert_equal(data_type, builder.value_data_type)
+  end
+
+  def test_append_value
+    field = Arrow::Field.new("value", Arrow::Int8DataType.new)
+    data_type = Arrow::FixedSizeListDataType.new(field, 2)
+    builder = Arrow::FixedSizeListArrayBuilder.new(data_type)
+    value_builder = builder.value_builder
+
+    # Append first list: [1, 2]
+    builder.append_value
+    value_builder.append_value(1)
+    value_builder.append_value(2)
+
+    # Append second list: [3, 4]
+    builder.append_value
+    value_builder.append_value(3)
+    value_builder.append_value(4)
+
+    array = builder.finish
+    assert_equal(2, array.length)
+    assert_equal([1, 2], array.get_value(0).length.times.collect {|i|
+ array.get_value(0).get_value(i)})
+    assert_equal([3, 4], array.get_value(1).length.times.collect {|i|
+ array.get_value(1).get_value(i)})
+  end
+
+  def test_append_null
+    field = Arrow::Field.new("value", Arrow::Int8DataType.new)
+    data_type = Arrow::FixedSizeListDataType.new(field, 2)
+    builder = Arrow::FixedSizeListArrayBuilder.new(data_type)
+    value_builder = builder.value_builder
+
+    # Append first list: [1, 2]
+    builder.append_value
+    value_builder.append_value(1)
+    value_builder.append_value(2)
+
+    # Append null list
+    builder.append_null
+
+    # Append third list: [5, 6]
+    builder.append_value
+    value_builder.append_value(5)
+    value_builder.append_value(6)
+
+    array = builder.finish
+    assert_equal(3, array.length)
+    assert_equal([1, 2], array.get_value(0).length.times.collect {|i|
+ array.get_value(0).get_value(i)})

Review Comment:
   ```suggestion
       assert_equal([1, 2], get_value(array, 0))
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to