Skip to content

Commit

Permalink
add ukraine addresses (#393)
Browse files Browse the repository at this point in the history
  • Loading branch information
cieslarmichal authored Jan 1, 2024
1 parent b9cfea4 commit d282f23
Show file tree
Hide file tree
Showing 7 changed files with 672 additions and 27 deletions.
13 changes: 5 additions & 8 deletions include/faker-cxx/types/AddressCountry.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,19 @@ enum class AddressCountry
Poland,
France,
Russia,
Ukraine
};

const std::vector<AddressCountry> addressCountries{
AddressCountry::Usa,
AddressCountry::Poland,
AddressCountry::France,
AddressCountry::Russia,
AddressCountry::Usa, AddressCountry::Poland, AddressCountry::France,
AddressCountry::Russia, AddressCountry::Ukraine,
};

inline std::string toString(AddressCountry country)
{
std::map<AddressCountry, std::string> countryToStringMapping{
{AddressCountry::Usa, "Usa"},
{AddressCountry::Poland, "Poland"},
{AddressCountry::France, "France"},
{AddressCountry::Russia, "Russia"},
{AddressCountry::Usa, "Usa"}, {AddressCountry::Poland, "Poland"}, {AddressCountry::France, "France"},
{AddressCountry::Russia, "Russia"}, {AddressCountry::Ukraine, "Ukraine"},
};

return countryToStringMapping.at(country);
Expand Down
15 changes: 7 additions & 8 deletions src/modules/location/Location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "data/russia/RussiaAddresses.h"
#include "data/States.h"
#include "data/TimeZones.h"
#include "data/ukraine/UkraineAddresses.h"
#include "data/usa/UsaAddresses.h"
#include "faker-cxx/Helper.h"
#include "faker-cxx/Person.h"
Expand All @@ -21,17 +22,15 @@ namespace faker
namespace
{
const std::map<AddressCountry, CountryAddresses> countryToCountryAddressesMapping{
{AddressCountry::Usa, usaAddresses},
{AddressCountry::Poland, polandAddresses},
{AddressCountry::Russia, russiaAddresses},
{AddressCountry::France, franceAddresses},
{AddressCountry::Usa, usaAddresses}, {AddressCountry::Poland, polandAddresses},
{AddressCountry::Russia, russiaAddresses}, {AddressCountry::France, franceAddresses},
{AddressCountry::Ukraine, ukraineAddresses},
};

const std::map<AddressCountry, Country> countryAddressToCountryMapping{
{AddressCountry::Usa, Country::Usa},
{AddressCountry::Poland, Country::Poland},
{AddressCountry::Russia, Country::Russia},
{AddressCountry::France, Country::France},
{AddressCountry::Usa, Country::Usa}, {AddressCountry::Poland, Country::Poland},
{AddressCountry::Russia, Country::Russia}, {AddressCountry::France, Country::France},
{AddressCountry::Ukraine, Country::Ukraine},
};
}

Expand Down
69 changes: 58 additions & 11 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/russia/RussianFirstNames.h"
#include "../person/data/russia/RussianLastNames.h"
#include "../person/data/ukraine/UkrainianFirstNames.h"
#include "../person/data/ukraine/UkrainianLastNames.h"
#include "../string/data/Characters.h"
#include "data/Countries.h"
#include "data/CountryAddresses.h"
Expand All @@ -18,6 +20,7 @@
#include "data/russia/RussiaAddresses.h"
#include "data/States.h"
#include "data/TimeZones.h"
#include "data/ukraine/UkraineAddresses.h"
#include "data/usa/UsaAddresses.h"

using namespace ::testing;
Expand All @@ -26,17 +29,17 @@ using namespace faker;
namespace
{
const std::map<AddressCountry, CountryAddresses> countryToCountryAddressesMapping{
{AddressCountry::Usa, usaAddresses},
{AddressCountry::Poland, polandAddresses},
{AddressCountry::Russia, russiaAddresses},
{AddressCountry::France, franceAddresses},
{AddressCountry::Usa, usaAddresses}, {AddressCountry::Poland, polandAddresses},
{AddressCountry::Russia, russiaAddresses}, {AddressCountry::France, franceAddresses},
{AddressCountry::Ukraine, ukraineAddresses},
};

const std::map<AddressCountry, std::string> generatedTestName{
{AddressCountry::Usa, "shouldGenerateAmericanAddress"},
{AddressCountry::France, "shouldGenerateFrenchAddress"},
{AddressCountry::Poland, "shouldGeneratePolishAddress"},
{AddressCountry::Russia, "shouldGenerateRussianAddress"},
{AddressCountry::Ukraine, "shouldGenerateUkrainianAddress"},
};
}

Expand Down Expand Up @@ -242,20 +245,16 @@ TEST_F(LocationTest, shouldGenerateRussiaStreetAddress)
firstNames.insert(firstNames.end(), russianFemalesFirstNames.begin(), russianFemalesFirstNames.end());

std::vector<std::string> lastNames{russianMalesLastNames};
firstNames.insert(firstNames.end(), russianFemalesLastNames.begin(), russianFemalesLastNames.end());
lastNames.insert(lastNames.end(), russianFemalesLastNames.begin(), russianFemalesLastNames.end());

ASSERT_TRUE(std::ranges::any_of(russiaStreetPrefixes, [&generatedStreetAddress](const std::string& prefix)
{ return generatedStreetAddress.find(prefix) != std::string::npos; }));
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; }) ||
std::ranges::any_of(russiaStreetNames,
[&generatedStreetAddress](const std::string& streetName)
{
return generatedStreetAddress.find(streetName) != std::string::npos;
;
}));
std::ranges::any_of(russiaStreetNames, [&generatedStreetAddress](const std::string& streetName)
{ return generatedStreetAddress.find(streetName) != std::string::npos; }));
}

TEST_F(LocationTest, shouldGenerateFranceStreet)
Expand Down Expand Up @@ -394,3 +393,51 @@ TEST_F(LocationTest, shouldGenerateTimeZone)
ASSERT_TRUE(std::ranges::any_of(timeZones, [generatedTimeZone](const std::string& timeZone)
{ return timeZone == generatedTimeZone; }));
}

TEST_F(LocationTest, shouldGenerateUkraineStreet)
{
const auto generatedStreet = Location::street(AddressCountry::Ukraine);

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(ukraineStreetPrefixes, [&generatedStreetPrefix](const std::string& streetPrefix)
{ return streetPrefix == generatedStreetPrefix; }));

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

std::vector<std::string> lastNames{ukrainianMalesLastNames};
lastNames.insert(lastNames.end(), ukrainianFemalesLastNames.begin(), ukrainianFemalesLastNames.end());

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(ukraineStreetNames, [&generatedStreetSuffix](const std::string& streetName)
{ return generatedStreetSuffix.find(streetName) != std::string::npos; }));
}

TEST_F(LocationTest, shouldGenerateUkraineStreetAddress)
{
const auto generatedStreetAddress = Location::streetAddress(AddressCountry::Ukraine);

ASSERT_TRUE(std::ranges::any_of(ukraineStreetPrefixes, [&generatedStreetAddress](const std::string& prefix)
{ return generatedStreetAddress.find(prefix) != std::string::npos; }));

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

std::vector<std::string> lastNames{ukrainianMalesLastNames};
lastNames.insert(lastNames.end(), ukrainianFemalesLastNames.begin(), ukrainianFemalesLastNames.end());

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; }) ||
std::ranges::any_of(ukraineStreetNames, [&generatedStreetAddress](const std::string& streetName)
{ return generatedStreetAddress.find(streetName) != std::string::npos; }));
}
31 changes: 31 additions & 0 deletions src/modules/location/data/ukraine/UkraineAddresses.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include "../CountryAddresses.h"
#include "UkraineCities.h"
#include "UkraineStreetNames.h"
#include "UkraineStreetPrefixes.h"

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

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

const std::vector<std::string> ukraineSecondaryAddressFormats{"кв. ###", "кв. ##", "кв. #"};

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

const std::vector<std::string> ukraineStreetFormats{"{streetPrefix} {firstName}", "{streetPrefix} {lastName}",
"{streetPrefix} {streetName}"};

const CountryAddresses ukraineAddresses{ukraineCities,
ukraineZipCodeFormat,
ukraineAddressFormats,
ukraineSecondaryAddressFormats,
ukraineStreetFormats,
ukraineStreetPrefixes,
ukraineStreetNames,
{},
ukraineBuildingNumberFormats};
}
Loading

0 comments on commit d282f23

Please sign in to comment.