From b0592c59e121378659a3f1d0647e2059645faf51 Mon Sep 17 00:00:00 2001 From: Duy Huynh Date: Sat, 13 Jan 2024 18:49:24 -0600 Subject: [PATCH] =?UTF-8?q?Add=20location=20addresses=20data=20from=20Finl?= =?UTF-8?q?and=20=F0=9F=87=AB=F0=9F=87=AE=20(#440)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add finland location * fix test fail * Fix bugs * Change test --- include/faker-cxx/types/AddressCountry.h | 4 +- src/modules/location/Location.cpp | 5 +- src/modules/location/LocationTest.cpp | 123 +++++++++++++----- .../location/data/finland/FinlandAddresses.h | 36 +++++ .../location/data/finland/FinlandCities.h | 30 +++++ .../location/data/finland/FinlandStates.h | 29 +++++ .../data/finland/FinlandStreetSuffixes.h | 21 +++ 7 files changed, 214 insertions(+), 34 deletions(-) create mode 100644 src/modules/location/data/finland/FinlandAddresses.h create mode 100644 src/modules/location/data/finland/FinlandCities.h create mode 100644 src/modules/location/data/finland/FinlandStates.h create mode 100644 src/modules/location/data/finland/FinlandStreetSuffixes.h diff --git a/include/faker-cxx/types/AddressCountry.h b/include/faker-cxx/types/AddressCountry.h index c32730f58..23aa2ece2 100644 --- a/include/faker-cxx/types/AddressCountry.h +++ b/include/faker-cxx/types/AddressCountry.h @@ -22,6 +22,7 @@ namespace faker Denmark, Spain, Brazil, + Finland }; const std::vector addressCountries{ @@ -29,7 +30,7 @@ namespace faker AddressCountry::Russia, AddressCountry::Ukraine, AddressCountry::Italy, AddressCountry::Germany, AddressCountry::Czech, AddressCountry::India, AddressCountry::Denmark, AddressCountry::Australia, AddressCountry::Spain, - AddressCountry::Brazil, + AddressCountry::Brazil, AddressCountry::Finland, }; inline std::string toString(AddressCountry country) @@ -40,6 +41,7 @@ namespace faker {AddressCountry::Germany, "Germany"}, {AddressCountry::Czech, "Czech"}, {AddressCountry::Australia, "Australia"}, {AddressCountry::India, "India"}, {AddressCountry::Denmark, "Denmark"}, {AddressCountry::Spain, "Spain"}, {AddressCountry::Brazil, "Brazil"}, + {AddressCountry::Finland, "Finland"}, }; return countryToStringMapping.at(country); diff --git a/src/modules/location/Location.cpp b/src/modules/location/Location.cpp index cf8d26ad7..af7d4b0c4 100644 --- a/src/modules/location/Location.cpp +++ b/src/modules/location/Location.cpp @@ -12,6 +12,7 @@ #include "data/poland/PolandAddresses.h" #include "data/italy/ItalyAddresses.h" #include "data/russia/RussiaAddresses.h" +#include "data/finland/FinlandAddresses.h" #include "data/brazil/BrazilAddresses.h" #include "data/TimeZones.h" #include "data/ukraine/UkraineAddresses.h" @@ -35,7 +36,7 @@ namespace faker {AddressCountry::Germany, germanyAddresses}, {AddressCountry::Czech, czechAddresses}, {AddressCountry::Australia, australiaAddresses}, {AddressCountry::India, indiaAddresses}, {AddressCountry::Denmark, denmarkAddresses}, {AddressCountry::Spain, spainAddresses}, - {AddressCountry::Brazil, brazilAddresses} + {AddressCountry::Brazil, brazilAddresses}, {AddressCountry::Finland, finlandAddresses}, }; const std::map countryAddressToCountryMapping{ @@ -45,7 +46,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} + {AddressCountry::Brazil, Country::Brazil}, {AddressCountry::Finland, Country::Finland}, }; } diff --git a/src/modules/location/LocationTest.cpp b/src/modules/location/LocationTest.cpp index ca38b245e..ab5b71995 100644 --- a/src/modules/location/LocationTest.cpp +++ b/src/modules/location/LocationTest.cpp @@ -17,6 +17,10 @@ #include "../person/data/ukraine/UkrainianLastNames.h" #include "../person/data/italy/ItalianFirstNames.h" #include "../person/data/italy/ItalianLastNames.h" +#include "../person/data/australia/AustralianFirstNames.h" +#include "../person/data/australia/AustralianLastNames.h" +#include "../person/data/finland/FinnishFirstNames.h" +#include "../person/data/finland/FinnishLastNames.h" #include "../string/data/Characters.h" #include "data/Countries.h" #include "data/CountryAddresses.h" @@ -35,6 +39,7 @@ #include "data/denmark/DenmarkAddresses.h" #include "data/spain/SpainAddresses.h" #include "data/brazil/BrazilAddresses.h" +#include "data/finland/FinlandAddresses.h" using namespace ::testing; using namespace faker; @@ -48,7 +53,7 @@ namespace {AddressCountry::Germany, germanyAddresses}, {AddressCountry::Czech, czechAddresses}, {AddressCountry::Australia, australiaAddresses}, {AddressCountry::India, indiaAddresses}, {AddressCountry::Denmark, denmarkAddresses}, {AddressCountry::Spain, spainAddresses}, - {AddressCountry::Brazil, brazilAddresses} + {AddressCountry::Brazil, brazilAddresses}, {AddressCountry::Finland, finlandAddresses}, }; const std::map generatedTestName{ @@ -64,7 +69,8 @@ namespace {AddressCountry::India, "shouldGenerateIndiaAddress"}, {AddressCountry::Denmark, "shouldGenerateDenmarkAddress"}, {AddressCountry::Spain, "shouldGenerateSpainAddress"}, - {AddressCountry::Brazil, "shouldGenerateBrazilAddress"} + {AddressCountry::Brazil, "shouldGenerateBrazilAddress"}, + {AddressCountry::Finland, "shouldGenerateFinlandAddress"}, }; } @@ -199,14 +205,22 @@ TEST_P(LocationTest, shouldGenerateSecondaryAddress) countryAddresses.secondaryAddressFormats, [&generatedSecondaryAddress, &country](const std::string& secondaryAddressFormat) { + if (country == faker::AddressCountry::Finland) + { + if (generatedSecondaryAddress.size() == 1) + { + return generatedSecondaryAddress == secondaryAddressFormat; + } + } + const auto secondaryAddressElements = StringHelper::split(secondaryAddressFormat, " "); + const auto generatedSecondaryAddressElements = StringHelper::split(generatedSecondaryAddress, " "); + const auto& secondaryAddressPrefix = secondaryAddressElements[0]; const auto& secondaryAddressNumber = secondaryAddressElements[1]; - const auto generatedSecondaryAddressElements = StringHelper::split(generatedSecondaryAddress, " "); - const auto& generatedSecondaryAddressPrefix = generatedSecondaryAddressElements[0]; const auto& generatedSecondaryAddressNumber = generatedSecondaryAddressElements[1]; @@ -610,18 +624,20 @@ TEST_F(LocationTest, shouldGenerateCzechStreetAddress) } TEST_F(LocationTest, shouldGenerateAustraliaStreet) -{ +{ const auto generatedStreet = Location::street(AddressCountry::Australia); - const auto generatedStreetElements = StringHelper::split(generatedStreet, " "); - - const auto& generatedStreetSuffix = - StringHelper::join({generatedStreetElements.begin() + 1, generatedStreetElements.end()}); - - ASSERT_GE(generatedStreetElements.size(), 2); + std::vector firstNames{australianMalesFirstNames}; + firstNames.insert(firstNames.end(), australianFemalesFirstNames.begin(), australianFemalesFirstNames.end()); - ASSERT_TRUE(std::ranges::any_of(australiaStreetSuffixes, [&generatedStreetSuffix](const std::string& streetSuffix) - { return streetSuffix == generatedStreetSuffix; })); + std::vector lastNames{australianLastNames}; + + ASSERT_TRUE((std::ranges::any_of(firstNames, [&generatedStreet](const std::string& firstName) + { return generatedStreet.find(firstName) != std::string::npos; }) || + std::ranges::any_of(lastNames, [&generatedStreet](const std::string& lastName) + { return generatedStreet.find(lastName) != std::string::npos; })) && + std::ranges::any_of(australiaStreetSuffixes, [&generatedStreet](const std::string& streetSuffix) + { return generatedStreet.find(streetSuffix) != std::string::npos; })); } TEST_F(LocationTest, shouldGenerateAustraliaStreetAddress) @@ -632,13 +648,22 @@ TEST_F(LocationTest, shouldGenerateAustraliaStreetAddress) const auto& generatedBuildingNumber = generatedStreetAddressElements[0]; const auto& generatedStreetSuffix = - StringHelper::join({generatedStreetAddressElements.begin() + 2, generatedStreetAddressElements.end()}); + StringHelper::join({generatedStreetAddressElements.begin() + 1, generatedStreetAddressElements.end()}); + + std::vector firstNames{australianMalesFirstNames}; + firstNames.insert(firstNames.end(), australianFemalesFirstNames.begin(), australianFemalesFirstNames.end()); + + std::vector lastNames{australianLastNames}; - ASSERT_GE(generatedStreetAddressElements.size(), 3); ASSERT_TRUE(!generatedBuildingNumber.empty() && generatedBuildingNumber.size() <= 4); ASSERT_TRUE(checkIfAllCharactersAreNumeric(generatedBuildingNumber)); - ASSERT_TRUE(std::ranges::any_of(australiaStreetSuffixes, [&generatedStreetSuffix](const std::string& streetSuffix) - { return streetSuffix == generatedStreetSuffix; })); + + ASSERT_TRUE((std::ranges::any_of(firstNames, [&generatedStreetSuffix](const std::string& firstName) + { return generatedStreetSuffix.find(firstName) != std::string::npos; }) || + std::ranges::any_of(lastNames, [&generatedStreetSuffix](const std::string& lastName) + { return generatedStreetSuffix.find(lastName) != std::string::npos; })) && + std::ranges::any_of(australiaStreetSuffixes, [&generatedStreetSuffix](const std::string& streetSuffix) + { return generatedStreetSuffix.find(streetSuffix) != std::string::npos; })); } TEST_F(LocationTest, shouldGenerateIndiaStreet) @@ -693,24 +718,17 @@ TEST_F(LocationTest, shouldGenerateSpainStreet) { const auto generatedStreet = Location::street(AddressCountry::Spain); - const auto generatedStreetElements = StringHelper::split(generatedStreet, " "); - - const auto& generatedStreetPrefix = generatedStreetElements[0]; - const auto& generatedStreetSuffix = - StringHelper::join({generatedStreetElements.begin() + 1, generatedStreetElements.end()}); - - ASSERT_TRUE(std::ranges::any_of(spainStreetSuffixes, [&generatedStreetPrefix](const std::string& streetSuffix) - { return streetSuffix == generatedStreetPrefix; })); - std::vector firstNames{spanishMalesFirstNames}; firstNames.insert(firstNames.end(), spanishFemalesFirstNames.begin(), spanishFemalesFirstNames.end()); std::vector lastNames{spanishLastNames}; - - ASSERT_TRUE(std::ranges::any_of(firstNames, [&generatedStreetSuffix](const std::string& firstName) - { return generatedStreetSuffix.find(firstName) != std::string::npos; }) || - std::ranges::any_of(lastNames, [&generatedStreetSuffix](const std::string& lastName) - { return generatedStreetSuffix.find(lastName) != std::string::npos; })); + + ASSERT_TRUE((std::ranges::any_of(firstNames, [&generatedStreet](const std::string& firstName) + { return generatedStreet.find(firstName) != std::string::npos; }) || + std::ranges::any_of(lastNames, [&generatedStreet](const std::string& lastName) + { return generatedStreet.find(lastName) != std::string::npos; })) && + std::ranges::any_of(spainStreetSuffixes, [&generatedStreet](const std::string& streetSuffix) + { return generatedStreet.find(streetSuffix) != std::string::npos; })); } TEST_F(LocationTest, shouldGenerateSpainStreetAddress) @@ -730,3 +748,46 @@ TEST_F(LocationTest, shouldGenerateSpainStreetAddress) std::ranges::any_of(lastNames, [&generatedStreetAddress](const std::string& lastName) { return generatedStreetAddress.find(lastName) != std::string::npos; })); } + +TEST_F(LocationTest, shouldGenerateFinlandStreet) +{ + const auto generatedStreet = Location::street(AddressCountry::Finland); + + const auto generatedStreetElements = StringHelper::split(generatedStreet, " "); + + const auto& generatedStreetPrefix = generatedStreetElements[0]; + const auto& generatedStreetSuffix = generatedStreetElements[1]; + + std::vector firstNames{finnishMalesFirstNames}; + firstNames.insert(firstNames.end(), finnishFemalesFirstNames.begin(), finnishFemalesFirstNames.end()); + + std::vector lastNames{finnishLastNames}; + + ASSERT_GE(generatedStreetElements.size(), 2); + + ASSERT_TRUE(std::ranges::any_of(finlandStreetSuffixes, [&generatedStreetSuffix](const std::string& streetSuffix) + { return streetSuffix == generatedStreetSuffix; })); + + ASSERT_TRUE(std::ranges::any_of(firstNames, [&generatedStreetPrefix](const std::string& firstName) + { return generatedStreetPrefix.find(firstName) != std::string::npos; }) || + std::ranges::any_of(lastNames, [&generatedStreetPrefix](const std::string& lastName) + { return generatedStreetPrefix.find(lastName) != std::string::npos; })); +} + +TEST_F(LocationTest, shouldGenerateFinlandStreetAddress) +{ + const auto generatedStreetAddress = Location::streetAddress(AddressCountry::Finland); + + ASSERT_TRUE(std::ranges::any_of(finlandStreetSuffixes, [&generatedStreetAddress](const std::string& suffix) + { return generatedStreetAddress.find(suffix) != std::string::npos; })); + + std::vector firstNames{finnishMalesFirstNames}; + firstNames.insert(firstNames.end(), finnishFemalesFirstNames.begin(), finnishFemalesFirstNames.end()); + + std::vector lastNames{finnishLastNames}; + + ASSERT_TRUE(std::ranges::any_of(firstNames, [&generatedStreetAddress](const std::string& firstName) + { return generatedStreetAddress.find(firstName) != std::string::npos; }) || + std::ranges::any_of(lastNames, [&generatedStreetAddress](const std::string& lastName) + { return generatedStreetAddress.find(lastName) != std::string::npos; })); +} \ No newline at end of file diff --git a/src/modules/location/data/finland/FinlandAddresses.h b/src/modules/location/data/finland/FinlandAddresses.h new file mode 100644 index 000000000..ae21df71b --- /dev/null +++ b/src/modules/location/data/finland/FinlandAddresses.h @@ -0,0 +1,36 @@ +#pragma once + +#include "../CountryAddresses.h" +#include "FinlandCities.h" +#include "FinlandStates.h" +#include "FinlandStreetSuffixes.h" + +namespace faker { + +const std::string finlandZipCodeFormat{"#####"}; + +const std::vector finlandAddressFormats{"{street} {buildingNumber}", "{street} {buildingNumber} {secondaryAddress}"}; + +const std::vector finlandSecondaryAddressFormats{"A", "B", "C", "A #", "A ##", "B #", "B ##", "C #", "C ##"}; + +const std::vector finlandBuildingNumberFormats{"###", "##", "#"}; + +const std::vector finlandStreetFormats{"{firstName} {streetSuffix}", "{lastName} {streetSuffix}"}; + +const std::vector finlandCityFormats{"{cityName}"}; + +const CountryAddresses finlandAddresses{finlandZipCodeFormat, + finlandAddressFormats, + finlandSecondaryAddressFormats, + finlandStreetFormats, + {}, + {}, + finlandStreetSuffixes, + finlandBuildingNumberFormats, + finlandCityFormats, + {}, + finlandCities, + {}, + finlandStates, + {}}; +} \ No newline at end of file diff --git a/src/modules/location/data/finland/FinlandCities.h b/src/modules/location/data/finland/FinlandCities.h new file mode 100644 index 000000000..c70d61021 --- /dev/null +++ b/src/modules/location/data/finland/FinlandCities.h @@ -0,0 +1,30 @@ +#pragma once + +#include +#include + +namespace faker +{ +const std::vector finlandCities{ + "Espoo", + "Helsinki", + "Hyvinkää", + "Iisalmi", + "Joensuu", + "Jyväskylä", + "Kokkola", + "Kuopio", + "Lahti", + "Oulu", + "Pori", + "Porvoo", + "Raisio", + "Rovaniemi", + "Sastamala", + "Tampere", + "Turku", + "Vaasa", + "Valkeakoski", + "Vantaa", +}; +} diff --git a/src/modules/location/data/finland/FinlandStates.h b/src/modules/location/data/finland/FinlandStates.h new file mode 100644 index 000000000..6d941a008 --- /dev/null +++ b/src/modules/location/data/finland/FinlandStates.h @@ -0,0 +1,29 @@ +#pragma once + +#include +#include + +namespace faker +{ +const std::vector finlandStates = { + "Ahvenanmaa", + "Etelä-Karjala", + "Etelä-Pohjanmaa", + "Etelä-Savo", + "Kainuu", + "Kanta-Häme", + "Keski-Pohjanmaa", + "Keski-Suomi", + "Kymenlaakso", + "Lappi", + "Päijät-Häme", + "Pirkanmaa", + "Pohjanmaa", + "Pohjois-Karjala", + "Pohjois-Pohjanmaa", + "Pohjois-Savo", + "Satakunta", + "Uusimaa", + "Varsinais-Suomi", +}; +} diff --git a/src/modules/location/data/finland/FinlandStreetSuffixes.h b/src/modules/location/data/finland/FinlandStreetSuffixes.h new file mode 100644 index 000000000..e553ca7de --- /dev/null +++ b/src/modules/location/data/finland/FinlandStreetSuffixes.h @@ -0,0 +1,21 @@ +#pragma once + +#include +#include + +namespace faker +{ +const std::vector finlandStreetSuffixes = { + "katu", + "tie", + "kuja", + "polku", + "kaari", + "linja", + "raitti", + "rinne", + "penger", + "ranta", + "väylä", +}; +}