From 4fd336c527f7aaab3dc19c6a818ddf31e3bba016 Mon Sep 17 00:00:00 2001 From: Guru Mehar Rachaputi Date: Mon, 24 Jun 2024 13:30:04 +0200 Subject: [PATCH] refactor: sport module migrate (#684) (#717) * refactor: sport module migrate (#684) sport module migration from class to functions within sport namespace Signed-off-by: Guru Mehar Rachaputi * Update Sport.h Changed sport() function to sportName() * Update Sport.cpp Changed sport() to sportName() * Update SportData.h Changed "Sport" namespace to lowercase "sport" * Update SportTest.cpp Change sport() to sportName() and "Sport" to lowercase "sport" in sport namespace * refactor: sport module migrate (#684) 1. sport module migration from class to functions within sport namespace 2. changed function name from sport() to sportName() 3. changelog updated Signed-off-by: Guru Mehar Rachaputi --------- Signed-off-by: Guru Mehar Rachaputi --- CHANGELOG.md | 1 + include/faker-cxx/Sport.h | 17 +++++++---------- src/modules/sport/Sport.cpp | 22 +++++++++++----------- tests/modules/sport/SportTest.cpp | 21 +++++++++++---------- 4 files changed, 30 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 75832dbfa..f4ab3824e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ All notable changes to this project will be documented in this file * changed classes to namespaces for functions grouping, for example use `number::integer` instead of `Number::integer`, applies to all modules * changed std::string to std::string_view in functions where is was possible +* changed function name from sport() to sportName() in sport module ### Features diff --git a/include/faker-cxx/Sport.h b/include/faker-cxx/Sport.h index 4d2a1a7a4..72bb12911 100644 --- a/include/faker-cxx/Sport.h +++ b/include/faker-cxx/Sport.h @@ -2,11 +2,8 @@ #include -namespace faker +namespace faker::sport { -class Sport -{ -public: /** * @brief Returns a random sport. * @@ -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. @@ -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. @@ -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. @@ -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. @@ -60,6 +58,5 @@ class Sport * Sport::sportEvent() // "Super Bowl" * @endcode */ - static std::string_view sportEvent(); -}; + std::string_view sportEvent(); } diff --git a/src/modules/sport/Sport.cpp b/src/modules/sport/Sport.cpp index 385bc3f98..ea0ccb0af 100644 --- a/src/modules/sport/Sport.cpp +++ b/src/modules/sport/Sport.cpp @@ -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); } } diff --git a/tests/modules/sport/SportTest.cpp b/tests/modules/sport/SportTest.cpp index caa729258..a916eb2c4 100644 --- a/tests/modules/sport/SportTest.cpp +++ b/tests/modules/sport/SportTest.cpp @@ -9,6 +9,7 @@ using namespace ::testing; using namespace faker; +using namespace faker::sport; class SportTest : public Test { @@ -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; })); }