Skip to content

Commit

Permalink
Merge branch 'main' into duyhn/add-people-names-from-South-Africa
Browse files Browse the repository at this point in the history
  • Loading branch information
cieslarmichal authored Jan 13, 2024
2 parents 037dce8 + 9a84da9 commit 07825cf
Show file tree
Hide file tree
Showing 26 changed files with 468 additions and 88 deletions.
4 changes: 3 additions & 1 deletion include/faker-cxx/types/AddressCountry.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ namespace faker
India,
Denmark,
Spain,
Brazil,
};

const std::vector<AddressCountry> addressCountries{
AddressCountry::Usa, AddressCountry::Poland, AddressCountry::France,
AddressCountry::Russia, AddressCountry::Ukraine, AddressCountry::Italy,
AddressCountry::Germany, AddressCountry::Czech, AddressCountry::India,
AddressCountry::Denmark, AddressCountry::Australia, AddressCountry::Spain,
AddressCountry::Brazil,
};

inline std::string toString(AddressCountry country)
Expand All @@ -37,7 +39,7 @@ namespace faker
{AddressCountry::Russia, "Russia"}, {AddressCountry::Ukraine, "Ukraine"}, {AddressCountry::Italy, "Italy"},
{AddressCountry::Germany, "Germany"}, {AddressCountry::Czech, "Czech"}, {AddressCountry::Australia, "Australia"},
{AddressCountry::India, "India"}, {AddressCountry::Denmark, "Denmark"},
{AddressCountry::Spain, "Spain"},
{AddressCountry::Spain, "Spain"}, {AddressCountry::Brazil, "Brazil"},
};

return countryToStringMapping.at(country);
Expand Down
4 changes: 3 additions & 1 deletion include/faker-cxx/types/Country.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ enum class Country
Syria,
Malta,
SouthAfrica,
Azerbaijan,
};

const std::vector<Country> countries{
Expand All @@ -79,7 +80,7 @@ const std::vector<Country> countries{
Country::Ireland, Country::Belarus, Country::Estonia, Country::Iran, Country::Bulgaria,
Country::Moldova, Country::Lithuania, Country::Iceland, Country::Palestine, Country::Israel,
Country::Vietnam, Country::Monaco, Country::Bosnia, Country::Lebanon, Country::Syria,
Country::Malta, Country::SouthAfrica,
Country::Malta, Country::SouthAfrica, Country::Azerbaijan,
};

inline std::string toString(Country country)
Expand Down Expand Up @@ -142,6 +143,7 @@ inline std::string toString(Country country)
{Country::Syria, "Syria"},
{Country::Malta, "Malta"},
{Country::SouthAfrica, "South Africa"},
{Country::Azerbaijan, "Azerbaijan"},
};

return countryToStringMapping.at(country);
Expand Down
17 changes: 16 additions & 1 deletion src/modules/location/Location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "data/poland/PolandAddresses.h"
#include "data/italy/ItalyAddresses.h"
#include "data/russia/RussiaAddresses.h"
#include "data/brazil/BrazilAddresses.h"
#include "data/TimeZones.h"
#include "data/ukraine/UkraineAddresses.h"
#include "data/germany/GermanyAddresses.h"
Expand All @@ -34,6 +35,7 @@ namespace faker
{AddressCountry::Germany, germanyAddresses}, {AddressCountry::Czech, czechAddresses},
{AddressCountry::Australia, australiaAddresses}, {AddressCountry::India, indiaAddresses},
{AddressCountry::Denmark, denmarkAddresses}, {AddressCountry::Spain, spainAddresses},
{AddressCountry::Brazil, brazilAddresses}
};

const std::map<AddressCountry, Country> countryAddressToCountryMapping{
Expand All @@ -43,6 +45,7 @@ namespace faker
{AddressCountry::Germany, Country::Germany}, {AddressCountry::Czech, Country::Czech},
{AddressCountry::Australia, Country::Australia}, {AddressCountry::India, Country::India},
{AddressCountry::Denmark, Country::Denmark}, {AddressCountry::Spain, Country::Spain},
{AddressCountry::Brazil, Country::Brazil}
};
}

Expand Down Expand Up @@ -76,7 +79,19 @@ namespace faker
{
const auto& countryAddresses = countryToCountryAddressesMapping.at(country);

return Helper::arrayElement<std::string>(countryAddresses.cities);
const auto cityFormat = Helper::arrayElement<std::string>(countryAddresses.cityFormats);

const auto dataGeneratorsMapping = std::map<std::string, std::function<std::string()>>{
{"firstName", [&country]() { return Person::firstName(countryAddressToCountryMapping.at(country)); }},
{"lastName", [&country]() { return Person::lastName(countryAddressToCountryMapping.at(country)); }},
{"cityName",
[&countryAddresses]() { return Helper::arrayElement<std::string>(countryAddresses.cities); }},
{"cityPrefix",
[&countryAddresses]() { return Helper::arrayElement<std::string>(countryAddresses.cityPrefixes); }},
{"citySuffix",
[&countryAddresses]() { return Helper::arrayElement<std::string>(countryAddresses.citySuffixes); }}};

return FormatHelper::fillTokenValues(cityFormat, dataGeneratorsMapping);
}

std::string Location::zipCode(AddressCountry country)
Expand Down
30 changes: 28 additions & 2 deletions src/modules/location/LocationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "../person/data/england/EnglishLastNames.h"
#include "../person/data/spain/SpanishFirstNames.h"
#include "../person/data/spain/SpanishLastNames.h"
#include "../person/data/brazil/BrazilianFirstNames.h"
#include "../person/data/brazil/BrazilianLastNames.h"
#include "../person/data/russia/RussianFirstNames.h"
#include "../person/data/russia/RussianLastNames.h"
#include "../person/data/ukraine/UkrainianFirstNames.h"
Expand All @@ -32,6 +34,7 @@
#include "data/india/IndiaAddresses.h"
#include "data/denmark/DenmarkAddresses.h"
#include "data/spain/SpainAddresses.h"
#include "data/brazil/BrazilAddresses.h"

using namespace ::testing;
using namespace faker;
Expand All @@ -45,6 +48,7 @@ namespace
{AddressCountry::Germany, germanyAddresses}, {AddressCountry::Czech, czechAddresses},
{AddressCountry::Australia, australiaAddresses}, {AddressCountry::India, indiaAddresses},
{AddressCountry::Denmark, denmarkAddresses}, {AddressCountry::Spain, spainAddresses},
{AddressCountry::Brazil, brazilAddresses}
};

const std::map<AddressCountry, std::string> generatedTestName{
Expand All @@ -60,6 +64,7 @@ namespace
{AddressCountry::India, "shouldGenerateIndiaAddress"},
{AddressCountry::Denmark, "shouldGenerateDenmarkAddress"},
{AddressCountry::Spain, "shouldGenerateSpainAddress"},
{AddressCountry::Brazil, "shouldGenerateBrazilAddress"}
};
}

Expand Down Expand Up @@ -124,8 +129,29 @@ TEST_P(LocationTest, shouldGenerateCity)

const auto generatedCity = Location::city(country);

ASSERT_TRUE(std::ranges::any_of(countryAddresses.cities,
[&generatedCity](const std::string& city) { return city == generatedCity; }));
if (country == faker::AddressCountry::Brazil)
{
const auto generatedCityElements = StringHelper::split(generatedCity, " ");

const auto& generatedCityPrefix = generatedCityElements[0];

std::vector<std::string> firstNames{brazilianMalesFirstNames};
firstNames.insert(firstNames.end(), brazilianFemalesFirstNames.begin(), brazilianFemalesFirstNames.end());

std::vector<std::string> lastNames{brazilianLastNames};

ASSERT_TRUE(std::ranges::any_of(firstNames,
[&generatedCityPrefix](const std::string& firstName) { return generatedCityPrefix.find(firstName) != std::string::npos; }) ||
std::ranges::any_of(lastNames,
[&generatedCityPrefix](const std::string& lastName) { return generatedCityPrefix.find(lastName) != std::string::npos; }) ||
std::ranges::any_of(brazilCitySuffixes,
[&generatedCity](const std::string& citySuffix) { return generatedCity.find(citySuffix) != std::string::npos; }));

} else
{
ASSERT_TRUE(std::ranges::any_of(countryAddresses.cities,
[&generatedCity](const std::string& city){ return city == generatedCity; }));
}
}

TEST_P(LocationTest, shouldGenerateZipCode)
Expand Down
5 changes: 4 additions & 1 deletion src/modules/location/data/CountryAddresses.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace faker
{
struct CountryAddresses
{
std::vector<std::string> cities;
std::string zipCodeFormat;
std::vector<std::string> addressFormats;
std::vector<std::string> secondaryAddressFormats;
Expand All @@ -16,6 +15,10 @@ struct CountryAddresses
std::vector<std::string> streetNames;
std::vector<std::string> streetSuffixes;
std::vector<std::string> buildingNumberFormats;
std::vector<std::string> cityFormats;
std::vector<std::string> cityPrefixes;
std::vector<std::string> cities;
std::vector<std::string> citySuffixes;
std::vector<std::string> states;
std::vector<std::string> counties;
};
Expand Down
8 changes: 6 additions & 2 deletions src/modules/location/data/australia/AustraliaAddresses.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,20 @@ const std::vector<std::string> australiaBuildingNumberFormats{"####", "###", "##

const std::vector<std::string> australiaStreetFormats{"{firstName} {streetSuffix}", "{lastName} {streetSuffix}"};

const std::vector<std::string> australiaCityFormats{"{cityName}"};

const CountryAddresses australiaAddresses{australiaCities,
australiaZipCodeFormat,
const CountryAddresses australiaAddresses{australiaZipCodeFormat,
australiaAddressFormats,
{},
australiaStreetFormats,
{},
{},
australiaStreetSuffixes,
australiaBuildingNumberFormats,
australiaCityFormats,
{},
australiaCities,
{},
australiaStates,
{}};
}
37 changes: 37 additions & 0 deletions src/modules/location/data/brazil/BrazilAddresses.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include "../CountryAddresses.h"
#include "BrazilCitySuffixes.h"
#include "BrazilStreetSuffixes.h"
#include "BrazilStates.h"

namespace faker
{
const std::string brazilZipCodeFormat{"#####-###"};

const std::vector<std::string> brazilAddressFormats{"{street} {buildingNumber}",
"{street} {buildingNumber} {secondaryAddress}"};

const std::vector<std::string> brazilSecondaryAddressFormats{"Apto. ###", "Sobrado ##", "Casa #", "Lote ##", "Quadra ##"};

const std::vector<std::string> brazilBuildingNumberFormats{"#####", "####", "###"};

const std::vector<std::string> brazilStreetFormats{"{firstName} {streetSuffix}", "{lastName} {streetSuffix}"};

const std::vector<std::string> brazilCityFormats{"{firstName} {citySuffix}", "{lastName} {citySuffix}"};

const CountryAddresses brazilAddresses{ brazilZipCodeFormat,
brazilAddressFormats,
brazilSecondaryAddressFormats,
brazilStreetFormats,
{},
{},
brazilStreetSuffixes,
brazilBuildingNumberFormats,
brazilCityFormats,
{},
{},
brazilCitySuffixes,
brazilStates,
{}};
}
11 changes: 11 additions & 0 deletions src/modules/location/data/brazil/BrazilCitySuffixes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include <string>
#include <vector>

namespace faker
{
const std::vector<std::string> brazilCitySuffixes{
"do Descoberto", "de Nossa Senhora", "do Norte", "do Sul"
};
}
37 changes: 37 additions & 0 deletions src/modules/location/data/brazil/BrazilStates.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include <string>
#include <vector>

namespace faker
{
const std::vector<std::string> brazilStates = {
"Acre",
"Alagoas",
"Amapá",
"Amazonas",
"Bahia",
"Ceará",
"Distrito Federal",
"Espírito Santo",
"Goiás",
"Maranhão",
"Mato Grosso",
"Mato Grosso do Sul",
"Minas Gerais",
"Pará",
"Paraíba",
"Paraná",
"Pernambuco",
"Piauí",
"Rio de Janeiro",
"Rio Grande do Norte",
"Rio Grande do Sul",
"Rondônia",
"Roraima",
"Santa Catarina",
"São Paulo",
"Sergipe",
"Tocantins",
};
}
11 changes: 11 additions & 0 deletions src/modules/location/data/brazil/BrazilStreetSuffixes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include <string>
#include <vector>

namespace faker
{
const std::vector<std::string> brazilStreetSuffixes{
"Rua", "Avenida", "Travessa", "Alameda", "Marginal", "Rodovia",
};
}
9 changes: 7 additions & 2 deletions src/modules/location/data/czech/CzechAddresses.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,20 @@ const std::vector<std::string> czechBuildingNumberFormats{"#", "##", "###"};

const std::vector<std::string> czechStreetFormats{"{streetName}"};

const CountryAddresses czechAddresses{czechCities,
czechZipCodeFormat,
const std::vector<std::string> czechCityFormats{"{cityName}"};

const CountryAddresses czechAddresses{czechZipCodeFormat,
czechAddressFormats,
czechSecondaryAddressFormats,
czechStreetFormats,
{},
czechStreetNames,
{},
czechBuildingNumberFormats,
czechCityFormats,
{},
czechCities,
{},
czechStates,
{}};
}
38 changes: 22 additions & 16 deletions src/modules/location/data/denmark/DenmarkAddresses.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,31 @@
#include "DenmarkStreetNames.h"

namespace faker {
const std::string denmarkZipCodeFormat{"####"};

const std::vector<std::string> denmarkAddressFormats{"{street} {buildingNumber}", "{street} {buildingNumber} {secondaryAddress}"};
const std::string denmarkZipCodeFormat{"####"};

const std::vector<std::string> denmarkSecondaryAddressFormats{"#. tv", "#. th"};
const std::vector<std::string> denmarkAddressFormats{"{street} {buildingNumber}", "{street} {buildingNumber} {secondaryAddress}"};

const std::vector<std::string> denmarkBuildingNumberFormats{"#", "##", "###", "##A", "##B"};
const std::vector<std::string> denmarkSecondaryAddressFormats{"#. tv", "#. th"};

const std::vector<std::string> denmarkStreetFormats{"{streetName}"};
const std::vector<std::string> denmarkBuildingNumberFormats{"#", "##", "###", "##A", "##B"};

const CountryAddresses denmarkAddresses{denmarkCities,
denmarkZipCodeFormat,
denmarkAddressFormats,
denmarkSecondaryAddressFormats,
denmarkStreetFormats,
{},
denmarkStreetNames,
{},
denmarkBuildingNumberFormats,
denmarkStates,
{}};
const std::vector<std::string> denmarkStreetFormats{"{streetName}"};

const std::vector<std::string> denmarkCityFormats{"{cityName}"};

const CountryAddresses denmarkAddresses{denmarkZipCodeFormat,
denmarkAddressFormats,
denmarkSecondaryAddressFormats,
denmarkStreetFormats,
{},
denmarkStreetNames,
{},
denmarkBuildingNumberFormats,
denmarkCityFormats,
{},
denmarkCities,
{},
denmarkStates,
{}};
}
Loading

0 comments on commit 07825cf

Please sign in to comment.