Skip to content

Commit

Permalink
Added Latvian addresses (#515)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaljok authored Mar 19, 2024
1 parent 1e05cac commit ef83eed
Show file tree
Hide file tree
Showing 7 changed files with 584 additions and 3 deletions.
3 changes: 3 additions & 0 deletions include/faker-cxx/types/AddressCountry.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ enum class AddressCountry
Finland,
Estonia,
Romania,
Latvia
};

const std::vector<AddressCountry> addressCountries{
AddressCountry::Usa, AddressCountry::Poland, AddressCountry::France, AddressCountry::Russia,
AddressCountry::Ukraine, AddressCountry::Italy, AddressCountry::Germany, AddressCountry::Czech,
AddressCountry::India, AddressCountry::Denmark, AddressCountry::Australia, AddressCountry::Spain,
AddressCountry::Brazil, AddressCountry::Finland, AddressCountry::Estonia, AddressCountry::Romania,
AddressCountry::Latvia
};

inline std::string toString(AddressCountry country)
Expand All @@ -53,6 +55,7 @@ inline std::string toString(AddressCountry country)
{AddressCountry::Finland, "Finland"},
{AddressCountry::Estonia, "Estonia"},
{AddressCountry::Romania, "Romania"},
{AddressCountry::Latvia, "Latvia"},
};

return countryToStringMapping.at(country);
Expand Down
8 changes: 6 additions & 2 deletions src/modules/location/Location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "data/germany/GermanyAddresses.h"
#include "data/india/IndiaAddresses.h"
#include "data/italy/ItalyAddresses.h"
#include "data/latvia/LatviaAddresses.h"
#include "data/poland/PolandAddresses.h"
#include "data/romania/RomaniaAddresses.h"
#include "data/russia/RussiaAddresses.h"
Expand Down Expand Up @@ -47,7 +48,8 @@ const std::map<AddressCountry, CountryAddresses> countryToCountryAddressesMappin
{AddressCountry::Brazil, brazilAddresses},
{AddressCountry::Finland, finlandAddresses},
{AddressCountry::Estonia, estoniaAddresses},
{AddressCountry::Romania, romaniaAddresses}};
{AddressCountry::Romania, romaniaAddresses},
{AddressCountry::Latvia, latviaAddresses}};

const std::map<AddressCountry, Country> countryAddressToCountryMapping{{AddressCountry::Usa, Country::Usa},
{AddressCountry::Poland, Country::Poland},
Expand All @@ -64,7 +66,9 @@ const std::map<AddressCountry, Country> countryAddressToCountryMapping{{AddressC
{AddressCountry::Brazil, Country::Brazil},
{AddressCountry::Finland, Country::Finland},
{AddressCountry::Estonia, Country::Estonia},
{AddressCountry::Romania, Country::Romania}};
{AddressCountry::Romania, Country::Romania},
{AddressCountry::Latvia, Country::Latvia},
};
}

std::string Location::country()
Expand Down
33 changes: 32 additions & 1 deletion src/modules/location/LocationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "data/germany/GermanyAddresses.h"
#include "data/india/IndiaAddresses.h"
#include "data/italy/ItalyAddresses.h"
#include "data/latvia/LatviaAddresses.h"
#include "data/poland/PolandAddresses.h"
#include "data/romania/RomaniaAddresses.h"
#include "data/russia/RussiaAddresses.h"
Expand Down Expand Up @@ -67,6 +68,7 @@ const std::map<AddressCountry, CountryAddresses> countryToCountryAddressesMappin
{AddressCountry::Finland, finlandAddresses},
{AddressCountry::Estonia, estoniaAddresses},
{AddressCountry::Romania, romaniaAddresses},
{AddressCountry::Latvia, latviaAddresses},
};

const std::map<AddressCountry, std::string> generatedTestName{
Expand All @@ -86,6 +88,7 @@ const std::map<AddressCountry, std::string> generatedTestName{
{AddressCountry::Finland, "shouldGenerateFinlandAddress"},
{AddressCountry::Estonia, "shouldGenerateEstoniaAddress"},
{AddressCountry::Romania, "shouldGenerateRomaniaAddress"},
{AddressCountry::Latvia, "shouldGenerateLatviaAddress"},
};
}

Expand Down Expand Up @@ -190,7 +193,17 @@ TEST_P(LocationTest, shouldGenerateZipCode)
const auto generatedZipCode = Location::zipCode(country);

ASSERT_EQ(generatedZipCode.size(), countryAddresses.zipCodeFormat.size());
ASSERT_TRUE(checkIfZipCode(generatedZipCode));

if (country == AddressCountry::Latvia)
{
// Latvian ZIP codes have mandatory "LV" prefix (https://en.wikipedia.org/wiki/Postal_codes_in_Latvia)
ASSERT_TRUE(generatedZipCode.starts_with("LV"));
ASSERT_TRUE(checkIfAllCharactersAreNumeric(generatedZipCode.substr(2, 4)));
}
else
{
ASSERT_TRUE(checkIfZipCode(generatedZipCode));
}
}

TEST_P(LocationTest, shouldGenerateBuildingNumber)
Expand Down Expand Up @@ -828,3 +841,21 @@ TEST_F(LocationTest, shouldGenerateEstoniaStreetAddress)
ASSERT_TRUE(std::ranges::any_of(estoniaStreetNames, [&generatedStreetAddress](const std::string& streetName)
{ return generatedStreetAddress.find(streetName) != std::string::npos; }));
}

TEST_F(LocationTest, shouldGenerateLatviaStreet)
{
const auto generatedStreet = Location::street(AddressCountry::Latvia);
ASSERT_TRUE(std::ranges::any_of(latviaStreetNames, [&generatedStreet](const std::string& streetName)
{ return generatedStreet.find(streetName) != std::string::npos; }));
ASSERT_TRUE(std::ranges::any_of(latviaStreetSuffixes, [&generatedStreet](const std::string& streetName)
{ return generatedStreet.find(streetName) == std::string::npos; }));
}

TEST_F(LocationTest, shouldGenerateLatviaStreetAddress)
{
const auto generatedAddress = Location::streetAddress(AddressCountry::Latvia);
ASSERT_TRUE(std::ranges::any_of(latviaStreetNames, [&generatedAddress](const std::string& streetName)
{ return generatedAddress.find(streetName) != std::string::npos; }));
ASSERT_TRUE(std::ranges::any_of(digitSet, [&generatedAddress](const char& digit)
{ return generatedAddress.back() == digit; }));
}
41 changes: 41 additions & 0 deletions src/modules/location/data/latvia/LatviaAddresses.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#pragma once

#include "../CountryAddresses.h"
#include "LatviaCities.h"
#include "LatviaStates.h"
#include "LatviaStreetNames.h"

namespace faker
{
const std::string latviaZipCodeFormat{"LV####"};

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

const std::vector<std::string> latviaSecondaryAddressFormats{"dz. ##", "- ##"};

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

const std::vector<std::string> latviaStreetSuffixes{"iela", "ceļš", "prospekts", "bulvāris",
"gatve", "gāte", "laukums", "dambis"};

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

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

const CountryAddresses latviaAddresses{latviaZipCodeFormat,
latviaAddressFormats,
latviaSecondaryAddressFormats,
latviaStreetFormats,
{},
latviaStreetNames,
latviaStreetSuffixes,
latviaBuildingNumberFormats,
latviaCityFormats,
{},
latviaCities,
{},
latviaStates,
{}};
}
113 changes: 113 additions & 0 deletions src/modules/location/data/latvia/LatviaCities.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#pragma once

#include <string>
#include <vector>

namespace faker
{
const std::vector<std::string> latviaCities{
// Cities
"Ainaži", "Aizkraukle", "Aizpute", "Aknīste", "Aloja", "Alūksne", "Ape", "Auce", "Baldone", "Baloži", "Balvi",
"Bauska", "Brocēni", "Cēsis", "Cesvaine", "Dagda", "Daugavpils", "Dobele", "Durbe", "Grobiņa", "Gulbene", "Ikšķile",
"Ilūkste", "Jaunjelgava", "Jēkabpils", "Jelgava", "Jūrmala", "Kandava", "Kārsava", "Krāslava", "Kuldīga", "Ķegums",
"Lielvārde", "Liepāja", "Līgatne", "Limbaži", "Līvāni", "Lubāna", "Ludza", "Madona", "Mazsalaca", "Ogre", "Olaine",
"Pāvilosta", "Piltene", "Pļaviņas", "Preiļi", "Priekule", "Rēzekne", "Rīga", "Rūjiena", "Sabile", "Salacgrīva",
"Salaspils", "Saldus", "Saulkrasti", "Seda", "Sigulda", "Skrunda", "Smiltene", "Staicele", "Stende", "Strenči",
"Subate", "Talsi", "Tukums", "Valdemārpils", "Valka", "Valmiera", "Vangaži", "Varakļāni", "Ventspils", "Viesīte",
"Viļaka", "Viļāni", "Zilupe",

// Parishes
"Aizkraukles pagasts", "Daudzeses pagasts", "Jaunjelgavas pagasts", "Seces pagasts", "Sērenes pagasts",
"Staburaga pagasts", "Sunākstes pagasts", "Bebru pagasts", "Iršu pagasts", "Kokneses pagasts", "Mazzalves pagasts",
"Neretas pagasts", "Pilskalnes pagasts", "Zalves pagasts", "Aiviekstes pagasts", "Klintaines pagasts",
"Vietalvas pagasts", "Skrīveru pagasts", "Alsviķu pagasts", "Annas pagasts", "Ilzenes pagasts",
"Jaunalūksnes pagasts", "Jaunannas pagasts", "Jaunlaicenes pagasts", "Kalncempju pagasts", "Liepnas pagasts",
"Malienas pagasts", "Mālupes pagasts", "Mārkalnes pagasts", "Pededzes pagasts", "Veclaicenes pagasts",
"Zeltiņu pagasts", "Ziemera pagasts", "Ambeļu pagasts", "Biķernieku pagasts", "Demenes pagasts", "Dubnas pagasts",
"Kalkūnes pagasts", "Kalupes pagasts", "Laucesas pagasts", "Līksnas pagasts", "Maļinovas pagasts", "Medumu pagasts",
"Naujenes pagasts", "Nīcgales pagasts", "Salienas pagasts", "Skrudalienas pagasts", "Sventes pagasts",
"Tabores pagasts", "Vaboles pagasts", "Vecsalienas pagasts", "Višķu pagasts", "Bebrenes pagasts", "Dvietes pagasts",
"Eglaines pagasts", "Pilskalnes pagasts", "Prodes pagasts", "Šēderes pagasts", "Ādažu pagasts",
"Carnikavas pagasts", "Baltinavas pagasts", "Balvu pagasts", "Bērzkalnes pagasts", "Bērzpils pagasts",
"Briežuciema pagasts", "Krišjāņu pagasts", "Kubulu pagasts", "Lazdulejas pagasts", "Tilžas pagasts",
"Vectilžas pagasts", "Vīksnas pagasts", "Lazdukalna pagasts", "Rugāju pagasts", "Kupravas pagasts",
"Medņevas pagasts", "Susāju pagasts", "Šķilbēnu pagasts", "Vecumu pagasts", "Žīguru pagasts", "Brunavas pagasts",
"Ceraukstes pagasts", "Codes pagasts", "Dāviņu pagasts", "Gailīšu pagasts", "Īslīces pagasts", "Mežotnes pagasts",
"Vecsaules pagasts", "Iecavas pagasts", "Rundāles pagasts", "Svitenes pagasts", "Viesturu pagasts",
"Bārbeles pagasts", "Kurmenes pagasts", "Skaistkalnes pagasts", "Stelpes pagasts", "Valles pagasts",
"Vecumnieku pagasts", "Amatas pagasts", "Drabešu pagasts", "Nītaures pagasts", "Skujenes pagasts", "Zaubes pagasts",
"Vaives pagasts", "Jaunpiebalgas pagasts", "Zosēnu pagasts", "Līgatnes pagasts", "Raiskuma pagasts",
"Stalbes pagasts", "Straupes pagasts", "Liepas pagasts", "Mārsnēnu pagasts", "Priekuļu pagasts",
"Veselavas pagasts", "Dzērbenes pagasts", "Inešu pagasts", "Kaives pagasts", "Taurenes pagasts",
"Vecpiebalgas pagasts", "Aizputes pagasts", "Cīravas pagasts", "Kalvenes pagasts", "Kazdangas pagasts",
"Lažas pagasts", "Dunalkas pagasts", "Durbes pagasts", "Tadaiķu pagasts", "Vecpils pagasts", "Bārtas pagasts",
"Gaviezes pagasts", "Grobiņas pagasts", "Medzes pagasts", "Nīcas pagasts", "Otaņķu pagasts", "Sakas pagasts",
"Vērgales pagasts", "Bunkas pagasts", "Gramzdas pagasts", "Kalētu pagasts", "Priekules pagasts", "Virgas pagasts",
"Dunikas pagasts", "Rucavas pagasts", "Embūtes pagasts", "Vaiņodes pagasts", "Bēnes pagasts", "Īles pagasts",
"Lielauces pagasts", "Ukru pagasts", "Vecauces pagasts", "Vītiņu pagasts", "Annenieku pagasts", "Auru pagasts",
"Bērzes pagasts", "Bikstu pagasts", "Dobeles pagasts", "Jaunbērzes pagasts", "Krimūnu pagasts", "Naudītes pagasts",
"Penkules pagasts", "Zebrenes pagasts", "Augstkalnes pagasts", "Bukaišu pagasts", "Tērvetes pagasts",
"Beļavas pagasts", "Daukstu pagasts", "Druvienas pagasts", "Galgauskas pagasts", "Jaungulbenes pagasts",
"Lejasciema pagasts", "Litenes pagasts", "Lizuma pagasts", "Līgo pagasts", "Rankas pagasts", "Stāmerienas pagasts",
"Stradu pagasts", "Tirzas pagasts", "Elejas pagasts", "Glūdas pagasts", "Jaunsvirlaukas pagasts",
"Kalnciema pagasts", "Lielplatones pagasts", "Līvbērzes pagasts", "Platones pagasts", "Sesavas pagasts",
"Svētes pagasts", "Valgundes pagasts", "Vilces pagasts", "Vircavas pagasts", "Zaļenieku pagasts", "Cenu pagasts",
"Ozolnieku pagasts", "Salgales pagasts", "Aknīstes pagasts", "Asares pagasts", "Gārsenes pagasts", "Ābeļu pagasts",
"Dignājas pagasts", "Dunavas pagasts", "Kalna pagasts", "Leimaņu pagasts", "Rubenes pagasts", "Zasas pagasts",
"Atašienes pagasts", "Krustpils pagasts", "Kūku pagasts", "Mežāres pagasts", "Variešu pagasts", "Vīpes pagasts",
"Salas pagasts", "Sēlpils pagasts", "Elkšņu pagasts", "Rites pagasts", "Saukas pagasts", "Viesītes pagasts",
"Grāveru pagasts", "Kastuļinas pagasts", "Šķeltovas pagasts", "Andrupenes pagasts", "Andzeļu pagasts",
"Asūnes pagasts", "Bērziņu pagasts", "Dagdas pagasts", "Ezernieku pagasts", "Konstantinovas pagasts",
"Ķepovas pagasts", "Svariņu pagasts", "Šķaunes pagasts", "Aulejas pagasts", "Indras pagasts", "Izvaltas pagasts",
"Kalniešu pagasts", "Kaplavas pagasts", "Kombuļu pagasts", "Krāslavas pagasts", "Piedrujas pagasts",
"Robežnieku pagasts", "Skaistas pagasts", "Ūdrīšu pagasts", "Ēdoles pagasts", "Gudenieku pagasts",
"Īvandes pagasts", "Kabiles pagasts", "Kurmāles pagasts", "Laidu pagasts", "Padures pagasts", "Pelču pagasts",
"Rendas pagasts", "Rumbas pagasts", "Snēpeles pagasts", "Turlavas pagasts", "Vārmes pagasts", "Nīkrāces pagasts",
"Raņķu pagasts", "Rudbāržu pagasts", "Skrundas pagasts", "Alsungas pagasts", "Baldones pagasts",
"Daugmales pagasts", "Ķekavas pagasts", "Alojas pagasts", "Braslavas pagasts", "Brīvzemnieku pagasts",
"Staiceles pagasts", "Katvaru pagasts", "Limbažu pagasts", "Pāles pagasts", "Skultes pagasts", "Umurgas pagasts",
"Vidrižu pagasts", "Viļķenes pagasts", "Ainažu pagasts", "Liepupes pagasts", "Salacgrīvas pagasts",
"Jersikas pagasts", "Rožupes pagasts", "Rudzātu pagasts", "Sutru pagasts", "Turku pagasts", "Blontu pagasts",
"Ciblas pagasts", "Līdumnieku pagasts", "Pušmucovas pagasts", "Zvirgzdenes pagasts", "Goliševas pagasts",
"Malnavas pagasts", "Mežvidu pagasts", "Mērdzenes pagasts", "Salnavas pagasts", "Briģu pagasts", "Cirmas pagasts",
"Isnaudas pagasts", "Istras pagasts", "Nirzas pagasts", "Ņukšu pagasts", "Pildas pagasts", "Pureņu pagasts",
"Rundēnu pagasts", "Lauderu pagasts", "Pasienes pagasts", "Zaļesjes pagasts", "Cesvaines pagasts", "Ērgļu pagasts",
"Jumurdas pagasts", "Sausnējas pagasts", "Indrānu pagasts", "Aronas pagasts", "Barkavas pagasts",
"Bērzaunes pagasts", "Dzelzavas pagasts", "Kalsnavas pagasts", "Lazdonas pagasts", "Liezēres pagasts",
"Ļaudonas pagasts", "Mārcienas pagasts", "Mētrienas pagasts", "Ošupes pagasts", "Praulienas pagasts",
"Sarkaņu pagasts", "Vestienas pagasts", "Babītes pagasts", "Salas pagasts", "Mārupes pagasts", "Tīnūžu pagasts",
"Birzgales pagasts", "Rembates pagasts", "Tomes pagasts", "Jumpravas pagasts", "Lēdmanes pagasts",
"Lielvārdes pagasts", "Krapes pagasts", "Ķeipenes pagasts", "Lauberes pagasts", "Madlienas pagasts",
"Mazozolu pagasts", "Meņģeles pagasts", "Ogresgala pagasts", "Suntažu pagasts", "Taurupes pagasts",
"Olaines pagasts", "Aglonas pagasts", "Aizkalnes pagasts", "Pelēču pagasts", "Preiļu pagasts", "Saunas pagasts",
"Galēnu pagasts", "Riebiņu pagasts", "Rušonas pagasts", "Silajāņu pagasts", "Sīļukalna pagasts",
"Stabulnieku pagasts", "Rožkalnu pagasts", "Upmalas pagasts", "Vārkavas pagasts", "Audriņu pagasts",
"Bērzgales pagasts", "Čornajas pagasts", "Dricānu pagasts", "Feimaņu pagasts", "Gaigalavas pagasts",
"Griškānu pagasts", "Ilzeskalna pagasts", "Kantinieku pagasts", "Kaunatas pagasts", "Lendžu pagasts",
"Lūznavas pagasts", "Maltas pagasts", "Mākoņkalna pagasts", "Nagļu pagasts", "Nautrēnu pagasts",
"Ozolaines pagasts", "Ozolmuižas pagasts", "Pušas pagasts", "Rikavas pagasts", "Sakstagala pagasts",
"Silmalas pagasts", "Stoļerovas pagasts", "Stružānu pagasts", "Vērēmu pagasts", "Dekšāres pagasts",
"Sokolku pagasts", "Viļānu pagasts", "Garkalnes pagasts", "Ropažu pagasts", "Stopiņu pagasts", "Salaspils pagasts",
"Blīdenes pagasts", "Cieceres pagasts", "Gaiķu pagasts", "Remtes pagasts", "Ezeres pagasts", "Jaunauces pagasts",
"Jaunlutriņu pagasts", "Kursīšu pagasts", "Lutriņu pagasts", "Nīgrandes pagasts", "Novadnieku pagasts",
"Pampāļu pagasts", "Rubas pagasts", "Saldus pagasts", "Šķēdes pagasts", "Vadakstes pagasts", "Zaņas pagasts",
"Zirņu pagasts", "Zvārdes pagasts", "Saulkrastu pagasts", "Sējas pagasts", "Inčukalna pagasts", "Krimuldas pagasts",
"Lēdurgas pagasts", "Allažu pagasts", "Mores pagasts", "Siguldas pagasts", "Mālpils pagasts", "Apes pagasts",
"Gaujienas pagasts", "Trapenes pagasts", "Virešu pagasts", "Drustu pagasts", "Raunas pagasts", "Bilskas pagasts",
"Blomes pagasts", "Brantu pagasts", "Grundzāles pagasts", "Launkalnes pagasts", "Palsmanes pagasts",
"Smiltenes pagasts", "Variņu pagasts", "Dundagas pagasts", "Kolkas pagasts", "Abavas pagasts", "Ārlavas pagasts",
"Balgales pagasts", "Ģibuļu pagasts", "Īves pagasts", "Ķūļciema pagasts", "Laidzes pagasts", "Laucienes pagasts",
"Lībagu pagasts", "Lubes pagasts", "Strazdes pagasts", "Valdgales pagasts", "Vandzenes pagasts", "Virbu pagasts",
"Mērsraga pagasts", "Rojas pagasts", "Engures pagasts", "Lapmežciema pagasts", "Smārdes pagasts",
"Jaunpils pagasts", "Viesatu pagasts", "Cēres pagasts", "Kandavas pagasts", "Matkules pagasts", "Vānes pagasts",
"Zantes pagasts", "Zemītes pagasts", "Degoles pagasts", "Džūkstes pagasts", "Irlavas pagasts", "Jaunsātu pagasts",
"Lestenes pagasts", "Pūres pagasts", "Sēmes pagasts", "Slampes pagasts", "Tumes pagasts", "Zentenes pagasts",
"Ērģemes pagasts", "Kārķu pagasts", "Valkas pagasts", "Vijciema pagasts", "Zvārtavas pagasts", "Brenguļu pagasts",
"Kauguru pagasts", "Trikātas pagasts", "Burtnieku pagasts", "Ēveles pagasts", "Matīšu pagasts", "Rencēnu pagasts",
"Valmieras pagasts", "Vecates pagasts", "Bērzaines pagasts", "Dikļu pagasts", "Kocēnu pagasts", "Vaidavas pagasts",
"Zilākalna pagasts", "Mazsalacas pagasts", "Ramatas pagasts", "Sēļu pagasts", "Skaņkalnes pagasts", "Ķoņu pagasts",
"Naukšēnu pagasts", "Ipiķu pagasts", "Jeru pagasts", "Lodes pagasts", "Vilpulkas pagasts", "Jērcēnu pagasts",
"Plāņu pagasts", "Murmastienes pagasts", "Varakļānu pagasts", "Ances pagasts", "Jūrkalnes pagasts",
"Piltenes pagasts", "Popes pagasts", "Puzes pagasts", "Tārgales pagasts", "Ugāles pagasts", "Usmas pagasts",
"Užavas pagasts", "Vārves pagasts", "Ziru pagasts", "Zlēku pagasts"};
}
Loading

0 comments on commit ef83eed

Please sign in to comment.