From 4f1c82e05eb5d3d526c71001628581aeb16427d1 Mon Sep 17 00:00:00 2001 From: Eric Floyd Date: Sat, 21 Oct 2023 19:23:14 -0400 Subject: [PATCH] added nationality function --- include/faker-cxx/Person.h | 12 ++++++++++++ src/modules/person/Person.cpp | 6 ++++++ src/modules/person/PersonTest.cpp | 9 +++++++++ src/modules/person/data/Nationalities.h | 19 +++++++++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 src/modules/person/data/Nationalities.h diff --git a/include/faker-cxx/Person.h b/include/faker-cxx/Person.h index 574059caf..ea8e687ea 100644 --- a/include/faker-cxx/Person.h +++ b/include/faker-cxx/Person.h @@ -157,5 +157,17 @@ class Person * @endcode */ static std::string language(); + + /** + * @brief Returns a random nationality. + * + * @returns Nationality. + * + * @code + * Person::nationality() // "Romanian" + * @endcode + */ + + static std::string nationality(); }; } diff --git a/src/modules/person/Person.cpp b/src/modules/person/Person.cpp index 9a7b8e8a9..c8d64b5a0 100644 --- a/src/modules/person/Person.cpp +++ b/src/modules/person/Person.cpp @@ -22,6 +22,7 @@ #include "data/italian/ItalianFirstNamesMales.h" #include "data/italian/ItalianLastNames.h" #include "data/JobTitles.h" +#include "data/Nationalities.h" #include "data/nepalese/NepaleseFirstNamesFemales.h" #include "data/nepalese/NepaleseFirstNamesMales.h" #include "data/nepalese/NepaleseLastNames.h" @@ -195,4 +196,9 @@ std::string Person::language() { return toString(Helper::arrayElement(languages)); } + +std::string Person::nationality() +{ + return Helper::arrayElement(nationalities); +} } diff --git a/src/modules/person/PersonTest.cpp b/src/modules/person/PersonTest.cpp index 976b956a3..6eb6ddaa9 100644 --- a/src/modules/person/PersonTest.cpp +++ b/src/modules/person/PersonTest.cpp @@ -24,6 +24,7 @@ #include "data/italian/ItalianFirstNamesMales.h" #include "data/italian/ItalianLastNames.h" #include "data/JobTitles.h" +#include "data/Nationalities.h" #include "data/polish/PolishFirstNamesFemales.h" #include "data/polish/PolishFirstNamesMales.h" #include "data/polish/PolishLastNames.h" @@ -335,3 +336,11 @@ TEST_F(PersonTest, shouldGenerateLanguage) ASSERT_TRUE(std::ranges::any_of(languages, [generatedLanguage](Language language) { return generatedLanguage == toString(language); })); } + +TEST_F(PersonTest, shouldGenerateNationality) +{ + const auto generatedNationality = Person::nationality(); + + ASSERT_TRUE(std::ranges::any_of(nationalities, [generatedNationality](const std::string& nationality) + { return generatedNationality == nationality; })); +} diff --git a/src/modules/person/data/Nationalities.h b/src/modules/person/data/Nationalities.h new file mode 100644 index 000000000..b8df6b5a6 --- /dev/null +++ b/src/modules/person/data/Nationalities.h @@ -0,0 +1,19 @@ +#pragma once + +#include +#include + +namespace faker +{ +const std::vector nationalities = { + "American", "British", "Canadian", "French", "German", "Japanese", "Australian", + "Chinese", "Indian", "Italian", "Mexican", "Russian", "Brazilian", "Swedish", + "South Korean", "Spanish", "Dutch", "Norwegian", "Turkish", "Greek", "Egyptian", + "Israeli", "Saudi Arabian", "South African", "Swiss", "Argentinian", "New Zealander", "Thai", + "Vietnamese", "Irish", "Polish", "Portuguese", "Danish", "Scottish", "Welsh", + "Belgian", "Austrian", "Finnish", "Hungarian", "Czech", "Romanian", "Ukrainian", + "Swedish", "Norwegian", "Singaporean", "Malaysian", "Filipino", "Indonesian", "Kuwaiti", + "Qatari", "Emirati", "Jordanian", "Chilean", "Peruvian", "Colombian", "Venezuelan", + "Ecuadorian", "Bolivian", "Costa Rican", "Panamanian", "Honduran", "Guatemalan", +}; +}