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

Add location addresses data from Finland 🇫🇮 #440

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
4 changes: 3 additions & 1 deletion include/faker-cxx/types/AddressCountry.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ namespace faker
Denmark,
Spain,
Brazil,
Finland
};

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,
AddressCountry::Brazil, AddressCountry::Finland,
};

inline std::string toString(AddressCountry country)
Expand All @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions 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/finland/FinlandAddresses.h"
#include "data/brazil/BrazilAddresses.h"
#include "data/TimeZones.h"
#include "data/ukraine/UkraineAddresses.h"
Expand All @@ -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<AddressCountry, Country> countryAddressToCountryMapping{
Expand All @@ -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},
};
}

Expand Down
123 changes: 92 additions & 31 deletions src/modules/location/LocationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
Expand All @@ -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<AddressCountry, std::string> generatedTestName{
Expand All @@ -64,7 +69,8 @@ namespace
{AddressCountry::India, "shouldGenerateIndiaAddress"},
{AddressCountry::Denmark, "shouldGenerateDenmarkAddress"},
{AddressCountry::Spain, "shouldGenerateSpainAddress"},
{AddressCountry::Brazil, "shouldGenerateBrazilAddress"}
{AddressCountry::Brazil, "shouldGenerateBrazilAddress"},
{AddressCountry::Finland, "shouldGenerateFinlandAddress"},
};
}

Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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<std::string> 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<std::string> 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)
Expand All @@ -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<std::string> firstNames{australianMalesFirstNames};
firstNames.insert(firstNames.end(), australianFemalesFirstNames.begin(), australianFemalesFirstNames.end());

std::vector<std::string> 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)
Expand Down Expand Up @@ -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<std::string> firstNames{spanishMalesFirstNames};
firstNames.insert(firstNames.end(), spanishFemalesFirstNames.begin(), spanishFemalesFirstNames.end());

std::vector<std::string> 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)
Expand All @@ -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<std::string> firstNames{finnishMalesFirstNames};
firstNames.insert(firstNames.end(), finnishFemalesFirstNames.begin(), finnishFemalesFirstNames.end());

std::vector<std::string> 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<std::string> firstNames{finnishMalesFirstNames};
firstNames.insert(firstNames.end(), finnishFemalesFirstNames.begin(), finnishFemalesFirstNames.end());

std::vector<std::string> 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; }));
}
36 changes: 36 additions & 0 deletions src/modules/location/data/finland/FinlandAddresses.h
Original file line number Diff line number Diff line change
@@ -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<std::string> finlandAddressFormats{"{street} {buildingNumber}", "{street} {buildingNumber} {secondaryAddress}"};

const std::vector<std::string> finlandSecondaryAddressFormats{"A", "B", "C", "A #", "A ##", "B #", "B ##", "C #", "C ##"};

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

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

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

const CountryAddresses finlandAddresses{finlandZipCodeFormat,
finlandAddressFormats,
finlandSecondaryAddressFormats,
finlandStreetFormats,
{},
{},
finlandStreetSuffixes,
finlandBuildingNumberFormats,
finlandCityFormats,
{},
finlandCities,
{},
finlandStates,
{}};
}
30 changes: 30 additions & 0 deletions src/modules/location/data/finland/FinlandCities.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include <string>
#include <vector>

namespace faker
{
const std::vector<std::string> finlandCities{
"Espoo",
"Helsinki",
"Hyvinkää",
"Iisalmi",
"Joensuu",
"Jyväskylä",
"Kokkola",
"Kuopio",
"Lahti",
"Oulu",
"Pori",
"Porvoo",
"Raisio",
"Rovaniemi",
"Sastamala",
"Tampere",
"Turku",
"Vaasa",
"Valkeakoski",
"Vantaa",
};
}
29 changes: 29 additions & 0 deletions src/modules/location/data/finland/FinlandStates.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include <string>
#include <vector>

namespace faker
{
const std::vector<std::string> 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",
};
}
21 changes: 21 additions & 0 deletions src/modules/location/data/finland/FinlandStreetSuffixes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include <string>
#include <vector>

namespace faker
{
const std::vector<std::string> finlandStreetSuffixes = {
"katu",
"tie",
"kuja",
"polku",
"kaari",
"linja",
"raitti",
"rinne",
"penger",
"ranta",
"väylä",
};
}