From 6cb265211cf1e5ba238a2248c04c09086aa4fb1a Mon Sep 17 00:00:00 2001 From: Guru Mehar Rachaputi Date: Tue, 25 Jun 2024 20:02:52 +0200 Subject: [PATCH] refactor: hacker module - hacker module migration from class to functions within hacker namespace Signed-off-by: Guru Mehar Rachaputi --- include/faker-cxx/Hacker.h | 30 +++++++++++++---------------- src/modules/hacker/Hacker.cpp | 14 +++++++------- src/modules/hacker/HackerData.h | 2 +- tests/modules/hacker/HackerTest.cpp | 13 +++++++------ 4 files changed, 28 insertions(+), 31 deletions(-) diff --git a/include/faker-cxx/Hacker.h b/include/faker-cxx/Hacker.h index f8d72ab89..9642319f4 100644 --- a/include/faker-cxx/Hacker.h +++ b/include/faker-cxx/Hacker.h @@ -2,21 +2,18 @@ #include -namespace faker +namespace faker::hacker { -class Hacker -{ -public: /** * @brief Returns a hacker abbreviation. * * @returns abbreviation. * * @code - * Hacker::abbreviation() // "TCP" + * hacker::abbreviation() // "TCP" * @endcode */ - static std::string_view abbreviation(); + std::string_view abbreviation(); /** * @brief Returns a random adjective. @@ -24,10 +21,10 @@ class Hacker * @returns adjective. * * @code - * Hacker::adjective() // "open-source" + * hacker::adjective() // "open-source" * @endcode */ - static std::string_view adjective(); + std::string_view adjective(); /** * @brief Returns a random noun. @@ -35,10 +32,10 @@ class Hacker * @returns noun. * * @code - * Hacker::noun() // "coder" + * hacker::noun() // "coder" * @endcode */ - static std::string_view noun(); + std::string_view noun(); /** * @brief Returns a random verb. @@ -46,10 +43,10 @@ class Hacker * @returns verb. * * @code - * Hacker::verb() // "run" + * hacker::verb() // "run" * @endcode */ - static std::string_view verb(); + std::string_view verb(); /** * @brief Returns a random ingverb. @@ -57,10 +54,10 @@ class Hacker * @returns ingverb. * * @code - * Hacker::ingverb() // "backing up" + * hacker::ingverb() // "backing up" * @endcode */ - static std::string_view ingverb(); + std::string_view ingverb(); /** * @brief Returns a random phrase. @@ -68,9 +65,8 @@ class Hacker * @return phrase. * * @code - * Hacker::phrase() // "If we bypass the monitor, we can get to the TCP monitor through the neural EXE monitor!" + * hacker::phrase() // "If we bypass the monitor, we can get to the TCP monitor through the neural EXE monitor!" * @endcode */ - static std::string phrase(); -}; + std::string phrase(); } diff --git a/src/modules/hacker/Hacker.cpp b/src/modules/hacker/Hacker.cpp index 783f5b0ee..d7fd09698 100644 --- a/src/modules/hacker/Hacker.cpp +++ b/src/modules/hacker/Hacker.cpp @@ -7,34 +7,34 @@ #include "faker-cxx/Helper.h" #include "HackerData.h" -namespace faker +namespace faker::hacker { -std::string_view Hacker::abbreviation() +std::string_view abbreviation() { return Helper::arrayElement(abbreviations); } -std::string_view Hacker::adjective() +std::string_view adjective() { return Helper::arrayElement(adjectives); } -std::string_view Hacker::noun() +std::string_view noun() { return Helper::arrayElement(nouns); } -std::string_view Hacker::verb() +std::string_view verb() { return Helper::arrayElement(verbs); } -std::string_view Hacker::ingverb() +std::string_view ingverb() { return Helper::arrayElement(ingverbs); } -std::string Hacker::phrase() +std::string phrase() { const auto splitRandomPhrase = StringHelper::split(static_cast(Helper::arrayElement(phrases))); diff --git a/src/modules/hacker/HackerData.h b/src/modules/hacker/HackerData.h index a9024c548..494278d50 100644 --- a/src/modules/hacker/HackerData.h +++ b/src/modules/hacker/HackerData.h @@ -3,7 +3,7 @@ #include #include -namespace faker +namespace faker::hacker { const auto abbreviations = std::to_array({ "e.g.", "i.e.", "etc.", "Mr.", "Mrs.", "Ms.", "Dr.", "Prof.", diff --git a/tests/modules/hacker/HackerTest.cpp b/tests/modules/hacker/HackerTest.cpp index 881d70d5a..96a12adbb 100644 --- a/tests/modules/hacker/HackerTest.cpp +++ b/tests/modules/hacker/HackerTest.cpp @@ -10,6 +10,7 @@ using namespace ::testing; using namespace faker; +using namespace faker::hacker; class HackerTest : public Test { @@ -18,7 +19,7 @@ class HackerTest : public Test TEST_F(HackerTest, shouldGenerateAbbreviation) { - const auto generatedAbbreviation = Hacker::abbreviation(); + const auto generatedAbbreviation = abbreviation(); ASSERT_TRUE(std::ranges::any_of(abbreviations, [generatedAbbreviation](const std::string_view& abbreviation) { return abbreviation == generatedAbbreviation; })); @@ -26,7 +27,7 @@ TEST_F(HackerTest, shouldGenerateAbbreviation) TEST_F(HackerTest, shouldGenerateAdjective) { - const auto generatedAdjective = Hacker::adjective(); + const auto generatedAdjective = adjective(); ASSERT_TRUE(std::ranges::any_of(adjectives, [generatedAdjective](const std::string_view& adjective) { return adjective == generatedAdjective; })); @@ -34,7 +35,7 @@ TEST_F(HackerTest, shouldGenerateAdjective) TEST_F(HackerTest, shouldGenerateNoun) { - const auto generatedNoun = Hacker::noun(); + const auto generatedNoun = noun(); ASSERT_TRUE( std::ranges::any_of(nouns, [generatedNoun](const std::string_view& noun) { return noun == generatedNoun; })); @@ -42,7 +43,7 @@ TEST_F(HackerTest, shouldGenerateNoun) TEST_F(HackerTest, shouldGenerateVerb) { - const auto generatedVerb = Hacker::verb(); + const auto generatedVerb = verb(); ASSERT_TRUE( std::ranges::any_of(verbs, [generatedVerb](const std::string_view& verb) { return verb == generatedVerb; })); @@ -50,7 +51,7 @@ TEST_F(HackerTest, shouldGenerateVerb) TEST_F(HackerTest, shouldGenerateIngverb) { - const auto generatedIngverb = Hacker::ingverb(); + const auto generatedIngverb = ingverb(); ASSERT_TRUE(std::ranges::any_of(ingverbs, [generatedIngverb](const std::string_view& ingverb) { return ingverb == generatedIngverb; })); @@ -58,7 +59,7 @@ TEST_F(HackerTest, shouldGenerateIngverb) TEST_F(HackerTest, shouldGeneratePhrase) { - const auto generatedPhrase = Hacker::phrase(); + const auto generatedPhrase = phrase(); bool hasAdjective, hasNoun, hasVerb, hasAbbreviation; hasAdjective = hasNoun = hasVerb = hasAbbreviation = false;