Skip to content

Commit

Permalink
feature/location-france (#169)
Browse files Browse the repository at this point in the history
* Added french cities
Created a list containing the 1,000 most populous cities, ordered by name

* Added french street prefixes

* Added french street suffixes

* Added french address format
Based on faker-js

* Added france to maps

* Added tests
  • Loading branch information
Globostofo authored Oct 1, 2023
1 parent 6b77e45 commit 4425277
Show file tree
Hide file tree
Showing 6 changed files with 1,150 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/modules/location/Location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#include "data/poland/PolandCities.h"
#include "data/poland/PolandStreetNames.h"
#include "data/poland/PolandStreetPrefixes.h"
#include "data/france/FranceAddressFormat.h"
#include "data/france/FranceCities.h"
#include "data/france/FranceStreetPrefixes.h"
#include "data/france/FranceStreetSuffixes.h"
#include "data/States.h"
#include "data/TimeZones.h"
#include "data/usa/UsaAddressFormat.h"
Expand All @@ -29,7 +33,8 @@ namespace
const std::map<Country, std::vector<std::string>> countryToCitiesMapping{
{Country::Usa, usaCities},
{Country::Russia, russiaCities},
{Country::Poland, polandCities}
{Country::Poland, polandCities},
{Country::France, franceCities}
};

const std::map<Country, std::vector<std::string>> countryToStreetsMapping{
Expand All @@ -39,38 +44,45 @@ const std::map<Country, std::vector<std::string>> countryToStreetsMapping{
const std::map<Country, std::string> countryToZipCodeFormatMapping{
{Country::Usa, usaZipCodeFormat},
{Country::Russia, russiaZipCodeFormat},
{Country::Poland, polandZipCodeFormat}
{Country::Poland, polandZipCodeFormat},
{Country::France, franceZipCodeFormat}
};

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

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

const std::map<Country, std::vector<std::string>> countryToSecondaryAddressFormatsMapping{
{Country::Usa, usaSecondaryAddressFormats},
{Country::France, franceSecondaryAddressFormats}
};

const std::map<Country, std::string> countryToAddressFormatMapping{
{Country::Usa, usaAddressFormat},
{Country::Russia, russiaAddressFormat},
{Country::Poland, polandAddressFormat}
{Country::Poland, polandAddressFormat},
{Country::France, franceAddressFormat}
};

const std::map<Country, std::vector<std::string>> countryToStreetSuffixesMapping{
{Country::Usa, usaStreetSuffixes},
{Country::France, franceStreetSuffixes}
};

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

Expand Down
76 changes: 76 additions & 0 deletions src/modules/location/LocationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#include "data/TimeZones.h"
#include "data/usa/UsaCities.h"
#include "data/usa/UsaStreetSuffixes.h"
#include "data/france/FranceCities.h"
#include "data/france/FranceStreetPrefixes.h"
#include "data/france/FranceStreetSuffixes.h"

using namespace ::testing;
using namespace faker;
Expand Down Expand Up @@ -229,6 +232,79 @@ TEST_F(LocationTest, shouldGeneratePolandStreetAddress)
{ return street == generatedStreetName; }));
}

TEST_F(LocationTest, shouldGenerateFranceCity)
{
const auto generatedCity = Location::city(Country::France);

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

TEST_F(LocationTest, shouldGenerateFranceZipCode)
{
const auto generatedZipCode = Location::zipCode(Country::France);

ASSERT_EQ(generatedZipCode.size(), 5);
ASSERT_TRUE(checkIfAllCharactersAreNumeric(generatedZipCode));
}

TEST_F(LocationTest, shouldGenerateFranceBuildingNumber)
{
const auto generatedBuildingNumber = Location::buildingNumber(Country::France);

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

TEST_F(LocationTest, shouldGenerateFranceSecondaryAddress)
{
const auto generatedSecondaryAddress = Location::secondaryAddress(Country::France);

ASSERT_TRUE(generatedSecondaryAddress.starts_with("Apt. ") || generatedSecondaryAddress.starts_with("Étage "));

const auto generatedSecondaryAddressParts = StringHelper::split(generatedSecondaryAddress, " ");

const auto& generatedBuildingNumber = generatedSecondaryAddressParts[1];

ASSERT_TRUE(generatedBuildingNumber.size() == 3 || generatedBuildingNumber.size() == 1);
ASSERT_TRUE(checkIfAllCharactersAreNumeric(generatedBuildingNumber));
}

TEST_F(LocationTest, shouldGenerateFranceStreet)
{
const auto generatedStreet = Location::street(Country::France);

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

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

ASSERT_GE(generatedStreetElements.size(), 2);
ASSERT_TRUE(std::ranges::any_of(franceStreetPrefixes, [generatedStreetPrefix](const std::string& streetPrefix)
{ return streetPrefix == generatedStreetPrefix; }));
ASSERT_TRUE(std::ranges::any_of(franceStreetSuffixes, [generatedStreetSuffix](const std::string& streetSuffix)
{ return streetSuffix == generatedStreetSuffix; }));
}

TEST_F(LocationTest, shouldGenerateFranceStreetAddress)
{
const auto generatedStreetAddress = Location::streetAddress(Country::France);

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.size() >= 1 && generatedBuildingNumber.size() <= 4);
ASSERT_TRUE(checkIfAllCharactersAreNumeric(generatedBuildingNumber));
ASSERT_TRUE(std::ranges::any_of(franceStreetPrefixes, [generatedStreetPrefix](const std::string& streetPrefix)
{ return streetPrefix == generatedStreetPrefix; }));
ASSERT_TRUE(std::ranges::any_of(franceStreetSuffixes, [generatedStreetSuffix](const std::string& streetSuffix)
{ return streetSuffix == generatedStreetSuffix; }));
}

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

#include <string>
#include <vector>

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

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

const std::string franceZipCodeFormat = "#####";

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

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

}
Loading

0 comments on commit 4425277

Please sign in to comment.