Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added nationality function #212

Merged
merged 1 commit into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions include/faker-cxx/Person.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
}
6 changes: 6 additions & 0 deletions src/modules/person/Person.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -195,4 +196,9 @@ std::string Person::language()
{
return toString(Helper::arrayElement<Language>(languages));
}

std::string Person::nationality()
{
return Helper::arrayElement<std::string>(nationalities);
}
}
9 changes: 9 additions & 0 deletions src/modules/person/PersonTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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; }));
}
19 changes: 19 additions & 0 deletions src/modules/person/data/Nationalities.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <string>
#include <vector>

namespace faker
{
const std::vector<std::string> 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",
};
}