Skip to content

Commit

Permalink
Rework gtests SequenceTest to remove using namepace cudf (#12985)
Browse files Browse the repository at this point in the history
Remove the `using namespace cudf;` from the top of the source file to make it easier to follow. Seemed an unnecessary usage and violated the spirit of #12784

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

Approvers:
  - Bradley Dice (https://github.com/bdice)
  - Nghia Truong (https://github.com/ttnghia)
  - Vyas Ramasubramani (https://github.com/vyasr)

URL: #12985
  • Loading branch information
davidwendt authored Mar 22, 2023
1 parent 0d1fb96 commit d9ad58c
Showing 1 changed file with 40 additions and 46 deletions.
86 changes: 40 additions & 46 deletions cpp/tests/filling/sequence_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, NVIDIA CORPORATION.
* Copyright (c) 2020-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.
Expand All @@ -14,20 +14,14 @@
* limitations under the License.
*/

#include <cudf/scalar/scalar.hpp>

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

#include <cudf/filling.hpp>
#include <cudf/scalar/scalar_factories.hpp>
#include <cudf/unary.hpp>

using namespace cudf;
using namespace cudf::test;
#include <cudf/scalar/scalar.hpp>

template <typename T>
class SequenceTypedTestFixture : public cudf::test::BaseFixture {
Expand All @@ -44,13 +38,13 @@ TYPED_TEST(SequenceTypedTestFixture, Incrementing)
{
using T = TypeParam;

numeric_scalar<T> init(0);
numeric_scalar<T> step(1);
cudf::numeric_scalar<T> init(0);
cudf::numeric_scalar<T> step(1);

size_type num_els = 10;
cudf::size_type num_els = 10;

T expected[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
fixed_width_column_wrapper<T> expected_w(expected, expected + num_els);
cudf::test::fixed_width_column_wrapper<T> expected_w(expected, expected + num_els);

auto result = cudf::sequence(num_els, init, step);

Expand All @@ -61,13 +55,13 @@ TYPED_TEST(SequenceTypedTestFixture, Decrementing)
{
using T = TypeParam;

numeric_scalar<T> init(0);
numeric_scalar<T> step(-5);
cudf::numeric_scalar<T> init(0);
cudf::numeric_scalar<T> step(-5);

size_type num_els = 10;
cudf::size_type num_els = 10;

T expected[] = {0, -5, -10, -15, -20, -25, -30, -35, -40, -45};
fixed_width_column_wrapper<T> expected_w(expected, expected + num_els);
cudf::test::fixed_width_column_wrapper<T> expected_w(expected, expected + num_els);

auto result = cudf::sequence(num_els, init, step);

Expand All @@ -78,13 +72,13 @@ TYPED_TEST(SequenceTypedTestFixture, EmptyOutput)
{
using T = TypeParam;

numeric_scalar<T> init(0);
numeric_scalar<T> step(-5);
cudf::numeric_scalar<T> init(0);
cudf::numeric_scalar<T> step(-5);

size_type num_els = 0;
cudf::size_type num_els = 0;

T expected[] = {};
fixed_width_column_wrapper<T> expected_w(expected, expected + num_els);
cudf::test::fixed_width_column_wrapper<T> expected_w(expected, expected + num_els);

auto result = cudf::sequence(num_els, init, step);

Expand All @@ -93,44 +87,44 @@ TYPED_TEST(SequenceTypedTestFixture, EmptyOutput)

TEST_F(SequenceTestFixture, BadTypes)
{
string_scalar string_init("zero");
string_scalar string_step("???");
cudf::string_scalar string_init("zero");
cudf::string_scalar string_step("???");
EXPECT_THROW(cudf::sequence(10, string_init, string_step), cudf::logic_error);

numeric_scalar<bool> bool_init(true);
numeric_scalar<bool> bool_step(false);
cudf::numeric_scalar<bool> bool_init(true);
cudf::numeric_scalar<bool> bool_step(false);
EXPECT_THROW(cudf::sequence(10, bool_init, bool_step), cudf::logic_error);

timestamp_scalar<timestamp_s> ts_init(duration_s{10}, true);
timestamp_scalar<timestamp_s> ts_step(duration_s{10}, true);
cudf::timestamp_scalar<cudf::timestamp_s> ts_init(cudf::duration_s{10}, true);
cudf::timestamp_scalar<cudf::timestamp_s> ts_step(cudf::duration_s{10}, true);
EXPECT_THROW(cudf::sequence(10, ts_init, ts_step), cudf::logic_error);
}

TEST_F(SequenceTestFixture, MismatchedInputs)
{
numeric_scalar<int> init(0);
numeric_scalar<float> step(-5);
cudf::numeric_scalar<int> init(0);
cudf::numeric_scalar<float> step(-5);
EXPECT_THROW(cudf::sequence(10, init, step), cudf::logic_error);

numeric_scalar<int> init2(0);
numeric_scalar<int8_t> step2(-5);
cudf::numeric_scalar<int> init2(0);
cudf::numeric_scalar<int8_t> step2(-5);
EXPECT_THROW(cudf::sequence(10, init2, step2), cudf::logic_error);

numeric_scalar<float> init3(0);
numeric_scalar<double> step3(-5);
cudf::numeric_scalar<float> init3(0);
cudf::numeric_scalar<double> step3(-5);
EXPECT_THROW(cudf::sequence(10, init3, step3), cudf::logic_error);
}

TYPED_TEST(SequenceTypedTestFixture, DefaultStep)
{
using T = TypeParam;

numeric_scalar<T> init(0);
cudf::numeric_scalar<T> init(0);

size_type num_els = 10;
cudf::size_type num_els = 10;

T expected[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
fixed_width_column_wrapper<T> expected_w(expected, expected + num_els);
cudf::test::fixed_width_column_wrapper<T> expected_w(expected, expected + num_els);

auto result = cudf::sequence(num_els, init);

Expand All @@ -140,11 +134,11 @@ TYPED_TEST(SequenceTypedTestFixture, DefaultStep)
TEST_F(SequenceTestFixture, DateSequenceBasic)
{
// Timestamp generated using https://www.epochconverter.com/
timestamp_scalar<timestamp_s> init(1629852896L, true); // 2021-08-25 00:54:56 GMT
size_type size{5};
size_type months{1};
cudf::timestamp_scalar<cudf::timestamp_s> init(1629852896L, true); // 2021-08-25 00:54:56 GMT
cudf::size_type size{5};
cudf::size_type months{1};

fixed_width_column_wrapper<timestamp_s, int64_t> expected{
cudf::test::fixed_width_column_wrapper<cudf::timestamp_s, int64_t> expected{
1629852896L, // 2021-08-25 00:54:56 GMT
1632531296L, // 2021-09-25 00:54:56 GMT
1635123296L, // 2021-10-25 00:54:56 GMT
Expand All @@ -160,11 +154,11 @@ TEST_F(SequenceTestFixture, DateSequenceBasic)
TEST_F(SequenceTestFixture, DateSequenceLeapYear)
{
// Timestamp generated using https://www.epochconverter.com/
timestamp_scalar<timestamp_s> init(951876379L, true); // 2000-02-29 02:06:19 GMT
size_type size{5};
size_type months{12};
cudf::timestamp_scalar<cudf::timestamp_s> init(951876379L, true); // 2000-02-29 02:06:19 GMT
cudf::size_type size{5};
cudf::size_type months{12};

fixed_width_column_wrapper<timestamp_s, int64_t> expected{
cudf::test::fixed_width_column_wrapper<cudf::timestamp_s, int64_t> expected{
951876379L, // 2000-02-29 02:06:19 GMT Leap Year
983412379L, // 2001-02-28 02:06:19 GMT
1014948379L, // 2002-02-28 02:06:19 GMT
Expand All @@ -179,9 +173,9 @@ TEST_F(SequenceTestFixture, DateSequenceLeapYear)

TEST_F(SequenceTestFixture, DateSequenceBadTypes)
{
numeric_scalar<int64_t> init(951876379, true);
size_type size = 5;
size_type months = 12;
cudf::numeric_scalar<int64_t> init(951876379, true);
cudf::size_type size = 5;
cudf::size_type months = 12;

EXPECT_THROW(calendrical_month_sequence(size, init, months), cudf::logic_error);
}

0 comments on commit d9ad58c

Please sign in to comment.