Skip to content

Commit

Permalink
Added Sport Module
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-bodhi committed Oct 10, 2023
1 parent 9e7ec1f commit 020f3c0
Show file tree
Hide file tree
Showing 9 changed files with 234 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ set(FAKER_SOURCES
src/modules/music/Music.cpp
src/modules/movie/Movie.cpp
src/modules/hacker/Hacker.cpp
src/modules/sport/Sport.cpp
)

set(FAKER_UT_SOURCES
Expand Down Expand Up @@ -70,6 +71,7 @@ set(FAKER_UT_SOURCES
src/modules/music/MusicTest.cpp
src/modules/movie/MovieTest.cpp
src/modules/hacker/HackerTest.cpp
src/modules/sport/SportTest.cpp
)

add_library(${LIBRARY_NAME} ${FAKER_SOURCES})
Expand Down
65 changes: 65 additions & 0 deletions include/faker-cxx/Sport.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#pragma once

#include <string>

namespace faker
{
class Sport
{
public:
/**
* @brief Returns a random sport.
*
* @returns sport.
*
* @code
* Sport::sport() // "football"
* @endcode
*/
static std::string sport();

/**
* @brief Returns a random soccer team.
*
* @returns soccer team.
*
* @code
* Sport::soccerTeam() // "Manchester United"
* @endcode
*/
static std::string soccerTeam();

/**
* @brief Returns a random male athlete.
*
* @returns male athlete.
*
* @code
* Sport::maleAthlete() // "Cristiano Ronaldo"
* @endcode
*/
static std::string maleAthlete();

/**
* @brief Returns a random female athlete.
*
* @returns female athlete.
*
* @code
* Sport::femaleAthlete() // "Serena Williams"
* @endcode
*/
static std::string femaleAthlete();

/**
* @brief Returns a random Sport Event.
*
* @returns Sport Event.
*
* @code
* Sport::sportEvent() // "Super Bowl"
* @endcode
*/
static std::string sportEvent();
};
}
39 changes: 39 additions & 0 deletions src/modules/sport/Sport.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "faker-cxx/Sport.h"
#include "faker-cxx/Helper.h"


#include <string>

#include "data/FemaleAthletes.h"
#include "data/MaleAthletes.h"
#include "data/SoccerTeams.h"
#include "data/SportEvents.h"
#include "data/SportNames.h"

namespace faker
{
std::string Sport::sport()
{
return Helper::arrayElement<std::string>(sportNames);
}

std::string Sport::soccerTeam()
{
return Helper::arrayElement<std::string>(soccerTeams);
}

std::string Sport::maleAthlete()
{
return Helper::arrayElement<std::string>(maleAthletes);
}

std::string Sport::femaleAthlete()
{
return Helper::arrayElement<std::string>(femaleAthletes);
}

std::string Sport::sportEvent()
{
return Helper::arrayElement<std::string>(sportEvents);
}
}
60 changes: 60 additions & 0 deletions src/modules/sport/SportTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include "faker-cxx/Sport.h"

#include <algorithm>
#include <string>

#include "gtest/gtest.h"

#include "data/FemaleAthletes.h"
#include "data/MaleAthletes.h"
#include "data/SoccerTeams.h"
#include "data/SportEvents.h"
#include "data/SportNames.h"

using namespace ::testing;
using namespace faker;

class SportTest : public Test
{
public:
};

TEST_F(SportTest, shouldGenerateSport)
{
std::string generatedSport = Sport::sport();

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

TEST_F(SportTest, shouldGenerateSoccerTeam)
{
std::string generatedSoccerTeam = Sport::soccerTeam();

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

TEST_F(SportTest, shouldGenerateSportEvent)
{
std::string generatedSportEvent = Sport::sportEvent();

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

TEST_F(SportTest, shouldGenerateMaleAthlete)
{
std::string generatedMaleAthlete = Sport::maleAthlete();

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

TEST_F(SportTest, shouldGenerateFemaleAthlete)
{
std::string generatedFemaleAthlete = Sport::femaleAthlete();

ASSERT_TRUE(std::ranges::any_of(femaleAthletes, [generatedFemaleAthlete](const std::string& femaleAthlete)
{ return femaleAthlete == generatedFemaleAthlete; }));
}
12 changes: 12 additions & 0 deletions src/modules/sport/data/FemaleAthletes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include <string>
#include <vector>

namespace faker
{
const std::vector<std::string> femaleAthletes = {
"Serena Williams", "Simone Biles", "Mia Hamm", "Ronda Rousey", "Lindsey Vonn", "Alex Morgan",
"Martina Navratilova", "Jackie Joyner-Kersee", "Nadia Comăneci", "Steffi Graf",
};
}
12 changes: 12 additions & 0 deletions src/modules/sport/data/MaleAthletes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include <string>
#include <vector>

namespace faker
{
const std::vector<std::string> maleAthletes = {
"Lionel Messi", "Cristiano Ronaldo", "LeBron James", "Usain Bolt", "Michael Phelps",
"Roger Federer", "Kobe Bryant", "Tom Brady", "Muhammad Ali", "Michael Jordan",
};
}
12 changes: 12 additions & 0 deletions src/modules/sport/data/SoccerTeams.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include <string>
#include <vector>

namespace faker
{
const std::vector<std::string> soccerTeams{
"FC Barcelona", "Real Madrid CF", "Manchester United FC", "Liverpool FC", "FC Bayern Munich",
"AC Milan", "Inter Milan", "Juventus FC", "Paris Saint-Germain FC", "Chelsea FC",
};
}
20 changes: 20 additions & 0 deletions src/modules/sport/data/SportEvents.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include <string>
#include <vector>

namespace faker
{
const std::vector<std::string> sportEvents = {
"World Cup",
"Olympics",
"Super Bowl",
"World Athletics Championship",
"UEFA Champions League",
"NBA Finals",
"Wimbledon",
"ICC Cricket World Cup",
"The Masters",
"Rugby World Cup",
};
}
12 changes: 12 additions & 0 deletions src/modules/sport/data/SportNames.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include <string>
#include <vector>

namespace faker
{
const std::vector<std::string> sportNames = {
"Soccer", "Cricket", "Basketball", "Tennis", "Volleyball", "Table Tennis",
"Golf", "Baseball", "American Football", "Rugby",
};
}

0 comments on commit 020f3c0

Please sign in to comment.