From 9c6f60e6b26157adecd1b5798b7861ded11b35d3 Mon Sep 17 00:00:00 2001 From: David Wendt Date: Thu, 6 Jan 2022 13:15:31 -0500 Subject: [PATCH] Add strings tests to transpose_test.cpp --- cpp/include/cudf_test/type_lists.hpp | 9 +++- cpp/tests/transpose/transpose_test.cpp | 58 ++++++++++++++++---------- 2 files changed, 43 insertions(+), 24 deletions(-) diff --git a/cpp/include/cudf_test/type_lists.hpp b/cpp/include/cudf_test/type_lists.hpp index 097d072a5b4..3c46b912639 100644 --- a/cpp/include/cudf_test/type_lists.hpp +++ b/cpp/include/cudf_test/type_lists.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2021, NVIDIA CORPORATION. + * Copyright (c) 2019-2022, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -158,6 +158,13 @@ std::enable_if_t::value, TypeParam> make_type_pa return TypeParam{typename TypeParam::duration(init_value)}; } +template +std::enable_if_t, TypeParam> make_type_param_scalar( + T const init_value) +{ + return std::to_string(init_value); +} + /** * @brief Type list for all integral types except type bool. */ diff --git a/cpp/tests/transpose/transpose_test.cpp b/cpp/tests/transpose/transpose_test.cpp index 7b7b7d8a4a9..e3d9808b211 100644 --- a/cpp/tests/transpose/transpose_test.cpp +++ b/cpp/tests/transpose/transpose_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, NVIDIA CORPORATION. + * Copyright (c) 2019-2022, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,9 +22,9 @@ #include #include #include +#include namespace { -using cudf::test::fixed_width_column_wrapper; template auto generate_vectors(size_t ncols, size_t nrows, F generator) @@ -59,10 +59,10 @@ auto transpose_vectors(std::vector> const& input) return transposed; } -template +template auto make_columns(std::vector> const& values) { - std::vector> columns; + std::vector columns; columns.reserve(values.size()); for (auto const& value_col : values) { @@ -72,11 +72,11 @@ auto make_columns(std::vector> const& values) return columns; } -template +template auto make_columns(std::vector> const& values, std::vector> const& valids) { - std::vector> columns; + std::vector columns; columns.reserve(values.size()); for (size_t col = 0; col < values.size(); ++col) { @@ -86,15 +86,14 @@ auto make_columns(std::vector> const& values, return columns; } -template -auto make_table_view(std::vector> const& cols) +template +auto make_table_view(std::vector const& cols) { std::vector views(cols.size()); - std::transform( - cols.begin(), cols.end(), views.begin(), [](fixed_width_column_wrapper const& col) { - return static_cast(col); - }); + std::transform(cols.begin(), cols.end(), views.begin(), [](auto const& col) { + return static_cast(col); + }); return cudf::table_view(views); } @@ -102,6 +101,10 @@ auto make_table_view(std::vector> const& cols) template void run_test(size_t ncols, size_t nrows, bool add_nulls) { + using ColumnWrapper = std::conditional_t, + cudf::test::strings_column_wrapper, + cudf::test::fixed_width_column_wrapper>; + std::mt19937 rng(1); // Generate values as vector of vectors @@ -109,8 +112,8 @@ void run_test(size_t ncols, size_t nrows, bool add_nulls) ncols, nrows, [&rng]() { return cudf::test::make_type_param_scalar(rng()); }); auto const valuesT = transpose_vectors(values); - std::vector> input_cols; - std::vector> expected_cols; + std::vector input_cols; + std::vector expected_cols; std::vector expected_nulls(nrows); if (add_nulls) { @@ -129,11 +132,11 @@ void run_test(size_t ncols, size_t nrows, bool add_nulls) }); // Create column wrappers from vector of vectors - input_cols = make_columns(values, valids); - expected_cols = make_columns(valuesT, validsT); + input_cols = make_columns(values, valids); + expected_cols = make_columns(valuesT, validsT); } else { - input_cols = make_columns(values); - expected_cols = make_columns(valuesT); + input_cols = make_columns(values); + expected_cols = make_columns(valuesT); } // Create table views from column wrappers @@ -158,7 +161,13 @@ template class TransposeTest : public cudf::test::BaseFixture { }; -TYPED_TEST_SUITE(TransposeTest, cudf::test::FixedWidthTypes); +// Using std::string here instead of cudf::test::StringTypes allows us to +// use std::vector utilities in this file just like the fixed-width types. +// Should consider changing cudf::test::StringTypes to std::string instead of cudf::string_view. +using StdStringType = cudf::test::Types; +using TransposeTypes = cudf::test::Concat; + +TYPED_TEST_SUITE(TransposeTest, TransposeTypes); // cudf::test::FixedWidthTypes); TYPED_TEST(TransposeTest, SingleValue) { run_test(1, 1, false); } @@ -182,11 +191,14 @@ TYPED_TEST(TransposeTest, EmptyTable) { run_test(0, 0, false); } TYPED_TEST(TransposeTest, EmptyColumns) { run_test(10, 0, false); } -TYPED_TEST(TransposeTest, MismatchedColumns) +class TransposeTestError : public cudf::test::BaseFixture { +}; + +TEST_F(TransposeTestError, MismatchedColumns) { - fixed_width_column_wrapper col1({1, 2, 3}); - fixed_width_column_wrapper col2{{4, 5, 6}}; - fixed_width_column_wrapper col3{{7, 8, 9}}; + cudf::test::fixed_width_column_wrapper col1({1, 2, 3}); + cudf::test::fixed_width_column_wrapper col2{{4, 5, 6}}; + cudf::test::fixed_width_column_wrapper col3{{7, 8, 9}}; cudf::table_view input{{col1, col2, col3}}; EXPECT_THROW(cudf::transpose(input), cudf::logic_error); }