Skip to content

Commit

Permalink
refactor: sport module migrate (#684)
Browse files Browse the repository at this point in the history
sport module migration from class to functions within sport namespace

Signed-off-by: Guru Mehar Rachaputi <[email protected]>
  • Loading branch information
00thirdeye00 committed Jun 24, 2024
1 parent f52b959 commit 582f3ac
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 32 deletions.
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 sport();

/**
* @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 sport()
{
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);
}
}
2 changes: 1 addition & 1 deletion src/modules/sport/SportData.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <array>
#include <string>

namespace faker::sport
namespace faker::Sport
{
const auto femaleAthletes = std::to_array<std::string_view>({
"Alex Morgan", "Jackie Joyner-Kersee", "Lindsey Vonn", "Martina Navratilova", "Mia Hamm",
Expand Down
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 = sport();

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

0 comments on commit 582f3ac

Please sign in to comment.