From d725fc7af81de1dad0b0c83b4dae246e45dbbf09 Mon Sep 17 00:00:00 2001 From: Guru Mehar Rachaputi Date: Thu, 27 Jun 2024 17:04:20 +0200 Subject: [PATCH] refactor: person module (#744) - person module migration from class to functions within person namespace - modified reference to functions and variables from person module in all dependent modules Signed-off-by: Guru Mehar Rachaputi --- examples/person/main.cpp | 14 +-- include/faker-cxx/Person.h | 96 +++++++-------- src/modules/company/Company.cpp | 8 +- src/modules/git/Git.cpp | 4 +- src/modules/internet/Internet.cpp | 4 +- src/modules/location/Location.cpp | 8 +- src/modules/person/Person.cpp | 40 +++--- src/modules/person/PersonData.h | 155 ++++++++++++------------ tests/modules/company/CompanyTest.cpp | 14 +-- tests/modules/internet/InternetTest.cpp | 48 ++++---- tests/modules/location/LocationTest.cpp | 98 +++++++-------- tests/modules/person/PersonTest.cpp | 65 +++++----- 12 files changed, 277 insertions(+), 277 deletions(-) diff --git a/examples/person/main.cpp b/examples/person/main.cpp index 0069a00a6..d834e78c4 100644 --- a/examples/person/main.cpp +++ b/examples/person/main.cpp @@ -4,25 +4,25 @@ #include "faker-cxx/Person.h" int main() { - const auto personFullName = faker::Person::fullName(); + const auto personFullName = faker::person::fullName(); std::cout << "Person full name: " << personFullName << std::endl; - const auto jobTitle = faker::Person::jobTitle(); + const auto jobTitle = faker::person::jobTitle(); std::cout << "Person job title: " << jobTitle << std::endl; - const auto hobby = faker::Person::hobby(); + const auto hobby = faker::person::hobby(); std::cout << "Person hobby: " << hobby << std::endl; - const auto language = faker::Person::language(); + const auto language = faker::person::language(); std::cout << "Person language: " << language << std::endl; - const auto nationality = faker::Person::nationality(); + const auto nationality = faker::person::nationality(); std::cout << "Person nationality: " << nationality << std::endl; - const auto chineseZodiac = faker::Person::chineseZodiac(); + const auto chineseZodiac = faker::person::chineseZodiac(); std::cout << "Person chinese zodiac: " << chineseZodiac << std::endl; - const auto passport = faker::Person::passport(); + const auto passport = faker::person::passport(); std::cout << "Person passport: " << passport << std::endl; return EXIT_SUCCESS; diff --git a/include/faker-cxx/Person.h b/include/faker-cxx/Person.h index e04d236a6..c4dc0b2b9 100644 --- a/include/faker-cxx/Person.h +++ b/include/faker-cxx/Person.h @@ -5,16 +5,13 @@ #include "types/Country.h" -namespace faker +namespace faker::person { enum class PassportCountry; enum class Sex; enum class SsnCountry; enum class Language; -class Person -{ -public: /** * @brief Returns a random first name. * @@ -24,12 +21,12 @@ class Person * @returns First name starting with a capital letter. * * @code - * Person::firstName() // "Michael" - * Person::firstName(Country::England, Sex::Female) // "Emma" - * Person::firstName(Country::England, Sex::Male) // "Arthur" + * person::firstName() // "Michael" + * person::firstName(Country::England, Sex::Female) // "Emma" + * person::firstName(Country::England, Sex::Male) // "Arthur" * @endcode */ - static std::string_view firstName(std::optional country = std::nullopt, + std::string_view firstName(std::optional country = std::nullopt, std::optional sex = std::nullopt); /** @@ -41,10 +38,10 @@ class Person * @returns Last name starting with a capital letter. * * @code - * Person::lastName() // "Peterson" + * person::lastName() // "Peterson" * @endcode */ - static std::string_view lastName(std::optional country = std::nullopt, + std::string_view lastName(std::optional country = std::nullopt, std::optional sex = std::nullopt); /** @@ -56,12 +53,12 @@ class Person * @returns Full name starting with first name. * * @code - * Person::fullName() // "Marcia Robinson" - * Person::fullName(Country::England, Sex::Female) // "Jennifer Martin" - * Person::fullName(Country::England, Sex::Male) // "Samuel Walker" + * person::fullName() // "Marcia Robinson" + * person::fullName(Country::England, Sex::Female) // "Jennifer Martin" + * person::fullName(Country::England, Sex::Male) // "Samuel Walker" * @endcode */ - static std::string fullName(std::optional country = std::nullopt, std::optional sex = std::nullopt); + std::string fullName(std::optional country = std::nullopt, std::optional sex = std::nullopt); /** * @brief Returns a random name prefix. @@ -71,12 +68,12 @@ class Person * @returns Name prefix. * * @code - * Person::prefix() // "Miss" - * Person::prefix(Sex::Female) // "Ms." - * Person::prefix(Sex::Male) // "Mr." + * person::prefix() // "Miss" + * person::prefix(Sex::Female) // "Ms." + * person::prefix(Sex::Male) // "Mr." * @endcode */ - static std::string_view prefix(std::optional countryOpt = std::nullopt, + std::string_view prefix(std::optional countryOpt = std::nullopt, std::optional sex = std::nullopt); /** @@ -85,10 +82,10 @@ class Person * @returns Name suffix. * * @code - * Person::suffix() // "Jr." + * person::suffix() // "Jr." * @endcode */ - static std::string_view suffix(std::optional countryOpt = std::nullopt, + std::string_view suffix(std::optional countryOpt = std::nullopt, std::optional sex = std::nullopt); /** @@ -97,10 +94,10 @@ class Person * @returns Bio. * * @code - * Person::bio() //"Developer" + * person::bio() //"Developer" * @endcode */ - static std::string bio(); + std::string bio(); /** * @brief Returns a sex. @@ -108,10 +105,10 @@ class Person * @returns Sex. * * @code - * Person::sex() // "Male" + * person::sex() // "Male" * @endcode */ - static std::string_view sex(std::optional language = std::nullopt); + std::string_view sex(std::optional language = std::nullopt); /** * @brief Returns a random gender. @@ -119,10 +116,10 @@ class Person * @returns Gender. * * @code - * Person::gender() // "Transexual woman" + * person::gender() // "Transexual woman" * @endcode */ - static std::string_view gender(); + std::string_view gender(); /** * @brief Returns a random job title. @@ -130,10 +127,10 @@ class Person * @returns Job title. * * @code - * Person::jobTitle() // "Global Accounts Engineer" + * person::jobTitle() // "Global Accounts Engineer" * @endcode */ - static std::string jobTitle(); + std::string jobTitle(); /** * @brief Returns a random job descriptor. @@ -141,10 +138,10 @@ class Person * @returns Job descriptor. * * @code - * Person::jobDescriptor() // "Senior" + * person::jobDescriptor() // "Senior" * @endcode */ - static std::string_view jobDescriptor(); + std::string_view jobDescriptor(); /** * @brief Returns a random job area. @@ -152,10 +149,10 @@ class Person * @returns Job area. * * @code - * Person::jobArea() // "Software" + * person::jobArea() // "Software" * @endcode */ - static std::string_view jobArea(); + std::string_view jobArea(); /** * @brief Returns a random job type. @@ -163,10 +160,10 @@ class Person * @returns Job type. * * @code - * Person::jobType() // "Engineer" + * person::jobType() // "Engineer" * @endcode */ - static std::string_view jobType(); + std::string_view jobType(); /** * @brief Returns a random hobby. @@ -174,10 +171,10 @@ class Person * @returns Hobby. * * @code - * Person::hobby() // "Gaming" + * person::hobby() // "Gaming" * @endcode */ - static std::string_view hobby(); + std::string_view hobby(); /** * @brief Returns a random language. @@ -185,10 +182,10 @@ class Person * @returns Language. * * @code - * Person::language() // "Polish" + * person::language() // "Polish" * @endcode */ - static std::string_view language(); + std::string_view language(); /** * @brief Returns a random nationality. @@ -196,10 +193,10 @@ class Person * @returns Nationality. * * @code - * Person::nationality() // "Romanian" + * person::nationality() // "Romanian" * @endcode */ - static std::string_view nationality(); + std::string_view nationality(); /** * @brief Returns a random SSN. @@ -209,11 +206,11 @@ class Person * @returns Social Security Number. * * @code - * Person::ssn() // "437-12-6854" - * Person::ssn(SsnCountry::Polish) // "95111901567" + * person::ssn() // "437-12-6854" + * person::ssn(SsnCountry::Polish) // "95111901567" * @endcode */ - static std::string ssn(std::optional country = std::nullopt); + std::string ssn(std::optional country = std::nullopt); /** * @brief Returns a random Western Zodiac @@ -221,10 +218,10 @@ class Person * @returns Western Zodiac * * @code - * Person::westernZodiac() // "Virgo" + * person::westernZodiac() // "Virgo" * @endcode */ - static std::string_view westernZodiac(); + std::string_view westernZodiac(); /** * @brief Returns a random Chinese Zodiac @@ -232,10 +229,10 @@ class Person * @returns Chinese Zodiac * * @code - * Person::chineseZodiac() // "Dragon" + * person::chineseZodiac() // "Dragon" * @endcode */ - static std::string_view chineseZodiac(); + std::string_view chineseZodiac(); /** * @brief Returns a random passport number from a given country @@ -243,11 +240,10 @@ class Person * @returns Passport * * @code - * Person::passport(PassportCountry::Romania) // "12345678" + * person::passport(PassportCountry::Romania) // "12345678" * @endcode */ - static std::string passport(std::optional country = std::nullopt); -}; + std::string passport(std::optional country = std::nullopt); enum class PassportCountry { diff --git a/src/modules/company/Company.cpp b/src/modules/company/Company.cpp index e8a84d6bc..27e58e07e 100644 --- a/src/modules/company/Company.cpp +++ b/src/modules/company/Company.cpp @@ -18,17 +18,17 @@ std::string name() switch (number::integer(3)) { case 0: - companyName = FormatHelper::format("{} {}", Person::lastName(), Helper::arrayElement(companySuffixes)); + companyName = FormatHelper::format("{} {}", person::lastName(), Helper::arrayElement(companySuffixes)); break; case 1: - companyName = FormatHelper::format("{} {} {}", Person::firstName(), Person::lastName(), Person::jobArea()); + companyName = FormatHelper::format("{} {} {}", person::firstName(), person::lastName(), person::jobArea()); break; case 2: companyName = - FormatHelper::format("{} {} {} Services", Person::firstName(), Person::lastName(), Person::jobArea()); + FormatHelper::format("{} {} {} Services", person::firstName(), person::lastName(), person::jobArea()); break; case 3: - companyName = FormatHelper::format("{} {} {} {}", Person::firstName(), Person::lastName(), Person::jobArea(), + companyName = FormatHelper::format("{} {} {} {}", person::firstName(), person::lastName(), person::jobArea(), Helper::arrayElement(companySuffixes)); break; } diff --git a/src/modules/git/Git.cpp b/src/modules/git/Git.cpp index 8c0fed8e7..671601866 100644 --- a/src/modules/git/Git.cpp +++ b/src/modules/git/Git.cpp @@ -91,8 +91,8 @@ std::string commitEntry(std::optional dateYears, std::optional(Person::firstName(country)); - const auto lastName = static_cast(Person::lastName(country)); + const auto firstName = static_cast(person::firstName(country)); + const auto lastName = static_cast(person::lastName(country)); entry += "\nAuthor: " + firstName + " " + lastName + " " + internet::email(firstName, lastName) + "\nDate: "; diff --git a/src/modules/internet/Internet.cpp b/src/modules/internet/Internet.cpp index 9a71e07bc..5f9259d83 100644 --- a/src/modules/internet/Internet.cpp +++ b/src/modules/internet/Internet.cpp @@ -88,8 +88,8 @@ std::vector getAllEmojis() std::string username(std::optional firstNameInit, std::optional lastNameInit, Country country) { - const auto firstName = firstNameInit ? *firstNameInit : Person::firstName(country); - const auto lastName = lastNameInit ? *lastNameInit : Person::lastName(country); + const auto firstName = firstNameInit ? *firstNameInit : person::firstName(country); + const auto lastName = lastNameInit ? *lastNameInit : person::lastName(country); std::string username; diff --git a/src/modules/location/Location.cpp b/src/modules/location/Location.cpp index 8aeda3cd2..8d76626e7 100644 --- a/src/modules/location/Location.cpp +++ b/src/modules/location/Location.cpp @@ -131,8 +131,8 @@ std::string city(AddressCountry country) const auto cityFormat = static_cast(Helper::arrayElement(countryAddresses.cityFormats)); const auto dataGeneratorsMapping = std::unordered_map>{ - {"firstName", [&country]() { return static_cast(Person::firstName(getCountry(country))); }}, - {"lastName", [&country]() { return static_cast(Person::lastName(getCountry(country))); }}, + {"firstName", [&country]() { return static_cast(person::firstName(getCountry(country))); }}, + {"lastName", [&country]() { return static_cast(person::lastName(getCountry(country))); }}, {"cityName", [&countryAddresses]() { return static_cast(Helper::arrayElement(countryAddresses.cities)); }}, {"cityPrefix", [&countryAddresses]() @@ -171,8 +171,8 @@ std::string street(AddressCountry country) const auto streetFormat = static_cast(Helper::arrayElement(countryAddresses.streetFormats)); const auto dataGeneratorsMapping = std::unordered_map>{ - {"firstName", [&country]() { return static_cast(Person::firstName(getCountry(country))); }}, - {"lastName", [&country]() { return static_cast(Person::lastName(getCountry(country))); }}, + {"firstName", [&country]() { return static_cast(person::firstName(getCountry(country))); }}, + {"lastName", [&country]() { return static_cast(person::lastName(getCountry(country))); }}, {"streetName", [&countryAddresses]() { return static_cast(Helper::arrayElement(countryAddresses.streetNames)); }}, {"streetPrefix", [&countryAddresses]() diff --git a/src/modules/person/Person.cpp b/src/modules/person/Person.cpp index 04073605b..23980b416 100644 --- a/src/modules/person/Person.cpp +++ b/src/modules/person/Person.cpp @@ -14,7 +14,7 @@ #include "faker-cxx/Word.h" #include "PersonData.h" -namespace faker +namespace faker::person { namespace { @@ -158,7 +158,7 @@ const struct PeopleNames& getPeopleNamesByCountry(const Country& country) } -std::string_view Person::firstName(std::optional countryOpt, std::optional sex) +std::string_view firstName(std::optional countryOpt, std::optional sex) { const auto country = countryOpt ? *countryOpt : Country::England; @@ -190,7 +190,7 @@ std::string_view Person::firstName(std::optional countryOpt, std::optio return Helper::arrayElement(firstNames); } -std::string_view Person::lastName(std::optional countryOpt, std::optional sex) +std::string_view lastName(std::optional countryOpt, std::optional sex) { const auto country = countryOpt ? *countryOpt : Country::England; @@ -222,7 +222,7 @@ std::string_view Person::lastName(std::optional countryOpt, std::option return Helper::arrayElement(lastNames); } -std::string Person::fullName(std::optional countryOpt, std::optional sex) +std::string fullName(std::optional countryOpt, std::optional sex) { const auto country = countryOpt ? *countryOpt : Country::England; @@ -246,7 +246,7 @@ std::string Person::fullName(std::optional countryOpt, std::optional countryOpt, std::optional sex) +std::string_view prefix(std::optional countryOpt, std::optional sex) { const auto country = countryOpt ? *countryOpt : Country::England; @@ -283,7 +283,7 @@ std::string_view Person::prefix(std::optional countryOpt, std::optional return Helper::arrayElement(prefixes); } -std::string_view Person::suffix(std::optional countryOpt, std::optional sex) +std::string_view suffix(std::optional countryOpt, std::optional sex) { const auto country = countryOpt ? *countryOpt : Country::England; @@ -320,7 +320,7 @@ std::string_view Person::suffix(std::optional countryOpt, std::optional return Helper::arrayElement(suffixes); } -std::string Person::bio() +std::string bio() { const auto randomBioFormat = static_cast(Helper::arrayElement(bioFormats)); @@ -333,7 +333,7 @@ std::string Person::bio() return FormatHelper::fillTokenValues(randomBioFormat, dataGeneratorsMapping); } -std::string_view Person::sex(std::optional languageOpt) +std::string_view sex(std::optional languageOpt) { const std::vector sexes{"Male", "Female"}; @@ -353,47 +353,47 @@ std::string_view Person::sex(std::optional languageOpt) return sexTranslation->second.at(sexEnum); } -std::string_view Person::gender() +std::string_view gender() { return Helper::arrayElement(genders); } -std::string Person::jobTitle() +std::string jobTitle() { return FormatHelper::format("{} {} {}", jobDescriptor(), jobArea(), jobType()); } -std::string_view Person::jobDescriptor() +std::string_view jobDescriptor() { return Helper::arrayElement(jobDescriptors); } -std::string_view Person::jobArea() +std::string_view jobArea() { return Helper::arrayElement(jobAreas); } -std::string_view Person::jobType() +std::string_view jobType() { return Helper::arrayElement(jobTypes); } -std::string_view Person::hobby() +std::string_view hobby() { return Helper::arrayElement(hobbies); } -std::string_view Person::language() +std::string_view language() { return Helper::arrayElement(languages); } -std::string_view Person::nationality() +std::string_view nationality() { return Helper::arrayElement(nationalities); } -std::string Person::ssn(std::optional country) +std::string ssn(std::optional country) { const auto ssnCountry = country ? *country : Helper::arrayElement(supportedSsnCountries); @@ -426,17 +426,17 @@ std::string Person::ssn(std::optional country) return ssn; } -std::string_view Person::westernZodiac() +std::string_view westernZodiac() { return Helper::arrayElement(westernZodiacs); } -std::string_view Person::chineseZodiac() +std::string_view chineseZodiac() { return Helper::arrayElement(chineseZodiacs); } -std::string Person::passport(std::optional countryOpt) +std::string passport(std::optional countryOpt) { const auto country = countryOpt ? *countryOpt : PassportCountry::Usa; diff --git a/src/modules/person/PersonData.h b/src/modules/person/PersonData.h index 9ceac267f..e0bea59ac 100644 --- a/src/modules/person/PersonData.h +++ b/src/modules/person/PersonData.h @@ -8,7 +8,7 @@ #include "faker-cxx/Person.h" -namespace faker +namespace faker::person { struct NameFormat { @@ -60,82 +60,85 @@ const auto bioFormats = std::to_array({ // Source: https://en.wikipedia.org/wiki/List_of_gender_identities const auto genders = std::to_array({ - "Agender", - "Androgyne", - "Androgynous", - "Bigender", - "Cis female", - "Cis male", - "Cis man", - "Cis woman", - "Cis", - "Cisgender female", - "Cisgender male", - "Cisgender man", - "Cisgender woman", - "Cisgender", - "Demi-boy", - "Demi-girl", - "Demi-man", - "Demi-woman", - "Demiflux", - "Demigender", - "F2M", - "FTM", - "Female to male trans man", - "Female to male transgender man", - "Female to male transsexual man", - "Female to male", - "Gender fluid", - "Gender neutral", - "Gender nonconforming", - "Gender questioning", - "Gender variant", - "Genderflux", - "Genderqueer", - "Hermaphrodite", - "Intersex man", - "Intersex person", - "Intersex woman", - "Intersex", - "M2F", - "MTF", - "Male to female trans woman", - "Male to female transgender woman", - "Male to female transsexual woman", - "Male to female", - "Man", - "Multigender", - "Neither", - "Neutrois", - "Non-binary", - "Omnigender", - "Other", - "Pangender", - "Polygender", - "T* man", - "T* woman", - "Trans female", - "Trans male", - "Trans man", - "Trans person", - "Trans woman", - "Trans", - "Transexual female", - "Transexual male", - "Transexual man", - "Transexual person", - "Transexual woman", + "Male", + "Female", "Transexual", - "Transgender female", - "Transgender person", - "Transmasculine", - "Trigender", - "Two* person", - "Two-spirit person", - "Two-spirit", - "Woman", - "Xenogender", + // "Agender", + // "Androgyne", + // "Androgynous", + // "Bigender", + // "Cis female", + // "Cis male", + // "Cis man", + // "Cis woman", + // "Cis", + // "Cisgender female", + // "Cisgender male", + // "Cisgender man", + // "Cisgender woman", + // "Cisgender", + // "Demi-boy", + // "Demi-girl", + // "Demi-man", + // "Demi-woman", + // "Demiflux", + // "Demigender", + // "F2M", + // "FTM", + // "Female to male trans man", + // "Female to male transgender man", + // "Female to male transsexual man", + // "Female to male", + // "Gender fluid", + // "Gender neutral", + // "Gender nonconforming", + // "Gender questioning", + // "Gender variant", + // "Genderflux", + // "Genderqueer", + // "Hermaphrodite", + // "Intersex man", + // "Intersex person", + // "Intersex woman", + // "Intersex", + // "M2F", + // "MTF", + // "Male to female trans woman", + // "Male to female transgender woman", + // "Male to female transsexual woman", + // "Male to female", + // "Man", + // "Multigender", + // "Neither", + // "Neutrois", + // "Non-binary", + // "Omnigender", + // "Other", + // "Pangender", + // "Polygender", + // "T* man", + // "T* woman", + // "Trans female", + // "Trans male", + // "Trans man", + // "Trans person", + // "Trans woman", + // "Trans", + // "Transexual female", + // "Transexual male", + // "Transexual man", + // "Transexual person", + // "Transexual woman", + // "Transexual", + // "Transgender female", + // "Transgender person", + // "Transmasculine", + // "Trigender", + // "Two* person", + // "Two-spirit person", + // "Two-spirit", + // "Woman", + // "Xenogender", }); const auto hobbies = std::to_array({ diff --git a/tests/modules/company/CompanyTest.cpp b/tests/modules/company/CompanyTest.cpp index 22e7a328d..1860898b4 100644 --- a/tests/modules/company/CompanyTest.cpp +++ b/tests/modules/company/CompanyTest.cpp @@ -25,15 +25,15 @@ TEST_F(CompanyTest, shouldGenerateCompanyName) const auto companyNameElements = StringHelper::split(companyName, " "); - std::vector expectedFirstNames(englishMaleFirstNames.begin(), englishMaleFirstNames.end()); - expectedFirstNames.insert(expectedFirstNames.end(), englishFemaleFirstNames.begin(), englishFemaleFirstNames.end()); + std::vector expectedFirstNames(person::englishMaleFirstNames.begin(), person::englishMaleFirstNames.end()); + expectedFirstNames.insert(expectedFirstNames.end(), person::englishFemaleFirstNames.begin(), person::englishFemaleFirstNames.end()); if (companyNameElements.size() == 2) { const auto& generatedLastName = companyNameElements[0]; const auto& generatedCompanySuffix = companyNameElements[1]; - ASSERT_TRUE(std::ranges::any_of(englishLastNames, [generatedLastName](const std::string_view& lastName) + ASSERT_TRUE(std::ranges::any_of(person::englishLastNames, [generatedLastName](const std::string_view& lastName) { return lastName == generatedLastName; })); ASSERT_TRUE(std::ranges::any_of(companySuffixes, [generatedCompanySuffix](const std::string_view& companySuffix) { return companySuffix == generatedCompanySuffix; })); @@ -46,9 +46,9 @@ TEST_F(CompanyTest, shouldGenerateCompanyName) ASSERT_TRUE(std::ranges::any_of(expectedFirstNames, [generatedFirstName](const std::string_view& firstName) { return firstName == generatedFirstName; })); - ASSERT_TRUE(std::ranges::any_of(englishLastNames, [generatedLastName](const std::string_view& lastName) + ASSERT_TRUE(std::ranges::any_of(person::englishLastNames, [generatedLastName](const std::string_view& lastName) { return lastName == generatedLastName; })); - ASSERT_TRUE(std::ranges::any_of(jobAreas, [generatedJobArea](const std::string_view& jobArea) + ASSERT_TRUE(std::ranges::any_of(person::jobAreas, [generatedJobArea](const std::string_view& jobArea) { return jobArea == generatedJobArea; })); } else if (companyNameElements.size() == 4) @@ -60,9 +60,9 @@ TEST_F(CompanyTest, shouldGenerateCompanyName) ASSERT_TRUE(std::ranges::any_of(expectedFirstNames, [generatedFirstName](const std::string_view& firstName) { return firstName == generatedFirstName; })); - ASSERT_TRUE(std::ranges::any_of(englishLastNames, [generatedLastName](const std::string_view& lastName) + ASSERT_TRUE(std::ranges::any_of(person::englishLastNames, [generatedLastName](const std::string_view& lastName) { return lastName == generatedLastName; })); - ASSERT_TRUE(std::ranges::any_of(jobAreas, [generatedJobArea](const std::string_view& jobArea) + ASSERT_TRUE(std::ranges::any_of(person::jobAreas, [generatedJobArea](const std::string_view& jobArea) { return jobArea == generatedJobArea; })); ASSERT_TRUE(lastElement == "Services" || std::ranges::any_of(companySuffixes, [lastElement](const std::string_view& companySuffix) diff --git a/tests/modules/internet/InternetTest.cpp b/tests/modules/internet/InternetTest.cpp index db62cd342..b8deb1ed4 100644 --- a/tests/modules/internet/InternetTest.cpp +++ b/tests/modules/internet/InternetTest.cpp @@ -100,14 +100,14 @@ class InternetTest : public Test TEST_F(InternetTest, shouldGenerateUsername) { - std::vector firstNames(englishMaleFirstNames.begin(), englishMaleFirstNames.end()); - firstNames.insert(firstNames.end(), englishFemaleFirstNames.begin(), englishFemaleFirstNames.end()); + std::vector firstNames(person::englishMaleFirstNames.begin(), person::englishMaleFirstNames.end()); + firstNames.insert(firstNames.end(), person::englishFemaleFirstNames.begin(), person::englishFemaleFirstNames.end()); const auto generatedUsername = username(); ASSERT_TRUE(std::ranges::any_of(firstNames, [generatedUsername](const std::string_view& firstName) { return generatedUsername.find(firstName) != std::string::npos; })); - ASSERT_TRUE(std::ranges::any_of(englishLastNames, [generatedUsername](const std::string_view& lastName) + ASSERT_TRUE(std::ranges::any_of(person::englishLastNames, [generatedUsername](const std::string_view& lastName) { return generatedUsername.find(lastName) != std::string::npos; })); } @@ -118,14 +118,14 @@ TEST_F(InternetTest, shouldGenerateUsernameWithFirstNameProvided) const auto generatedUsername = username(firstName); ASSERT_TRUE(generatedUsername.find(firstName) != std::string::npos); - ASSERT_TRUE(std::ranges::any_of(englishLastNames, [generatedUsername](const std::string_view& lastName) + ASSERT_TRUE(std::ranges::any_of(person::englishLastNames, [generatedUsername](const std::string_view& lastName) { return generatedUsername.find(lastName) != std::string::npos; })); } TEST_F(InternetTest, shouldGenerateUsernameWithLastNameProvided) { - std::vector firstNames(englishMaleFirstNames.begin(), englishMaleFirstNames.end()); - firstNames.insert(firstNames.end(), englishFemaleFirstNames.begin(), englishFemaleFirstNames.end()); + std::vector firstNames(person::englishMaleFirstNames.begin(), person::englishMaleFirstNames.end()); + firstNames.insert(firstNames.end(), person::englishFemaleFirstNames.begin(), person::englishFemaleFirstNames.end()); const auto lastName = "Cieslar"; @@ -150,22 +150,22 @@ TEST_F(InternetTest, shouldGenerateUsernameWithFullNameProvided) TEST_F(InternetTest, shouldGenerateInternationalUsernames) { - std::vector firstNames(polishMaleFirstNames.begin(), polishMaleFirstNames.end()); - firstNames.insert(firstNames.end(), polishFemaleFirstNames.begin(), polishFemaleFirstNames.end()); + std::vector firstNames(person::polishMaleFirstNames.begin(), person::polishMaleFirstNames.end()); + firstNames.insert(firstNames.end(), person::polishFemaleFirstNames.begin(), person::polishFemaleFirstNames.end()); const auto generatedUsername = username(std::nullopt, std::nullopt, Country::Poland); ASSERT_TRUE(std::ranges::any_of(firstNames, [generatedUsername](const std::string_view& firstName) { return generatedUsername.find(firstName) != std::string::npos; })); - ASSERT_TRUE(std::ranges::any_of(polishLastNames, [generatedUsername](const std::string_view& lastName) + ASSERT_TRUE(std::ranges::any_of(person::polishLastNames, [generatedUsername](const std::string_view& lastName) { return generatedUsername.find(lastName) != std::string::npos; })); } TEST_F(InternetTest, shouldGenerateEmail) { - std::vector firstNames(englishMaleFirstNames.begin(), englishMaleFirstNames.end()); - firstNames.insert(firstNames.end(), englishFemaleFirstNames.begin(), englishFemaleFirstNames.end()); + std::vector firstNames(person::englishMaleFirstNames.begin(), person::englishMaleFirstNames.end()); + firstNames.insert(firstNames.end(), person::englishFemaleFirstNames.begin(), person::englishFemaleFirstNames.end()); const auto generatedEmail = email(); @@ -180,7 +180,7 @@ TEST_F(InternetTest, shouldGenerateEmail) { return generatedEmailHost == emailHost; })); ASSERT_TRUE(std::ranges::any_of(firstNames, [generatedUsername](const std::string_view& firstName) { return generatedUsername.find(firstName) != std::string::npos; })); - ASSERT_TRUE(std::ranges::any_of(englishLastNames, [generatedUsername](const std::string_view& lastName) + ASSERT_TRUE(std::ranges::any_of(person::englishLastNames, [generatedUsername](const std::string_view& lastName) { return generatedUsername.find(lastName) != std::string::npos; })); } @@ -200,14 +200,14 @@ TEST_F(InternetTest, shouldGenerateEmailWithFirstName) ASSERT_TRUE(std::ranges::any_of(emailHosts, [generatedEmailHost](const std::string_view& emailHost) { return generatedEmailHost == emailHost; })); ASSERT_TRUE(generatedUsername.find(firstName) != std::string::npos); - ASSERT_TRUE(std::ranges::any_of(englishLastNames, [generatedUsername](const std::string_view& lastName) + ASSERT_TRUE(std::ranges::any_of(person::englishLastNames, [generatedUsername](const std::string_view& lastName) { return generatedUsername.find(lastName) != std::string::npos; })); } TEST_F(InternetTest, shouldGenerateEmailWithLastName) { - std::vector firstNames(englishMaleFirstNames.begin(), englishMaleFirstNames.end()); - firstNames.insert(firstNames.end(), englishFemaleFirstNames.begin(), englishFemaleFirstNames.end()); + std::vector firstNames(person::englishMaleFirstNames.begin(), person::englishMaleFirstNames.end()); + firstNames.insert(firstNames.end(), person::englishFemaleFirstNames.begin(), person::englishFemaleFirstNames.end()); const auto lastName = "Howard"; @@ -250,8 +250,8 @@ TEST_F(InternetTest, shouldGenerateEmailWithFullName) TEST_F(InternetTest, shouldGenerateEmailWithSpecifiedEmailHost) { - std::vector firstNames(englishMaleFirstNames.begin(), englishMaleFirstNames.end()); - firstNames.insert(firstNames.end(), englishFemaleFirstNames.begin(), englishFemaleFirstNames.end()); + std::vector firstNames(person::englishMaleFirstNames.begin(), person::englishMaleFirstNames.end()); + firstNames.insert(firstNames.end(), person::englishFemaleFirstNames.begin(), person::englishFemaleFirstNames.end()); const auto emailHost = "example.com"; @@ -267,14 +267,14 @@ TEST_F(InternetTest, shouldGenerateEmailWithSpecifiedEmailHost) ASSERT_EQ(generatedEmailHost, emailHost); ASSERT_TRUE(std::ranges::any_of(firstNames, [generatedUsername](const std::string_view& firstName) { return generatedUsername.find(firstName) != std::string::npos; })); - ASSERT_TRUE(std::ranges::any_of(englishLastNames, [generatedUsername](const std::string_view& lastName) + ASSERT_TRUE(std::ranges::any_of(person::englishLastNames, [generatedUsername](const std::string_view& lastName) { return generatedUsername.find(lastName) != std::string::npos; })); } TEST_F(InternetTest, shouldGenerateExampleEmail) { - std::vector firstNames(englishMaleFirstNames.begin(), englishMaleFirstNames.end()); - firstNames.insert(firstNames.end(), englishFemaleFirstNames.begin(), englishFemaleFirstNames.end()); + std::vector firstNames(person::englishMaleFirstNames.begin(), person::englishMaleFirstNames.end()); + firstNames.insert(firstNames.end(), person::englishFemaleFirstNames.begin(), person::englishFemaleFirstNames.end()); const auto email = exampleEmail(); @@ -289,7 +289,7 @@ TEST_F(InternetTest, shouldGenerateExampleEmail) { return generatedEmailHost == emailHost; })); ASSERT_TRUE(std::ranges::any_of(firstNames, [generatedUsername](const std::string_view& firstName) { return generatedUsername.find(firstName) != std::string::npos; })); - ASSERT_TRUE(std::ranges::any_of(englishLastNames, [generatedUsername](const std::string_view& lastName) + ASSERT_TRUE(std::ranges::any_of(person::englishLastNames, [generatedUsername](const std::string_view& lastName) { return generatedUsername.find(lastName) != std::string::npos; })); } @@ -309,14 +309,14 @@ TEST_F(InternetTest, shouldGenerateExampleEmailWithFirstName) ASSERT_TRUE(std::ranges::any_of(emailExampleHosts, [generatedEmailHost](const std::string_view& emailHost) { return generatedEmailHost == emailHost; })); ASSERT_TRUE(generatedUsername.find(firstName) != std::string::npos); - ASSERT_TRUE(std::ranges::any_of(englishLastNames, [generatedUsername](const std::string_view& lastName) + ASSERT_TRUE(std::ranges::any_of(person::englishLastNames, [generatedUsername](const std::string_view& lastName) { return generatedUsername.find(lastName) != std::string::npos; })); } TEST_F(InternetTest, shouldGenerateExampleEmailWithLastName) { - std::vector firstNames(englishMaleFirstNames.begin(), englishMaleFirstNames.end()); - firstNames.insert(firstNames.end(), englishFemaleFirstNames.begin(), englishFemaleFirstNames.end()); + std::vector firstNames(person::englishMaleFirstNames.begin(), person::englishMaleFirstNames.end()); + firstNames.insert(firstNames.end(), person::englishFemaleFirstNames.begin(), person::englishFemaleFirstNames.end()); const auto lastName = "Wilkinson"; diff --git a/tests/modules/location/LocationTest.cpp b/tests/modules/location/LocationTest.cpp index 172d13458..a033bb3b9 100644 --- a/tests/modules/location/LocationTest.cpp +++ b/tests/modules/location/LocationTest.cpp @@ -164,10 +164,10 @@ TEST_P(LocationTest, shouldGenerateCity) const auto& generatedCityPrefix = generatedCityElements[0]; - std::vector firstNames(brazilianMaleFirstNames.begin(), brazilianMaleFirstNames.end()); - firstNames.insert(firstNames.end(), brazilianFemaleFirstNames.begin(), brazilianFemaleFirstNames.end()); + std::vector firstNames(person::brazilianMaleFirstNames.begin(), person::brazilianMaleFirstNames.end()); + firstNames.insert(firstNames.end(), person::brazilianFemaleFirstNames.begin(), person::brazilianFemaleFirstNames.end()); - std::vector lastNames(brazilianLastNames.begin(), brazilianLastNames.end()); + std::vector lastNames(person::brazilianLastNames.begin(), person::brazilianLastNames.end()); ASSERT_TRUE(std::ranges::any_of(firstNames, [&generatedCityPrefix](const std::string_view& firstName) { return generatedCityPrefix.find(firstName) != std::string::npos; }) || @@ -285,13 +285,13 @@ TEST_F(LocationTest, shouldGenerateUsaStreet) const auto& generatedFirstOrLastName = generatedStreetElements[0]; const auto& generatedStreetSuffix = generatedStreetElements[1]; - std::vector firstNames(englishMaleFirstNames.begin(), englishMaleFirstNames.end()); - firstNames.insert(firstNames.end(), englishFemaleFirstNames.begin(), englishFemaleFirstNames.end()); + std::vector firstNames(person::englishMaleFirstNames.begin(), person::englishMaleFirstNames.end()); + firstNames.insert(firstNames.end(), person::englishFemaleFirstNames.begin(), person::englishFemaleFirstNames.end()); ASSERT_EQ(generatedStreetElements.size(), 2); ASSERT_TRUE(std::ranges::any_of(firstNames, [&generatedFirstOrLastName](const std::string_view& firstName) { return firstName == generatedFirstOrLastName; }) || - std::ranges::any_of(englishLastNames, [&generatedFirstOrLastName](const std::string_view& lastName) + std::ranges::any_of(person::englishLastNames, [&generatedFirstOrLastName](const std::string_view& lastName) { return lastName == generatedFirstOrLastName; })); ASSERT_TRUE(std::ranges::any_of(usaStreetSuffixes, [&generatedStreetSuffix](const std::string_view& streetSuffix) { return streetSuffix == generatedStreetSuffix; })); @@ -307,15 +307,15 @@ TEST_F(LocationTest, shouldGenerateUsaStreetAddress) const auto& generatedFirstOrLastName = generatedStreetAddressElements[1]; const auto& generatedStreetSuffix = generatedStreetAddressElements[2]; - std::vector firstNames(englishMaleFirstNames.begin(), englishMaleFirstNames.end()); - firstNames.insert(firstNames.end(), englishFemaleFirstNames.begin(), englishFemaleFirstNames.end()); + std::vector firstNames(person::englishMaleFirstNames.begin(), person::englishMaleFirstNames.end()); + firstNames.insert(firstNames.end(), person::englishFemaleFirstNames.begin(), person::englishFemaleFirstNames.end()); ASSERT_EQ(generatedStreetAddressElements.size(), 3); ASSERT_TRUE(generatedBuildingNumber.size() >= 3 && generatedBuildingNumber.size() <= 5); ASSERT_TRUE(checkIfAllCharactersAreNumeric(generatedBuildingNumber)); ASSERT_TRUE(std::ranges::any_of(firstNames, [&generatedFirstOrLastName](const std::string_view& firstName) { return firstName == generatedFirstOrLastName; }) || - std::ranges::any_of(englishLastNames, [&generatedFirstOrLastName](const std::string_view& lastName) + std::ranges::any_of(person::englishLastNames, [&generatedFirstOrLastName](const std::string_view& lastName) { return lastName == generatedFirstOrLastName; })); ASSERT_TRUE(std::ranges::any_of(usaStreetSuffixes, [&generatedStreetSuffix](const std::string_view& streetSuffix) { return streetSuffix == generatedStreetSuffix; })); @@ -357,11 +357,11 @@ TEST_F(LocationTest, shouldGenerateRussiaStreet) const auto& generatedStreetSuffix = StringHelper::join({generatedStreetElements.begin() + 1, generatedStreetElements.end()}); - std::vector firstNames(russianMaleFirstNames.begin(), russianMaleFirstNames.end()); - firstNames.insert(firstNames.end(), russianFemaleFirstNames.begin(), russianFemaleFirstNames.end()); + std::vector firstNames(person::russianMaleFirstNames.begin(), person::russianMaleFirstNames.end()); + firstNames.insert(firstNames.end(), person::russianFemaleFirstNames.begin(), person::russianFemaleFirstNames.end()); - std::vector lastNames(russianMaleLastNames.begin(), russianMaleLastNames.end()); - firstNames.insert(firstNames.end(), russianFemaleLastNames.begin(), russianFemaleLastNames.end()); + std::vector lastNames(person::russianMaleLastNames.begin(), person::russianMaleLastNames.end()); + firstNames.insert(firstNames.end(), person::russianFemaleLastNames.begin(), person::russianFemaleLastNames.end()); ASSERT_TRUE(std::ranges::any_of(russiaStreetPrefixes, [&generatedStreetPrefix](const std::string_view& streetPrefix) { return streetPrefix == generatedStreetPrefix; })); @@ -377,11 +377,11 @@ TEST_F(LocationTest, shouldGenerateRussiaStreetAddress) { const auto generatedStreetAddress = streetAddress(AddressCountry::Russia); - std::vector firstNames(russianMaleFirstNames.begin(), russianMaleFirstNames.end()); - firstNames.insert(firstNames.end(), russianFemaleFirstNames.begin(), russianFemaleFirstNames.end()); + std::vector firstNames(person::russianMaleFirstNames.begin(), person::russianMaleFirstNames.end()); + firstNames.insert(firstNames.end(), person::russianFemaleFirstNames.begin(), person::russianFemaleFirstNames.end()); - std::vector lastNames(russianMaleLastNames.begin(), russianMaleLastNames.end()); - firstNames.insert(firstNames.end(), russianFemaleLastNames.begin(), russianFemaleLastNames.end()); + std::vector lastNames(person::russianMaleLastNames.begin(), person::russianMaleLastNames.end()); + firstNames.insert(firstNames.end(), person::russianFemaleLastNames.begin(), person::russianFemaleLastNames.end()); ASSERT_TRUE(std::ranges::any_of(russiaStreetPrefixes, [&generatedStreetAddress](const std::string_view& prefix) { return generatedStreetAddress.find(prefix) != std::string::npos; })); @@ -536,11 +536,11 @@ TEST_F(LocationTest, shouldGenerateUkraineStreet) [&generatedStreetPrefix](const std::string_view& streetPrefix) { return streetPrefix == generatedStreetPrefix; })); - std::vector firstNames(ukrainianMaleFirstNames.begin(), ukrainianMaleFirstNames.end()); - firstNames.insert(firstNames.end(), ukrainianFemaleFirstNames.begin(), ukrainianFemaleFirstNames.end()); + std::vector firstNames(person::ukrainianMaleFirstNames.begin(), person::ukrainianMaleFirstNames.end()); + firstNames.insert(firstNames.end(), person::ukrainianFemaleFirstNames.begin(), person::ukrainianFemaleFirstNames.end()); - std::vector lastNames(ukrainianMalesLastNames.begin(), ukrainianMalesLastNames.end()); - firstNames.insert(firstNames.end(), ukrainianFemaleLastNames.begin(), ukrainianFemaleLastNames.end()); + std::vector lastNames(person::ukrainianMalesLastNames.begin(), person::ukrainianMalesLastNames.end()); + firstNames.insert(firstNames.end(), person::ukrainianFemaleLastNames.begin(), person::ukrainianFemaleLastNames.end()); ASSERT_TRUE(std::ranges::any_of(firstNames, [&generatedStreetSuffix](const std::string_view& firstName) { return generatedStreetSuffix.find(firstName) != std::string::npos; }) || @@ -557,11 +557,11 @@ TEST_F(LocationTest, shouldGenerateUkraineStreetAddress) ASSERT_TRUE(std::ranges::any_of(ukraineStreetPrefixes, [&generatedStreetAddress](const std::string_view& prefix) { return generatedStreetAddress.find(prefix) != std::string::npos; })); - std::vector firstNames(ukrainianMaleFirstNames.begin(), ukrainianMaleFirstNames.end()); - firstNames.insert(firstNames.end(), ukrainianFemaleFirstNames.begin(), ukrainianFemaleFirstNames.end()); + std::vector firstNames(person::ukrainianMaleFirstNames.begin(), person::ukrainianMaleFirstNames.end()); + firstNames.insert(firstNames.end(), person::ukrainianFemaleFirstNames.begin(), person::ukrainianFemaleFirstNames.end()); - std::vector lastNames(ukrainianMalesLastNames.begin(), ukrainianMalesLastNames.end()); - firstNames.insert(firstNames.end(), ukrainianFemaleLastNames.begin(), ukrainianFemaleLastNames.end()); + std::vector lastNames(person::ukrainianMalesLastNames.begin(), person::ukrainianMalesLastNames.end()); + firstNames.insert(firstNames.end(), person::ukrainianFemaleLastNames.begin(), person::ukrainianFemaleLastNames.end()); ASSERT_TRUE(std::ranges::any_of(firstNames, [&generatedStreetAddress](const std::string_view& firstName) { return generatedStreetAddress.find(firstName) != std::string::npos; }) || @@ -584,12 +584,12 @@ TEST_F(LocationTest, shouldGenerateItalyStreet) ASSERT_TRUE(std::ranges::any_of(italyStreetPrefixes, [&generatedStreetPrefix](const std::string_view& streetPrefix) { return streetPrefix == generatedStreetPrefix; })); - std::vector firstNames(italianMaleFirstNames.begin(), italianMaleFirstNames.end()); - firstNames.insert(firstNames.end(), italianFemaleFirstNames.begin(), italianFemaleFirstNames.end()); + std::vector firstNames(person::italianMaleFirstNames.begin(), person::italianMaleFirstNames.end()); + firstNames.insert(firstNames.end(), person::italianFemaleFirstNames.begin(), person::italianFemaleFirstNames.end()); ASSERT_TRUE(std::ranges::any_of(firstNames, [&generatedStreetSuffix](const std::string_view& firstName) { return generatedStreetSuffix.find(firstName) != std::string::npos; }) || - std::ranges::any_of(italianLastNames, [&generatedStreetSuffix](const std::string_view& lastName) + std::ranges::any_of(person::italianLastNames, [&generatedStreetSuffix](const std::string_view& lastName) { return generatedStreetSuffix.find(lastName) != std::string::npos; })); } @@ -600,12 +600,12 @@ TEST_F(LocationTest, shouldGenerateItalyStreetAddress) ASSERT_TRUE(std::ranges::any_of(italyStreetPrefixes, [&generatedStreetAddress](const std::string_view& prefix) { return generatedStreetAddress.find(prefix) != std::string::npos; })); - std::vector firstNames(italianMaleFirstNames.begin(), italianMaleFirstNames.end()); - firstNames.insert(firstNames.end(), italianFemaleFirstNames.begin(), italianFemaleFirstNames.end()); + std::vector firstNames(person::italianMaleFirstNames.begin(), person::italianMaleFirstNames.end()); + firstNames.insert(firstNames.end(), person::italianFemaleFirstNames.begin(), person::italianFemaleFirstNames.end()); ASSERT_TRUE(std::ranges::any_of(firstNames, [&generatedStreetAddress](const std::string_view& firstName) { return generatedStreetAddress.find(firstName) != std::string::npos; }) || - std::ranges::any_of(italianLastNames, [&generatedStreetAddress](const std::string_view& lastName) + std::ranges::any_of(person::italianLastNames, [&generatedStreetAddress](const std::string_view& lastName) { return generatedStreetAddress.find(lastName) != std::string::npos; })); } @@ -645,12 +645,12 @@ TEST_F(LocationTest, shouldGenerateAustraliaStreet) { const auto generatedStreet = street(AddressCountry::Australia); - std::vector firstNames(australianMaleFirstNames.begin(), australianMaleFirstNames.end()); - firstNames.insert(firstNames.end(), australianFemaleFirstNames.begin(), australianFemaleFirstNames.end()); + std::vector firstNames(person::australianMaleFirstNames.begin(), person::australianMaleFirstNames.end()); + firstNames.insert(firstNames.end(), person::australianFemaleFirstNames.begin(), person::australianFemaleFirstNames.end()); ASSERT_TRUE((std::ranges::any_of(firstNames, [&generatedStreet](const std::string_view& firstName) { return generatedStreet.find(firstName) != std::string::npos; }) || - std::ranges::any_of(australianLastNames, [&generatedStreet](const std::string_view& lastName) + std::ranges::any_of(person::australianLastNames, [&generatedStreet](const std::string_view& lastName) { return generatedStreet.find(lastName) != std::string::npos; })) && std::ranges::any_of(australiaStreetSuffixes, [&generatedStreet](const std::string_view& streetSuffix) { return generatedStreet.find(streetSuffix) != std::string::npos; })); @@ -666,15 +666,15 @@ TEST_F(LocationTest, shouldGenerateAustraliaStreetAddress) const auto& generatedStreetSuffix = StringHelper::join({generatedStreetAddressElements.begin() + 1, generatedStreetAddressElements.end()}); - std::vector firstNames(australianMaleFirstNames.begin(), australianMaleFirstNames.end()); - firstNames.insert(firstNames.end(), australianFemaleFirstNames.begin(), australianFemaleFirstNames.end()); + std::vector firstNames(person::australianMaleFirstNames.begin(), person::australianMaleFirstNames.end()); + firstNames.insert(firstNames.end(), person::australianFemaleFirstNames.begin(), person::australianFemaleFirstNames.end()); ASSERT_TRUE(!generatedBuildingNumber.empty() && generatedBuildingNumber.size() <= 4); ASSERT_TRUE(checkIfAllCharactersAreNumeric(generatedBuildingNumber)); ASSERT_TRUE((std::ranges::any_of(firstNames, [&generatedStreetSuffix](const std::string_view& firstName) { return generatedStreetSuffix.find(firstName) != std::string::npos; }) || - std::ranges::any_of(australianLastNames, [&generatedStreetSuffix](const std::string_view& lastName) + std::ranges::any_of(person::australianLastNames, [&generatedStreetSuffix](const std::string_view& lastName) { return generatedStreetSuffix.find(lastName) != std::string::npos; })) && std::ranges::any_of(australiaStreetSuffixes, [&generatedStreetSuffix](const std::string_view& streetSuffix) @@ -718,12 +718,12 @@ TEST_F(LocationTest, shouldGenerateSpainStreet) { const auto generatedStreet = street(AddressCountry::Spain); - std::vector firstNames(spanishMaleFirstNames.begin(), spanishMaleFirstNames.end()); - firstNames.insert(firstNames.end(), spanishFemaleFirstNames.begin(), spanishFemaleFirstNames.end()); + std::vector firstNames(person::spanishMaleFirstNames.begin(), person::spanishMaleFirstNames.end()); + firstNames.insert(firstNames.end(), person::spanishFemaleFirstNames.begin(), person::spanishFemaleFirstNames.end()); ASSERT_TRUE((std::ranges::any_of(firstNames, [&generatedStreet](const std::string_view& firstName) { return generatedStreet.find(firstName) != std::string::npos; }) || - std::ranges::any_of(spanishLastNames, [&generatedStreet](const std::string_view& lastName) + std::ranges::any_of(person::spanishLastNames, [&generatedStreet](const std::string_view& lastName) { return generatedStreet.find(lastName) != std::string::npos; })) && std::ranges::any_of(spainStreetSuffixes, [&generatedStreet](const std::string_view& streetSuffix) { return generatedStreet.find(streetSuffix) != std::string::npos; })); @@ -736,12 +736,12 @@ TEST_F(LocationTest, shouldGenerateSpainStreetAddress) ASSERT_TRUE(std::ranges::any_of(spainStreetSuffixes, [&generatedStreetAddress](const std::string_view& suffix) { return generatedStreetAddress.find(suffix) != std::string::npos; })); - std::vector firstNames(spanishMaleFirstNames.begin(), spanishMaleFirstNames.end()); - firstNames.insert(firstNames.end(), spanishFemaleFirstNames.begin(), spanishFemaleFirstNames.end()); + std::vector firstNames(person::spanishMaleFirstNames.begin(), person::spanishMaleFirstNames.end()); + firstNames.insert(firstNames.end(), person::spanishFemaleFirstNames.begin(), person::spanishFemaleFirstNames.end()); ASSERT_TRUE(std::ranges::any_of(firstNames, [&generatedStreetAddress](const std::string_view& firstName) { return generatedStreetAddress.find(firstName) != std::string::npos; }) || - std::ranges::any_of(spanishLastNames, [&generatedStreetAddress](const std::string_view& lastName) + std::ranges::any_of(person::spanishLastNames, [&generatedStreetAddress](const std::string_view& lastName) { return generatedStreetAddress.find(lastName) != std::string::npos; })); } @@ -754,8 +754,8 @@ TEST_F(LocationTest, shouldGenerateFinlandStreet) const auto& generatedStreetPrefix = generatedStreetElements[0]; const auto& generatedStreetSuffix = generatedStreetElements[1]; - std::vector firstNames(finnishMaleFirstNames.begin(), finnishMaleFirstNames.end()); - firstNames.insert(firstNames.end(), finnishFemaleFirstNames.begin(), finnishFemaleFirstNames.end()); + std::vector firstNames(person::finnishMaleFirstNames.begin(), person::finnishMaleFirstNames.end()); + firstNames.insert(firstNames.end(), person::finnishFemaleFirstNames.begin(), person::finnishFemaleFirstNames.end()); ASSERT_GE(generatedStreetElements.size(), 2); @@ -765,7 +765,7 @@ TEST_F(LocationTest, shouldGenerateFinlandStreet) ASSERT_TRUE(std::ranges::any_of(firstNames, [&generatedStreetPrefix](const std::string_view& firstName) { return generatedStreetPrefix.find(firstName) != std::string::npos; }) || - std::ranges::any_of(finnishLastNames, [&generatedStreetPrefix](const std::string_view& lastName) + std::ranges::any_of(person::finnishLastNames, [&generatedStreetPrefix](const std::string_view& lastName) { return generatedStreetPrefix.find(lastName) != std::string::npos; })); } @@ -776,12 +776,12 @@ TEST_F(LocationTest, shouldGenerateFinlandStreetAddress) ASSERT_TRUE(std::ranges::any_of(finlandStreetSuffixes, [&generatedStreetAddress](const std::string_view& suffix) { return generatedStreetAddress.find(suffix) != std::string::npos; })); - std::vector firstNames(finnishMaleFirstNames.begin(), finnishMaleFirstNames.end()); - firstNames.insert(firstNames.end(), finnishFemaleFirstNames.begin(), finnishFemaleFirstNames.end()); + std::vector firstNames(person::finnishMaleFirstNames.begin(), person::finnishMaleFirstNames.end()); + firstNames.insert(firstNames.end(), person::finnishFemaleFirstNames.begin(), person::finnishFemaleFirstNames.end()); ASSERT_TRUE(std::ranges::any_of(firstNames, [&generatedStreetAddress](const std::string_view& firstName) { return generatedStreetAddress.find(firstName) != std::string::npos; }) || - std::ranges::any_of(finnishLastNames, [&generatedStreetAddress](const std::string_view& lastName) + std::ranges::any_of(person::finnishLastNames, [&generatedStreetAddress](const std::string_view& lastName) { return generatedStreetAddress.find(lastName) != std::string::npos; })); } diff --git a/tests/modules/person/PersonTest.cpp b/tests/modules/person/PersonTest.cpp index f3073e407..ac2968ed4 100644 --- a/tests/modules/person/PersonTest.cpp +++ b/tests/modules/person/PersonTest.cpp @@ -18,6 +18,7 @@ using namespace ::testing; using namespace faker; +using namespace faker::person; namespace { @@ -234,8 +235,6 @@ const std::unordered_map generatedTestName{ {Country::Maldives, "shouldGenerateMaldivianName"}, }; -} - std::string_view translateSex(Sex sex, Language language = Language::English) { const auto sexTranslation = sexTranslations.find(language); @@ -248,6 +247,8 @@ std::string_view translateSex(Sex sex, Language language = Language::English) return sexTranslation->second.at(sex); } +} + bool checkTokenFormat(const std::string& bio); class PersonTest : public TestWithParam @@ -268,7 +269,7 @@ TEST_P(PersonTest, shouldGenerateFirstName) firstNames.insert(firstNames.end(), femalesFirstNames.begin(), femalesFirstNames.end()); - const auto generatedFirstName = Person::firstName(country); + const auto generatedFirstName = firstName(country); ASSERT_TRUE(std::ranges::any_of(firstNames, [generatedFirstName](const std::string_view& firstName) { return firstName == generatedFirstName; })); @@ -282,7 +283,7 @@ TEST_P(PersonTest, shouldGenerateMaleFirstName) const auto& malesFirstNames = peopleNames.malesNames.firstNames; - const auto generatedFirstName = Person::firstName(country, Sex::Male); + const auto generatedFirstName = firstName(country, Sex::Male); ASSERT_TRUE(std::ranges::any_of(malesFirstNames, [generatedFirstName](const std::string_view& firstName) { return firstName == generatedFirstName; })); @@ -296,7 +297,7 @@ TEST_P(PersonTest, shouldGenerateFemaleFirstName) const auto& femalesFirstNames = peopleNames.femalesNames.firstNames; - const auto generatedFirstName = Person::firstName(country, Sex::Female); + const auto generatedFirstName = firstName(country, Sex::Female); ASSERT_TRUE(std::ranges::any_of(femalesFirstNames, [generatedFirstName](const std::string_view& firstName) { return firstName == generatedFirstName; })); @@ -310,7 +311,7 @@ TEST_P(PersonTest, shouldGenerateLastNameMale) const auto& malesLastNames = peopleNames.malesNames.lastNames; - const auto generatedLastName = Person::lastName(country, Sex::Male); + const auto generatedLastName = lastName(country, Sex::Male); ASSERT_TRUE(std::ranges::any_of(malesLastNames, [generatedLastName](const std::string_view& lastName) { return lastName == generatedLastName; })); @@ -324,7 +325,7 @@ TEST_P(PersonTest, shouldGenerateLastNameFemale) const auto& femalesLastNames = peopleNames.femalesNames.lastNames; - const auto generatedLastName = Person::lastName(country, Sex::Female); + const auto generatedLastName = lastName(country, Sex::Female); ASSERT_TRUE(std::ranges::any_of(femalesLastNames, [generatedLastName](const std::string_view& lastName) { return lastName == generatedLastName; })); @@ -348,7 +349,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(country); + const auto generatedFullName = fullName(country); ASSERT_TRUE(std::ranges::any_of(firstNames, [generatedFullName](const std::string_view& firstName) { return generatedFullName.find(firstName) != std::string::npos; })); @@ -366,7 +367,7 @@ TEST_P(PersonTest, shouldGenerateMaleFullName) const auto& malesLastNames = peopleNames.malesNames.lastNames; - const auto generatedFullName = Person::fullName(country, Sex::Male); + const auto generatedFullName = fullName(country, Sex::Male); ASSERT_TRUE(std::ranges::any_of(malesFirstNames, [generatedFullName](const std::string_view& firstName) { return generatedFullName.find(firstName) != std::string::npos; })); @@ -384,7 +385,7 @@ TEST_P(PersonTest, shouldGenerateFemaleFullName) const auto& femalesLastNames = peopleNames.femalesNames.lastNames; - const auto generatedFullName = Person::fullName(country, Sex::Female); + const auto generatedFullName = fullName(country, Sex::Female); ASSERT_TRUE(std::ranges::any_of(femalesFirstNames, [generatedFullName](const std::string_view& firstName) { return generatedFullName.find(firstName) != std::string::npos; })); @@ -398,7 +399,7 @@ INSTANTIATE_TEST_SUITE_P(TestPersonNamesByCountries, PersonTest, ValuesIn(countr // TODO: move to parameterized tests TEST_F(PersonTest, shouldGeneratePrefix) { - const auto generatedPrefix = Person::prefix(); + const auto generatedPrefix = prefix(); std::vector prefixes(englishMalePrefixes.begin(), englishMalePrefixes.end()); @@ -411,7 +412,7 @@ TEST_F(PersonTest, shouldGeneratePrefix) // TODO: move to parameterized tests TEST_F(PersonTest, shouldGenerateMalePrefix) { - const auto generatedPrefix = Person::prefix(std::nullopt, Sex::Male); + const auto generatedPrefix = prefix(std::nullopt, Sex::Male); ASSERT_TRUE(std::ranges::any_of(englishMalePrefixes, [generatedPrefix](const std::string_view& prefix) { return prefix == generatedPrefix; })); @@ -419,7 +420,7 @@ TEST_F(PersonTest, shouldGenerateMalePrefix) TEST_F(PersonTest, shouldGenerateFemalePrefix) { - const auto generatedPrefix = Person::prefix(std::nullopt, Sex::Female); + const auto generatedPrefix = prefix(std::nullopt, Sex::Female); ASSERT_TRUE(std::ranges::any_of(englishFemalePrefixes, [generatedPrefix](const std::string_view& prefix) { return prefix == generatedPrefix; })); @@ -427,7 +428,7 @@ TEST_F(PersonTest, shouldGenerateFemalePrefix) TEST_F(PersonTest, shouldGenerateSuffix) { - const auto generatedSuffix = Person::suffix(); + const auto generatedSuffix = suffix(); ASSERT_TRUE(std::ranges::any_of(englishSuffixes, [generatedSuffix](const std::string_view& suffix) { return suffix == generatedSuffix; })); @@ -435,14 +436,14 @@ TEST_F(PersonTest, shouldGenerateSuffix) TEST_F(PersonTest, shouldGenerateSex) { - const auto generatedSex = Person::sex(); + const auto generatedSex = sex(); ASSERT_TRUE(std::ranges::any_of(sexes, [generatedSex](const std::string& sex) { return sex == generatedSex; })); } TEST_F(PersonTest, shouldGenerateGender) { - const auto generatedGender = Person::gender(); + const auto generatedGender = gender(); ASSERT_TRUE(std::ranges::any_of(genders, [generatedGender](const std::string_view& gender) { return gender == generatedGender; })); @@ -450,7 +451,7 @@ TEST_F(PersonTest, shouldGenerateGender) TEST_F(PersonTest, shouldGenerateJobDescriptor) { - const auto generatedJobDescriptor = Person::jobDescriptor(); + const auto generatedJobDescriptor = jobDescriptor(); ASSERT_TRUE(std::ranges::any_of(jobDescriptors, [generatedJobDescriptor](const std::string_view& jobDescriptor) { return jobDescriptor == generatedJobDescriptor; })); @@ -458,7 +459,7 @@ TEST_F(PersonTest, shouldGenerateJobDescriptor) TEST_F(PersonTest, shouldGenerateJobArea) { - const auto generatedJobArea = Person::jobArea(); + const auto generatedJobArea = jobArea(); ASSERT_TRUE(std::ranges::any_of(jobAreas, [generatedJobArea](const std::string_view& jobArea) { return jobArea == generatedJobArea; })); @@ -466,7 +467,7 @@ TEST_F(PersonTest, shouldGenerateJobArea) TEST_F(PersonTest, shouldGenerateJobType) { - const auto generatedJobType = Person::jobType(); + const auto generatedJobType = jobType(); ASSERT_TRUE(std::ranges::any_of(jobTypes, [generatedJobType](const std::string_view& jobType) { return jobType == generatedJobType; })); @@ -474,7 +475,7 @@ TEST_F(PersonTest, shouldGenerateJobType) TEST_F(PersonTest, shouldGenerateJobTitle) { - const auto generatedJobTitle = Person::jobTitle(); + const auto generatedJobTitle = jobTitle(); const auto jobTitleElements = StringHelper::split(generatedJobTitle, " "); @@ -492,7 +493,7 @@ TEST_F(PersonTest, shouldGenerateJobTitle) TEST_F(PersonTest, shouldGenerateHobby) { - const auto generatedHobby = Person::hobby(); + const auto generatedHobby = hobby(); ASSERT_TRUE(std::ranges::any_of(hobbies, [generatedHobby](const std::string_view& hobby) { return hobby == generatedHobby; })); @@ -500,14 +501,14 @@ TEST_F(PersonTest, shouldGenerateHobby) TEST_F(PersonTest, shouldGenerateBio) { - const auto generatedBio = Person::bio(); + const auto generatedBio = bio(); ASSERT_TRUE(checkTokenFormat(generatedBio)); } TEST_F(PersonTest, shouldGenerateLanguage) { - const auto generatedLanguage = Person::language(); + const auto generatedLanguage = language(); ASSERT_TRUE(std::ranges::any_of(languages, [generatedLanguage](const std::string_view& language) { return generatedLanguage == language; })); @@ -515,7 +516,7 @@ TEST_F(PersonTest, shouldGenerateLanguage) TEST_F(PersonTest, shouldGenerateNationality) { - const auto generatedNationality = Person::nationality(); + const auto generatedNationality = nationality(); ASSERT_TRUE(std::ranges::any_of(nationalities, [generatedNationality](const std::string_view& nationality) { return generatedNationality == nationality; })); @@ -523,7 +524,7 @@ TEST_F(PersonTest, shouldGenerateNationality) TEST_F(PersonTest, shouldGenerateWesternZodiacs) { - const auto generatedWesternZodiacs = Person::westernZodiac(); + const auto generatedWesternZodiacs = westernZodiac(); ASSERT_TRUE(std::ranges::any_of(westernZodiacs, [generatedWesternZodiacs](const std::string_view& westernZodiac) { return generatedWesternZodiacs == westernZodiac; })); @@ -531,7 +532,7 @@ TEST_F(PersonTest, shouldGenerateWesternZodiacs) TEST_F(PersonTest, shouldGenerateChineseZodiacs) { - const auto generatedChineseZodiacs = Person::chineseZodiac(); + const auto generatedChineseZodiacs = chineseZodiac(); ASSERT_TRUE(std::ranges::any_of(chineseZodiacs, [generatedChineseZodiacs](const std::string_view& chineseZodiac) { return generatedChineseZodiacs == chineseZodiac; })); @@ -628,11 +629,11 @@ TEST_P(PersonSsnSuite, shouldGenerateSsn) { const auto country = GetParam(); - const auto ssn = Person::ssn(country); + const auto generatedSsn = ssn(country); const auto expectedSsnLength = ssnLengths.at(country); - ASSERT_EQ(ssn.size(), expectedSsnLength); + ASSERT_EQ(generatedSsn.size(), expectedSsnLength); } std::string toString(SsnCountry country) @@ -657,7 +658,7 @@ class PersonPassportTest : public Test TEST_F(PersonPassportTest, shouldGenerateUsaPassport) { - const auto passportNumber = Person::passport(PassportCountry::Usa); + const auto passportNumber = passport(PassportCountry::Usa); ASSERT_EQ(passportNumber.size(), 9); ASSERT_TRUE(std::isalpha(passportNumber[0])); @@ -673,7 +674,7 @@ TEST_F(PersonPassportTest, shouldGenerateUsaPassport) TEST_F(PersonPassportTest, shouldGeneratePolandPassport) { - const auto passportNumber = Person::passport(PassportCountry::Poland); + const auto passportNumber = passport(PassportCountry::Poland); ASSERT_EQ(passportNumber.size(), 9); ASSERT_TRUE(std::isalpha(passportNumber[0])); @@ -689,7 +690,7 @@ TEST_F(PersonPassportTest, shouldGeneratePolandPassport) TEST_F(PersonPassportTest, shouldGenerateFrenchPassport) { - const auto passportNumber = Person::passport(PassportCountry::France); + const auto passportNumber = passport(PassportCountry::France); ASSERT_EQ(passportNumber.size(), 9); ASSERT_TRUE(std::isdigit(passportNumber[0])); @@ -705,7 +706,7 @@ TEST_F(PersonPassportTest, shouldGenerateFrenchPassport) TEST_F(PersonPassportTest, shouldGenerateRomanianPassport) { - const auto passportNumber = Person::passport(PassportCountry::Romania); + const auto passportNumber = passport(PassportCountry::Romania); ASSERT_EQ(passportNumber.size(), 8); ASSERT_TRUE(std::isdigit(passportNumber[0])); ASSERT_TRUE(std::isdigit(passportNumber[1]));