Skip to content

Commit

Permalink
refactor: sport module migrate (#684) (#717)
Browse files Browse the repository at this point in the history
* refactor: sport module migrate (#684)

sport module migration from class to functions within sport namespace

Signed-off-by: Guru Mehar Rachaputi <[email protected]>

* 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 <[email protected]>

---------

Signed-off-by: Guru Mehar Rachaputi <[email protected]>
  • Loading branch information
00thirdeye00 authored Jun 24, 2024
1 parent f52b959 commit 4fd336c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 31 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

0 comments on commit 4fd336c

Please sign in to comment.