Skip to content

Commit

Permalink
Use parameterized test in NamePropertyTest
Browse files Browse the repository at this point in the history
To make code more readable, use parameterized test according to existing TODO comment.

**Self evaluation:**
1. Build test:     [X]Passed [ ]Failed [ ]Skipped
2. Run test:     [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: heka1024 <[email protected]>
  • Loading branch information
heka1024 authored and jijoongmoon committed Mar 19, 2024
1 parent 206e37c commit 7fb71e2
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions test/unittest/unittest_common_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,24 @@
#include <tensor_dim.h>

#include <array>
/**
* @brief NamePropertyTest
* @tparam std::string string which will be used as name
*/
class NamePropertyTest : public ::testing::TestWithParam<std::string> {};

/// @todo change this to typed param test
/// <type, list of string, value pair, list of invalid string, value pair>
TEST(NameProperty, setPropertyValid_p) {
TEST_P(NamePropertyTest, setPropertyValid_p) {
nntrainer::props::Name n;
EXPECT_NO_THROW(n.set("layer"));
EXPECT_EQ(n.get(), "layer");

EXPECT_NO_THROW(n.set("layer-"));
EXPECT_EQ(n.get(), "layer-");
std::string param = GetParam();

EXPECT_NO_THROW(n.set("laye-r"));
EXPECT_EQ(n.get(), "laye-r");

EXPECT_NO_THROW(n.set("layer/a"));
EXPECT_EQ(n.get(), "layer/a");

EXPECT_NO_THROW(n.set("laye__r"));
EXPECT_EQ(n.get(), "laye__r");
EXPECT_NO_THROW(n.set(param));
EXPECT_EQ(n.get(), param);
}

GTEST_PARAMETER_TEST(NamePropertyTests, NamePropertyTest,
::testing::Values("layer", "layer-", "laye-r", "layer/a",
"laye__r"));

/**
* @brief NameTest
* @tparam std::string string which will be added as suffix to name
Expand Down Expand Up @@ -72,7 +69,7 @@ GTEST_PARAMETER_TEST(ForbiddenSuffixTests, NameTest,
"=", "+0", "(0)", "{0}", "[0]", "<0>",
";", ":", ",", "?", " ", " layer"));

TEST(NameProperty, mustStartWithAlphaNumeric_01_n) {
TEST(NamePropertyTest, mustStartWithAlphaNumeric_01_n) {
nntrainer::props::Name n;
EXPECT_THROW(n.set("/layer"), std::invalid_argument);
}
Expand Down

0 comments on commit 7fb71e2

Please sign in to comment.