You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by sh...@apache.org on 2019/03/10 01:09:36 UTC

[arrow] branch master updated: ARROW-4813: [Ruby] Add tests for == and !=

This is an automated email from the ASF dual-hosted git repository.

shiro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new 0ad791e  ARROW-4813: [Ruby] Add tests for == and !=
0ad791e is described below

commit 0ad791e64759e4bbc69aad195b7d31aeb92f0cf9
Author: Kouhei Sutou <ko...@clear-code.com>
AuthorDate: Sun Mar 10 10:09:22 2019 +0900

    ARROW-4813: [Ruby] Add tests for == and !=
    
    Author: Kouhei Sutou <ko...@clear-code.com>
    
    Closes #3853 from kou/ruby-equal-test and squashes the following commits:
    
    7b8c52bc <Kouhei Sutou>  Add tests for == and !=
---
 ruby/red-arrow/red-arrow.gemspec                   |  2 +-
 ruby/red-arrow/test/test-array.rb                  | 14 ++++++
 .../test/{test-array.rb => test-buffer.rb}         | 37 +++++----------
 ruby/red-arrow/test/test-chunked-array.rb          | 22 +++++++++
 ruby/red-arrow/test/test-column.rb                 | 24 ++++++++++
 ruby/red-arrow/test/test-data-type.rb              | 20 ++++++++
 .../test/{test-array.rb => test-decimal128.rb}     | 45 +++++++++---------
 ruby/red-arrow/test/test-field.rb                  | 20 ++++++++
 ruby/red-arrow/test/test-record-batch.rb           | 14 ++++++
 ruby/red-arrow/test/test-schema.rb                 | 14 ++++++
 ruby/red-arrow/test/test-table.rb                  | 14 ++++++
 .../test/{test-array.rb => test-tensor.rb}         | 53 ++++++++++++----------
 12 files changed, 204 insertions(+), 75 deletions(-)

diff --git a/ruby/red-arrow/red-arrow.gemspec b/ruby/red-arrow/red-arrow.gemspec
index 2d417f0..121f567 100644
--- a/ruby/red-arrow/red-arrow.gemspec
+++ b/ruby/red-arrow/red-arrow.gemspec
@@ -45,7 +45,7 @@ Gem::Specification.new do |spec|
   spec.test_files += Dir.glob("test/**/*")
   spec.extensions = ["dependency-check/Rakefile"]
 
-  spec.add_runtime_dependency("gobject-introspection", ">= 3.3.1")
+  spec.add_runtime_dependency("gobject-introspection", ">= 3.3.5")
   spec.add_runtime_dependency("pkg-config")
   spec.add_runtime_dependency("native-package-installer")
 
diff --git a/ruby/red-arrow/test/test-array.rb b/ruby/red-arrow/test/test-array.rb
index 3dd7635..793a262 100644
--- a/ruby/red-arrow/test/test-array.rb
+++ b/ruby/red-arrow/test/test-array.rb
@@ -49,5 +49,19 @@ class ArrayTest < Test::Unit::TestCase
                      @array[-1])
       end
     end
+
+    sub_test_case("#==") do
+      test("Arrow::Array") do
+        assert do
+          @array == @array
+        end
+      end
+
+      test("not Arrow::Array") do
+        assert do
+          not (@array == 29)
+        end
+      end
+    end
   end
 end
diff --git a/ruby/red-arrow/test/test-array.rb b/ruby/red-arrow/test/test-buffer.rb
similarity index 54%
copy from ruby/red-arrow/test/test-array.rb
copy to ruby/red-arrow/test/test-buffer.rb
index 3dd7635..64f1907 100644
--- a/ruby/red-arrow/test/test-array.rb
+++ b/ruby/red-arrow/test/test-buffer.rb
@@ -15,38 +15,23 @@
 # specific language governing permissions and limitations
 # under the License.
 
-class ArrayTest < Test::Unit::TestCase
-  sub_test_case(".new") do
-    test("Boolean") do
-      array = Arrow::BooleanArray.new([true, false, true])
-      assert_equal([true, false, true],
-                   array.to_a)
-    end
-  end
-
+class BufferTest < Test::Unit::TestCase
   sub_test_case("instance methods") do
     def setup
-      @values = [true, false, nil, true]
-      @array = Arrow::BooleanArray.new(@values)
+      @buffer = Arrow::Buffer.new("Hello")
     end
 
-    test("#each") do
-      assert_equal(@values, @array.to_a)
-    end
-
-    sub_test_case("#[]") do
-      test("valid range") do
-        assert_equal(@values,
-                     @array.length.times.collect {|i| @array[i]})
-      end
-
-      test("out of range") do
-        assert_nil(@array[@array.length])
+    sub_test_case("#==") do
+      test("Arrow::Buffer") do
+        assert do
+          @buffer == @buffer
+        end
       end
 
-      test("negative index") do
-        assert_equal(@values.last,
-                     @array[-1])
+      test("not Arrow::Buffer") do
+        assert do
+          not (@buffer == 29)
+        end
       end
     end
   end
diff --git a/ruby/red-arrow/test/test-chunked-array.rb b/ruby/red-arrow/test/test-chunked-array.rb
index 2344d80..853922a 100644
--- a/ruby/red-arrow/test/test-chunked-array.rb
+++ b/ruby/red-arrow/test/test-chunked-array.rb
@@ -62,4 +62,26 @@ class ChunkedArrayTest < Test::Unit::TestCase
                    ])
     end
   end
+
+  sub_test_case("#==") do
+    def setup
+      arrays = [
+        Arrow::BooleanArray.new([true]),
+        Arrow::BooleanArray.new([false, true]),
+      ]
+      @chunked_array = Arrow::ChunkedArray.new(arrays)
+    end
+
+    test("Arrow::ChunkedArray") do
+      assert do
+        @chunked_array == @chunked_array
+      end
+    end
+
+    test("not Arrow::ChunkedArray") do
+      assert do
+        not (@chunked_array == 29)
+      end
+    end
+  end
 end
diff --git a/ruby/red-arrow/test/test-column.rb b/ruby/red-arrow/test/test-column.rb
index c6bf827..81bf0e0 100644
--- a/ruby/red-arrow/test/test-column.rb
+++ b/ruby/red-arrow/test/test-column.rb
@@ -40,4 +40,28 @@ class ColumnTest < Test::Unit::TestCase
     assert_equal([1, [true, false, nil, true]],
                  [packed_column.data.n_chunks, packed_column.to_a])
   end
+
+  sub_test_case("#==") do
+    def setup
+      arrays = [
+        Arrow::BooleanArray.new([true]),
+        Arrow::BooleanArray.new([false, true]),
+      ]
+      chunked_array = Arrow::ChunkedArray.new(arrays)
+      @column = Arrow::Column.new(Arrow::Field.new("visible", :boolean),
+                                  chunked_array)
+    end
+
+    test("Arrow::Column") do
+      assert do
+        @column == @column
+      end
+    end
+
+    test("not Arrow::Column") do
+      assert do
+        not (@column == 29)
+      end
+    end
+  end
 end
diff --git a/ruby/red-arrow/test/test-data-type.rb b/ruby/red-arrow/test/test-data-type.rb
index c9dbfc6..747eff8 100644
--- a/ruby/red-arrow/test/test-data-type.rb
+++ b/ruby/red-arrow/test/test-data-type.rb
@@ -44,4 +44,24 @@ class DataTypeTest < Test::Unit::TestCase
                    Arrow::DataType.resolve(type: :list, field: field))
     end
   end
+
+  sub_test_case("instance methods") do
+    def setup
+      @data_type = Arrow::StringDataType.new
+    end
+
+    sub_test_case("#==") do
+      test("Arrow::DataType") do
+        assert do
+          @data_type == @data_type
+        end
+      end
+
+      test("not Arrow::DataType") do
+        assert do
+          not (@data_type == 29)
+        end
+      end
+    end
+  end
 end
diff --git a/ruby/red-arrow/test/test-array.rb b/ruby/red-arrow/test/test-decimal128.rb
similarity index 56%
copy from ruby/red-arrow/test/test-array.rb
copy to ruby/red-arrow/test/test-decimal128.rb
index 3dd7635..82c6fe3 100644
--- a/ruby/red-arrow/test/test-array.rb
+++ b/ruby/red-arrow/test/test-decimal128.rb
@@ -15,38 +15,37 @@
 # specific language governing permissions and limitations
 # under the License.
 
-class ArrayTest < Test::Unit::TestCase
-  sub_test_case(".new") do
-    test("Boolean") do
-      array = Arrow::BooleanArray.new([true, false, true])
-      assert_equal([true, false, true],
-                   array.to_a)
-    end
-  end
-
+class Decimal128Test < Test::Unit::TestCase
   sub_test_case("instance methods") do
     def setup
-      @values = [true, false, nil, true]
-      @array = Arrow::BooleanArray.new(@values)
+      @decimal128 = Arrow::Decimal128.new("10.1")
     end
 
-    test("#each") do
-      assert_equal(@values, @array.to_a)
-    end
+    sub_test_case("#==") do
+      test("Arrow::Decimal128") do
+        assert do
+          @decimal128 == @decimal128
+        end
+      end
 
-    sub_test_case("#[]") do
-      test("valid range") do
-        assert_equal(@values,
-                     @array.length.times.collect {|i| @array[i]})
+      test("not Arrow::Decimal128") do
+        assert do
+          not (@decimal128 == 10.1)
+        end
       end
+    end
 
-      test("out of range") do
-        assert_nil(@array[@array.length])
+    sub_test_case("#!=") do
+      test("Arrow::Decimal128") do
+        assert do
+          not (@decimal128 != @decimal128)
+        end
       end
 
-      test("negative index") do
-        assert_equal(@values.last,
-                     @array[-1])
+      test("not Arrow::Decimal128") do
+        assert do
+          @decimal128 != 10.1
+        end
       end
     end
   end
diff --git a/ruby/red-arrow/test/test-field.rb b/ruby/red-arrow/test/test-field.rb
index 9be2068..1b6bc4b 100644
--- a/ruby/red-arrow/test/test-field.rb
+++ b/ruby/red-arrow/test/test-field.rb
@@ -68,4 +68,24 @@ class FieldTest < Test::Unit::TestCase
                    Arrow::Field.new(description).to_s)
     end
   end
+
+  sub_test_case("instance methods") do
+    def setup
+      @field = Arrow::Field.new("count", :uint32)
+    end
+
+    sub_test_case("#==") do
+      test("Arrow::Field") do
+        assert do
+          @field == @field
+        end
+      end
+
+      test("not Arrow::Field") do
+        assert do
+          not (@field == 29)
+        end
+      end
+    end
+  end
 end
diff --git a/ruby/red-arrow/test/test-record-batch.rb b/ruby/red-arrow/test/test-record-batch.rb
index d33298b..82035a2 100644
--- a/ruby/red-arrow/test/test-record-batch.rb
+++ b/ruby/red-arrow/test/test-record-batch.rb
@@ -108,5 +108,19 @@ class RecordBatchTest < Test::Unit::TestCase
       assert_equal(Arrow::Table.new(@schema, [@counts]),
                    @record_batch.to_table)
     end
+
+    sub_test_case("#==") do
+      test("Arrow::RecordBatch") do
+        assert do
+          @record_batch == @record_batch
+        end
+      end
+
+      test("not Arrow::RecordBatch") do
+        assert do
+          not (@record_batch == 29)
+        end
+      end
+    end
   end
 end
diff --git a/ruby/red-arrow/test/test-schema.rb b/ruby/red-arrow/test/test-schema.rb
index 6cfbbb1..b8800a6 100644
--- a/ruby/red-arrow/test/test-schema.rb
+++ b/ruby/red-arrow/test/test-schema.rb
@@ -100,5 +100,19 @@ class SchemaTest < Test::Unit::TestCase
         end
       end
     end
+
+    sub_test_case("#==") do
+      test("Arrow::Schema") do
+        assert do
+          @schema == @schema
+        end
+      end
+
+      test("not Arrow::Schema") do
+        assert do
+          not (@schema == 29)
+        end
+      end
+    end
   end
 end
diff --git a/ruby/red-arrow/test/test-table.rb b/ruby/red-arrow/test/test-table.rb
index 2876f76..6af2b57 100644
--- a/ruby/red-arrow/test/test-table.rb
+++ b/ruby/red-arrow/test/test-table.rb
@@ -596,5 +596,19 @@ visible: false
         end
       end
     end
+
+    sub_test_case("#==") do
+      test("Arrow::Table") do
+        assert do
+          @table == @table
+        end
+      end
+
+      test("not Arrow::Table") do
+        assert do
+          not (@table == 29)
+        end
+      end
+    end
   end
 end
diff --git a/ruby/red-arrow/test/test-array.rb b/ruby/red-arrow/test/test-tensor.rb
similarity index 54%
copy from ruby/red-arrow/test/test-array.rb
copy to ruby/red-arrow/test/test-tensor.rb
index 3dd7635..ffa1e32 100644
--- a/ruby/red-arrow/test/test-array.rb
+++ b/ruby/red-arrow/test/test-tensor.rb
@@ -15,38 +15,41 @@
 # specific language governing permissions and limitations
 # under the License.
 
-class ArrayTest < Test::Unit::TestCase
-  sub_test_case(".new") do
-    test("Boolean") do
-      array = Arrow::BooleanArray.new([true, false, true])
-      assert_equal([true, false, true],
-                   array.to_a)
-    end
-  end
-
+class TensorTest < Test::Unit::TestCase
   sub_test_case("instance methods") do
     def setup
-      @values = [true, false, nil, true]
-      @array = Arrow::BooleanArray.new(@values)
-    end
+      raw_data = [
+        1, 2,
+        3, 4,
 
-    test("#each") do
-      assert_equal(@values, @array.to_a)
-    end
+        5, 6,
+        7, 8,
 
-    sub_test_case("#[]") do
-      test("valid range") do
-        assert_equal(@values,
-                     @array.length.times.collect {|i| @array[i]})
-      end
+        9, 10,
+        11, 12,
+      ]
+      data = Arrow::Buffer.new(raw_data.pack("c*"))
+      shape = [3, 2, 2]
+      strides = []
+      names = ["a", "b", "c"]
+      @tensor = Arrow::Tensor.new(Arrow::Int8DataType.new,
+                                  data,
+                                  shape,
+                                  strides,
+                                  names)
+    end
 
-      test("out of range") do
-        assert_nil(@array[@array.length])
+    sub_test_case("#==") do
+      test("Arrow::Tensor") do
+        assert do
+          @tensor == @tensor
+        end
       end
 
-      test("negative index") do
-        assert_equal(@values.last,
-                     @array[-1])
+      test("not Arrow::Tensor") do
+        assert do
+          not (@tensor == 29)
+        end
       end
     end
   end