pitrou commented on a change in pull request #9643:
URL: https://github.com/apache/arrow/pull/9643#discussion_r595191577



##########
File path: cpp/src/arrow/util/stl_util_test.cc
##########
@@ -92,5 +93,66 @@ TEST(StlUtilTest, ArgSortPermute) {
   ExpectSortPermutation({b, c, d, e, a, f}, {4, 0, 1, 2, 3, 5}, 2);
 }
 
+TEST(StlUtilTest, VectorFlatten) {
+  std::vector<int> a{1, 2, 3};
+  std::vector<int> b{4, 5, 6};
+  std::vector<int> c{7, 8, 9};
+  std::vector<std::vector<int>> vecs{a, b, c};
+  auto actual = FlattenVectors(vecs);
+  std::vector<int> expected{1, 2, 3, 4, 5, 6, 7, 8, 9};
+  ASSERT_EQ(expected, actual);
+}
+
+TEST(StlUtilTest, VectorMap) {
+  std::vector<int> input{1, 2, 3};
+  std::vector<std::string> expected{"1", "2", "3"};
+  auto actual = MapVector([](int item) { return std::to_string(item); }, 
input);
+  ASSERT_EQ(expected, actual);
+}
+
+TEST(StlUtilTest, VectorMaybeMapFails) {
+  std::vector<int> input{1, 2, 3};
+  auto mapper = [](int item) -> Result<std::string> {
+    if (item == 1) {
+      return Status::Invalid("XYZ");
+    }
+    return std::to_string(item);
+  };
+  ASSERT_RAISES(Invalid, MaybeMapVector(mapper, input));
+}
+
+TEST(StlUtilTest, VectorMaybeMap) {
+  std::vector<int> input{1, 2, 3};
+  std::vector<std::string> expected{"1", "2", "3"};
+  EXPECT_OK_AND_ASSIGN(
+      auto actual,
+      MaybeMapVector([](int item) -> Result<std::string> { return 
std::to_string(item); },
+                     input));
+  ASSERT_EQ(expected, actual);
+}
+
+TEST(StlUtilTest, VectorUnwrapOrRaise) {
+  // FIXME There should be an easier way to construct these vectors
+  std::vector<Result<MoveOnlyDataType>> all_good;
+  all_good.push_back(Result<MoveOnlyDataType>(MoveOnlyDataType(1)));

Review comment:
       I've opened https://github.com/westonpace/arrow/pull/6 for this.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to