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

refactor: add locale to esports module #965

Merged
merged 3 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions include/faker-cxx/esport.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,72 @@
#include <string_view>

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

namespace faker::esport
{
/**
* @brief Returns a random player name.
*
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @return Player name.
*
* @code
* faker::esport::player() // "Faker"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view player();
FAKER_CXX_EXPORT std::string_view player(Locale locale = Locale::en_US);

/**
* @brief Returns a random esport team.
*
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @return Esport team.
*
* @code
* faker::esport::team() // "Karmine Corp"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view team();
FAKER_CXX_EXPORT std::string_view team(Locale locale = Locale::en_US);

/**
* @brief Returns a random esport league.
*
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @return Esport League.
*
* @code
* faker::esport::league() // "LEC"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view league();
FAKER_CXX_EXPORT std::string_view league(Locale locale = Locale::en_US);

/**
* @brief Returns a random esport event.
*
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @return Esport Event.
*
* @code
* faker::esport::event() // "Faker"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view event();
FAKER_CXX_EXPORT std::string_view event(Locale locale = Locale::en_US);

/**
* @brief Returns a random competitive video game.
*
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @return Competitive video game.
*
* @code
* faker::esport::game() // "Rocket League"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view game();
FAKER_CXX_EXPORT std::string_view game(Locale locale = Locale::en_US);
}
42 changes: 32 additions & 10 deletions src/modules/esport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,51 @@

namespace faker::esport
{
std::string_view player()

namespace
{
const struct EsportDefinition& getEsportDefinition(Locale locale)
{
return helper::randomElement(players);
switch (locale)
{
default:
return enUSEsportDefinition;
}
}
}

std::string_view team()
std::string_view player(Locale locale)
{
return helper::randomElement(teams);
const auto& esportDefinition = getEsportDefinition(locale);

return helper::randomElement(esportDefinition.players);
}

std::string_view league()
std::string_view team(Locale locale)
{
return helper::randomElement(leagues);
const auto& esportDefinition = getEsportDefinition(locale);

return helper::randomElement(esportDefinition.teams);
}

std::string_view event()
std::string_view league(Locale locale)
{
return helper::randomElement(events);
const auto& esportDefinition = getEsportDefinition(locale);

return helper::randomElement(esportDefinition.leagues);
}

std::string_view game()
std::string_view event(Locale locale)
{
return helper::randomElement(games);
const auto& esportDefinition = getEsportDefinition(locale);

return helper::randomElement(esportDefinition.events);
}

std::string_view game(Locale locale)
{
const auto& esportDefinition = getEsportDefinition(locale);

return helper::randomElement(esportDefinition.games);
}
}
28 changes: 23 additions & 5 deletions src/modules/esport_data.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
#pragma once

#include <array>
#include <span>
#include <string_view>

namespace faker::esport
{
const auto players = std::to_array<std::string_view>(
struct EsportDefinition
{
std::span<const std::string_view> players;
std::span<const std::string_view> teams;
std::span<const std::string_view> leagues;
std::span<const std::string_view> events;
std::span<const std::string_view> games;
};

const auto enUSPlayers = std::to_array<std::string_view>(
{"Adam", "Alvaro", "Brokenblade", "Canna", "Caps", "Carzzy", "Closer", "Comp", "Elyoya",
"Finn", "Flakked", "Fresskowy", "Hans Sama", "Humanoid", "Hylissang", "Ice", "IgNar", "Irrelevant",
"Isma", "Jackies", "Jankos", "Juhan", "Jun", "Labrov", "Larssen", "Luon", "Lyncas",
Expand All @@ -20,27 +30,35 @@ const auto players = std::to_array<std::string_view>(
"Pyosik", "Quantum", "Raptor", "Rascal", "Samver", "SeTab", "ShowMaker", "Sponge", "Sylvie",
"Teddy", "Viper", "Vital", "YoungJae", "Zeka", "Zeus", "kingen"});

const auto teams = std::to_array<std::string_view>(
const auto enUSTeams = std::to_array<std::string_view>(
{"Team Liquid", "G2 Esports", "OpTic Gaming", "Natus Vincere", "Astralis", "NRG",
"7figures Esports", "HEROIC", "Faze Clan", "Fnatic", "Virtus.pro", "Ninjas in Pyjamas",
"CompLexity", "TSM", "BIG", "Karmine Corp", "Cloud9", "Evil Geniuses",
"Team VItality", "Mouz", "100 Thieves", "NaVi", "Team Secret", "Vitality",
"Gambit Esports", "BDS", "Gentle Mates"});

const auto leagues = std::to_array<std::string_view>(
const auto enUSLeagues = std::to_array<std::string_view>(
{"LEC", "LPL", "LCK", "LCS NA", "LFL", "PUBG Mobile Super League", "VCT", "VCT GC", "F1 Esports Series",
"Overwatch League", "Superliga", "Prime League", "TCL", "Call of Duty League", "RLCS"});

const auto events =
const auto enUSEvents =
std::to_array<std::string_view>({"MSI", "EMEA Masters", "League of Legends World Championship", "EWC",
"The International", "Fortnite World Cup", "Six Invitational", "Capcom X Cup",
"VCT Masters"
"RLCS Major",
"IEM"});

const auto games = std::to_array<std::string_view>({"Valorant", "League Of Legend", "Rocket League", "Fifa",
const auto enUSGames = std::to_array<std::string_view>({"Valorant", "League Of Legend", "Rocket League", "Fifa",
"Overwatch", "CSGO", "Fortnite", "Dota 2",
"Street Fighter,"
"Apex Legends",
"TFT", "PUBG", "Call of Duty"});

const EsportDefinition enUSEsportDefinition = {
.players = enUSPlayers,
.teams = enUSTeams,
.leagues = enUSLeagues,
.events = enUSEvents,
.games = enUSGames
};
}
55 changes: 44 additions & 11 deletions tests/modules/esport_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,82 @@
#include "faker-cxx/esport.h"

using namespace ::testing;
using namespace faker;
using namespace faker::esport;

class EsportTest : public Test
namespace
{
const struct EsportDefinition& getEsportDefinition(Locale locale)
{
switch (locale)
{
default:
return enUSEsportDefinition;
}
}
}

class EsportTest : public TestWithParam<Locale>
{
public:
};

TEST_F(EsportTest, shouldGeneratePlayer)
{
const auto generatedPlayer = player();
const auto locale = GetParam();

const auto& esportDefinition = getEsportDefinition(locale);

const auto generatedPlayer = player(locale);

ASSERT_TRUE(std::ranges::any_of(players, [generatedPlayer](const std::string_view& player)
ASSERT_TRUE(std::ranges::any_of(esportDefinition.players, [generatedPlayer](const std::string_view& player)
{ return generatedPlayer == player; }));
}

TEST_F(EsportTest, shouldGenerateTeam)
{
const auto generatedTeam = team();
const auto locale = GetParam();

const auto& esportDefinition = getEsportDefinition(locale);

const auto generatedTeam = team(locale);

ASSERT_TRUE(
std::ranges::any_of(teams, [generatedTeam](const std::string_view& team) { return generatedTeam == team; }));
std::ranges::any_of(esportDefinition.teams, [generatedTeam](const std::string_view& team) { return generatedTeam == team; }));
}

TEST_F(EsportTest, shouldGenerateLeague)
{
const auto generatedLeague = league();
const auto locale = GetParam();

const auto& esportDefinition = getEsportDefinition(locale);

ASSERT_TRUE(std::ranges::any_of(leagues, [generatedLeague](const std::string_view& league)
const auto generatedLeague = league(locale);

ASSERT_TRUE(std::ranges::any_of(esportDefinition.leagues, [generatedLeague](const std::string_view& league)
{ return generatedLeague == league; }));
}

TEST_F(EsportTest, shouldGenerateEvent)
{
const auto generatedEvent = event();
const auto locale = GetParam();

const auto& esportDefinition = getEsportDefinition(locale);

ASSERT_TRUE(std::ranges::any_of(events, [generatedEvent](const std::string_view& event)
const auto generatedEvent = event(locale);

ASSERT_TRUE(std::ranges::any_of(esportDefinition.events, [generatedEvent](const std::string_view& event)
{ return generatedEvent == event; }));
}

TEST_F(EsportTest, shouldGenerateGame)
{
const auto generatedGame = game();
const auto locale = GetParam();

const auto& esportDefinition = getEsportDefinition(locale);

const auto generatedGame = game(locale);

ASSERT_TRUE(
std::ranges::any_of(games, [generatedGame](const std::string_view& game) { return generatedGame == game; }));
std::ranges::any_of(esportDefinition.games, [generatedGame](const std::string_view& game) { return generatedGame == game; }));
}
Loading