You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/08/09 20:42:41 UTC

[GitHub] [arrow] rtpsw commented on a diff in pull request #13784: ARROW-17290: [C++] Add order-comparisons for numeric scalars

rtpsw commented on code in PR #13784:
URL: https://github.com/apache/arrow/pull/13784#discussion_r941784539


##########
cpp/src/arrow/scalar_test.cc:
##########
@@ -156,6 +157,90 @@ TYPED_TEST(TestNumericScalar, Basics) {
   ASSERT_FALSE(two->ApproxEquals(ScalarType(3)));
 }
 
+template <typename T>
+void TestNumericScalarOrder(typename NumericScalar<T>::ValueType v1,
+                            typename NumericScalar<T>::ValueType v2,
+                            const OrderOptions& options, bool expectedLessThan,
+                            bool expectedIsAtMost, bool expectedMoreThan,
+                            bool expectedIsAtLeast) {
+  NumericScalar<T> s1{v1}, s2{v2};
+
+#define ARROW_NUMERIC_ORDER_TEST(Op)                                                    \
+  ASSERT_EQ(expected##Op, Scalar##Op(s1, s2, options));                                 \
+  ASSERT_EQ(expected##Op, s1.Op(s2, options));                                          \
+  ASSERT_OK_AND_ASSIGN(auto actual##Op, Scalar##Op(static_cast<Scalar&>(s1),            \
+                                                   static_cast<Scalar&>(s2), options)); \
+  ASSERT_EQ(expected##Op, actual##Op);
+
+  ARROW_NUMERIC_ORDER_TEST(LessThan);
+  ARROW_NUMERIC_ORDER_TEST(IsAtMost);
+  ARROW_NUMERIC_ORDER_TEST(MoreThan);
+  ARROW_NUMERIC_ORDER_TEST(IsAtLeast);
+
+#undef ARROW_NUMERIC_ORDER_TEST
+}
+
+template <typename T>
+void TestNumericScalarOrder(typename NumericScalar<T>::ValueType v1,
+                            typename NumericScalar<T>::ValueType v2,
+                            bool expectedLessThan, bool expectedIsAtMost,
+                            bool expectedMoreThan, bool expectedIsAtLeast) {
+  auto p1 = std::make_shared<NumericScalar<T>>(v1);
+  auto p2 = std::make_shared<NumericScalar<T>>(v2);
+  auto& s1 = *p1;
+  auto& s2 = *p2;
+  using Order = util::OrderComparable<NumericScalar<T>>;
+  ASSERT_EQ(expectedLessThan, typename Order::PtrsLessThan()(p1, p2));
+  ASSERT_EQ(expectedIsAtMost, typename Order::PtrsIsAtMost()(p1, p2));
+  ASSERT_EQ(expectedMoreThan, typename Order::PtrsMoreThan()(p1, p2));
+  ASSERT_EQ(expectedIsAtLeast, typename Order::PtrsIsAtLeast()(p1, p2));
+  ASSERT_EQ(expectedLessThan, s1 < s2);
+  ASSERT_EQ(expectedIsAtMost, s1 <= s2);
+  ASSERT_EQ(expectedMoreThan, s1 > s2);
+  ASSERT_EQ(expectedIsAtLeast, s1 >= s2);
+  TestNumericScalarOrder<T>(v1, v2, OrderOptions::Defaults(), expectedLessThan,
+                            expectedIsAtMost, expectedMoreThan, expectedIsAtLeast);
+}
+
+#define TEST_FLOATING_POINT_SCALAR_ORDER(...)        \
+  {                                                  \
+    TestNumericScalarOrder<FloatType>(__VA_ARGS__);  \

Review Comment:
   AFAICS, both [GCC](https://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html) and [MSVC](https://docs.microsoft.com/en-us/cpp/preprocessor/variadic-macros?view=msvc-170) documentation say it is part of the C standard,



-- 
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: github-unsubscribe@arrow.apache.org

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