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

wesm 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 c6359cb  ARROW-1929: [C++] Copy over testing utility code from 
PARQUET-1092
c6359cb is described below

commit c6359cbcb61b904e49efbb33b70d3be040622e9e
Author: Wes McKinney <[email protected]>
AuthorDate: Mon Mar 5 14:20:45 2018 -0500

    ARROW-1929: [C++] Copy over testing utility code from PARQUET-1092
    
    This code was introduced in parquet-cpp in 
https://github.com/apache/parquet-cpp/pull/426
    
    Author: Wes McKinney <[email protected]>
    
    Closes #1697 from wesm/ARROW-1929 and squashes the following commits:
    
    3f34b389 <Wes McKinney> Change namespace to avoid conflict with parquet-cpp 
builds
    3cccaea6 <Wes McKinney> Migrate testing utility code from PARQUET-1092
---
 cpp/src/arrow/array-test.cc |  6 ++--
 cpp/src/arrow/table-test.cc |  6 ++--
 cpp/src/arrow/test-util.h   | 85 ++++++++++++++++++++++++++++++++++++---------
 3 files changed, 75 insertions(+), 22 deletions(-)

diff --git a/cpp/src/arrow/array-test.cc b/cpp/src/arrow/array-test.cc
index c3ac082..bda1946 100644
--- a/cpp/src/arrow/array-test.cc
+++ b/cpp/src/arrow/array-test.cc
@@ -2480,19 +2480,19 @@ TEST_F(TestListArray, TestFromArrays) {
 
   ListArray expected1(list_type, length, offsets1->data()->buffers[1], values,
                       offsets1->data()->buffers[0], 0);
-  AssertArraysEqual(expected1, *list1);
+  test::AssertArraysEqual(expected1, *list1);
 
   // Use null bitmap from offsets3, but clean offsets from non-null version
   ListArray expected3(list_type, length, offsets1->data()->buffers[1], values,
                       offsets3->data()->buffers[0], 1);
-  AssertArraysEqual(expected3, *list3);
+  test::AssertArraysEqual(expected3, *list3);
 
   // Check that the last offset bit is zero
   ASSERT_TRUE(BitUtil::BitNotSet(list3->null_bitmap()->data(), length + 1));
 
   ListArray expected4(list_type, length, offsets2->data()->buffers[1], values,
                       offsets4->data()->buffers[0], 1);
-  AssertArraysEqual(expected4, *list4);
+  test::AssertArraysEqual(expected4, *list4);
 
   // Test failure modes
 
diff --git a/cpp/src/arrow/table-test.cc b/cpp/src/arrow/table-test.cc
index af74416..24c8d5e 100644
--- a/cpp/src/arrow/table-test.cc
+++ b/cpp/src/arrow/table-test.cc
@@ -116,11 +116,11 @@ TEST_F(TestChunkedArray, SliceEquals) {
 
   std::shared_ptr<ChunkedArray> slice = one_->Slice(125, 50);
   ASSERT_EQ(slice->length(), 50);
-  ASSERT_TRUE(slice->Equals(one_->Slice(125, 50)));
+  test::AssertChunkedEqual(*one_->Slice(125, 50), *slice);
 
   std::shared_ptr<ChunkedArray> slice2 = one_->Slice(75)->Slice(25)->Slice(25, 
50);
   ASSERT_EQ(slice2->length(), 50);
-  ASSERT_TRUE(slice2->Equals(slice));
+  test::AssertChunkedEqual(*slice, *slice2);
 }
 
 class TestColumn : public TestChunkedArray {
@@ -390,7 +390,7 @@ TEST_F(TestTable, ConcatenateTables) {
 
   ASSERT_OK(ConcatenateTables({t1, t2}, &result));
   ASSERT_OK(Table::FromRecordBatches({batch1, batch2}, &expected));
-  ASSERT_TRUE(result->Equals(*expected));
+  test::AssertTablesEqual(*expected, *result);
 
   // Error states
   std::vector<std::shared_ptr<Table>> empty_tables;
diff --git a/cpp/src/arrow/test-util.h b/cpp/src/arrow/test-util.h
index 1a34808..ab68fd4 100644
--- a/cpp/src/arrow/test-util.h
+++ b/cpp/src/arrow/test-util.h
@@ -35,6 +35,7 @@
 #include "arrow/memory_pool.h"
 #include "arrow/pretty_print.h"
 #include "arrow/status.h"
+#include "arrow/table.h"
 #include "arrow/type.h"
 #include "arrow/type_traits.h"
 #include "arrow/util/bit-util.h"
@@ -77,6 +78,18 @@ namespace arrow {
 
 using ArrayVector = std::vector<std::shared_ptr<Array>>;
 
+#define ASSERT_ARRAYS_EQUAL(LEFT, RIGHT)                                       
        \
+  do {                                                                         
        \
+    if (!(LEFT).Equals((RIGHT))) {                                             
        \
+      std::stringstream pp_result;                                             
        \
+      std::stringstream pp_expected;                                           
        \
+                                                                               
        \
+      EXPECT_OK(PrettyPrint(RIGHT, 0, &pp_result));                            
        \
+      EXPECT_OK(PrettyPrint(LEFT, 0, &pp_expected));                           
        \
+      FAIL() << "Got: \n" << pp_result.str() << "\nExpected: \n" << 
pp_expected.str(); \
+    }                                                                          
        \
+  } while (false)
+
 namespace test {
 
 template <typename T, typename U>
@@ -288,6 +301,62 @@ Status MakeRandomBytePoolBuffer(int64_t length, 
MemoryPool* pool,
   return Status::OK();
 }
 
+void AssertArraysEqual(const Array& expected, const Array& actual) {
+  ASSERT_ARRAYS_EQUAL(expected, actual);
+}
+
+void AssertChunkedEqual(const ChunkedArray& expected, const ChunkedArray& 
actual) {
+  ASSERT_EQ(expected.num_chunks(), actual.num_chunks()) << "# chunks unequal";
+  if (!actual.Equals(expected)) {
+    std::stringstream pp_result;
+    std::stringstream pp_expected;
+
+    for (int i = 0; i < actual.num_chunks(); ++i) {
+      auto c1 = actual.chunk(i);
+      auto c2 = expected.chunk(i);
+      if (!c1->Equals(*c2)) {
+        EXPECT_OK(::arrow::PrettyPrint(*c1, 0, &pp_result));
+        EXPECT_OK(::arrow::PrettyPrint(*c2, 0, &pp_expected));
+        FAIL() << "Chunk " << i << " Got: " << pp_result.str()
+               << "\nExpected: " << pp_expected.str();
+      }
+    }
+  }
+}
+
+void PrintColumn(const Column& col, std::stringstream* ss) {
+  const ChunkedArray& carr = *col.data();
+  for (int i = 0; i < carr.num_chunks(); ++i) {
+    auto c1 = carr.chunk(i);
+    *ss << "Chunk " << i << std::endl;
+    EXPECT_OK(::arrow::PrettyPrint(*c1, 0, ss));
+    *ss << std::endl;
+  }
+}
+
+void AssertTablesEqual(const Table& expected, const Table& actual,
+                       bool same_chunk_layout = true) {
+  ASSERT_EQ(expected.num_columns(), actual.num_columns());
+
+  if (same_chunk_layout) {
+    for (int i = 0; i < actual.num_columns(); ++i) {
+      AssertChunkedEqual(*expected.column(i)->data(), 
*actual.column(i)->data());
+    }
+  } else {
+    std::stringstream ss;
+    if (!actual.Equals(expected)) {
+      for (int i = 0; i < expected.num_columns(); ++i) {
+        ss << "Actual column " << i << std::endl;
+        PrintColumn(*actual.column(i), &ss);
+
+        ss << "Expected column " << i << std::endl;
+        PrintColumn(*expected.column(i), &ss);
+      }
+      FAIL() << ss.str();
+    }
+  }
+}
+
 }  // namespace test
 
 template <typename TYPE, typename C_TYPE>
@@ -352,26 +421,10 @@ Status MakeArray(const std::vector<uint8_t>& valid_bytes, 
const std::vector<T>&
   return builder->Finish(out);
 }
 
-#define ASSERT_ARRAYS_EQUAL(LEFT, RIGHT)                                       
        \
-  do {                                                                         
        \
-    if (!(LEFT).Equals((RIGHT))) {                                             
        \
-      std::stringstream pp_result;                                             
        \
-      std::stringstream pp_expected;                                           
        \
-                                                                               
        \
-      EXPECT_OK(PrettyPrint(RIGHT, 0, &pp_result));                            
        \
-      EXPECT_OK(PrettyPrint(LEFT, 0, &pp_expected));                           
        \
-      FAIL() << "Got: \n" << pp_result.str() << "\nExpected: \n" << 
pp_expected.str(); \
-    }                                                                          
        \
-  } while (false)
-
 #define DECL_T() typedef typename TestFixture::T T;
 
 #define DECL_TYPE() typedef typename TestFixture::Type Type;
 
-void AssertArraysEqual(const Array& expected, const Array& actual) {
-  ASSERT_ARRAYS_EQUAL(expected, actual);
-}
-
 #define ASSERT_BATCHES_EQUAL(LEFT, RIGHT)    \
   do {                                       \
     if (!(LEFT).ApproxEquals(RIGHT)) {       \

-- 
To stop receiving notification emails like this one, please contact
[email protected].

Reply via email to