diff --git a/cpp/src/arrow/compute/kernels/scalar_compare_test.cc b/cpp/src/arrow/compute/kernels/scalar_compare_test.cc index 0ee757b1280..2fceca6bdc6 100644 --- a/cpp/src/arrow/compute/kernels/scalar_compare_test.cc +++ b/cpp/src/arrow/compute/kernels/scalar_compare_test.cc @@ -373,46 +373,38 @@ TYPED_TEST(TestNumericCompareKernel, TestNullScalar) { TYPED_TEST_SUITE(TestNumericCompareKernel, NumericArrowTypes); template -void DoRandomCompare(const std::shared_ptr& type) { - using ScalarType = typename TypeTraits::ScalarType; - using CType = typename TypeTraits::CType; - auto rand = random::RandomArrayGenerator(0x5416447); - const int64_t length = 1000; - for (auto null_probability : {0.0, 0.01, 0.1, 0.25, 0.5, 1.0}) { - for (auto op : {EQUAL, NOT_EQUAL, GREATER, LESS_EQUAL}) { - auto data = - rand.Numeric(length, 0, 100, null_probability); - - auto data1 = - rand.Numeric(length, 0, 100, null_probability); - auto data2 = - rand.Numeric(length, 0, 100, null_probability); - - // Create view of data as the type (e.g. timestamp) - auto array1 = Datum(*data1->View(type)); - auto array2 = Datum(*data2->View(type)); - auto fifty = Datum(std::make_shared(CType(50), type)); - auto options = CompareOptions(op); - - ValidateCompare(options, array1, fifty); - ValidateCompare(options, fifty, array1); - ValidateCompare(options, array1, array2); +struct CompareRandomNumeric { + static void Test(const std::shared_ptr& type) { + using ScalarType = typename TypeTraits::ScalarType; + using CType = typename TypeTraits::CType; + auto rand = random::RandomArrayGenerator(0x5416447); + const int64_t length = 1000; + for (auto null_probability : {0.0, 0.01, 0.1, 0.25, 0.5, 1.0}) { + for (auto op : {EQUAL, NOT_EQUAL, GREATER, LESS_EQUAL}) { + auto data = + rand.Numeric(length, 0, 100, null_probability); + + auto data1 = + rand.Numeric(length, 0, 100, null_probability); + auto data2 = + rand.Numeric(length, 0, 100, null_probability); + + // Create view of data as the type (e.g. timestamp) + auto array1 = Datum(*data1->View(type)); + auto array2 = Datum(*data2->View(type)); + auto fifty = Datum(std::make_shared(CType(50), type)); + auto options = CompareOptions(op); + + ValidateCompare(options, array1, fifty); + ValidateCompare(options, fifty, array1); + ValidateCompare(options, array1, array2); + } } } -} - -TYPED_TEST(TestNumericCompareKernel, RandomCompare) { - DoRandomCompare(TypeTraits::type_singleton()); -} +}; -TEST(TestTemporalCompareKernel, RandomCompare) { - DoRandomCompare(date32()); - DoRandomCompare(date64()); - DoRandomCompare(time32(TimeUnit::SECOND)); - DoRandomCompare(time64(TimeUnit::MICRO)); - DoRandomCompare(timestamp(TimeUnit::SECOND)); - DoRandomCompare(timestamp(TimeUnit::MICRO)); - DoRandomCompare(duration(TimeUnit::MILLI)); +TEST(TestCompareKernel, PrimitiveRandomTests) { + TestRandomPrimitiveCTypes(); } TYPED_TEST(TestNumericCompareKernel, SimpleCompareArrayArray) { diff --git a/cpp/src/arrow/compute/kernels/test_util.h b/cpp/src/arrow/compute/kernels/test_util.h index f01f5c7cc6b..9b85c873c0d 100644 --- a/cpp/src/arrow/compute/kernels/test_util.h +++ b/cpp/src/arrow/compute/kernels/test_util.h @@ -104,5 +104,26 @@ using TestingStringTypes = static constexpr random::SeedType kRandomSeed = 0x0ff1ce; +template