Skip to content

Commit

Permalink
Extract debug tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ttnghia committed Oct 20, 2023
1 parent cb6b874 commit ae2dd49
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 101 deletions.
1 change: 1 addition & 0 deletions cpp/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
137 changes: 137 additions & 0 deletions cpp/tests/utilities_tests/column_debug_tests.cpp
Original file line number Diff line number Diff line change
@@ -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 <cudf/strings/strings_column_view.hpp>

#include <cudf_test/base_fixture.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/cudf_gtest.hpp>
#include <cudf_test/debug_utilities.hpp>
#include <cudf_test/type_lists.hpp>

#include <thrust/iterator/transform_iterator.h>

#include <type_traits>

template <typename T>
struct ColumnDebugTestIntegral : public cudf::test::BaseFixture {};
template <typename T>
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<TypeParam> cudf_col({1, 2, 3, 4, 5});
auto std_col = cudf::test::make_type_param_vector<TypeParam>({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<std::string>(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<TypeParam> cudf_col{{1, 2, 3, 4, 5}, {1, 0, 1, 0, 1}};
auto std_col = cudf::test::make_type_param_vector<TypeParam>({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<TypeParam> cudf_col(
{10001523.25, 2.0, 3.75, 0.000000034, 5.3});

auto expected = std::is_same_v<TypeParam, double>
? "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<TypeParam> cudf_col(
{10001523.25, 2.0, 3.75, 0.000000034, 5.3}, {1, 0, 1, 0, 1});

auto expected = std::is_same_v<TypeParam, double>
? "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::duration_s, int32_t> 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<char const*> 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,é\\\\ré,e\\\\\\abell"};
EXPECT_EQ(cudf::test::to_string(input, delimiter), expected);
}
101 changes: 0 additions & 101 deletions cpp/tests/utilities_tests/column_utilities_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <cudf_test/column_utilities.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/cudf_gtest.hpp>
#include <cudf_test/debug_utilities.hpp>
#include <cudf_test/type_lists.hpp>

#include <thrust/iterator/constant_iterator.h>
Expand Down Expand Up @@ -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::duration_s, int32_t> 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<TypeParam> cudf_col({1, 2, 3, 4, 5});
auto std_col = cudf::test::make_type_param_vector<TypeParam>({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<std::string>(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<TypeParam> cudf_col{{1, 2, 3, 4, 5}, {1, 0, 1, 0, 1}};
auto std_col = cudf::test::make_type_param_vector<TypeParam>({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<TypeParam> cudf_col(
{10001523.25, 2.0, 3.75, 0.000000034, 5.3});

auto expected = std::is_same_v<TypeParam, double>
? "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<TypeParam> cudf_col(
{10001523.25, 2.0, 3.75, 0.000000034, 5.3}, {1, 0, 1, 0, 1});

auto expected = std::is_same_v<TypeParam, double>
? "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<char const*> 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,é\\\\ré,e\\\\\\abell"};
EXPECT_EQ(cudf::test::to_string(input, delimiter), expected);
}

TYPED_TEST(ColumnUtilitiesTestFixedPoint, NonNullableToHost)
{
using namespace numeric;
Expand Down

0 comments on commit ae2dd49

Please sign in to comment.