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: sport module migrate (#684) #717

Merged
Merged
Show file tree
Hide file tree
Changes from 5 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
17 changes: 7 additions & 10 deletions include/faker-cxx/Sport.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

#include <string_view>

namespace faker
namespace faker::sport
{
class Sport
{
public:
/**
* @brief Returns a random sport.
*
Expand All @@ -16,7 +13,8 @@ class Sport
* Sport::sport() // "football"
* @endcode
*/
static std::string_view sport();

std::string_view sportName();

/**
* @brief Returns a random soccer team.
Expand All @@ -27,7 +25,7 @@ class Sport
* Sport::soccerTeam() // "Manchester United"
* @endcode
*/
static std::string_view soccerTeam();
std::string_view soccerTeam();

/**
* @brief Returns a random male athlete.
Expand All @@ -38,7 +36,7 @@ class Sport
* Sport::maleAthlete() // "Cristiano Ronaldo"
* @endcode
*/
static std::string_view maleAthlete();
std::string_view maleAthlete();

/**
* @brief Returns a random female athlete.
Expand All @@ -49,7 +47,7 @@ class Sport
* Sport::femaleAthlete() // "Serena Williams"
* @endcode
*/
static std::string_view femaleAthlete();
std::string_view femaleAthlete();

/**
* @brief Returns a random Sport Event.
Expand All @@ -60,6 +58,5 @@ class Sport
* Sport::sportEvent() // "Super Bowl"
* @endcode
*/
static std::string_view sportEvent();
};
std::string_view sportEvent();
}
22 changes: 11 additions & 11 deletions src/modules/sport/Sport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@
#include "faker-cxx/Helper.h"
#include "SportData.h"

namespace faker
namespace faker::sport
{
std::string_view Sport::sport()
std::string_view sportName()
{
return Helper::arrayElement(sport::sportNames);
return Helper::arrayElement(sportNames);
}

std::string_view Sport::soccerTeam()
std::string_view soccerTeam()
{
return Helper::arrayElement(sport::soccerTeams);
return Helper::arrayElement(soccerTeams);
}

std::string_view Sport::maleAthlete()
std::string_view maleAthlete()
{
return Helper::arrayElement(sport::maleAthletes);
return Helper::arrayElement(maleAthletes);
}

std::string_view Sport::femaleAthlete()
std::string_view femaleAthlete()
{
return Helper::arrayElement(sport::femaleAthletes);
return Helper::arrayElement(femaleAthletes);
}

std::string_view Sport::sportEvent()
std::string_view sportEvent()
{
return Helper::arrayElement(sport::sportEvents);
return Helper::arrayElement(sportEvents);
}
}
21 changes: 11 additions & 10 deletions tests/modules/sport/SportTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

using namespace ::testing;
using namespace faker;
using namespace faker::sport;

class SportTest : public Test
{
Expand All @@ -17,41 +18,41 @@ class SportTest : public Test

TEST_F(SportTest, shouldGenerateSport)
{
const auto generatedSport = Sport::sport();
const auto generatedSport = sportName();

ASSERT_TRUE(std::ranges::any_of(sport::sportNames, [generatedSport](const std::string_view& sport)
ASSERT_TRUE(std::ranges::any_of(sportNames, [generatedSport](const std::string_view& sport)
{ return sport == generatedSport; }));
}

TEST_F(SportTest, shouldGenerateSoccerTeam)
{
const auto generatedSoccerTeam = Sport::soccerTeam();
const auto generatedSoccerTeam = soccerTeam();

ASSERT_TRUE(std::ranges::any_of(sport::soccerTeams, [generatedSoccerTeam](const std::string_view& soccerTeam)
ASSERT_TRUE(std::ranges::any_of(soccerTeams, [generatedSoccerTeam](const std::string_view& soccerTeam)
{ return soccerTeam == generatedSoccerTeam; }));
}

TEST_F(SportTest, shouldGenerateSportEvent)
{
const auto generatedSportEvent = Sport::sportEvent();
const auto generatedSportEvent = sportEvent();

ASSERT_TRUE(std::ranges::any_of(sport::sportEvents, [generatedSportEvent](const std::string_view& sportEvent)
ASSERT_TRUE(std::ranges::any_of(sportEvents, [generatedSportEvent](const std::string_view& sportEvent)
{ return sportEvent == generatedSportEvent; }));
}

TEST_F(SportTest, shouldGenerateMaleAthlete)
{
const auto generatedMaleAthlete = Sport::maleAthlete();
const auto generatedMaleAthlete = maleAthlete();

ASSERT_TRUE(std::ranges::any_of(sport::maleAthletes, [generatedMaleAthlete](const std::string_view& maleAthlete)
ASSERT_TRUE(std::ranges::any_of(maleAthletes, [generatedMaleAthlete](const std::string_view& maleAthlete)
{ return maleAthlete == generatedMaleAthlete; }));
}

TEST_F(SportTest, shouldGenerateFemaleAthlete)
{
const auto generatedFemaleAthlete = Sport::femaleAthlete();
const auto generatedFemaleAthlete = femaleAthlete();

ASSERT_TRUE(std::ranges::any_of(sport::femaleAthletes,
ASSERT_TRUE(std::ranges::any_of(femaleAthletes,
[generatedFemaleAthlete](const std::string_view& femaleAthlete)
{ return femaleAthlete == generatedFemaleAthlete; }));
}
Loading