pitrou commented on code in PR #50642:
URL: https://github.com/apache/arrow/pull/50642#discussion_r3657987746


##########
cpp/src/arrow/compute/kernels/scalar_round_arithmetic_test.cc:
##########
@@ -507,218 +507,180 @@ TEST(TestUnaryRound, DispatchBestRound) {
   }
 }
 
-class TestUnaryRoundArithmeticDecimal : public TestRoundArithmeticDecimal {};
+// Const ndigits test case used by both TestUnaryRoundArithmeticDecimal and
+// TestBinaryRoundArithmeticDecimal
+struct RoundDecimalTestCase {
+  std::string kind;  // "CheckScalar" or "CheckRaises"

Review Comment:
   It would seem more intuitive to have this be a `StatusCode` or similar.



##########
cpp/src/arrow/compute/kernels/scalar_round_arithmetic_test.cc:
##########
@@ -1007,6 +969,138 @@ TEST_F(TestUnaryRoundArithmeticDecimal, 
RoundToMultipleHalfToOdd) {
   }
 }
 
+class TestBinaryRoundArithmeticDecimal : public TestRoundArithmeticDecimal {
+ protected:
+  void RunBinaryRoundDecimalTestVariants(
+      const std::string& round_func,
+      const std::vector<RoundDecimalTestVariant>& decimal_test_variants) {
+    RoundBinaryOptions options;
+    for (const auto& variant : decimal_test_variants) {
+      for (std::shared_ptr<DataType> ty : variant.decimal_types) {
+        std::shared_ptr<Array> values;
+        if (variant.scientific_data) {
+          values = DecimalArrayFromJSON(ty, variant.input_json);
+        } else {
+          values = ArrayFromJSON(ty, variant.input_json);
+        }
+
+        for (const auto& test_case : variant.cases) {
+          options.round_mode = test_case.round_mode;
+
+          auto ndigits_scalar = *arrow::MakeScalar(int32(), test_case.ndigits);

Review Comment:
   Can you use `ASSERT_OK_AND_ASSIGN` here?



##########
cpp/src/arrow/compute/kernels/scalar_round_arithmetic_test.cc:
##########
@@ -1007,6 +969,138 @@ TEST_F(TestUnaryRoundArithmeticDecimal, 
RoundToMultipleHalfToOdd) {
   }
 }
 
+class TestBinaryRoundArithmeticDecimal : public TestRoundArithmeticDecimal {
+ protected:
+  void RunBinaryRoundDecimalTestVariants(
+      const std::string& round_func,
+      const std::vector<RoundDecimalTestVariant>& decimal_test_variants) {
+    RoundBinaryOptions options;
+    for (const auto& variant : decimal_test_variants) {
+      for (std::shared_ptr<DataType> ty : variant.decimal_types) {
+        std::shared_ptr<Array> values;
+        if (variant.scientific_data) {
+          values = DecimalArrayFromJSON(ty, variant.input_json);
+        } else {
+          values = ArrayFromJSON(ty, variant.input_json);
+        }
+
+        for (const auto& test_case : variant.cases) {
+          options.round_mode = test_case.round_mode;
+
+          auto ndigits_scalar = *arrow::MakeScalar(int32(), test_case.ndigits);
+          ASSERT_OK_AND_ASSIGN(auto ndigits_arr,
+                               MakeArrayFromScalar(*ndigits_scalar, 
values->length()));
+
+          if (test_case.kind == "CheckScalar") {
+            std::shared_ptr<Array> expected_arr;
+            if (variant.scientific_data) {
+              expected_arr = DecimalArrayFromJSON(ty, test_case.expected);
+            } else {
+              expected_arr = ArrayFromJSON(ty, test_case.expected);
+            }
+            CheckScalar(round_func, {values, ndigits_arr}, expected_arr, 
&options);
+          } else {  // test_case.kind == "CheckRaises"
+            CheckRaises(round_func, {values, ndigits_arr}, test_case.expected, 
&options);
+          }
+        }
+      }
+    }
+  }
+};
+
+// Check two modes exhaustively, give all modes a simple test
+TEST_F(TestBinaryRoundArithmeticDecimal, Round) {
+  RunBinaryRoundDecimalTestVariants("round_binary", 
GetRoundDecimalTestCases());
+}
+
+TEST_F(TestBinaryRoundArithmeticDecimal, RoundTowardsInfinity) {
+  RunBinaryRoundDecimalTestVariants("round_binary",
+                                    GetRoundTowardsInfinityDecimalTestCases());
+}
+
+TEST_F(TestBinaryRoundArithmeticDecimal, RoundHalfToEven) {
+  RunBinaryRoundDecimalTestVariants("round_binary", 
GetRoundHalfToEvenDecimalTestCases());
+}
+
+// Test binary round where ndigits varies per element
+TEST_F(TestBinaryRoundArithmeticDecimal, RoundNDigitsArray) {
+  const auto func = "round_binary";
+  RoundBinaryOptions options;
+
+  for (const auto& ty : {decimal128(4, 2), decimal256(4, 2)}) {
+    auto values = ArrayFromJSON(
+        ty,
+        R"(["61.55", "61.55", "61.52", "60.50", "65.00", "65.95", "-61.55", 
"-61.55", "-61.52", "-60.50", "-65.00", "-65.95", null, "32.78"])");

Review Comment:
   Could you reformat these long JSON literals over 2 lines so as to take less 
horizontal space?



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