pitrou commented on a change in pull request #7784:
URL: https://github.com/apache/arrow/pull/7784#discussion_r467870651
##########
File path: cpp/src/arrow/compute/kernels/scalar_arithmetic_test.cc
##########
@@ -53,35 +69,84 @@ class TestBinaryArithmetic : public TestBase {
void SetUp() { options_.check_overflow = false; }
+ std::shared_ptr<Scalar> MakeNullScalar() {
+ return arrow::MakeNullScalar(type_singleton());
+ }
+
+ std::shared_ptr<Scalar> MakeScalar(CType value) {
+ return *arrow::MakeScalar(type_singleton(), value);
+ }
+
// (Scalar, Scalar)
void AssertBinop(BinaryFunction func, CType lhs, CType rhs, CType expected) {
- ASSERT_OK_AND_ASSIGN(auto left, MakeScalar(type_singleton(), lhs));
- ASSERT_OK_AND_ASSIGN(auto right, MakeScalar(type_singleton(), rhs));
- ASSERT_OK_AND_ASSIGN(auto exp, MakeScalar(type_singleton(), expected));
+ auto left = MakeScalar(lhs);
+ auto right = MakeScalar(rhs);
+ auto exp = MakeScalar(expected);
ASSERT_OK_AND_ASSIGN(auto actual, func(left, right, options_, nullptr));
- AssertScalarsEqual(*exp, *actual.scalar(), true);
+ AssertScalarsEqual(*exp, *actual.scalar(), /*verbose=*/true);
}
// (Scalar, Array)
void AssertBinop(BinaryFunction func, CType lhs, const std::string& rhs,
const std::string& expected) {
- ASSERT_OK_AND_ASSIGN(auto left, MakeScalar(type_singleton(), lhs));
+ auto left = MakeScalar(lhs);
+ AssertBinop(func, left, rhs, expected);
+ }
+
+ // (Scalar, Array)
+ void AssertBinop(BinaryFunction func, const std::shared_ptr<Scalar>& left,
+ const std::string& rhs, const std::string& expected) {
auto right = ArrayFromJSON(type_singleton(), rhs);
auto exp = ArrayFromJSON(type_singleton(), expected);
ASSERT_OK_AND_ASSIGN(auto actual, func(left, right, options_, nullptr));
ValidateAndAssertApproxEqual(actual.make_array(), expected);
}
+ // (Array, Scalar)
+ void AssertBinop(BinaryFunction func, const std::string& lhs, CType rhs,
+ const std::string& expected) {
+ auto right = MakeScalar(rhs);
+ AssertBinop(func, lhs, right, expected);
+ }
+
+ // (Array, Scalar)
+ void AssertBinop(BinaryFunction func, const std::string& lhs,
+ const std::shared_ptr<Scalar>& right, const std::string&
expected) {
+ auto left = ArrayFromJSON(type_singleton(), lhs);
+ auto exp = ArrayFromJSON(type_singleton(), expected);
+
+ ASSERT_OK_AND_ASSIGN(auto actual, func(left, right, options_, nullptr));
+ ValidateAndAssertApproxEqual(actual.make_array(), expected);
+ }
+
// (Array, Array)
void AssertBinop(BinaryFunction func, const std::string& lhs, const
std::string& rhs,
const std::string& expected) {
auto left = ArrayFromJSON(type_singleton(), lhs);
auto right = ArrayFromJSON(type_singleton(), rhs);
+ AssertBinop(func, ArrayFromJSON(type_singleton(), lhs),
+ ArrayFromJSON(type_singleton(), rhs), expected);
Review comment:
Indeed :-)
----------------------------------------------------------------
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:
[email protected]