Skip to content

Commit

Permalink
Added Poland to location module (#95)
Browse files Browse the repository at this point in the history
* Added Polish Cities
* Added Polish example street names
* Added Polish Address Formats
  • Loading branch information
Sienq authored Sep 19, 2023
1 parent 6aab320 commit 5ea7de6
Show file tree
Hide file tree
Showing 6 changed files with 6,454 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/modules/location/Location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#include "data/russia/RussiaAddressFormat.h"
#include "data/russia/RussiaCities.h"
#include "data/russia/RussiaStreetPrefixes.h"
#include "data/poland/PolandAddressFromat.h"
#include "data/poland/PolandCities.h"
#include "data/poland/PolandStreetNames.h"
#include "data/poland/PolandStreetPrefixes.h"
#include "data/States.h"
#include "data/TimeZones.h"
#include "data/usa/UsaAddressFormat.h"
Expand All @@ -25,21 +29,29 @@ namespace
const std::map<Country, std::vector<std::string>> countryToCitiesMapping{
{Country::Usa, usaCities},
{Country::Russia, russiaCities},
{Country::Poland, polandCities}
};

const std::map<Country, std::vector<std::string>> countryToStreetsMapping{
{Country::Poland, polandStreets}
};

const std::map<Country, std::string> countryToZipCodeFormatMapping{
{Country::Usa, usaZipCodeFormat},
{Country::Russia, russiaZipCodeFormat},
{Country::Poland, polandZipCodeFormat}
};

const std::map<Country, std::vector<std::string>> countryToBuildingNumberFormatsMapping{
{Country::Usa, usaBuildingNumberFormats},
{Country::Russia, russiaBuildingNumberFormats},
{Country::Poland, polandBuildingNumberFormats}
};

const std::map<Country, std::vector<std::string>> countryToStreetFormatsMapping{
{Country::Usa, usaStreetFormats},
{Country::Russia, russiaStreetFormats},
{Country::Poland, polandStreetFormats}
};

const std::map<Country, std::vector<std::string>> countryToSecondaryAddressFormatsMapping{
Expand All @@ -49,6 +61,7 @@ const std::map<Country, std::vector<std::string>> countryToSecondaryAddressForma
const std::map<Country, std::string> countryToAddressFormatMapping{
{Country::Usa, usaAddressFormat},
{Country::Russia, russiaAddressFormat},
{Country::Poland, polandAddressFormat}
};

const std::map<Country, std::vector<std::string>> countryToStreetSuffixesMapping{
Expand All @@ -57,6 +70,7 @@ const std::map<Country, std::vector<std::string>> countryToStreetSuffixesMapping

const std::map<Country, std::vector<std::string>> countryToStreetPrefixesMapping{
{Country::Russia, russiaStreetPrefixes},
{Country::Poland, polandStreetPrefixes}
};
}

Expand Down Expand Up @@ -148,6 +162,11 @@ std::string Location::street(Country country)

streetNameElements.push_back(streetPrefix);
}
else if (streetFormatElement == "{streetName}")
{
const auto& streets = countryToStreetsMapping.at(country);
streetNameElements.push_back(Helper::arrayElement<std::string>(streets));
}
}

return StringHelper::join(streetNameElements, " ");
Expand Down
61 changes: 61 additions & 0 deletions src/modules/location/LocationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#include "data/Directions.h"
#include "data/russia/RussiaCities.h"
#include "data/russia/RussiaStreetPrefixes.h"
#include "data/poland/PolandCities.h"
#include "data/poland/PolandStreetNames.h"
#include "data/poland/PolandStreetPrefixes.h"
#include "data/States.h"
#include "data/TimeZones.h"
#include "data/usa/UsaCities.h"
Expand Down Expand Up @@ -168,6 +171,64 @@ TEST_F(LocationTest, shouldGenerateRussiaBuildingNumber)
ASSERT_TRUE(checkIfAllCharactersAreNumeric(generatedBuildingNumber));
}

TEST_F(LocationTest, shouldGeneratePolandCity)
{
const auto generatedCity = Location::city(Country::Poland);

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

TEST_F(LocationTest, shouldGeneratePolandZipCode)
{
const auto generatedZipCode = Location::zipCode(Country::Poland);

ASSERT_EQ(generatedZipCode.size(), 6);
ASSERT_TRUE(generatedZipCode[2] == '-');
}

TEST_F(LocationTest, shouldGeneratePolandBuildingNumber)
{
const auto generatedBuildingNumber = Location::buildingNumber(Country::Poland);

ASSERT_TRUE(generatedBuildingNumber.size() >= 1 && generatedBuildingNumber.size() <= 3);
ASSERT_TRUE(checkIfAllCharactersAreNumeric(generatedBuildingNumber));
}

TEST_F(LocationTest, shouldGeneratePolandStreetAddress)
{
const auto generatedStreetAddress = Location::streetAddress(Country::Poland);

const auto generatedStreetAddressElements = StringHelper::split(generatedStreetAddress, " ");

std::vector<std::string> street{};

std::string generatedStreetName{};

if(generatedStreetAddressElements.size() > 3)
{
for(size_t i = 1; i < generatedStreetAddressElements.size() -1; ++i )
{
street.push_back(generatedStreetAddressElements.at(i));
}
generatedStreetName = StringHelper::join(street);
}
else
{
generatedStreetName = generatedStreetAddressElements[1];
}

const auto& generatedBuildingNumber = generatedStreetAddressElements.back();
const auto& generatedStreetPrefix = generatedStreetAddressElements.front();

ASSERT_TRUE(generatedBuildingNumber.size() >= 1 && generatedBuildingNumber.size() <= 3);
ASSERT_TRUE(checkIfAllCharactersAreNumeric(generatedBuildingNumber));
ASSERT_TRUE(std::ranges::any_of(polandStreetPrefixes, [generatedStreetPrefix](const std::string& prefix)
{ return prefix == generatedStreetPrefix; }));
ASSERT_TRUE(std::ranges::any_of(polandStreets, [generatedStreetName](const std::string& street)
{ return street == generatedStreetName; }));
}

TEST_F(LocationTest, shouldGenerateLatitude)
{
const auto latitude = Location::latitude();
Expand Down
16 changes: 16 additions & 0 deletions src/modules/location/data/poland/PolandAddressFromat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include <string>
#include <vector>

namespace faker
{
const std::string polandAddressFormat = "{street} {buildingNumber}";

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

const std::string polandZipCodeFormat = "##-###";

const std::vector<std::string> polandStreetFormats = {"{streetPrefix} {streetName}"};

}
Loading

0 comments on commit 5ea7de6

Please sign in to comment.