Skip to content

Commit

Permalink
Cleanup some libcudf strings gtests (#9489)
Browse files Browse the repository at this point in the history
Random gtests cleanup for some strings gtests:
- Reworked the class names to use the same base class in `substring_tests.cpp`, `pad_tests.cpp`, `char_types_tests.cpp`
- Renamed the regex-replace tests from `StringsReplaceTests` to `StringsReplaceRegexTest`
- Refactored code in `substring_tests.cpp` to simplify and organize the test clauses
- Renamed the utilities.cu to utilities.cpp (required no code change)

Authors:
  - David Wendt (https://github.com/davidwendt)

Approvers:
  - Karthikeyan (https://github.com/karthikeyann)
  - Bradley Dice (https://github.com/bdice)
  - Robert Maynard (https://github.com/robertmaynard)

URL: #9489
  • Loading branch information
davidwendt authored Oct 26, 2021
1 parent d5228f0 commit fea54e6
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 148 deletions.
2 changes: 1 addition & 1 deletion cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ add_library(cudftestutil STATIC
tests/utilities/column_utilities.cu
tests/utilities/table_utilities.cu
tests/io/metadata_utilities.cpp
tests/strings/utilities.cu)
tests/strings/utilities.cpp)

set_target_properties(cudftestutil
PROPERTIES BUILD_RPATH "\$ORIGIN"
Expand Down
3 changes: 3 additions & 0 deletions cpp/src/hash/md5_hash.cu
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ struct HasherDispatcher {
std::is_same_v<Element, string_view>) {
hasher->process(input_col.element<Element>(row_index));
} else {
(void)row_index;
cudf_assert(false && "Unsupported type for hash function.");
}
}
Expand All @@ -263,6 +264,8 @@ struct ListHasherDispatcher {
if (input_col.is_valid(i)) { hasher->process(input_col.element<Element>(i)); }
}
} else {
(void)offset_begin;
(void)offset_end;
cudf_assert(false && "Unsupported type for hash function.");
}
}
Expand Down
11 changes: 5 additions & 6 deletions cpp/tests/strings/chars_types_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@
struct StringsCharsTest : public cudf::test::BaseFixture {
};

class StringsCharsTestTypes
: public StringsCharsTest,
public testing::WithParamInterface<cudf::strings::string_character_types> {
class CharsTypes : public StringsCharsTest,
public testing::WithParamInterface<cudf::strings::string_character_types> {
};

TEST_P(StringsCharsTestTypes, AllTypes)
TEST_P(CharsTypes, AllTypes)
{
std::vector<const char*> h_strings{"Héllo",
"thesé",
Expand Down Expand Up @@ -84,8 +83,8 @@ TEST_P(StringsCharsTestTypes, AllTypes)
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*results, expected);
}

INSTANTIATE_TEST_CASE_P(StringsCharsTestAllTypes,
StringsCharsTestTypes,
INSTANTIATE_TEST_CASE_P(StringsCharsTest,
CharsTypes,
testing::ValuesIn(std::array<cudf::strings::string_character_types, 7>{
cudf::strings::string_character_types::DECIMAL,
cudf::strings::string_character_types::NUMERIC,
Expand Down
9 changes: 4 additions & 5 deletions cpp/tests/strings/pad_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,10 @@ TEST_F(StringsPadTest, ZeroSizeStringsColumn)
cudf::test::expect_strings_empty(results->view());
}

class StringsPadParmsTest : public StringsPadTest,
public testing::WithParamInterface<cudf::size_type> {
class PadParameters : public StringsPadTest, public testing::WithParamInterface<cudf::size_type> {
};

TEST_P(StringsPadParmsTest, Padding)
TEST_P(PadParameters, Padding)
{
std::vector<std::string> h_strings{"eee ddd", "bb cc", "aa", "bbb", "fff", "", "o"};
cudf::test::strings_column_wrapper strings(h_strings.begin(), h_strings.end());
Expand All @@ -128,8 +127,8 @@ TEST_P(StringsPadParmsTest, Padding)
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*results, expected);
}

INSTANTIATE_TEST_CASE_P(StringsPadParmWidthTest,
StringsPadParmsTest,
INSTANTIATE_TEST_CASE_P(StringsPadTest,
PadParameters,
testing::ValuesIn(std::array<cudf::size_type, 3>{5, 6, 7}));

TEST_F(StringsPadTest, ZFill)
Expand Down
26 changes: 13 additions & 13 deletions cpp/tests/strings/replace_regex_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2020, NVIDIA CORPORATION.
* Copyright (c) 2019-2021, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,10 +23,10 @@

#include <vector>

struct StringsReplaceTests : public cudf::test::BaseFixture {
struct StringsReplaceRegexTest : public cudf::test::BaseFixture {
};

TEST_F(StringsReplaceTests, ReplaceRegexTest)
TEST_F(StringsReplaceRegexTest, ReplaceRegexTest)
{
std::vector<const char*> h_strings{"the quick brown fox jumps over the lazy dog",
"the fat cat lays next to the other accénted cat",
Expand Down Expand Up @@ -59,7 +59,7 @@ TEST_F(StringsReplaceTests, ReplaceRegexTest)
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*results, expected);
}

TEST_F(StringsReplaceTests, ReplaceMultiRegexTest)
TEST_F(StringsReplaceRegexTest, ReplaceMultiRegexTest)
{
std::vector<const char*> h_strings{"the quick brown fox jumps over the lazy dog",
"the fat cat lays next to the other accénted cat",
Expand Down Expand Up @@ -95,7 +95,7 @@ TEST_F(StringsReplaceTests, ReplaceMultiRegexTest)
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*results, expected);
}

TEST_F(StringsReplaceTests, InvalidRegex)
TEST_F(StringsReplaceRegexTest, InvalidRegex)
{
cudf::test::strings_column_wrapper strings(
{"abc*def|ghi+jkl", ""}); // these do not really matter
Expand All @@ -116,7 +116,7 @@ TEST_F(StringsReplaceTests, InvalidRegex)
cudf::logic_error);
}

TEST_F(StringsReplaceTests, WithEmptyPattern)
TEST_F(StringsReplaceRegexTest, WithEmptyPattern)
{
std::vector<const char*> h_strings{"asd", "xcv"};
cudf::test::strings_column_wrapper strings(
Expand All @@ -133,7 +133,7 @@ TEST_F(StringsReplaceTests, WithEmptyPattern)
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*results, strings);
}

TEST_F(StringsReplaceTests, ReplaceBackrefsRegexTest)
TEST_F(StringsReplaceRegexTest, ReplaceBackrefsRegexTest)
{
std::vector<const char*> h_strings{"the quick brown fox jumps over the lazy dog",
"the fat cat lays next to the other accénted cat",
Expand Down Expand Up @@ -167,7 +167,7 @@ TEST_F(StringsReplaceTests, ReplaceBackrefsRegexTest)
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*results, expected);
}

TEST_F(StringsReplaceTests, ReplaceBackrefsRegexAltIndexPatternTest)
TEST_F(StringsReplaceRegexTest, ReplaceBackrefsRegexAltIndexPatternTest)
{
cudf::test::strings_column_wrapper strings({"12-3 34-5 67-89", "0-99: 777-888:: 5673-0"});
auto strings_view = cudf::strings_column_view(strings);
Expand All @@ -181,7 +181,7 @@ TEST_F(StringsReplaceTests, ReplaceBackrefsRegexAltIndexPatternTest)
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*results, expected);
}

TEST_F(StringsReplaceTests, ReplaceBackrefsRegexReversedTest)
TEST_F(StringsReplaceRegexTest, ReplaceBackrefsRegexReversedTest)
{
cudf::test::strings_column_wrapper strings(
{"A543", "Z756", "", "tést-string", "two-thréé four-fivé", "abcd-éfgh", "tést-string-again"});
Expand All @@ -200,7 +200,7 @@ TEST_F(StringsReplaceTests, ReplaceBackrefsRegexReversedTest)
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*results, expected);
}

TEST_F(StringsReplaceTests, BackrefWithGreedyQuantifier)
TEST_F(StringsReplaceRegexTest, BackrefWithGreedyQuantifier)
{
cudf::test::strings_column_wrapper input(
{"<h1>title</h1><h2>ABC</h2>", "<h1>1234567</h1><h2>XYZ</h2>"});
Expand All @@ -217,7 +217,7 @@ TEST_F(StringsReplaceTests, BackrefWithGreedyQuantifier)
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*results, expected);
}

TEST_F(StringsReplaceTests, ReplaceBackrefsRegexErrorTest)
TEST_F(StringsReplaceRegexTest, ReplaceBackrefsRegexErrorTest)
{
cudf::test::strings_column_wrapper strings({"this string left intentionally blank"});
auto view = cudf::strings_column_view(strings);
Expand All @@ -228,7 +228,7 @@ TEST_F(StringsReplaceTests, ReplaceBackrefsRegexErrorTest)
EXPECT_THROW(cudf::strings::replace_with_backrefs(view, "(\\w)", ""), cudf::logic_error);
}

TEST_F(StringsReplaceTests, MediumReplaceRegex)
TEST_F(StringsReplaceRegexTest, MediumReplaceRegex)
{
// This results in 95 regex instructions and falls in the 'medium' range.
std::string medium_regex =
Expand Down Expand Up @@ -256,7 +256,7 @@ TEST_F(StringsReplaceTests, MediumReplaceRegex)
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*results, expected);
}

TEST_F(StringsReplaceTests, LargeReplaceRegex)
TEST_F(StringsReplaceRegexTest, LargeReplaceRegex)
{
// This results in 117 regex instructions and falls in the 'large' range.
std::string large_regex =
Expand Down
Loading

0 comments on commit fea54e6

Please sign in to comment.