Skip to content

Commit

Permalink
feat : adding locale to sport module
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavobastian committed Nov 24, 2024
1 parent 576187d commit ab8d1b0
Show file tree
Hide file tree
Showing 5 changed files with 283 additions and 45 deletions.
19 changes: 13 additions & 6 deletions include/faker-cxx/sport.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,68 @@

#include "faker-cxx/export.h"

#include "faker-cxx/types/locale.h"

namespace faker::sport
{
/**
* @brief Returns a random sport.
*
* @param locale The locale. Defaults to `Locale::en_US`.
* @returns Sport.
*
* @code
* faker::sport::sport() // "football"
* @endcode
*/

FAKER_CXX_EXPORT std::string_view sportName();
FAKER_CXX_EXPORT std::string_view sportName(Locale locale = Locale::en_US);


/**
* @brief Returns a random soccer team.
*
* @returns Coccer team.
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @code
* faker::sport::soccerTeam() // "Manchester United"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view soccerTeam();
FAKER_CXX_EXPORT std::string_view soccerTeam(Locale locale = Locale::en_US);

/**
* @brief Returns a random male athlete.
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @returns Male athlete.
*
* @code
* faker::sport::maleAthlete() // "Cristiano Ronaldo"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view maleAthlete();
FAKER_CXX_EXPORT std::string_view maleAthlete(Locale locale = Locale::en_US);

/**
* @brief Returns a random female athlete.
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @returns Female athlete.
*
* @code
* faker::sport::femaleAthlete() // "Serena Williams"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view femaleAthlete();
FAKER_CXX_EXPORT std::string_view femaleAthlete(Locale locale = Locale::en_US);

/**
* @brief Returns a random Sport Event.
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @returns Sport Event.
*
* @code
* faker::sport::sportEvent() // "Super Bowl"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view sportEvent();
FAKER_CXX_EXPORT std::string_view sportEvent(Locale locale = Locale::en_US);
}
53 changes: 42 additions & 11 deletions src/modules/sport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,59 @@

namespace faker::sport
{
std::string_view sportName()
{
return helper::randomElement(sportNames);
std::string_view sportName(Locale locale)
{
auto localeLocal = locale;

if (sportMapSpan.find(locale) == sportMapSpan.end())
{
localeLocal = Locale::en_US;
}
return helper::randomElement((sportMapSpan.at(localeLocal)).sportNames);
}

std::string_view soccerTeam()
std::string_view soccerTeam(Locale locale)
{
return helper::randomElement(soccerTeams);
auto localeLocal = locale;

if (sportMapSpan.find(locale) == sportMapSpan.end())
{
localeLocal = Locale::en_US;
}
return helper::randomElement((sportMapSpan.at(localeLocal)).soccerTeams);
}

std::string_view maleAthlete()
std::string_view maleAthlete(Locale locale)
{
return helper::randomElement(maleAthletes);
auto localeLocal = locale;

if (sportMapSpan.find(locale) == sportMapSpan.end())
{
localeLocal = Locale::en_US;
}
return helper::randomElement((sportMapSpan.at(localeLocal)).maleAthletes);
}

std::string_view femaleAthlete()
std::string_view femaleAthlete(Locale locale)
{
return helper::randomElement(femaleAthletes);
auto localeLocal = locale;

if (sportMapSpan.find(locale) == sportMapSpan.end())
{
localeLocal = Locale::en_US;
}
return helper::randomElement((sportMapSpan.at(localeLocal)).femaleAthletes);
}

std::string_view sportEvent()
std::string_view sportEvent(Locale locale)
{
return helper::randomElement(sportEvents);
auto localeLocal = locale;

if (sportMapSpan.find(locale) == sportMapSpan.end())
{
localeLocal = Locale::en_US;
}
return helper::randomElement((sportMapSpan.at(localeLocal)).sportEvents);
}

}
176 changes: 171 additions & 5 deletions src/modules/sport_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,27 @@

#include <array>
#include <string>
#include <span>
#include <string_view>
#include <map>

namespace faker::sport
{
const auto femaleAthletes = std::to_array<std::string_view>({


struct SportDefinition
{
std::span<const std::string_view> femaleAthletes;
std::span<const std::string_view> maleAthletes;
std::span<const std::string_view> soccerTeams;
std::span<const std::string_view> sportEvents;
std::span<const std::string_view> sportNames;
};

//"en_US"


const auto enUsFemaleAthletes = std::to_array<std::string_view>({
"Alex Morgan",
"Jackie Joyner-Kersee",
"Lindsey Vonn",
Expand All @@ -18,7 +35,7 @@ const auto femaleAthletes = std::to_array<std::string_view>({
"Steffi Graf",
});

const auto maleAthletes = std::to_array<std::string_view>({
const auto enUSMaleAthletes = std::to_array<std::string_view>({
"Cristiano Ronaldo",
"Kobe Bryant",
"LeBron James",
Expand All @@ -31,7 +48,7 @@ const auto maleAthletes = std::to_array<std::string_view>({
"Usain Bolt",
});

const auto soccerTeams = std::to_array<std::string_view>({
const auto enUSSoccerTeams = std::to_array<std::string_view>({
"AC Milan",
"Chelsea FC",
"FC Barcelona",
Expand All @@ -44,7 +61,7 @@ const auto soccerTeams = std::to_array<std::string_view>({
"Real Madrid CF",
});

const auto sportEvents = std::to_array<std::string_view>({
const auto enUSSportEvents = std::to_array<std::string_view>({
"ICC Cricket World Cup",
"NBA Finals",
"Olympics",
Expand All @@ -57,7 +74,7 @@ const auto sportEvents = std::to_array<std::string_view>({
"World Cup",
});

const auto sportNames = std::to_array<std::string_view>({
const auto enUSSportNames = std::to_array<std::string_view>({
"American Football",
"Baseball",
"Basketball",
Expand All @@ -70,4 +87,153 @@ const auto sportNames = std::to_array<std::string_view>({
"Volleyball",
});

const SportDefinition enUSSportDefinition = {
.femaleAthletes = enUsFemaleAthletes,
.maleAthletes = enUSMaleAthletes,
.soccerTeams = enUSSoccerTeams,
.sportEvents = enUSSportEvents,
.sportNames = enUSSportNames
};


//"es_AR"
const auto esARSportNames = std::to_array<std::string_view>({
"Futbol","Baseball","Basquet","Cricket", "Golf","Rugby",
"Polo","Ping Pong","Tenis","Voley",
});

const auto esARFemaleAthletes = std::to_array<std::string_view>({
"Gabriela Sabatini",
"Gisela Dulko",
"Paula Pareto",
"Luciana Aymar",
"Georgina Bardach",
"Sabrina Ameghino",
"Noemí Simonetto",
"Micaela Retegui",
"Cecilia Carranza Saroli",
"VAnina Onetto",
});

const auto esARMaleAthletes = std::to_array<std::string_view>({
"Emanuel Ginóbili",
"Lionel Messi",
"Diego Maradona",
"Carlos Monzón",
"Guillermo Vilas",
"Carlos Reutemann",
"Nicolino Locche",
"Carlos Teves",
"Walter Pérez",
"Sebastián Crismanich",
});


const auto esARSoccerTeams = std::to_array<std::string_view>({
"Boca Juniors",
"River Plate",
"Colon Santa Fe",
"Independiente",
"Rosario Central",
"Racing",
"San Lorenzo",
"Newels Old Boys",
"Velez Sarfield",
"Talleres",
});


const auto esARSportEvents = std::to_array<std::string_view>({
"Superliga",
"Copa Argentina",
"Primera B Nacional",
"Liga Nacional de Basquet",
"Turismo Carretera",
"Copa Libertadores",
"Liga de Voley Argentina",
"Argentina Open Tennis",
"Juegos Argentinos de Alto Rendimiento",
"MotoGP",
});

const SportDefinition esARSportDefinition = {
.femaleAthletes = esARFemaleAthletes,
.maleAthletes = esARMaleAthletes,
.soccerTeams = esARSoccerTeams,
.sportEvents = esARSportEvents,
.sportNames = esARSportNames
};

//"pt-br"
const auto ptBRSportNames = std::to_array<std::string_view>({
"Futebol","Handebol","Tênis","boxe", "Golf","rúgbi",
"Polo","Natação","Artes marciais","Voleibol",
});

const auto ptBRFemaleAthletes = std::to_array<std::string_view>({
"Amanda Nunes",
"Natahsa Ferreira",
"Paula Pareto",
"Larissa França",
"Juliana Veloso",
"Leticia Santos",
"Sissi",
"Thaísa",
"Marta Vieira",
});

const auto ptBRMaleAthletes = std::to_array<std::string_view>({
"Pele",
"Ayrton Senna",
"Nelson Piquet",
"Ronaldo",
"Ronaldinho",
"Guga Kuerten",
"Kaka",
"Neymar",
"Garrincha",
"Socrates",
});

const auto ptBRSoccerTeams = std::to_array<std::string_view>({
"Sao Paulo",
"Flamengo",
"Inter Porto Alegre",
"Santos",
"Cruzeiro",
"Corinthians",
"Gremio",
"Atletico Mineiro",
"Vasco da Gamma",
"Botafogo",
});

const auto ptBRSportEvents = std::to_array<std::string_view>({
"Brasileirao",
"Campeonato Paulista",
"Copa Brasil",
"GP Interlagos",
"ATP 500 Rio de Janeiro",
"ATP 250 Sao Paulo",
"Libertadores de América",
"MotoGP Rio do Janeiro",
});

const SportDefinition ptBRSportDefinition = {
.femaleAthletes = ptBRFemaleAthletes,
.maleAthletes = ptBRMaleAthletes,
.soccerTeams = ptBRSoccerTeams,
.sportEvents = ptBRSportEvents,
.sportNames = ptBRSportNames
};


//general structure containing all the definitions

const std::map<faker::Locale, const SportDefinition> sportMapSpan({
{faker::Locale::en_US, {enUSSportDefinition}},
{faker::Locale::es_AR, {esARSportDefinition}},
{faker::Locale::pt_BR, {ptBRSportDefinition}},
});

}
1 change: 1 addition & 0 deletions tests/modules/internet_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <string>
#include <string_view>
#include <vector>
#include <chrono>

#include "gtest/gtest.h"

Expand Down
Loading

0 comments on commit ab8d1b0

Please sign in to comment.