From afd2e7fe8c53d0d91c37c7fa387e9856e2bd08db Mon Sep 17 00:00:00 2001 From: Michal Cieslar Date: Wed, 15 Nov 2023 15:57:04 +0100 Subject: [PATCH] change person api to use country instead of languages --- include/faker-cxx/Git.h | 5 +- include/faker-cxx/Person.h | 21 +- include/faker-cxx/types/Country.h | 39 +- src/modules/company/CompanyTest.cpp | 4 +- src/modules/git/Git.cpp | 10 +- src/modules/internet/InternetTest.cpp | 4 +- src/modules/location/Location.cpp | 2 +- src/modules/location/LocationTest.cpp | 6 +- src/modules/location/data/Countries.h | 492 +++++++++--------- src/modules/person/Person.cpp | 148 +++--- src/modules/person/PersonTest.cpp | 135 ++--- .../{danish => denmark}/DanishFirstNames.h | 0 .../{danish => denmark}/DanishLastNames.h | 0 .../{danish => denmark}/DanishMiddleNames.h | 0 .../{danish => denmark}/DanishPeopleNames.h | 0 .../data/{danish => denmark}/DanishPrefixes.h | 0 .../{english => england}/EnglishFirstNames.h | 0 .../{english => england}/EnglishLastNames.h | 0 .../{english => england}/EnglishPeopleNames.h | 0 .../{english => england}/EnglishPrefixes.h | 0 .../{english => england}/EnglishSuffixes.h | 0 .../{finnish => finland}/FinnishFirstNames.h | 0 .../{finnish => finland}/FinnishLastNames.h | 0 .../{finnish => finland}/FinnishPeopleNames.h | 0 .../{french => france}/FrenchFirstNames.h | 0 .../data/{french => france}/FrenchLastNames.h | 0 .../{french => france}/FrenchPeopleNames.h | 0 .../data/{french => france}/FrenchPrefixes.h | 0 .../{german => germany}/GermanFirstNames.h | 0 .../{german => germany}/GermanLastNames.h | 0 .../{german => germany}/GermanPeopleNames.h | 0 .../data/{german => germany}/GermanPrefixes.h | 0 .../data/{indian => india}/IndianFirstNames.h | 0 .../data/{indian => india}/IndianLastNames.h | 0 .../{indian => india}/IndianPeopleNames.h | 0 .../{italian => italy}/ItalianFirstNames.h | 0 .../{italian => italy}/ItalianLastNames.h | 0 .../{italian => italy}/ItalianPeopleNames.h | 0 .../data/{italian => italy}/ItalianPrefixes.h | 0 .../{nepalese => nepal}/NepaleseFirstNames.h | 0 .../{nepalese => nepal}/NepaleseLastNames.h | 0 .../{nepalese => nepal}/NepalesePeopleNames.h | 0 .../{polish => poland}/PolishFirstNames.h | 0 .../data/{polish => poland}/PolishLastNames.h | 0 .../{polish => poland}/PolishPeopleNames.h | 0 .../data/{polish => poland}/PolishPrefixes.h | 0 .../RomanianFirstNames.h | 0 .../{romanian => romania}/RomanianLastNames.h | 0 .../RomanianPeopleNames.h | 0 .../{romanian => romania}/RomanianPrefixes.h | 0 .../{romanian => romania}/RomanianSuffixes.h | 0 .../{russian => russia}/RussianFirstNames.h | 0 .../{russian => russia}/RussianLastNames.h | 0 .../{russian => russia}/RussianMiddleNames.h | 0 .../{russian => russia}/RussianPeopleNames.h | 0 .../{slovak => slovakia}/SlovakFirstNames.h | 0 .../{slovak => slovakia}/SlovakLastNames.h | 0 .../{slovak => slovakia}/SlovakPeopleNames.h | 0 .../{slovak => slovakia}/SlovakPrefixes.h | 0 .../{slovak => slovakia}/SlovakSuffixes.h | 0 .../{spanish => spain}/SpanishFirstNames.h | 0 .../{spanish => spain}/SpanishLastNames.h | 0 .../{spanish => spain}/SpanishPeopleNames.h | 0 .../data/{spanish => spain}/SpanishPrefixes.h | 0 .../{swedish => sweden}/SwedishFirstNames.h | 0 .../{swedish => sweden}/SwedishLastNames.h | 0 .../{swedish => sweden}/SwedishPeopleNames.h | 0 .../{swedish => sweden}/SwedishPrefixes.h | 0 .../{turkish => turkey}/TurkishFirstNames.h | 0 .../{turkish => turkey}/TurkishLastNames.h | 0 .../{turkish => turkey}/TurkishPeopleNames.h | 0 .../{turkish => turkey}/TurkishPrefixes.h | 0 .../UkrainianFirstNames.h | 0 .../UkrainianLastNames.h | 0 .../UkrainianMiddleNames.h | 0 .../UkrainianPeopleNames.h | 0 .../UkrainianPrefixes.h | 0 src/modules/person/data/usa/UsaPeopleNames.h | 22 + 78 files changed, 488 insertions(+), 400 deletions(-) rename src/modules/person/data/{danish => denmark}/DanishFirstNames.h (100%) rename src/modules/person/data/{danish => denmark}/DanishLastNames.h (100%) rename src/modules/person/data/{danish => denmark}/DanishMiddleNames.h (100%) rename src/modules/person/data/{danish => denmark}/DanishPeopleNames.h (100%) rename src/modules/person/data/{danish => denmark}/DanishPrefixes.h (100%) rename src/modules/person/data/{english => england}/EnglishFirstNames.h (100%) rename src/modules/person/data/{english => england}/EnglishLastNames.h (100%) rename src/modules/person/data/{english => england}/EnglishPeopleNames.h (100%) rename src/modules/person/data/{english => england}/EnglishPrefixes.h (100%) rename src/modules/person/data/{english => england}/EnglishSuffixes.h (100%) rename src/modules/person/data/{finnish => finland}/FinnishFirstNames.h (100%) rename src/modules/person/data/{finnish => finland}/FinnishLastNames.h (100%) rename src/modules/person/data/{finnish => finland}/FinnishPeopleNames.h (100%) rename src/modules/person/data/{french => france}/FrenchFirstNames.h (100%) rename src/modules/person/data/{french => france}/FrenchLastNames.h (100%) rename src/modules/person/data/{french => france}/FrenchPeopleNames.h (100%) rename src/modules/person/data/{french => france}/FrenchPrefixes.h (100%) rename src/modules/person/data/{german => germany}/GermanFirstNames.h (100%) rename src/modules/person/data/{german => germany}/GermanLastNames.h (100%) rename src/modules/person/data/{german => germany}/GermanPeopleNames.h (100%) rename src/modules/person/data/{german => germany}/GermanPrefixes.h (100%) rename src/modules/person/data/{indian => india}/IndianFirstNames.h (100%) rename src/modules/person/data/{indian => india}/IndianLastNames.h (100%) rename src/modules/person/data/{indian => india}/IndianPeopleNames.h (100%) rename src/modules/person/data/{italian => italy}/ItalianFirstNames.h (100%) rename src/modules/person/data/{italian => italy}/ItalianLastNames.h (100%) rename src/modules/person/data/{italian => italy}/ItalianPeopleNames.h (100%) rename src/modules/person/data/{italian => italy}/ItalianPrefixes.h (100%) rename src/modules/person/data/{nepalese => nepal}/NepaleseFirstNames.h (100%) rename src/modules/person/data/{nepalese => nepal}/NepaleseLastNames.h (100%) rename src/modules/person/data/{nepalese => nepal}/NepalesePeopleNames.h (100%) rename src/modules/person/data/{polish => poland}/PolishFirstNames.h (100%) rename src/modules/person/data/{polish => poland}/PolishLastNames.h (100%) rename src/modules/person/data/{polish => poland}/PolishPeopleNames.h (100%) rename src/modules/person/data/{polish => poland}/PolishPrefixes.h (100%) rename src/modules/person/data/{romanian => romania}/RomanianFirstNames.h (100%) rename src/modules/person/data/{romanian => romania}/RomanianLastNames.h (100%) rename src/modules/person/data/{romanian => romania}/RomanianPeopleNames.h (100%) rename src/modules/person/data/{romanian => romania}/RomanianPrefixes.h (100%) rename src/modules/person/data/{romanian => romania}/RomanianSuffixes.h (100%) rename src/modules/person/data/{russian => russia}/RussianFirstNames.h (100%) rename src/modules/person/data/{russian => russia}/RussianLastNames.h (100%) rename src/modules/person/data/{russian => russia}/RussianMiddleNames.h (100%) rename src/modules/person/data/{russian => russia}/RussianPeopleNames.h (100%) rename src/modules/person/data/{slovak => slovakia}/SlovakFirstNames.h (100%) rename src/modules/person/data/{slovak => slovakia}/SlovakLastNames.h (100%) rename src/modules/person/data/{slovak => slovakia}/SlovakPeopleNames.h (100%) rename src/modules/person/data/{slovak => slovakia}/SlovakPrefixes.h (100%) rename src/modules/person/data/{slovak => slovakia}/SlovakSuffixes.h (100%) rename src/modules/person/data/{spanish => spain}/SpanishFirstNames.h (100%) rename src/modules/person/data/{spanish => spain}/SpanishLastNames.h (100%) rename src/modules/person/data/{spanish => spain}/SpanishPeopleNames.h (100%) rename src/modules/person/data/{spanish => spain}/SpanishPrefixes.h (100%) rename src/modules/person/data/{swedish => sweden}/SwedishFirstNames.h (100%) rename src/modules/person/data/{swedish => sweden}/SwedishLastNames.h (100%) rename src/modules/person/data/{swedish => sweden}/SwedishPeopleNames.h (100%) rename src/modules/person/data/{swedish => sweden}/SwedishPrefixes.h (100%) rename src/modules/person/data/{turkish => turkey}/TurkishFirstNames.h (100%) rename src/modules/person/data/{turkish => turkey}/TurkishLastNames.h (100%) rename src/modules/person/data/{turkish => turkey}/TurkishPeopleNames.h (100%) rename src/modules/person/data/{turkish => turkey}/TurkishPrefixes.h (100%) rename src/modules/person/data/{ukrainian => ukraine}/UkrainianFirstNames.h (100%) rename src/modules/person/data/{ukrainian => ukraine}/UkrainianLastNames.h (100%) rename src/modules/person/data/{ukrainian => ukraine}/UkrainianMiddleNames.h (100%) rename src/modules/person/data/{ukrainian => ukraine}/UkrainianPeopleNames.h (100%) rename src/modules/person/data/{ukrainian => ukraine}/UkrainianPrefixes.h (100%) create mode 100644 src/modules/person/data/usa/UsaPeopleNames.h diff --git a/include/faker-cxx/Git.h b/include/faker-cxx/Git.h index aef4a2552..eb81eba03 100644 --- a/include/faker-cxx/Git.h +++ b/include/faker-cxx/Git.h @@ -3,6 +3,7 @@ #include #include +#include "faker-cxx/types/Country.h" #include "faker-cxx/types/Language.h" namespace faker @@ -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. * @@ -53,7 +54,7 @@ class Git */ static std::string commitEntry(std::optional dateYears = std::nullopt, std::optional shaLength = std::nullopt, - Language language = Language::English); + Country country = Country::England); /** * @brief Generates a random commit message. diff --git a/include/faker-cxx/Person.h b/include/faker-cxx/Person.h index 4af37e462..1f1dcd5db 100644 --- a/include/faker-cxx/Person.h +++ b/include/faker-cxx/Person.h @@ -3,6 +3,7 @@ #include #include +#include "faker-cxx/types/Country.h" #include "types/Language.h" #include "types/Sex.h" @@ -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 = std::nullopt); + static std::string firstName(Country country = Country::England, std::optional = 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. @@ -39,7 +40,7 @@ class Person * Person::lastName() // "Peterson" * @endcode */ - static std::string lastName(Language language = Language::English, std::optional = std::nullopt); + static std::string lastName(Country country = Country::England, std::optional = std::nullopt); /** * @brief Returns a random middle name. @@ -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 = std::nullopt); + static std::string fullName(Country country = Country::England, std::optional = std::nullopt); /** * @brief Returns a random name prefix. diff --git a/include/faker-cxx/types/Country.h b/include/faker-cxx/types/Country.h index 2f3da2493..bcabe430d 100644 --- a/include/faker-cxx/types/Country.h +++ b/include/faker-cxx/types/Country.h @@ -1,6 +1,8 @@ #pragma once +#include #include +#include namespace faker { @@ -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 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 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); +} } diff --git a/src/modules/company/CompanyTest.cpp b/src/modules/company/CompanyTest.cpp index 5980c5950..e397129a3 100644 --- a/src/modules/company/CompanyTest.cpp +++ b/src/modules/company/CompanyTest.cpp @@ -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" diff --git a/src/modules/git/Git.cpp b/src/modules/git/Git.cpp index 6707bab37..2544f626a 100644 --- a/src/modules/git/Git.cpp +++ b/src/modules/git/Git.cpp @@ -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 dateYears, std::optional shaLength, Language language) +std::string Git::commitEntry(std::optional dateYears, std::optional shaLength, Country country) { std::string entry = "commit "; + if (shaLength) { entry += commitSha(shaLength.emplace()); @@ -83,9 +84,11 @@ std::string Git::commitEntry(std::optional dateYears, std::optional dateYears, std::optional> countryToStreetPrefixesMapping std::string Location::country() { - return Helper::arrayElement(countries); + return Helper::arrayElement(allCountries); } std::string Location::countryCode() diff --git a/src/modules/location/LocationTest.cpp b/src/modules/location/LocationTest.cpp index 79344111b..698a2c4ec 100644 --- a/src/modules/location/LocationTest.cpp +++ b/src/modules/location/LocationTest.cpp @@ -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" @@ -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; })); } diff --git a/src/modules/location/data/Countries.h b/src/modules/location/data/Countries.h index ad832af62..7776a550a 100644 --- a/src/modules/location/data/Countries.h +++ b/src/modules/location/data/Countries.h @@ -5,252 +5,252 @@ namespace faker { -const std::vector countries = {"Afghanistan", - "Aland Islands", - "Albania", - "Algeria", - "American Samoa", - "Andorra", - "Angola", - "Anguilla", - "Antarctica", - "Antigua and Barbuda", - "Argentina", - "Armenia", - "Aruba", - "Australia", - "Austria", - "Azerbaijan", - "Bahamas", - "Bahrain", - "Bangladesh", - "Barbados", - "Belarus", - "Belgium", - "Belize", - "Benin", - "Bermuda", - "Bhutan", - "Bolivia", - "Bonaire, Sint Eustatius and Saba", - "Bosnia and Herzegovina", - "Botswana", - "Bouvet Island", - "Brazil", - "British Indian Ocean Territory (Chagos Archipelago)", - "Brunei Darussalam", - "Bulgaria", - "Burkina Faso", - "Burundi", - "Cambodia", - "Cameroon", - "Canada", - "Cape Verde", - "Cayman Islands", - "Central African Republic", - "Chad", - "Chile", - "China", - "Christmas Island", - "Cocos (Keeling) Islands", - "Colombia", - "Comoros", - "Congo", - "Cook Islands", - "Costa Rica", - "Croatia", - "Cuba", - "Curacao", - "Cyprus", - "Czechia", - "Democratic Republic of the Congo", - "Denmark", - "Djibouti", - "Dominica", - "Dominican Republic", - "Ecuador", - "Egypt", - "El Salvador", - "Equatorial Guinea", - "Eritrea", - "Estonia", - "Eswatini", - "Ethiopia", - "Faroe Islands", - "Falkland Islands (Malvinas)", - "Fiji", - "Finland", - "France", - "French Guiana", - "French Polynesia", - "French Southern Territories", - "Gabon", - "Gambia", - "Georgia", - "Germany", - "Ghana", - "Gibraltar", - "Greece", - "Greenland", - "Grenada", - "Guadeloupe", - "Guam", - "Guatemala", - "Guernsey", - "Guinea", - "Guinea-Bissau", - "Guyana", - "Haiti", - "Heard Island and McDonald Islands", - "Holy See (Vatican City State)", - "Honduras", - "Hong Kong", - "Hungary", - "Iceland", - "India", - "Indonesia", - "Iran", - "Iraq", - "Ireland", - "Isle of Man", - "Israel", - "Italy", - "Jamaica", - "Japan", - "Jersey", - "Jordan", - "Kazakhstan", - "Kenya", - "Kiribati", - "Republic of Korea", - "Kuwait", - "Kyrgyz Republic", - "Latvia", - "Lebanon", - "Lesotho", - "Liberia", - "Libyan Arab Jamahiriya", - "Liechtenstein", - "Lithuania", - "Luxembourg", - "Macao", - "Madagascar", - "Malawi", - "Malaysia", - "Maldives", - "Mali", - "Malta", - "Marshall Islands", - "Martinique", - "Mauritania", - "Mauritius", - "Mayotte", - "Mexico", - "Micronesia", - "Moldova", - "Monaco", - "Mongolia", - "Montenegro", - "Montserrat", - "Morocco", - "Mozambique", - "Myanmar", - "Namibia", - "Nauru", - "Nepal", - "Netherlands", - "New Caledonia", - "New Zealand", - "Nicaragua", - "Niger", - "Nigeria", - "Niue", - "Norfolk Island", - "North Macedonia", - "Northern Mariana Islands", - "Norway", - "Oman", - "Pakistan", - "Palau", - "Palestine", - "Panama", - "Papua New Guinea", - "Paraguay", - "Peru", - "Philippines", - "Pitcairn Islands", - "Poland", - "Portugal", - "Puerto Rico", - "Qatar", - "Reunion", - "Romania", - "Russian Federation", - "Rwanda", - "Saint Barthelemy", - "Saint Helena", - "Saint Kitts and Nevis", - "Saint Lucia", - "Saint Martin", - "Saint Pierre and Miquelon", - "Saint Vincent and the Grenadines", - "Samoa", - "San Marino", - "Sao Tome and Principe", - "Saudi Arabia", - "Senegal", - "Serbia", - "Seychelles", - "Sierra Leone", - "Singapore", - "Sint Maarten", - "Slovakia", - "Slovenia", - "Solomon Islands", - "Somalia", - "South Africa", - "South Georgia and the South Sandwich Islands", - "South Sudan", - "Spain", - "Sri Lanka", - "Sudan", - "Suriname", - "Svalbard & Jan Mayen Islands", - "Sweden", - "Switzerland", - "Syrian Arab Republic", - "Taiwan", - "Tajikistan", - "Tanzania", - "Thailand", - "Timor-Leste", - "Togo", - "Tokelau", - "Tonga", - "Trinidad and Tobago", - "Tunisia", - "Turkey", - "Turkmenistan", - "Turks and Caicos Islands", - "Tuvalu", - "Uganda", - "Ukraine", - "United Arab Emirates", - "United Kingdom", - "United States of America", - "United States Minor Outlying Islands", - "Uruguay", - "Uzbekistan", - "Vanuatu", - "Venezuela", - "Vietnam", - "Virgin Islands, British", - "Virgin Islands, U.S.", - "Wallis and Futuna", - "Western Sahara", - "Yemen", - "Zambia", - "Zimbabwe"}; +const std::vector allCountries = {"Afghanistan", + "Aland Islands", + "Albania", + "Algeria", + "American Samoa", + "Andorra", + "Angola", + "Anguilla", + "Antarctica", + "Antigua and Barbuda", + "Argentina", + "Armenia", + "Aruba", + "Australia", + "Austria", + "Azerbaijan", + "Bahamas", + "Bahrain", + "Bangladesh", + "Barbados", + "Belarus", + "Belgium", + "Belize", + "Benin", + "Bermuda", + "Bhutan", + "Bolivia", + "Bonaire, Sint Eustatius and Saba", + "Bosnia and Herzegovina", + "Botswana", + "Bouvet Island", + "Brazil", + "British Indian Ocean Territory (Chagos Archipelago)", + "Brunei Darussalam", + "Bulgaria", + "Burkina Faso", + "Burundi", + "Cambodia", + "Cameroon", + "Canada", + "Cape Verde", + "Cayman Islands", + "Central African Republic", + "Chad", + "Chile", + "China", + "Christmas Island", + "Cocos (Keeling) Islands", + "Colombia", + "Comoros", + "Congo", + "Cook Islands", + "Costa Rica", + "Croatia", + "Cuba", + "Curacao", + "Cyprus", + "Czechia", + "Democratic Republic of the Congo", + "Denmark", + "Djibouti", + "Dominica", + "Dominican Republic", + "Ecuador", + "Egypt", + "El Salvador", + "Equatorial Guinea", + "Eritrea", + "Estonia", + "Eswatini", + "Ethiopia", + "Faroe Islands", + "Falkland Islands (Malvinas)", + "Fiji", + "Finland", + "France", + "French Guiana", + "French Polynesia", + "French Southern Territories", + "Gabon", + "Gambia", + "Georgia", + "Germany", + "Ghana", + "Gibraltar", + "Greece", + "Greenland", + "Grenada", + "Guadeloupe", + "Guam", + "Guatemala", + "Guernsey", + "Guinea", + "Guinea-Bissau", + "Guyana", + "Haiti", + "Heard Island and McDonald Islands", + "Holy See (Vatican City State)", + "Honduras", + "Hong Kong", + "Hungary", + "Iceland", + "India", + "Indonesia", + "Iran", + "Iraq", + "Ireland", + "Isle of Man", + "Israel", + "Italy", + "Jamaica", + "Japan", + "Jersey", + "Jordan", + "Kazakhstan", + "Kenya", + "Kiribati", + "Republic of Korea", + "Kuwait", + "Kyrgyz Republic", + "Latvia", + "Lebanon", + "Lesotho", + "Liberia", + "Libyan Arab Jamahiriya", + "Liechtenstein", + "Lithuania", + "Luxembourg", + "Macao", + "Madagascar", + "Malawi", + "Malaysia", + "Maldives", + "Mali", + "Malta", + "Marshall Islands", + "Martinique", + "Mauritania", + "Mauritius", + "Mayotte", + "Mexico", + "Micronesia", + "Moldova", + "Monaco", + "Mongolia", + "Montenegro", + "Montserrat", + "Morocco", + "Mozambique", + "Myanmar", + "Namibia", + "Nauru", + "Nepal", + "Netherlands", + "New Caledonia", + "New Zealand", + "Nicaragua", + "Niger", + "Nigeria", + "Niue", + "Norfolk Island", + "North Macedonia", + "Northern Mariana Islands", + "Norway", + "Oman", + "Pakistan", + "Palau", + "Palestine", + "Panama", + "Papua New Guinea", + "Paraguay", + "Peru", + "Philippines", + "Pitcairn Islands", + "Poland", + "Portugal", + "Puerto Rico", + "Qatar", + "Reunion", + "Romania", + "Russian Federation", + "Rwanda", + "Saint Barthelemy", + "Saint Helena", + "Saint Kitts and Nevis", + "Saint Lucia", + "Saint Martin", + "Saint Pierre and Miquelon", + "Saint Vincent and the Grenadines", + "Samoa", + "San Marino", + "Sao Tome and Principe", + "Saudi Arabia", + "Senegal", + "Serbia", + "Seychelles", + "Sierra Leone", + "Singapore", + "Sint Maarten", + "Slovakia", + "Slovenia", + "Solomon Islands", + "Somalia", + "South Africa", + "South Georgia and the South Sandwich Islands", + "South Sudan", + "Spain", + "Sri Lanka", + "Sudan", + "Suriname", + "Svalbard & Jan Mayen Islands", + "Sweden", + "Switzerland", + "Syrian Arab Republic", + "Taiwan", + "Tajikistan", + "Tanzania", + "Thailand", + "Timor-Leste", + "Togo", + "Tokelau", + "Tonga", + "Trinidad and Tobago", + "Tunisia", + "Turkey", + "Turkmenistan", + "Turks and Caicos Islands", + "Tuvalu", + "Uganda", + "Ukraine", + "United Arab Emirates", + "United Kingdom", + "United States of America", + "United States Minor Outlying Islands", + "Uruguay", + "Uzbekistan", + "Vanuatu", + "Venezuela", + "Vietnam", + "Virgin Islands, British", + "Virgin Islands, U.S.", + "Wallis and Futuna", + "Western Sahara", + "Yemen", + "Zambia", + "Zimbabwe"}; const std::vector countryCodes = { "AD", "AE", "AF", "AG", "AI", "AL", "AM", "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", "BA", "BB", diff --git a/src/modules/person/Person.cpp b/src/modules/person/Person.cpp index 2aa267296..b5c7e2b62 100644 --- a/src/modules/person/Person.cpp +++ b/src/modules/person/Person.cpp @@ -1,30 +1,32 @@ #include "faker-cxx/Person.h" #include +#include #include #include "../../common/StringHelper.h" #include "data/czech/CzechPeopleNames.h" -#include "data/danish/DanishPeopleNames.h" -#include "data/english/EnglishPeopleNames.h" -#include "data/finnish/FinnishPeopleNames.h" -#include "data/french/FrenchPeopleNames.h" +#include "data/denmark/DanishPeopleNames.h" +#include "data/england/EnglishPeopleNames.h" +#include "data/finland/FinnishPeopleNames.h" +#include "data/france/FrenchPeopleNames.h" #include "data/Gender.h" -#include "data/german/GermanPeopleNames.h" +#include "data/germany/GermanPeopleNames.h" #include "data/Hobbies.h" -#include "data/indian/IndianPeopleNames.h" -#include "data/italian/ItalianPeopleNames.h" +#include "data/india/IndianPeopleNames.h" +#include "data/italy/ItalianPeopleNames.h" #include "data/JobTitles.h" #include "data/Nationalities.h" -#include "data/nepalese/NepalesePeopleNames.h" -#include "data/polish/PolishPeopleNames.h" -#include "data/romanian/RomanianPeopleNames.h" -#include "data/russian/RussianPeopleNames.h" -#include "data/slovak/SlovakPeopleNames.h" -#include "data/spanish/SpanishPeopleNames.h" -#include "data/swedish/SwedishPeopleNames.h" -#include "data/turkish/TurkishPeopleNames.h" -#include "data/ukrainian/UkrainianPeopleNames.h" +#include "data/nepal/NepalesePeopleNames.h" +#include "data/poland/PolishPeopleNames.h" +#include "data/romania/RomanianPeopleNames.h" +#include "data/russia/RussianPeopleNames.h" +#include "data/slovakia/SlovakPeopleNames.h" +#include "data/spain/SpanishPeopleNames.h" +#include "data/sweden/SwedishPeopleNames.h" +#include "data/turkey/TurkishPeopleNames.h" +#include "data/ukraine/UkrainianPeopleNames.h" +#include "data/usa/UsaPeopleNames.h" #include "data/ZodiacSigns.h" #include "faker-cxx/Helper.h" #include "fmt/format.h" @@ -35,25 +37,25 @@ namespace { const std::vector sexes{"Male", "Female"}; -const std::map languageToPeopleNamesMapping{ - {Language::English, englishPeopleNames}, {Language::French, frenchPeopleNames}, - {Language::German, germanPeopleNames}, {Language::Italian, italianPeopleNames}, - {Language::Polish, polishPeopleNames}, {Language::Russian, russianPeopleNames}, - {Language::Romanian, romanianPeopleNames}, {Language::Hindi, indianPeopleNames}, - {Language::Finnish, finnishPeopleNames}, {Language::Nepali, nepalesePeopleNames}, - {Language::Spanish, spanishPeopleNames}, {Language::Turkish, turkishPeopleNames}, - {Language::Czech, czechPeopleNames}, {Language::Slovak, slovakPeopleNames}, - {Language::Ukrainian, ukrainianPeopleNames}, {Language::Danish, danishPeopleNames}, - {Language::Swedish, swedishPeopleNames}}; - -std::string middleNameForLanguage(Language language, std::optional sex); -std::string prefixForLanguage(Language language, std::optional sex); -std::string suffixForLanguage(Language language, std::optional sex); +const std::map countryToPeopleNamesMapping{ + {Country::England, englishPeopleNames}, {Country::France, frenchPeopleNames}, + {Country::Germany, germanPeopleNames}, {Country::Italy, italianPeopleNames}, + {Country::Poland, polishPeopleNames}, {Country::Russia, russianPeopleNames}, + {Country::Romania, romanianPeopleNames}, {Country::India, indianPeopleNames}, + {Country::Finland, finnishPeopleNames}, {Country::Nepal, nepalesePeopleNames}, + {Country::Spain, spanishPeopleNames}, {Country::Turkey, turkishPeopleNames}, + {Country::Czech, czechPeopleNames}, {Country::Slovakia, slovakPeopleNames}, + {Country::Ukraine, ukrainianPeopleNames}, {Country::Denmark, danishPeopleNames}, + {Country::Sweden, swedishPeopleNames}, {Country::Usa, usaPeopleNames}}; + +std::string middleNameForCountry(Country country, std::optional sex); +std::string prefixForCountry(Country country, std::optional sex); +std::string suffixForCountry(Country country, std::optional sex); } -std::string Person::firstName(Language language, std::optional sex) +std::string Person::firstName(Country country, std::optional sex) { - const auto& peopleNames = languageToPeopleNamesMapping.at(language); + const auto& peopleNames = countryToPeopleNamesMapping.at(country); std::vector firstNames; @@ -81,9 +83,9 @@ std::string Person::firstName(Language language, std::optional sex) return Helper::arrayElement(firstNames); } -std::string Person::lastName(Language language, std::optional sex) +std::string Person::lastName(Country country, std::optional sex) { - const auto& peopleNames = languageToPeopleNamesMapping.at(language); + const auto& peopleNames = countryToPeopleNamesMapping.at(country); std::vector lastNames; @@ -115,7 +117,7 @@ std::string Person::middleName(std::optional sex) { std::vector allMiddleNames; - for (const auto& [_, peopleNames] : languageToPeopleNamesMapping) + for (const auto& [_, peopleNames] : countryToPeopleNamesMapping) { std::vector middleNames; @@ -155,9 +157,9 @@ std::string Person::middleName(std::optional sex) return Helper::arrayElement(allMiddleNames); } -std::string Person::fullName(Language language, std::optional sex) +std::string Person::fullName(Country country, std::optional sex) { - const auto& peopleNames = languageToPeopleNamesMapping.at(language); + const auto& peopleNames = countryToPeopleNamesMapping.at(country); std::vector> weightedElements; @@ -168,42 +170,62 @@ std::string Person::fullName(Language language, std::optional sex) const auto nameFormat = Helper::weightedArrayElement(weightedElements); - const auto nameFormatElements = StringHelper::split(nameFormat, " "); + std::string fullName; - std::vector nameElements; + int tokenStart = -1; - for (const auto& nameFormatElement : nameFormatElements) + for (auto i = 0u; i <= nameFormat.size(); i++) { - if (nameFormatElement == "{firstName}") + if (nameFormat[i] == '{') { - nameElements.push_back(Person::firstName(language, sex)); + tokenStart = static_cast(i) + 1; } - else if (nameFormatElement == "{middleName}") + else if (nameFormat[i] == '}' && tokenStart != -1 && static_cast(tokenStart) < i) { - nameElements.push_back(middleNameForLanguage(language, sex)); + const auto token = + nameFormat.substr(static_cast(tokenStart), i - static_cast(tokenStart)); + + std::string nameElement; + + if (token == "firstName") + { + nameElement = Person::firstName(country, sex); + } + else if (token == "middleName") + { + nameElement = middleNameForCountry(country, sex); + } + else if (token == "lastName") + { + nameElement = Person::lastName(country, sex); + } + else if (token == "prefix") + { + nameElement = prefixForCountry(country, sex); + } + else if (token == "suffix") + { + nameElement = suffixForCountry(country, sex); + } + + fullName += nameElement; + + tokenStart = -1; } - else if (nameFormatElement == "{lastName}") + else if (tokenStart == -1) { - nameElements.push_back(Person::lastName(language, sex)); - } - else if (nameFormatElement == "{prefix}") - { - nameElements.push_back(prefixForLanguage(language, sex)); - } - else if (nameFormatElement == "{suffix}") - { - nameElements.push_back(suffixForLanguage(language, sex)); + fullName += nameFormat[i]; } } - return StringHelper::join(nameElements, " "); + return fullName; } std::string Person::prefix(std::optional sex) { std::vector allPrefixes; - for (const auto& [_, peopleNames] : languageToPeopleNamesMapping) + for (const auto& [_, peopleNames] : countryToPeopleNamesMapping) { std::vector prefixes; @@ -247,7 +269,7 @@ std::string Person::suffix() { std::vector allSuffixes; - for (const auto& [_, peopleNames] : languageToPeopleNamesMapping) + for (const auto& [_, peopleNames] : countryToPeopleNamesMapping) { std::vector suffixes; @@ -314,9 +336,9 @@ std::string Person::nationality() namespace { -std::string middleNameForLanguage(Language language, std::optional sex) +std::string middleNameForCountry(Country country, std::optional sex) { - const auto& peopleNames = languageToPeopleNamesMapping.at(language); + const auto& peopleNames = countryToPeopleNamesMapping.at(country); std::vector middleNames; @@ -344,9 +366,9 @@ std::string middleNameForLanguage(Language language, std::optional sex) return Helper::arrayElement(middleNames); } -std::string prefixForLanguage(Language language, std::optional sex) +std::string prefixForCountry(Country country, std::optional sex) { - const auto& peopleNames = languageToPeopleNamesMapping.at(language); + const auto& peopleNames = countryToPeopleNamesMapping.at(country); std::vector prefixes; @@ -374,9 +396,9 @@ std::string prefixForLanguage(Language language, std::optional sex) return Helper::arrayElement(prefixes); } -std::string suffixForLanguage(Language language, std::optional sex) +std::string suffixForCountry(Country country, std::optional sex) { - const auto& peopleNames = languageToPeopleNamesMapping.at(language); + const auto& peopleNames = countryToPeopleNamesMapping.at(country); std::vector suffixes; diff --git a/src/modules/person/PersonTest.cpp b/src/modules/person/PersonTest.cpp index f4a1e7599..c3cca5dd4 100644 --- a/src/modules/person/PersonTest.cpp +++ b/src/modules/person/PersonTest.cpp @@ -6,28 +6,29 @@ #include "../../common/StringHelper.h" #include "data/czech/CzechPeopleNames.h" -#include "data/danish/DanishPeopleNames.h" -#include "data/english/EnglishPeopleNames.h" -#include "data/finnish/FinnishPeopleNames.h" -#include "data/french/FrenchPeopleNames.h" +#include "data/denmark/DanishPeopleNames.h" +#include "data/england/EnglishPeopleNames.h" +#include "data/finland/FinnishPeopleNames.h" +#include "data/france/FrenchPeopleNames.h" #include "data/Gender.h" -#include "data/german/GermanPeopleNames.h" +#include "data/germany/GermanPeopleNames.h" #include "data/Hobbies.h" -#include "data/indian/IndianPeopleNames.h" -#include "data/italian/ItalianPeopleNames.h" +#include "data/india/IndianPeopleNames.h" +#include "data/italy/ItalianPeopleNames.h" #include "data/JobTitles.h" #include "data/Nationalities.h" -#include "data/nepalese/NepalesePeopleNames.h" -#include "data/polish/PolishPeopleNames.h" -#include "data/romanian/RomanianPeopleNames.h" -#include "data/russian/RussianPeopleNames.h" -#include "data/slovak/SlovakPeopleNames.h" -#include "data/spanish/SpanishPeopleNames.h" -#include "data/swedish/SwedishPeopleNames.h" -#include "data/turkish/TurkishPeopleNames.h" -#include "data/ukrainian/UkrainianPeopleNames.h" +#include "data/nepal/NepalesePeopleNames.h" +#include "data/poland/PolishPeopleNames.h" +#include "data/romania/RomanianPeopleNames.h" +#include "data/russia/RussianPeopleNames.h" +#include "data/slovakia/SlovakPeopleNames.h" +#include "data/spain/SpanishPeopleNames.h" +#include "data/sweden/SwedishPeopleNames.h" +#include "data/turkey/TurkishPeopleNames.h" +#include "data/ukraine/UkrainianPeopleNames.h" #include "data/ZodiacSigns.h" #include "src/modules/person/data/PeopleNames.h" +#include "src/modules/person/data/usa/UsaPeopleNames.h" using namespace ::testing; using namespace faker; @@ -36,30 +37,30 @@ namespace { const std::vector sexes{"Male", "Female"}; -const std::map languageToPeopleNamesMapping{ - {Language::English, englishPeopleNames}, {Language::French, frenchPeopleNames}, - {Language::German, germanPeopleNames}, {Language::Italian, italianPeopleNames}, - {Language::Polish, polishPeopleNames}, {Language::Russian, russianPeopleNames}, - {Language::Romanian, romanianPeopleNames}, {Language::Hindi, indianPeopleNames}, - {Language::Finnish, finnishPeopleNames}, {Language::Nepali, nepalesePeopleNames}, - {Language::Spanish, spanishPeopleNames}, {Language::Turkish, turkishPeopleNames}, - {Language::Czech, czechPeopleNames}, {Language::Slovak, slovakPeopleNames}, - {Language::Ukrainian, ukrainianPeopleNames}, {Language::Danish, danishPeopleNames}, - {Language::Swedish, swedishPeopleNames}}; - -const std::map generatedTestName{ - {Language::English, "shouldGenerateEnglishName"}, {Language::French, "shouldGenerateFrenchName"}, - {Language::German, "shouldGenerateGermanName"}, {Language::Italian, "shouldGenerateItalianName"}, - {Language::Polish, "shouldGeneratePolishName"}, {Language::Russian, "shouldGenerateRussianName"}, - {Language::Romanian, "shouldGenerateRomanianName"}, {Language::Hindi, "shouldGenerateIndianName"}, - {Language::Finnish, "shouldGenerateFinnishName"}, {Language::Nepali, "shouldGenerateNepaleseName"}, - {Language::Spanish, "shouldGenerateSpanishName"}, {Language::Turkish, "shouldGenerateTurkishName"}, - {Language::Czech, "shouldGenerateCzechName"}, {Language::Slovak, "shouldGenerateSlovakName"}, - {Language::Ukrainian, "shouldGenerateUkrainianName"}, {Language::Danish, "shouldGenerateDanishName"}, - {Language::Swedish, "shouldGenerateSwedishName"}}; +const std::map countryToPeopleNamesMapping{ + {Country::England, englishPeopleNames}, {Country::France, frenchPeopleNames}, + {Country::Germany, germanPeopleNames}, {Country::Italy, italianPeopleNames}, + {Country::Poland, polishPeopleNames}, {Country::Russia, russianPeopleNames}, + {Country::Romania, romanianPeopleNames}, {Country::India, indianPeopleNames}, + {Country::Finland, finnishPeopleNames}, {Country::Nepal, nepalesePeopleNames}, + {Country::Spain, spanishPeopleNames}, {Country::Turkey, turkishPeopleNames}, + {Country::Czech, czechPeopleNames}, {Country::Slovakia, slovakPeopleNames}, + {Country::Ukraine, ukrainianPeopleNames}, {Country::Denmark, danishPeopleNames}, + {Country::Sweden, swedishPeopleNames}, {Country::Usa, usaPeopleNames}}; + +const std::map generatedTestName{ + {Country::England, "shouldGenerateEnglishName"}, {Country::France, "shouldGenerateFrenchName"}, + {Country::Germany, "shouldGenerateGermanName"}, {Country::Italy, "shouldGenerateItalianName"}, + {Country::Poland, "shouldGeneratePolishName"}, {Country::Russia, "shouldGenerateRussianName"}, + {Country::Romania, "shouldGenerateRomanianName"}, {Country::India, "shouldGenerateIndianName"}, + {Country::Finland, "shouldGenerateFinnishName"}, {Country::Nepal, "shouldGenerateNepaleseName"}, + {Country::Spain, "shouldGenerateSpanishName"}, {Country::Turkey, "shouldGenerateTurkishName"}, + {Country::Czech, "shouldGenerateCzechName"}, {Country::Slovakia, "shouldGenerateSlovakName"}, + {Country::Ukraine, "shouldGenerateUkrainianName"}, {Country::Denmark, "shouldGenerateDanishName"}, + {Country::Sweden, "shouldGenerateSwedishName"}, {Country::Usa, "shouldGenerateAmericanName"}}; } -class PersonTest : public TestWithParam +class PersonTest : public TestWithParam { public: PersonTest() @@ -73,7 +74,7 @@ class PersonTest : public TestWithParam void initializePrefixes() { - for (const auto& [_, peopleNames] : languageToPeopleNamesMapping) + for (const auto& [_, peopleNames] : countryToPeopleNamesMapping) { malesPrefixes.insert(malesPrefixes.end(), peopleNames.malesNames.prefixes.begin(), peopleNames.malesNames.prefixes.end()); @@ -90,7 +91,7 @@ class PersonTest : public TestWithParam void initializeSuffixes() { - for (const auto& [_, peopleNames] : languageToPeopleNamesMapping) + for (const auto& [_, peopleNames] : countryToPeopleNamesMapping) { malesSuffixes.insert(malesSuffixes.end(), peopleNames.malesNames.suffixes.begin(), peopleNames.malesNames.suffixes.end()); @@ -107,7 +108,7 @@ class PersonTest : public TestWithParam void initializeMiddleNames() { - for (const auto& [_, peopleNames] : languageToPeopleNamesMapping) + for (const auto& [_, peopleNames] : countryToPeopleNamesMapping) { malesMiddleNames.insert(malesMiddleNames.end(), peopleNames.malesNames.middleNames.begin(), peopleNames.malesNames.middleNames.end()); @@ -135,9 +136,9 @@ class PersonTest : public TestWithParam TEST_P(PersonTest, shouldGenerateFirstName) { - const auto language = GetParam(); + const auto country = GetParam(); - const auto& peopleNames = languageToPeopleNamesMapping.at(language); + const auto& peopleNames = countryToPeopleNamesMapping.at(country); const auto& malesFirstNames = peopleNames.malesNames.firstNames; const auto& femalesFirstNames = peopleNames.femalesNames.firstNames; @@ -146,7 +147,7 @@ TEST_P(PersonTest, shouldGenerateFirstName) firstNames.insert(firstNames.end(), femalesFirstNames.begin(), femalesFirstNames.end()); - const auto generatedFirstName = Person::firstName(language); + const auto generatedFirstName = Person::firstName(country); ASSERT_TRUE(std::ranges::any_of(firstNames, [generatedFirstName](const std::string& firstName) { return firstName == generatedFirstName; })); @@ -154,13 +155,13 @@ TEST_P(PersonTest, shouldGenerateFirstName) TEST_P(PersonTest, shouldGenerateMaleFirstName) { - const auto language = GetParam(); + const auto country = GetParam(); - const auto& peopleNames = languageToPeopleNamesMapping.at(language); + const auto& peopleNames = countryToPeopleNamesMapping.at(country); const auto& malesFirstNames = peopleNames.malesNames.firstNames; - const auto generatedFirstName = Person::firstName(language, Sex::Male); + const auto generatedFirstName = Person::firstName(country, Sex::Male); ASSERT_TRUE(std::ranges::any_of(malesFirstNames, [generatedFirstName](const std::string& firstName) { return firstName == generatedFirstName; })); @@ -168,13 +169,13 @@ TEST_P(PersonTest, shouldGenerateMaleFirstName) TEST_P(PersonTest, shouldGenerateFemaleFirstName) { - const auto language = GetParam(); + const auto country = GetParam(); - const auto& peopleNames = languageToPeopleNamesMapping.at(language); + const auto& peopleNames = countryToPeopleNamesMapping.at(country); const auto& femalesFirstNames = peopleNames.femalesNames.firstNames; - const auto generatedFirstName = Person::firstName(language, Sex::Female); + const auto generatedFirstName = Person::firstName(country, Sex::Female); ASSERT_TRUE(std::ranges::any_of(femalesFirstNames, [generatedFirstName](const std::string& firstName) { return firstName == generatedFirstName; })); @@ -182,13 +183,13 @@ TEST_P(PersonTest, shouldGenerateFemaleFirstName) TEST_P(PersonTest, shouldGenerateLastNameMale) { - const auto language = GetParam(); + const auto country = GetParam(); - const auto& peopleNames = languageToPeopleNamesMapping.at(language); + const auto& peopleNames = countryToPeopleNamesMapping.at(country); const auto& malesLastNames = peopleNames.malesNames.lastNames; - const auto generatedLastName = Person::lastName(language, Sex::Male); + const auto generatedLastName = Person::lastName(country, Sex::Male); ASSERT_TRUE(std::ranges::any_of(malesLastNames, [generatedLastName](const std::string& lastName) { return lastName == generatedLastName; })); @@ -196,13 +197,13 @@ TEST_P(PersonTest, shouldGenerateLastNameMale) TEST_P(PersonTest, shouldGenerateLastNameFemale) { - const auto language = GetParam(); + const auto country = GetParam(); - const auto& peopleNames = languageToPeopleNamesMapping.at(language); + const auto& peopleNames = countryToPeopleNamesMapping.at(country); const auto& femalesLastNames = peopleNames.femalesNames.lastNames; - const auto generatedLastName = Person::lastName(language, Sex::Female); + const auto generatedLastName = Person::lastName(country, Sex::Female); ASSERT_TRUE(std::ranges::any_of(femalesLastNames, [generatedLastName](const std::string& lastName) { return lastName == generatedLastName; })); @@ -210,9 +211,9 @@ TEST_P(PersonTest, shouldGenerateLastNameFemale) TEST_P(PersonTest, shouldGenerateFullName) { - const auto language = GetParam(); + const auto country = GetParam(); - const auto& peopleNames = languageToPeopleNamesMapping.at(language); + const auto& peopleNames = countryToPeopleNamesMapping.at(country); const auto& malesFirstNames = peopleNames.malesNames.firstNames; const auto& femalesFirstNames = peopleNames.femalesNames.firstNames; @@ -226,7 +227,7 @@ TEST_P(PersonTest, shouldGenerateFullName) firstNames.insert(firstNames.end(), femalesFirstNames.begin(), femalesFirstNames.end()); lastNames.insert(lastNames.end(), femalesLastNames.begin(), femalesLastNames.end()); - const auto generatedFullName = Person::fullName(language); + const auto generatedFullName = Person::fullName(country); ASSERT_TRUE(std::ranges::any_of(firstNames, [generatedFullName](const std::string& firstName) { return generatedFullName.find(firstName) != std::string::npos; })); @@ -236,15 +237,15 @@ TEST_P(PersonTest, shouldGenerateFullName) TEST_P(PersonTest, shouldGenerateMaleFullName) { - const auto language = GetParam(); + const auto country = GetParam(); - const auto& peopleNames = languageToPeopleNamesMapping.at(language); + const auto& peopleNames = countryToPeopleNamesMapping.at(country); const auto& malesFirstNames = peopleNames.malesNames.firstNames; const auto& malesLastNames = peopleNames.malesNames.lastNames; - const auto generatedFullName = Person::fullName(language, Sex::Male); + const auto generatedFullName = Person::fullName(country, Sex::Male); ASSERT_TRUE(std::ranges::any_of(malesFirstNames, [generatedFullName](const std::string& firstName) { return generatedFullName.find(firstName) != std::string::npos; })); @@ -254,15 +255,15 @@ TEST_P(PersonTest, shouldGenerateMaleFullName) TEST_P(PersonTest, shouldGenerateFemaleFullName) { - const auto language = GetParam(); + const auto country = GetParam(); - const auto& peopleNames = languageToPeopleNamesMapping.at(language); + const auto& peopleNames = countryToPeopleNamesMapping.at(country); const auto& femalesFirstNames = peopleNames.femalesNames.firstNames; const auto& femalesLastNames = peopleNames.femalesNames.lastNames; - const auto generatedFullName = Person::fullName(language, Sex::Female); + const auto generatedFullName = Person::fullName(country, Sex::Female); ASSERT_TRUE(std::ranges::any_of(femalesFirstNames, [generatedFullName](const std::string& firstName) { return generatedFullName.find(firstName) != std::string::npos; })); @@ -270,8 +271,8 @@ TEST_P(PersonTest, shouldGenerateFemaleFullName) { return generatedFullName.find(lastName) != std::string::npos; })); } -INSTANTIATE_TEST_SUITE_P(TestPersonNamesByLanguages, PersonTest, ValuesIn(languages), - [](const TestParamInfo& info) { return generatedTestName.at(info.param); }); +INSTANTIATE_TEST_SUITE_P(TestPersonNamesByCountries, PersonTest, ValuesIn(countries), + [](const TestParamInfo& info) { return generatedTestName.at(info.param); }); TEST_F(PersonTest, shouldGenerateMiddleName) { diff --git a/src/modules/person/data/danish/DanishFirstNames.h b/src/modules/person/data/denmark/DanishFirstNames.h similarity index 100% rename from src/modules/person/data/danish/DanishFirstNames.h rename to src/modules/person/data/denmark/DanishFirstNames.h diff --git a/src/modules/person/data/danish/DanishLastNames.h b/src/modules/person/data/denmark/DanishLastNames.h similarity index 100% rename from src/modules/person/data/danish/DanishLastNames.h rename to src/modules/person/data/denmark/DanishLastNames.h diff --git a/src/modules/person/data/danish/DanishMiddleNames.h b/src/modules/person/data/denmark/DanishMiddleNames.h similarity index 100% rename from src/modules/person/data/danish/DanishMiddleNames.h rename to src/modules/person/data/denmark/DanishMiddleNames.h diff --git a/src/modules/person/data/danish/DanishPeopleNames.h b/src/modules/person/data/denmark/DanishPeopleNames.h similarity index 100% rename from src/modules/person/data/danish/DanishPeopleNames.h rename to src/modules/person/data/denmark/DanishPeopleNames.h diff --git a/src/modules/person/data/danish/DanishPrefixes.h b/src/modules/person/data/denmark/DanishPrefixes.h similarity index 100% rename from src/modules/person/data/danish/DanishPrefixes.h rename to src/modules/person/data/denmark/DanishPrefixes.h diff --git a/src/modules/person/data/english/EnglishFirstNames.h b/src/modules/person/data/england/EnglishFirstNames.h similarity index 100% rename from src/modules/person/data/english/EnglishFirstNames.h rename to src/modules/person/data/england/EnglishFirstNames.h diff --git a/src/modules/person/data/english/EnglishLastNames.h b/src/modules/person/data/england/EnglishLastNames.h similarity index 100% rename from src/modules/person/data/english/EnglishLastNames.h rename to src/modules/person/data/england/EnglishLastNames.h diff --git a/src/modules/person/data/english/EnglishPeopleNames.h b/src/modules/person/data/england/EnglishPeopleNames.h similarity index 100% rename from src/modules/person/data/english/EnglishPeopleNames.h rename to src/modules/person/data/england/EnglishPeopleNames.h diff --git a/src/modules/person/data/english/EnglishPrefixes.h b/src/modules/person/data/england/EnglishPrefixes.h similarity index 100% rename from src/modules/person/data/english/EnglishPrefixes.h rename to src/modules/person/data/england/EnglishPrefixes.h diff --git a/src/modules/person/data/english/EnglishSuffixes.h b/src/modules/person/data/england/EnglishSuffixes.h similarity index 100% rename from src/modules/person/data/english/EnglishSuffixes.h rename to src/modules/person/data/england/EnglishSuffixes.h diff --git a/src/modules/person/data/finnish/FinnishFirstNames.h b/src/modules/person/data/finland/FinnishFirstNames.h similarity index 100% rename from src/modules/person/data/finnish/FinnishFirstNames.h rename to src/modules/person/data/finland/FinnishFirstNames.h diff --git a/src/modules/person/data/finnish/FinnishLastNames.h b/src/modules/person/data/finland/FinnishLastNames.h similarity index 100% rename from src/modules/person/data/finnish/FinnishLastNames.h rename to src/modules/person/data/finland/FinnishLastNames.h diff --git a/src/modules/person/data/finnish/FinnishPeopleNames.h b/src/modules/person/data/finland/FinnishPeopleNames.h similarity index 100% rename from src/modules/person/data/finnish/FinnishPeopleNames.h rename to src/modules/person/data/finland/FinnishPeopleNames.h diff --git a/src/modules/person/data/french/FrenchFirstNames.h b/src/modules/person/data/france/FrenchFirstNames.h similarity index 100% rename from src/modules/person/data/french/FrenchFirstNames.h rename to src/modules/person/data/france/FrenchFirstNames.h diff --git a/src/modules/person/data/french/FrenchLastNames.h b/src/modules/person/data/france/FrenchLastNames.h similarity index 100% rename from src/modules/person/data/french/FrenchLastNames.h rename to src/modules/person/data/france/FrenchLastNames.h diff --git a/src/modules/person/data/french/FrenchPeopleNames.h b/src/modules/person/data/france/FrenchPeopleNames.h similarity index 100% rename from src/modules/person/data/french/FrenchPeopleNames.h rename to src/modules/person/data/france/FrenchPeopleNames.h diff --git a/src/modules/person/data/french/FrenchPrefixes.h b/src/modules/person/data/france/FrenchPrefixes.h similarity index 100% rename from src/modules/person/data/french/FrenchPrefixes.h rename to src/modules/person/data/france/FrenchPrefixes.h diff --git a/src/modules/person/data/german/GermanFirstNames.h b/src/modules/person/data/germany/GermanFirstNames.h similarity index 100% rename from src/modules/person/data/german/GermanFirstNames.h rename to src/modules/person/data/germany/GermanFirstNames.h diff --git a/src/modules/person/data/german/GermanLastNames.h b/src/modules/person/data/germany/GermanLastNames.h similarity index 100% rename from src/modules/person/data/german/GermanLastNames.h rename to src/modules/person/data/germany/GermanLastNames.h diff --git a/src/modules/person/data/german/GermanPeopleNames.h b/src/modules/person/data/germany/GermanPeopleNames.h similarity index 100% rename from src/modules/person/data/german/GermanPeopleNames.h rename to src/modules/person/data/germany/GermanPeopleNames.h diff --git a/src/modules/person/data/german/GermanPrefixes.h b/src/modules/person/data/germany/GermanPrefixes.h similarity index 100% rename from src/modules/person/data/german/GermanPrefixes.h rename to src/modules/person/data/germany/GermanPrefixes.h diff --git a/src/modules/person/data/indian/IndianFirstNames.h b/src/modules/person/data/india/IndianFirstNames.h similarity index 100% rename from src/modules/person/data/indian/IndianFirstNames.h rename to src/modules/person/data/india/IndianFirstNames.h diff --git a/src/modules/person/data/indian/IndianLastNames.h b/src/modules/person/data/india/IndianLastNames.h similarity index 100% rename from src/modules/person/data/indian/IndianLastNames.h rename to src/modules/person/data/india/IndianLastNames.h diff --git a/src/modules/person/data/indian/IndianPeopleNames.h b/src/modules/person/data/india/IndianPeopleNames.h similarity index 100% rename from src/modules/person/data/indian/IndianPeopleNames.h rename to src/modules/person/data/india/IndianPeopleNames.h diff --git a/src/modules/person/data/italian/ItalianFirstNames.h b/src/modules/person/data/italy/ItalianFirstNames.h similarity index 100% rename from src/modules/person/data/italian/ItalianFirstNames.h rename to src/modules/person/data/italy/ItalianFirstNames.h diff --git a/src/modules/person/data/italian/ItalianLastNames.h b/src/modules/person/data/italy/ItalianLastNames.h similarity index 100% rename from src/modules/person/data/italian/ItalianLastNames.h rename to src/modules/person/data/italy/ItalianLastNames.h diff --git a/src/modules/person/data/italian/ItalianPeopleNames.h b/src/modules/person/data/italy/ItalianPeopleNames.h similarity index 100% rename from src/modules/person/data/italian/ItalianPeopleNames.h rename to src/modules/person/data/italy/ItalianPeopleNames.h diff --git a/src/modules/person/data/italian/ItalianPrefixes.h b/src/modules/person/data/italy/ItalianPrefixes.h similarity index 100% rename from src/modules/person/data/italian/ItalianPrefixes.h rename to src/modules/person/data/italy/ItalianPrefixes.h diff --git a/src/modules/person/data/nepalese/NepaleseFirstNames.h b/src/modules/person/data/nepal/NepaleseFirstNames.h similarity index 100% rename from src/modules/person/data/nepalese/NepaleseFirstNames.h rename to src/modules/person/data/nepal/NepaleseFirstNames.h diff --git a/src/modules/person/data/nepalese/NepaleseLastNames.h b/src/modules/person/data/nepal/NepaleseLastNames.h similarity index 100% rename from src/modules/person/data/nepalese/NepaleseLastNames.h rename to src/modules/person/data/nepal/NepaleseLastNames.h diff --git a/src/modules/person/data/nepalese/NepalesePeopleNames.h b/src/modules/person/data/nepal/NepalesePeopleNames.h similarity index 100% rename from src/modules/person/data/nepalese/NepalesePeopleNames.h rename to src/modules/person/data/nepal/NepalesePeopleNames.h diff --git a/src/modules/person/data/polish/PolishFirstNames.h b/src/modules/person/data/poland/PolishFirstNames.h similarity index 100% rename from src/modules/person/data/polish/PolishFirstNames.h rename to src/modules/person/data/poland/PolishFirstNames.h diff --git a/src/modules/person/data/polish/PolishLastNames.h b/src/modules/person/data/poland/PolishLastNames.h similarity index 100% rename from src/modules/person/data/polish/PolishLastNames.h rename to src/modules/person/data/poland/PolishLastNames.h diff --git a/src/modules/person/data/polish/PolishPeopleNames.h b/src/modules/person/data/poland/PolishPeopleNames.h similarity index 100% rename from src/modules/person/data/polish/PolishPeopleNames.h rename to src/modules/person/data/poland/PolishPeopleNames.h diff --git a/src/modules/person/data/polish/PolishPrefixes.h b/src/modules/person/data/poland/PolishPrefixes.h similarity index 100% rename from src/modules/person/data/polish/PolishPrefixes.h rename to src/modules/person/data/poland/PolishPrefixes.h diff --git a/src/modules/person/data/romanian/RomanianFirstNames.h b/src/modules/person/data/romania/RomanianFirstNames.h similarity index 100% rename from src/modules/person/data/romanian/RomanianFirstNames.h rename to src/modules/person/data/romania/RomanianFirstNames.h diff --git a/src/modules/person/data/romanian/RomanianLastNames.h b/src/modules/person/data/romania/RomanianLastNames.h similarity index 100% rename from src/modules/person/data/romanian/RomanianLastNames.h rename to src/modules/person/data/romania/RomanianLastNames.h diff --git a/src/modules/person/data/romanian/RomanianPeopleNames.h b/src/modules/person/data/romania/RomanianPeopleNames.h similarity index 100% rename from src/modules/person/data/romanian/RomanianPeopleNames.h rename to src/modules/person/data/romania/RomanianPeopleNames.h diff --git a/src/modules/person/data/romanian/RomanianPrefixes.h b/src/modules/person/data/romania/RomanianPrefixes.h similarity index 100% rename from src/modules/person/data/romanian/RomanianPrefixes.h rename to src/modules/person/data/romania/RomanianPrefixes.h diff --git a/src/modules/person/data/romanian/RomanianSuffixes.h b/src/modules/person/data/romania/RomanianSuffixes.h similarity index 100% rename from src/modules/person/data/romanian/RomanianSuffixes.h rename to src/modules/person/data/romania/RomanianSuffixes.h diff --git a/src/modules/person/data/russian/RussianFirstNames.h b/src/modules/person/data/russia/RussianFirstNames.h similarity index 100% rename from src/modules/person/data/russian/RussianFirstNames.h rename to src/modules/person/data/russia/RussianFirstNames.h diff --git a/src/modules/person/data/russian/RussianLastNames.h b/src/modules/person/data/russia/RussianLastNames.h similarity index 100% rename from src/modules/person/data/russian/RussianLastNames.h rename to src/modules/person/data/russia/RussianLastNames.h diff --git a/src/modules/person/data/russian/RussianMiddleNames.h b/src/modules/person/data/russia/RussianMiddleNames.h similarity index 100% rename from src/modules/person/data/russian/RussianMiddleNames.h rename to src/modules/person/data/russia/RussianMiddleNames.h diff --git a/src/modules/person/data/russian/RussianPeopleNames.h b/src/modules/person/data/russia/RussianPeopleNames.h similarity index 100% rename from src/modules/person/data/russian/RussianPeopleNames.h rename to src/modules/person/data/russia/RussianPeopleNames.h diff --git a/src/modules/person/data/slovak/SlovakFirstNames.h b/src/modules/person/data/slovakia/SlovakFirstNames.h similarity index 100% rename from src/modules/person/data/slovak/SlovakFirstNames.h rename to src/modules/person/data/slovakia/SlovakFirstNames.h diff --git a/src/modules/person/data/slovak/SlovakLastNames.h b/src/modules/person/data/slovakia/SlovakLastNames.h similarity index 100% rename from src/modules/person/data/slovak/SlovakLastNames.h rename to src/modules/person/data/slovakia/SlovakLastNames.h diff --git a/src/modules/person/data/slovak/SlovakPeopleNames.h b/src/modules/person/data/slovakia/SlovakPeopleNames.h similarity index 100% rename from src/modules/person/data/slovak/SlovakPeopleNames.h rename to src/modules/person/data/slovakia/SlovakPeopleNames.h diff --git a/src/modules/person/data/slovak/SlovakPrefixes.h b/src/modules/person/data/slovakia/SlovakPrefixes.h similarity index 100% rename from src/modules/person/data/slovak/SlovakPrefixes.h rename to src/modules/person/data/slovakia/SlovakPrefixes.h diff --git a/src/modules/person/data/slovak/SlovakSuffixes.h b/src/modules/person/data/slovakia/SlovakSuffixes.h similarity index 100% rename from src/modules/person/data/slovak/SlovakSuffixes.h rename to src/modules/person/data/slovakia/SlovakSuffixes.h diff --git a/src/modules/person/data/spanish/SpanishFirstNames.h b/src/modules/person/data/spain/SpanishFirstNames.h similarity index 100% rename from src/modules/person/data/spanish/SpanishFirstNames.h rename to src/modules/person/data/spain/SpanishFirstNames.h diff --git a/src/modules/person/data/spanish/SpanishLastNames.h b/src/modules/person/data/spain/SpanishLastNames.h similarity index 100% rename from src/modules/person/data/spanish/SpanishLastNames.h rename to src/modules/person/data/spain/SpanishLastNames.h diff --git a/src/modules/person/data/spanish/SpanishPeopleNames.h b/src/modules/person/data/spain/SpanishPeopleNames.h similarity index 100% rename from src/modules/person/data/spanish/SpanishPeopleNames.h rename to src/modules/person/data/spain/SpanishPeopleNames.h diff --git a/src/modules/person/data/spanish/SpanishPrefixes.h b/src/modules/person/data/spain/SpanishPrefixes.h similarity index 100% rename from src/modules/person/data/spanish/SpanishPrefixes.h rename to src/modules/person/data/spain/SpanishPrefixes.h diff --git a/src/modules/person/data/swedish/SwedishFirstNames.h b/src/modules/person/data/sweden/SwedishFirstNames.h similarity index 100% rename from src/modules/person/data/swedish/SwedishFirstNames.h rename to src/modules/person/data/sweden/SwedishFirstNames.h diff --git a/src/modules/person/data/swedish/SwedishLastNames.h b/src/modules/person/data/sweden/SwedishLastNames.h similarity index 100% rename from src/modules/person/data/swedish/SwedishLastNames.h rename to src/modules/person/data/sweden/SwedishLastNames.h diff --git a/src/modules/person/data/swedish/SwedishPeopleNames.h b/src/modules/person/data/sweden/SwedishPeopleNames.h similarity index 100% rename from src/modules/person/data/swedish/SwedishPeopleNames.h rename to src/modules/person/data/sweden/SwedishPeopleNames.h diff --git a/src/modules/person/data/swedish/SwedishPrefixes.h b/src/modules/person/data/sweden/SwedishPrefixes.h similarity index 100% rename from src/modules/person/data/swedish/SwedishPrefixes.h rename to src/modules/person/data/sweden/SwedishPrefixes.h diff --git a/src/modules/person/data/turkish/TurkishFirstNames.h b/src/modules/person/data/turkey/TurkishFirstNames.h similarity index 100% rename from src/modules/person/data/turkish/TurkishFirstNames.h rename to src/modules/person/data/turkey/TurkishFirstNames.h diff --git a/src/modules/person/data/turkish/TurkishLastNames.h b/src/modules/person/data/turkey/TurkishLastNames.h similarity index 100% rename from src/modules/person/data/turkish/TurkishLastNames.h rename to src/modules/person/data/turkey/TurkishLastNames.h diff --git a/src/modules/person/data/turkish/TurkishPeopleNames.h b/src/modules/person/data/turkey/TurkishPeopleNames.h similarity index 100% rename from src/modules/person/data/turkish/TurkishPeopleNames.h rename to src/modules/person/data/turkey/TurkishPeopleNames.h diff --git a/src/modules/person/data/turkish/TurkishPrefixes.h b/src/modules/person/data/turkey/TurkishPrefixes.h similarity index 100% rename from src/modules/person/data/turkish/TurkishPrefixes.h rename to src/modules/person/data/turkey/TurkishPrefixes.h diff --git a/src/modules/person/data/ukrainian/UkrainianFirstNames.h b/src/modules/person/data/ukraine/UkrainianFirstNames.h similarity index 100% rename from src/modules/person/data/ukrainian/UkrainianFirstNames.h rename to src/modules/person/data/ukraine/UkrainianFirstNames.h diff --git a/src/modules/person/data/ukrainian/UkrainianLastNames.h b/src/modules/person/data/ukraine/UkrainianLastNames.h similarity index 100% rename from src/modules/person/data/ukrainian/UkrainianLastNames.h rename to src/modules/person/data/ukraine/UkrainianLastNames.h diff --git a/src/modules/person/data/ukrainian/UkrainianMiddleNames.h b/src/modules/person/data/ukraine/UkrainianMiddleNames.h similarity index 100% rename from src/modules/person/data/ukrainian/UkrainianMiddleNames.h rename to src/modules/person/data/ukraine/UkrainianMiddleNames.h diff --git a/src/modules/person/data/ukrainian/UkrainianPeopleNames.h b/src/modules/person/data/ukraine/UkrainianPeopleNames.h similarity index 100% rename from src/modules/person/data/ukrainian/UkrainianPeopleNames.h rename to src/modules/person/data/ukraine/UkrainianPeopleNames.h diff --git a/src/modules/person/data/ukrainian/UkrainianPrefixes.h b/src/modules/person/data/ukraine/UkrainianPrefixes.h similarity index 100% rename from src/modules/person/data/ukrainian/UkrainianPrefixes.h rename to src/modules/person/data/ukraine/UkrainianPrefixes.h diff --git a/src/modules/person/data/usa/UsaPeopleNames.h b/src/modules/person/data/usa/UsaPeopleNames.h new file mode 100644 index 000000000..49ff3686e --- /dev/null +++ b/src/modules/person/data/usa/UsaPeopleNames.h @@ -0,0 +1,22 @@ +#pragma once + +#include "../england/EnglishFirstNames.h" +#include "../england/EnglishLastNames.h" +#include "../england/EnglishPrefixes.h" +#include "../england/EnglishSuffixes.h" +#include "../NameFormats.h" +#include "../PeopleNames.h" + +namespace faker +{ +const NameFormats usaPersonNameFormats{{{"{firstName} {lastName}", 49}, + {"{firstName} {lastName}-{lastName}", 7}, + {"{prefix} {firstName} {lastName}", 7}, + {"{firstName} {lastName} {suffix}", 7}, + {"{prefix} {firstName} {lastName} {suffix}", 1}}}; + +const PeopleNames usaPeopleNames{ + {englishMalesFirstNames, {}, englishLastNames, englishMalesPrefixes, englishSuffixes}, + {englishFemalesFirstNames, {}, englishLastNames, englishFemalesPrefixes, englishSuffixes}, + usaPersonNameFormats}; +}