Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Locale to sport module #995

Merged
merged 10 commits into from
Nov 24, 2024
17 changes: 11 additions & 6 deletions include/faker-cxx/sport.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,62 +3,67 @@
#include <string_view>

#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);
}
45 changes: 35 additions & 10 deletions src/modules/sport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,53 @@

namespace faker::sport
{
std::string_view sportName()
std::string_view sportName(Locale locale)
{
return helper::randomElement(sportNames);
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);
}
}
179 changes: 174 additions & 5 deletions src/modules/sport_data.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
#pragma once

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

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 +32,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 +45,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 +58,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 +71,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 +84,159 @@ 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 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 auto esARSportNames = std::to_array<std::string_view>({
"Futbol",
"Baseball",
"Basquet",
"Cricket",
"Golf",
"Rugby",
"Polo",
"Ping Pong",
"Tenis",
"Voley",
});

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

//"pt-br"

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 auto ptBRSportNames = std::to_array<std::string_view>({
"Futebol",
"Handebol",
"Tênis",
"boxe",
"Golf",
"rúgbi",
"Polo",
"Natação",
"Artes marciais",
"Voleibol",
});

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

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
Loading