Skip to content

Commit

Permalink
change person api to use country instead of languages
Browse files Browse the repository at this point in the history
  • Loading branch information
cieslarmichal committed Nov 15, 2023
1 parent c2d0a1f commit afd2e7f
Show file tree
Hide file tree
Showing 78 changed files with 488 additions and 400 deletions.
5 changes: 3 additions & 2 deletions include/faker-cxx/Git.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <optional>
#include <string>

#include "faker-cxx/types/Country.h"
#include "faker-cxx/types/Language.h"

namespace faker
Expand Down Expand Up @@ -39,7 +40,7 @@ class Git
*
* @param dateYears The range of years the date may be in the past. Defaults to `15`.
* @param shaLength The length of output SHA hash. Defaults to `40`.
* @param language The language set for name generating. Defaults to `English` (could be random, if there was a
* @param country The country set for name generating. Defaults to `England` (could be random, if there was a
random language generator).
* @returns Commit entry.
*
Expand All @@ -53,7 +54,7 @@ class Git
*/
static std::string commitEntry(std::optional<unsigned> dateYears = std::nullopt,
std::optional<unsigned> shaLength = std::nullopt,
Language language = Language::English);
Country country = Country::England);

/**
* @brief Generates a random commit message.
Expand Down
21 changes: 11 additions & 10 deletions include/faker-cxx/Person.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <optional>
#include <string>

#include "faker-cxx/types/Country.h"
#include "types/Language.h"
#include "types/Sex.h"

Expand All @@ -14,23 +15,23 @@ class Person
/**
* @brief Returns a random first name.
*
* @param language The local name language. Defaults to `Language::English`.
* @param country The local country. Defaults to `Country::England`.
* @param sex The optional sex to use.
*
* @returns First name starting with a capital letter.
*
* @code
* Person::firstName() // "Michael"
* Person::firstName(Language::English, Sex::Female) // "Emma"
* Person::firstName(Language::English, Sex::Male) // "Arthur"
* Person::firstName(Country::English, Sex::Female) // "Emma"
* Person::firstName(Country::English, Sex::Male) // "Arthur"
* @endcode
*/
static std::string firstName(Language language = Language::English, std::optional<Sex> = std::nullopt);
static std::string firstName(Country country = Country::England, std::optional<Sex> = std::nullopt);

/**
* @brief Returns a random last name.
*
* @param language The local name language. Defaults to `Language::English`.
* @param country The local country. Defaults to `Country::England`.
* @param sex The optional sex to use.
*
* @returns Last name starting with a capital letter.
Expand All @@ -39,7 +40,7 @@ class Person
* Person::lastName() // "Peterson"
* @endcode
*/
static std::string lastName(Language language = Language::English, std::optional<Sex> = std::nullopt);
static std::string lastName(Country country = Country::England, std::optional<Sex> = std::nullopt);

/**
* @brief Returns a random middle name.
Expand All @@ -57,18 +58,18 @@ class Person
/**
* @brief Returns a random full name.
*
* @param language The local name language. Defaults to `Language::English`.
* @param country The local country. Defaults to `Country::England`.
* @param sex The optional sex to use.
*
* @returns Full name starting with first name.
*
* @code
* Person::fullName() // "Marcia Robinson"
* Person::fullName(Language::English, Sex::Female) // "Jennifer Martin"
* Person::fullName(Language::English, Sex::Male) // "Samuel Walker"
* Person::fullName(Country::English, Sex::Female) // "Jennifer Martin"
* Person::fullName(Country::English, Sex::Male) // "Samuel Walker"
* @endcode
*/
static std::string fullName(Language language = Language::English, std::optional<Sex> = std::nullopt);
static std::string fullName(Country country = Country::England, std::optional<Sex> = std::nullopt);

/**
* @brief Returns a random name prefix.
Expand Down
39 changes: 38 additions & 1 deletion include/faker-cxx/types/Country.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

#include <map>
#include <string>
#include <vector>

namespace faker
{
Expand All @@ -11,6 +13,41 @@ enum class Country
France,
Germany,
Italy,
Russia
Russia,
England,
Romania,
India,
Finland,
Nepal,
Spain,
Turkey,
Czech,
Slovakia,
Ukraine,
Denmark,
Sweden
};

const std::vector<Country> countries{
Country::Usa, Country::England, Country::Poland, Country::Italy, Country::France, Country::Germany,
Country::Russia, Country::Romania, Country::India, Country::Finland, Country::Nepal, Country::Spain,
Country::Turkey, Country::Czech, Country::Slovakia, Country::Ukraine, Country::Denmark, Country::Sweden};

inline std::string toString(Country country)
{
std::map<Country, std::string> countryToStringMapping{
{Country::Usa, "Usa"}, {Country::England, "England"}, {Country::Poland, "Poland"},
{Country::Italy, "Italy"}, {Country::France, "France"}, {Country::Germany, "Germany"},
{Country::Russia, "Russia"}, {Country::Romania, "Romania"}, {Country::India, "India"},
{Country::Finland, "Finland"}, {Country::Nepal, "Nepal"}, {Country::Spain, "Spain"},
{Country::Turkey, "Turkey"}, {Country::Czech, "Czech"}, {Country::Slovakia, "Slovakia"},
{Country::Ukraine, "Ukraine"}, {Country::Denmark, "Denmark"}, {Country::Sweden, "Sweden"}};

return countryToStringMapping.at(country);
}

inline std::ostream& operator<<(std::ostream& os, Country country)
{
return os << toString(country);
}
}
4 changes: 2 additions & 2 deletions src/modules/company/CompanyTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include "gtest/gtest.h"

#include "../../common/StringHelper.h"
#include "../person/data/english/EnglishFirstNames.h"
#include "../person/data/english/EnglishLastNames.h"
#include "../person/data/england/EnglishFirstNames.h"
#include "../person/data/england/EnglishLastNames.h"
#include "../person/data/JobTitles.h"
#include "data/BuzzAdjectives.h"
#include "data/BuzzNouns.h"
Expand Down
10 changes: 7 additions & 3 deletions src/modules/git/Git.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ std::string Git::commitDate(unsigned years)
monthAbbreviatedNames[size_t(std::stoi(month) - 1)], day, time, year, timeZoneString);
}

std::string Git::commitEntry(std::optional<unsigned> dateYears, std::optional<unsigned> shaLength, Language language)
std::string Git::commitEntry(std::optional<unsigned> dateYears, std::optional<unsigned> shaLength, Country country)
{
std::string entry = "commit ";

if (shaLength)
{
entry += commitSha(shaLength.emplace());
Expand All @@ -83,9 +84,11 @@ std::string Git::commitEntry(std::optional<unsigned> dateYears, std::optional<un
entry += commitSha();
}

std::string firstName = Person::firstName(language);
std::string lastName = Person::lastName(language);
const auto firstName = Person::firstName(country);
const auto lastName = Person::lastName(country);

entry += "\nAuthor: " + firstName + " " + lastName + " " + Internet::email(firstName, lastName) + "\nDate: ";

if (dateYears)
{
entry += commitDate(dateYears.emplace());
Expand All @@ -96,6 +99,7 @@ std::string Git::commitEntry(std::optional<unsigned> dateYears, std::optional<un
}

entry += "\n\n\t" + commitMessage();

return entry;
}

Expand Down
4 changes: 2 additions & 2 deletions src/modules/internet/InternetTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#include "gtest/gtest.h"

#include "../../common/StringHelper.h"
#include "../person/data/english/EnglishFirstNames.h"
#include "../person/data/english/EnglishLastNames.h"
#include "../person/data/england/EnglishFirstNames.h"
#include "../person/data/england/EnglishLastNames.h"
#include "../string/data/Characters.h"
#include "../word/data/Adjectives.h"
#include "../word/data/Nouns.h"
Expand Down
2 changes: 1 addition & 1 deletion src/modules/location/Location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const std::map<Country, std::vector<std::string>> countryToStreetPrefixesMapping

std::string Location::country()
{
return Helper::arrayElement<std::string>(countries);
return Helper::arrayElement<std::string>(allCountries);
}

std::string Location::countryCode()
Expand Down
6 changes: 3 additions & 3 deletions src/modules/location/LocationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include "gtest/gtest.h"

#include "../../common/StringHelper.h"
#include "../person/data/english/EnglishFirstNames.h"
#include "../person/data/english/EnglishLastNames.h"
#include "../person/data/england/EnglishFirstNames.h"
#include "../person/data/england/EnglishLastNames.h"
#include "../string/data/Characters.h"
#include "data/Countries.h"
#include "data/Directions.h"
Expand Down Expand Up @@ -44,7 +44,7 @@ TEST_F(LocationTest, shouldGenerateCountry)
{
const auto generatedCountry = Location::country();

ASSERT_TRUE(std::ranges::any_of(countries, [generatedCountry](const std::string& country)
ASSERT_TRUE(std::ranges::any_of(allCountries, [generatedCountry](const std::string& country)
{ return country == generatedCountry; }));
}

Expand Down
Loading

0 comments on commit afd2e7f

Please sign in to comment.