From 8d6f495a43e4dbe3e9f96c3e2d3ab42e9998a0ee Mon Sep 17 00:00:00 2001 From: Wes McKinney Date: Thu, 18 Jun 2020 17:18:23 -0500 Subject: [PATCH 1/3] Refactor to share random tests testing amongst compare, take, filter kernels. Equip ArrayOf to generate random data for temporal, fixed size binary types --- .../compute/kernels/scalar_compare_test.cc | 66 ++--- cpp/src/arrow/compute/kernels/test_util.h | 20 ++ .../compute/kernels/vector_selection_test.cc | 247 ++++++++---------- cpp/src/arrow/testing/random.cc | 26 ++ 4 files changed, 182 insertions(+), 177 deletions(-) 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..eb7fd71bdfe 100644 --- a/cpp/src/arrow/compute/kernels/test_util.h +++ b/cpp/src/arrow/compute/kernels/test_util.h @@ -104,5 +104,25 @@ using TestingStringTypes = static constexpr random::SeedType kRandomSeed = 0x0ff1ce; +template