From 020f3c0e407a9dded89d935b94613b66408d868f Mon Sep 17 00:00:00 2001 From: Eric Floyd Date: Mon, 9 Oct 2023 21:17:41 -0400 Subject: [PATCH] Added Sport Module --- CMakeLists.txt | 2 + include/faker-cxx/Sport.h | 65 +++++++++++++++++++++++++ src/modules/sport/Sport.cpp | 39 +++++++++++++++ src/modules/sport/SportTest.cpp | 60 +++++++++++++++++++++++ src/modules/sport/data/FemaleAthletes.h | 12 +++++ src/modules/sport/data/MaleAthletes.h | 12 +++++ src/modules/sport/data/SoccerTeams.h | 12 +++++ src/modules/sport/data/SportEvents.h | 20 ++++++++ src/modules/sport/data/SportNames.h | 12 +++++ 9 files changed, 234 insertions(+) create mode 100644 include/faker-cxx/Sport.h create mode 100644 src/modules/sport/Sport.cpp create mode 100644 src/modules/sport/SportTest.cpp create mode 100644 src/modules/sport/data/FemaleAthletes.h create mode 100644 src/modules/sport/data/MaleAthletes.h create mode 100644 src/modules/sport/data/SoccerTeams.h create mode 100644 src/modules/sport/data/SportEvents.h create mode 100644 src/modules/sport/data/SportNames.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 04750b088..857e7799a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 @@ -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}) diff --git a/include/faker-cxx/Sport.h b/include/faker-cxx/Sport.h new file mode 100644 index 000000000..a9f0bfeb7 --- /dev/null +++ b/include/faker-cxx/Sport.h @@ -0,0 +1,65 @@ +#pragma once + +#include + +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(); +}; +} \ No newline at end of file diff --git a/src/modules/sport/Sport.cpp b/src/modules/sport/Sport.cpp new file mode 100644 index 000000000..253eb7d1c --- /dev/null +++ b/src/modules/sport/Sport.cpp @@ -0,0 +1,39 @@ +#include "faker-cxx/Sport.h" +#include "faker-cxx/Helper.h" + + +#include + +#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(sportNames); +} + +std::string Sport::soccerTeam() +{ + return Helper::arrayElement(soccerTeams); +} + +std::string Sport::maleAthlete() +{ + return Helper::arrayElement(maleAthletes); +} + +std::string Sport::femaleAthlete() +{ + return Helper::arrayElement(femaleAthletes); +} + +std::string Sport::sportEvent() +{ + return Helper::arrayElement(sportEvents); +} +} diff --git a/src/modules/sport/SportTest.cpp b/src/modules/sport/SportTest.cpp new file mode 100644 index 000000000..634cbfed1 --- /dev/null +++ b/src/modules/sport/SportTest.cpp @@ -0,0 +1,60 @@ +#include "faker-cxx/Sport.h" + +#include +#include + +#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; })); +} diff --git a/src/modules/sport/data/FemaleAthletes.h b/src/modules/sport/data/FemaleAthletes.h new file mode 100644 index 000000000..4fa90fc90 --- /dev/null +++ b/src/modules/sport/data/FemaleAthletes.h @@ -0,0 +1,12 @@ +#pragma once + +#include +#include + +namespace faker +{ +const std::vector femaleAthletes = { + "Serena Williams", "Simone Biles", "Mia Hamm", "Ronda Rousey", "Lindsey Vonn", "Alex Morgan", + "Martina Navratilova", "Jackie Joyner-Kersee", "Nadia Comăneci", "Steffi Graf", +}; +} diff --git a/src/modules/sport/data/MaleAthletes.h b/src/modules/sport/data/MaleAthletes.h new file mode 100644 index 000000000..d25143564 --- /dev/null +++ b/src/modules/sport/data/MaleAthletes.h @@ -0,0 +1,12 @@ +#pragma once + +#include +#include + +namespace faker +{ +const std::vector maleAthletes = { + "Lionel Messi", "Cristiano Ronaldo", "LeBron James", "Usain Bolt", "Michael Phelps", + "Roger Federer", "Kobe Bryant", "Tom Brady", "Muhammad Ali", "Michael Jordan", +}; +} diff --git a/src/modules/sport/data/SoccerTeams.h b/src/modules/sport/data/SoccerTeams.h new file mode 100644 index 000000000..c817b3184 --- /dev/null +++ b/src/modules/sport/data/SoccerTeams.h @@ -0,0 +1,12 @@ +#pragma once + +#include +#include + +namespace faker +{ +const std::vector 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", +}; +} diff --git a/src/modules/sport/data/SportEvents.h b/src/modules/sport/data/SportEvents.h new file mode 100644 index 000000000..f273b3da1 --- /dev/null +++ b/src/modules/sport/data/SportEvents.h @@ -0,0 +1,20 @@ +#pragma once + +#include +#include + +namespace faker +{ +const std::vector sportEvents = { + "World Cup", + "Olympics", + "Super Bowl", + "World Athletics Championship", + "UEFA Champions League", + "NBA Finals", + "Wimbledon", + "ICC Cricket World Cup", + "The Masters", + "Rugby World Cup", +}; +} diff --git a/src/modules/sport/data/SportNames.h b/src/modules/sport/data/SportNames.h new file mode 100644 index 000000000..b3ffe1ec0 --- /dev/null +++ b/src/modules/sport/data/SportNames.h @@ -0,0 +1,12 @@ +#pragma once + +#include +#include + +namespace faker +{ +const std::vector sportNames = { + "Soccer", "Cricket", "Basketball", "Tennis", "Volleyball", "Table Tennis", + "Golf", "Baseball", "American Football", "Rugby", +}; +}