Skip to content

Commit

Permalink
Added location addresses data from Belgium
Browse files Browse the repository at this point in the history
  • Loading branch information
krupalbhat committed Apr 21, 2024
1 parent 746ae19 commit 77a11a2
Show file tree
Hide file tree
Showing 8 changed files with 620 additions and 2 deletions.
3 changes: 2 additions & 1 deletion include/faker-cxx/Location.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ enum class AddressCountry
Estonia,
Romania,
Latvia,
Nepal
Nepal,
Belgium
};

class Location
Expand Down
6 changes: 5 additions & 1 deletion src/modules/location/Location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "../../common/mappers/precisionMapper/PrecisionMapper.h"
#include "data/australia/AustraliaAddresses.h"
#include "data/brazil/BrazilAddresses.h"
#include "data/belgium/BelgiumAddresses.h"
#include "data/Countries.h"
#include "data/czech/CzechAddresses.h"
#include "data/denmark/DenmarkAddresses.h"
Expand Down Expand Up @@ -51,7 +52,9 @@ const std::map<AddressCountry, CountryAddresses> countryToCountryAddressesMappin
{AddressCountry::Estonia, estoniaAddresses},
{AddressCountry::Romania, romaniaAddresses},
{AddressCountry::Latvia, latviaAddresses},
{AddressCountry::Nepal, nepalAddresses},};
{AddressCountry::Nepal, nepalAddresses},
{AddressCountry::Belgium, belgiumAddresses},
};

const std::map<AddressCountry, Country> countryAddressToCountryMapping{
{AddressCountry::Usa, Country::Usa},
Expand All @@ -72,6 +75,7 @@ const std::map<AddressCountry, Country> countryAddressToCountryMapping{
{AddressCountry::Romania, Country::Romania},
{AddressCountry::Latvia, Country::Latvia},
{AddressCountry::Nepal, Country::Nepal},
{AddressCountry::Belgium, Country::Belgium},
};
}

Expand Down
39 changes: 39 additions & 0 deletions src/modules/location/LocationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "data/brazil/BrazilAddresses.h"
#include "data/Countries.h"
#include "data/CountryAddresses.h"
#include "data/belgium/BelgiumAddresses.h"
#include "data/czech/CzechAddresses.h"
#include "data/denmark/DenmarkAddresses.h"
#include "data/Directions.h"
Expand Down Expand Up @@ -76,6 +77,7 @@ const std::map<AddressCountry, CountryAddresses> countryToCountryAddressesMappin
{AddressCountry::Romania, romaniaAddresses},
{AddressCountry::Latvia, latviaAddresses},
{AddressCountry::Nepal, nepalAddresses},
{AddressCountry::Belgium, belgiumAddresses},
};

const std::map<AddressCountry, std::string> generatedTestName{
Expand All @@ -97,6 +99,7 @@ const std::map<AddressCountry, std::string> generatedTestName{
{AddressCountry::Romania, "shouldGenerateRomaniaAddress"},
{AddressCountry::Latvia, "shouldGenerateLatviaAddress"},
{AddressCountry::Nepal, "shouldGenerateNepalAddress"},
{AddressCountry::Belgium, "shouldGenerateBelgiumAddress"},
};
}

Expand Down Expand Up @@ -898,3 +901,39 @@ TEST_F(LocationTest, shouldGenerateNepalStreetAddress)
ASSERT_TRUE(std::ranges::any_of(nepalStreetSuffixes, [&generatedStreetSuffix](const std::string& streetSuffix)
{ return streetSuffix == generatedStreetSuffix; }));
}

TEST_F(LocationTest, shouldGenerateBelgiumStreet)
{
const auto generatedStreet = Location::street(AddressCountry::Belgium);

const auto generatedStreetElements = StringHelper::split(generatedStreet, " ");

const auto& generatedStreetPrefix = generatedStreetElements[0];
const auto& generatedStreetSuffix =
StringHelper::join({generatedStreetElements.begin() + 1, generatedStreetElements.end()});

ASSERT_LT(generatedStreetElements.size(), 6);
ASSERT_TRUE(std::ranges::any_of(belgiumStreetPrefixes, [&generatedStreetPrefix](const std::string& streetPrefix)
{ return streetPrefix == generatedStreetPrefix; }));
ASSERT_TRUE(std::ranges::any_of(belgiumStreetSuffixes, [&generatedStreetSuffix](const std::string& streetSuffix)
{ return streetSuffix == generatedStreetSuffix; }));
}

TEST_F(LocationTest, shouldGenerateBelgiumStreetAddress)
{
const auto generatedStreetAddress = Location::streetAddress(AddressCountry::Belgium);

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

const auto& generatedBuildingNumber = generatedStreetAddressElements[0];
const auto& generatedStreetPrefix = generatedStreetAddressElements[1];
const auto& generatedStreetSuffix =
StringHelper::join({generatedStreetAddressElements.begin() + 2, generatedStreetAddressElements.end()});

ASSERT_GE(generatedStreetAddressElements.size(), 3);
ASSERT_TRUE(!generatedBuildingNumber.empty() && generatedBuildingNumber.size() <= 7);
ASSERT_TRUE(std::ranges::any_of(belgiumStreetPrefixes, [&generatedStreetPrefix](const std::string& streetPrefix)
{ return streetPrefix == generatedStreetPrefix; }));
ASSERT_TRUE(std::ranges::any_of(belgiumStreetSuffixes, [&generatedStreetSuffix](const std::string& streetSuffix)
{ return streetSuffix == generatedStreetSuffix; }));
}
38 changes: 38 additions & 0 deletions src/modules/location/data/belgium/BelgiumAddresses.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#pragma once

#include "../CountryAddresses.h"
#include "BelgiumCities.h"
#include "BelgiumStates.h"
#include "BelgiumStreetSuffixes.h"
#include "BelgiumStreetPrefixes.h"

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

const std::vector<std::string> belgiumAddressFormats{"{buildingNumber} {street}"};

const std::vector<std::string> belgiumSecondaryAddressFormats{"Apt. ###", "Étage #"};

const std::vector<std::string> belgiumBuildingNumberFormats{ "#", "##", "###", "# bis", "## bis",
"### bis", "###a", "###b", "###c", "###/2",};

const std::vector<std::string> belgiumStreetFormats{"{streetPrefix} {streetSuffix}"};

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

const CountryAddresses belgiumAddresses{belgiumZipCodeFormat,
belgiumAddressFormats,
belgiumSecondaryAddressFormats,
belgiumStreetFormats,
belgiumStreetPrefixes,
{},
belgiumStreetSuffixes,
belgiumBuildingNumberFormats,
belgiumCityFormats,
{},
belgiumCities,
{},
belgiumStates,
{}};
}
Loading

0 comments on commit 77a11a2

Please sign in to comment.