Skip to content

Commit

Permalink
"Added Support for Czech Location Addresses."
Browse files Browse the repository at this point in the history
  • Loading branch information
flamingchad committed Jan 7, 2024
1 parent bee8e90 commit 1f8a6bc
Show file tree
Hide file tree
Showing 6 changed files with 8,208 additions and 6 deletions.
5 changes: 3 additions & 2 deletions include/faker-cxx/types/AddressCountry.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,21 @@ enum class AddressCountry
Ukraine,
Italy,
Germany,
Czech,
};

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

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::Ukraine, "Ukraine"}, {AddressCountry::Italy, "Italy"},
{AddressCountry::Germany, "Germany"},
{AddressCountry::Germany, "Germany"}, {AddressCountry::Czech, "Czech"},
};

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 @@ -6,6 +6,7 @@
#include "../../common/mappers/precisionMapper/PrecisionMapper.h"
#include "data/Countries.h"
#include "data/Directions.h"
#include "data/czech/CzechAddresses.h"
#include "data/france/FranceAddresses.h"
#include "data/poland/PolandAddresses.h"
#include "data/italy/ItalyAddresses.h"
Expand All @@ -27,14 +28,14 @@ const std::map<AddressCountry, CountryAddresses> countryToCountryAddressesMappin
{AddressCountry::Usa, usaAddresses}, {AddressCountry::Poland, polandAddresses},
{AddressCountry::Russia, russiaAddresses}, {AddressCountry::France, franceAddresses},
{AddressCountry::Ukraine, ukraineAddresses}, {AddressCountry::Italy, italyAddresses},
{AddressCountry::Germany, germanyAddresses},
{AddressCountry::Germany, germanyAddresses}, {AddressCountry::Czech, czechAddresses},
};

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

Expand Down
26 changes: 24 additions & 2 deletions src/modules/location/LocationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@
#include "../person/data/ukraine/UkrainianLastNames.h"
#include "../person/data/italy/ItalianFirstNames.h"
#include "../person/data/italy/ItalianLastNames.h"
#include "../person/data/czech/CzechFirstNames.h"
#include "../person/data/czech/CzechLastNames.h"
#include "../string/data/Characters.h"
#include "data/Countries.h"
#include "data/CountryAddresses.h"
#include "data/Directions.h"
#include "data/czech/CzechAddresses.h"
#include "data/france/FranceAddresses.h"
#include "data/poland/PolandAddresses.h"
#include "data/russia/RussiaAddresses.h"
Expand All @@ -37,7 +40,7 @@ const std::map<AddressCountry, CountryAddresses> countryToCountryAddressesMappin
{AddressCountry::Usa, usaAddresses}, {AddressCountry::Poland, polandAddresses},
{AddressCountry::Russia, russiaAddresses}, {AddressCountry::France, franceAddresses},
{AddressCountry::Ukraine, ukraineAddresses}, {AddressCountry::Italy, italyAddresses},
{AddressCountry::Germany, germanyAddresses},
{AddressCountry::Germany, germanyAddresses}, {AddressCountry::Czech, czechAddresses},
};

const std::map<AddressCountry, std::string> generatedTestName{
Expand All @@ -48,6 +51,7 @@ const std::map<AddressCountry, std::string> generatedTestName{
{AddressCountry::Ukraine, "shouldGenerateUkrainianAddress"},
{AddressCountry::Italy, "shouldGenerateItalianAddress"},
{AddressCountry::Germany, "shouldGenerateGermanAddress"},
{AddressCountry::Czech, "shouldGenerateCzechAddress"},
};
}

Expand Down Expand Up @@ -518,4 +522,22 @@ TEST_F(LocationTest, shouldGenerateGermanyStreetAddress)

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

TEST_F(LocationTest, shouldGenerateCzechStreet)
{
const auto generatedStreet = Location::street(AddressCountry::Czech);

ASSERT_TRUE(std::ranges::any_of(czechStreetNames, [&generatedStreet](const std::string& streetName)
{ return streetName == generatedStreet; }));
}

TEST_F(LocationTest, shouldGenerateCzechStreetAddress)
{
const auto generatedStreetAddress = Location::streetAddress(AddressCountry::Czech);

std::vector<std::string> streetNames{czechStreetNames};

ASSERT_TRUE(std::ranges::any_of(streetNames, [&generatedStreetAddress](const std::string& streetName)
{ return generatedStreetAddress.find(streetName) != std::string::npos; }));
}
30 changes: 30 additions & 0 deletions src/modules/location/data/czech/CzechAddresses.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include "../CountryAddresses.h"
#include "CzechCities.h"
#include "CzechStreetNames.h"


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

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

const std::vector<std::string> czechSecondaryAddressFormats{"Apt. ###", "Suite ###"};

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

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

const CountryAddresses czechAddresses{czechCities,
czechZipCodeFormat,
czechAddressFormats,
czechSecondaryAddressFormats,
czechStreetFormats,
{},
czechStreetNames,
{},
czechBuildingNumberFormats};
}
Loading

0 comments on commit 1f8a6bc

Please sign in to comment.