Skip to content

Commit

Permalink
added nationality function (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-bodhi authored Oct 22, 2023
1 parent 0acf988 commit 63ecaa1
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
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",
};
}

0 comments on commit 63ecaa1

Please sign in to comment.