Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: hacker module #739

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 13 additions & 17 deletions include/faker-cxx/Hacker.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,71 @@

#include <string_view>

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.
*
* @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.
*
* @returns noun.
*
* @code
* Hacker::noun() // "coder"
* hacker::noun() // "coder"
* @endcode
*/
static std::string_view noun();
std::string_view noun();

/**
* @brief Returns a random verb.
*
* @returns verb.
*
* @code
* Hacker::verb() // "run"
* hacker::verb() // "run"
* @endcode
*/
static std::string_view verb();
std::string_view verb();

/**
* @brief Returns a random ingverb.
*
* @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.
*
* @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();
}
14 changes: 7 additions & 7 deletions src/modules/hacker/Hacker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>(Helper::arrayElement(phrases)));

Expand Down
2 changes: 1 addition & 1 deletion src/modules/hacker/HackerData.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <array>
#include <string_view>

namespace faker
namespace faker::hacker
{
const auto abbreviations = std::to_array<std::string_view>({
"e.g.", "i.e.", "etc.", "Mr.", "Mrs.", "Ms.", "Dr.", "Prof.",
Expand Down
13 changes: 7 additions & 6 deletions tests/modules/hacker/HackerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

using namespace ::testing;
using namespace faker;
using namespace faker::hacker;

class HackerTest : public Test
{
Expand All @@ -18,47 +19,47 @@ 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; }));
}

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; }));
}

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; }));
}

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; }));
}

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; }));
}

TEST_F(HackerTest, shouldGeneratePhrase)
{
const auto generatedPhrase = Hacker::phrase();
const auto generatedPhrase = phrase();
bool hasAdjective, hasNoun, hasVerb, hasAbbreviation;
hasAdjective = hasNoun = hasVerb = hasAbbreviation = false;

Expand Down
Loading