From ae2dd49b863ad9e1d058826b28ca50b429feb2ba Mon Sep 17 00:00:00 2001 From: Nghia Truong Date: Fri, 20 Oct 2023 10:11:14 -0700 Subject: [PATCH] Extract debug tests --- cpp/tests/CMakeLists.txt | 1 + .../utilities_tests/column_debug_tests.cpp | 137 ++++++++++++++++++ .../column_utilities_tests.cpp | 101 ------------- 3 files changed, 138 insertions(+), 101 deletions(-) create mode 100644 cpp/tests/utilities_tests/column_debug_tests.cpp diff --git a/cpp/tests/CMakeLists.txt b/cpp/tests/CMakeLists.txt index 3e30db7abcb..d50809d3e5a 100644 --- a/cpp/tests/CMakeLists.txt +++ b/cpp/tests/CMakeLists.txt @@ -357,6 +357,7 @@ ConfigureTest( ConfigureTest( UTILITIES_TEST utilities_tests/type_list_tests.cpp + utilities_tests/column_debug_tests.cpp utilities_tests/column_utilities_tests.cpp utilities_tests/column_wrapper_tests.cpp utilities_tests/lists_column_wrapper_tests.cpp diff --git a/cpp/tests/utilities_tests/column_debug_tests.cpp b/cpp/tests/utilities_tests/column_debug_tests.cpp new file mode 100644 index 00000000000..0dae407ad21 --- /dev/null +++ b/cpp/tests/utilities_tests/column_debug_tests.cpp @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2019-2023, NVIDIA CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include +#include +#include + +#include + +#include + +template +struct ColumnDebugTestIntegral : public cudf::test::BaseFixture {}; +template +struct ColumnDebugTestFloatingPoint : public cudf::test::BaseFixture {}; + +TYPED_TEST_SUITE(ColumnDebugTestIntegral, cudf::test::IntegralTypes); +TYPED_TEST_SUITE(ColumnDebugTestFloatingPoint, cudf::test::FloatingPointTypes); + +TYPED_TEST(ColumnDebugTestIntegral, PrintColumnNumeric) +{ + char const* delimiter = ","; + + cudf::test::fixed_width_column_wrapper cudf_col({1, 2, 3, 4, 5}); + auto std_col = cudf::test::make_type_param_vector({1, 2, 3, 4, 5}); + + std::stringstream tmp; + auto string_iter = + thrust::make_transform_iterator(std::begin(std_col), [](auto e) { return std::to_string(e); }); + + std::copy(string_iter, + string_iter + std_col.size() - 1, + std::ostream_iterator(tmp, delimiter)); + + tmp << std::to_string(std_col.back()); + + EXPECT_EQ(cudf::test::to_string(cudf_col, delimiter), tmp.str()); +} + +TYPED_TEST(ColumnDebugTestIntegral, PrintColumnWithInvalids) +{ + char const* delimiter = ","; + + cudf::test::fixed_width_column_wrapper cudf_col{{1, 2, 3, 4, 5}, {1, 0, 1, 0, 1}}; + auto std_col = cudf::test::make_type_param_vector({1, 2, 3, 4, 5}); + + std::ostringstream tmp; + tmp << std::to_string(std_col[0]) << delimiter << "NULL" << delimiter + << std::to_string(std_col[2]) << delimiter << "NULL" << delimiter + << std::to_string(std_col[4]); + + EXPECT_EQ(cudf::test::to_string(cudf_col, delimiter), tmp.str()); +} + +TYPED_TEST(ColumnDebugTestFloatingPoint, PrintColumnNumeric) +{ + char const* delimiter = ","; + + cudf::test::fixed_width_column_wrapper cudf_col( + {10001523.25, 2.0, 3.75, 0.000000034, 5.3}); + + auto expected = std::is_same_v + ? "10001523.25,2,3.75,3.4e-08,5.2999999999999998" + : "10001523,2,3.75,3.39999993e-08,5.30000019"; + + EXPECT_EQ(cudf::test::to_string(cudf_col, delimiter), expected); +} + +TYPED_TEST(ColumnDebugTestFloatingPoint, PrintColumnWithInvalids) +{ + char const* delimiter = ","; + + cudf::test::fixed_width_column_wrapper cudf_col( + {10001523.25, 2.0, 3.75, 0.000000034, 5.3}, {1, 0, 1, 0, 1}); + + auto expected = std::is_same_v + ? "10001523.25,NULL,3.75,NULL,5.2999999999999998" + : "10001523,NULL,3.75,NULL,5.30000019"; + + EXPECT_EQ(cudf::test::to_string(cudf_col, delimiter), expected); +} + +struct ColumnDebugStringsTest : public cudf::test::BaseFixture {}; + +TEST_F(ColumnDebugStringsTest, PrintColumnDuration) +{ + char const* delimiter = ","; + + cudf::test::fixed_width_column_wrapper cudf_col({100, 0, 7, 140000}); + + auto expected = "100 seconds,0 seconds,7 seconds,140000 seconds"; + + EXPECT_EQ(cudf::test::to_string(cudf_col, delimiter), expected); +} + +TEST_F(ColumnDebugStringsTest, StringsToString) +{ + char const* delimiter = ","; + + std::vector h_strings{"eee", "bb", nullptr, "", "aa", "bbb", "ééé"}; + cudf::test::strings_column_wrapper strings( + h_strings.begin(), + h_strings.end(), + thrust::make_transform_iterator(h_strings.begin(), [](auto str) { return str != nullptr; })); + + std::ostringstream tmp; + tmp << h_strings[0] << delimiter << h_strings[1] << delimiter << "NULL" << delimiter + << h_strings[3] << delimiter << h_strings[4] << delimiter << h_strings[5] << delimiter + << h_strings[6]; + + EXPECT_EQ(cudf::test::to_string(strings, delimiter), tmp.str()); +} + +TEST_F(ColumnDebugStringsTest, PrintEscapeStrings) +{ + char const* delimiter = ","; + cudf::test::strings_column_wrapper input({"e\te\ne", "é\bé\ré", "e\vé\fé\abell"}); + std::string expected{"e\\te\\ne,é\\bé\\ré,e\\vé\\fé\\abell"}; + EXPECT_EQ(cudf::test::to_string(input, delimiter), expected); +} diff --git a/cpp/tests/utilities_tests/column_utilities_tests.cpp b/cpp/tests/utilities_tests/column_utilities_tests.cpp index de16164baee..07d2bea2b28 100644 --- a/cpp/tests/utilities_tests/column_utilities_tests.cpp +++ b/cpp/tests/utilities_tests/column_utilities_tests.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include @@ -183,106 +182,6 @@ TEST_F(ColumnUtilitiesStringsTest, StringsToHostAllNulls) EXPECT_TRUE(std::all_of(results.begin(), results.end(), [](auto s) { return s.empty(); })); } -TEST_F(ColumnUtilitiesStringsTest, PrintColumnDuration) -{ - char const* delimiter = ","; - - cudf::test::fixed_width_column_wrapper cudf_col({100, 0, 7, 140000}); - - auto expected = "100 seconds,0 seconds,7 seconds,140000 seconds"; - - EXPECT_EQ(cudf::test::to_string(cudf_col, delimiter), expected); -} - -TYPED_TEST(ColumnUtilitiesTestIntegral, PrintColumnNumeric) -{ - char const* delimiter = ","; - - cudf::test::fixed_width_column_wrapper cudf_col({1, 2, 3, 4, 5}); - auto std_col = cudf::test::make_type_param_vector({1, 2, 3, 4, 5}); - - std::stringstream tmp; - auto string_iter = - thrust::make_transform_iterator(std::begin(std_col), [](auto e) { return std::to_string(e); }); - - std::copy(string_iter, - string_iter + std_col.size() - 1, - std::ostream_iterator(tmp, delimiter)); - - tmp << std::to_string(std_col.back()); - - EXPECT_EQ(cudf::test::to_string(cudf_col, delimiter), tmp.str()); -} - -TYPED_TEST(ColumnUtilitiesTestIntegral, PrintColumnWithInvalids) -{ - char const* delimiter = ","; - - cudf::test::fixed_width_column_wrapper cudf_col{{1, 2, 3, 4, 5}, {1, 0, 1, 0, 1}}; - auto std_col = cudf::test::make_type_param_vector({1, 2, 3, 4, 5}); - - std::ostringstream tmp; - tmp << std::to_string(std_col[0]) << delimiter << "NULL" << delimiter - << std::to_string(std_col[2]) << delimiter << "NULL" << delimiter - << std::to_string(std_col[4]); - - EXPECT_EQ(cudf::test::to_string(cudf_col, delimiter), tmp.str()); -} - -TYPED_TEST(ColumnUtilitiesTestFloatingPoint, PrintColumnNumeric) -{ - char const* delimiter = ","; - - cudf::test::fixed_width_column_wrapper cudf_col( - {10001523.25, 2.0, 3.75, 0.000000034, 5.3}); - - auto expected = std::is_same_v - ? "10001523.25,2,3.75,3.4e-08,5.2999999999999998" - : "10001523,2,3.75,3.39999993e-08,5.30000019"; - - EXPECT_EQ(cudf::test::to_string(cudf_col, delimiter), expected); -} - -TYPED_TEST(ColumnUtilitiesTestFloatingPoint, PrintColumnWithInvalids) -{ - char const* delimiter = ","; - - cudf::test::fixed_width_column_wrapper cudf_col( - {10001523.25, 2.0, 3.75, 0.000000034, 5.3}, {1, 0, 1, 0, 1}); - - auto expected = std::is_same_v - ? "10001523.25,NULL,3.75,NULL,5.2999999999999998" - : "10001523,NULL,3.75,NULL,5.30000019"; - - EXPECT_EQ(cudf::test::to_string(cudf_col, delimiter), expected); -} - -TEST_F(ColumnUtilitiesStringsTest, StringsToString) -{ - char const* delimiter = ","; - - std::vector h_strings{"eee", "bb", nullptr, "", "aa", "bbb", "ééé"}; - cudf::test::strings_column_wrapper strings( - h_strings.begin(), - h_strings.end(), - thrust::make_transform_iterator(h_strings.begin(), [](auto str) { return str != nullptr; })); - - std::ostringstream tmp; - tmp << h_strings[0] << delimiter << h_strings[1] << delimiter << "NULL" << delimiter - << h_strings[3] << delimiter << h_strings[4] << delimiter << h_strings[5] << delimiter - << h_strings[6]; - - EXPECT_EQ(cudf::test::to_string(strings, delimiter), tmp.str()); -} - -TEST_F(ColumnUtilitiesStringsTest, PrintEscapeStrings) -{ - char const* delimiter = ","; - cudf::test::strings_column_wrapper input({"e\te\ne", "é\bé\ré", "e\vé\fé\abell"}); - std::string expected{"e\\te\\ne,é\\bé\\ré,e\\vé\\fé\\abell"}; - EXPECT_EQ(cudf::test::to_string(input, delimiter), expected); -} - TYPED_TEST(ColumnUtilitiesTestFixedPoint, NonNullableToHost) { using namespace numeric;