From 13c5180a2540f1d2f6ef75d31bc1c8439d07a996 Mon Sep 17 00:00:00 2001 From: krupalbhat <56032256+krupalbhat@users.noreply.github.com> Date: Tue, 9 Apr 2024 17:49:56 +0530 Subject: [PATCH] Added location addresses data from Nepal (#529) --- include/faker-cxx/Location.h | 3 +- src/common/FormatHelper.h | 4 +- src/modules/location/Location.cpp | 5 +- src/modules/location/LocationTest.cpp | 34 ++++++++ .../location/data/nepal/NepalAddresses.h | 36 ++++++++ src/modules/location/data/nepal/NepalCities.h | 87 +++++++++++++++++++ src/modules/location/data/nepal/NepalStates.h | 17 ++++ .../location/data/nepal/NepalStreetSuffixes.h | 15 ++++ 8 files changed, 197 insertions(+), 4 deletions(-) create mode 100644 src/modules/location/data/nepal/NepalAddresses.h create mode 100644 src/modules/location/data/nepal/NepalCities.h create mode 100644 src/modules/location/data/nepal/NepalStates.h create mode 100644 src/modules/location/data/nepal/NepalStreetSuffixes.h diff --git a/include/faker-cxx/Location.h b/include/faker-cxx/Location.h index 68d85de94..c7394aa14 100644 --- a/include/faker-cxx/Location.h +++ b/include/faker-cxx/Location.h @@ -24,7 +24,8 @@ enum class AddressCountry Finland, Estonia, Romania, - Latvia + Latvia, + Nepal }; class Location diff --git a/src/common/FormatHelper.h b/src/common/FormatHelper.h index a844c3383..6356ee97c 100644 --- a/src/common/FormatHelper.h +++ b/src/common/FormatHelper.h @@ -5,7 +5,7 @@ #include #include -#if defined(__APPLE__) || defined(__GNUC__) && (__GNUC__ < 12) && !defined(__clang__) +#if defined(__APPLE__) || (defined(__GNUC__) && (__GNUC__ < 12) && !defined(__clang__)) #include #else #include @@ -16,7 +16,7 @@ namespace faker class FormatHelper { public: -#if defined(__APPLE__) || (defined(__GNUC__)) && (__GNUC__ < 12) && !defined(__clang__) +#if defined(__APPLE__) || (defined(__GNUC__) && (__GNUC__ < 12) && !defined(__clang__)) template static std::string format(fmt::format_string fmt, Args&&... args) { diff --git a/src/modules/location/Location.cpp b/src/modules/location/Location.cpp index 1f9bd64f5..b692a9d1c 100644 --- a/src/modules/location/Location.cpp +++ b/src/modules/location/Location.cpp @@ -18,6 +18,7 @@ #include "data/india/IndiaAddresses.h" #include "data/italy/ItalyAddresses.h" #include "data/latvia/LatviaAddresses.h" +#include "data/nepal/NepalAddresses.h" #include "data/poland/PolandAddresses.h" #include "data/romania/RomaniaAddresses.h" #include "data/russia/RussiaAddresses.h" @@ -49,7 +50,8 @@ const std::map countryToCountryAddressesMappin {AddressCountry::Finland, finlandAddresses}, {AddressCountry::Estonia, estoniaAddresses}, {AddressCountry::Romania, romaniaAddresses}, - {AddressCountry::Latvia, latviaAddresses}}; + {AddressCountry::Latvia, latviaAddresses}, + {AddressCountry::Nepal, nepalAddresses},}; const std::map countryAddressToCountryMapping{ {AddressCountry::Usa, Country::Usa}, @@ -69,6 +71,7 @@ const std::map countryAddressToCountryMapping{ {AddressCountry::Estonia, Country::Estonia}, {AddressCountry::Romania, Country::Romania}, {AddressCountry::Latvia, Country::Latvia}, + {AddressCountry::Nepal, Country::Nepal}, }; } diff --git a/src/modules/location/LocationTest.cpp b/src/modules/location/LocationTest.cpp index b9b34070b..c9c123d5a 100644 --- a/src/modules/location/LocationTest.cpp +++ b/src/modules/location/LocationTest.cpp @@ -36,6 +36,7 @@ #include "data/india/IndiaAddresses.h" #include "data/italy/ItalyAddresses.h" #include "data/latvia/LatviaAddresses.h" +#include "data/nepal/NepalAddresses.h" #include "data/poland/PolandAddresses.h" #include "data/romania/RomaniaAddresses.h" #include "data/russia/RussiaAddresses.h" @@ -74,6 +75,7 @@ const std::map countryToCountryAddressesMappin {AddressCountry::Estonia, estoniaAddresses}, {AddressCountry::Romania, romaniaAddresses}, {AddressCountry::Latvia, latviaAddresses}, + {AddressCountry::Nepal, nepalAddresses}, }; const std::map generatedTestName{ @@ -94,6 +96,7 @@ const std::map generatedTestName{ {AddressCountry::Estonia, "shouldGenerateEstoniaAddress"}, {AddressCountry::Romania, "shouldGenerateRomaniaAddress"}, {AddressCountry::Latvia, "shouldGenerateLatviaAddress"}, + {AddressCountry::Nepal, "shouldGenerateNepalAddress"}, }; } @@ -864,3 +867,34 @@ TEST_F(LocationTest, shouldGenerateLatviaStreetAddress) ASSERT_TRUE(std::ranges::any_of(digitSet, [&generatedAddress](const char& digit) { return generatedAddress.back() == digit; })); } + +TEST_F(LocationTest, shouldGenerateNepalStreet) +{ + const auto generatedStreet = Location::street(AddressCountry::Nepal); + + const auto generatedStreetElements = StringHelper::split(generatedStreet, " "); + + const auto& generatedStreetSuffix = + StringHelper::join({generatedStreetElements.begin() + 1, generatedStreetElements.end()}); + + ASSERT_GE(generatedStreetElements.size(), 2); + ASSERT_TRUE(std::ranges::any_of(nepalStreetSuffixes, [&generatedStreetSuffix](const std::string& streetSuffix) + { return streetSuffix == generatedStreetSuffix; })); +} + +TEST_F(LocationTest, shouldGenerateNepalStreetAddress) +{ + const auto generatedStreetAddress = Location::streetAddress(AddressCountry::Nepal); + + const auto generatedStreetAddressElements = StringHelper::split(generatedStreetAddress, " "); + + const auto& generatedBuildingNumber = generatedStreetAddressElements[0]; + const auto& generatedStreetSuffix = + StringHelper::join({generatedStreetAddressElements.begin() + 2, generatedStreetAddressElements.end()}); + + ASSERT_GE(generatedStreetAddressElements.size(), 3); + ASSERT_TRUE(!generatedBuildingNumber.empty()); + ASSERT_TRUE(checkIfAllCharactersAreNumeric(generatedBuildingNumber)); + ASSERT_TRUE(std::ranges::any_of(nepalStreetSuffixes, [&generatedStreetSuffix](const std::string& streetSuffix) + { return streetSuffix == generatedStreetSuffix; })); +} diff --git a/src/modules/location/data/nepal/NepalAddresses.h b/src/modules/location/data/nepal/NepalAddresses.h new file mode 100644 index 000000000..a6d147e15 --- /dev/null +++ b/src/modules/location/data/nepal/NepalAddresses.h @@ -0,0 +1,36 @@ +#pragma once + +#include "../CountryAddresses.h" +#include "NepalCities.h" +#include "NepalStates.h" +#include "NepalStreetSuffixes.h" + +namespace faker +{ +const std::string nepalZipCodeFormat{"######"}; + +const std::vector nepalAddressFormats{"{buildingNumber} {street}"}; + +const std::vector nepalSecondaryAddressFormats{"Apt. ###", "Flat ###"}; + +const std::vector nepalBuildingNumberFormats{"#####", "####", "###"}; + +const std::vector nepalStreetFormats{"{firstName} {streetSuffix}", "{lastName} {streetSuffix}"}; + +const std::vector nepalCityFormats{"{cityName}"}; + +const CountryAddresses nepalAddresses{nepalZipCodeFormat, + nepalAddressFormats, + nepalSecondaryAddressFormats, + nepalStreetFormats, + {}, + {}, + nepalStreetSuffixes, + nepalBuildingNumberFormats, + nepalCityFormats, + {}, + nepalCities, + {}, + nepalStates, + {}}; +} diff --git a/src/modules/location/data/nepal/NepalCities.h b/src/modules/location/data/nepal/NepalCities.h new file mode 100644 index 000000000..ac4ee95af --- /dev/null +++ b/src/modules/location/data/nepal/NepalCities.h @@ -0,0 +1,87 @@ +#pragma once + +#include +#include + +namespace faker +{ +const std::vector nepalCities{ + "Bhojpur", + "Dhankuta", + "Ilam", + "Bhadrapur", + "Diktel", + "Biratnagar", + "Siddhicharan", + "Phidim", + "Khandbari", + "Solududhkunda", + "Inaruwa", + "Phungling", + "Myanglung", + "Triyuga", + "Birgunj", + "Kalaiya", + "Gaur", + "Malangwa", + "Janakpur", + "Siraha", + "Jaleshwar", + "Rajbiraj", + "Kamalamai", + "Manthali", + "Bhimeshwar", + "Bhaktapur", + "Nilkantha", + "Kathmandu", + "Dhulikhel", + "Lalitpur", + "Bidur", + "Dhunche", + "Chautara", + "Bharatpur", + "Hetauda", + "Baglung", + "Gorkha", + "Pokhara", + "Besisahar", + "Chame", + "Jomsom", + "Beni", + "Kawasoti", + "Kusma", + "Putalibazar", + "Damauli", + "Taulihawa", + "Ramgram", + "Siddharthanagar", + "Sandhikharka", + "Tamghas", + "Tansen", + "Ghorahi", + "Pyuthan", + "Liwang", + "Rukumkot", + "Nepalganj", + "Gulariya", + "Musikot", + "Salyan", + "Dunai", + "Simikot", + "Chandannath", + "Manma", + "Gamgadhi", + "Birendranagar", + "Narayan", + "Khalanga", + "Dhangadhi", + "Mangalsen", + "Dipayal Silgadhi", + "Jayaprithvi", + "Martadi", + "Bheemdatta", + "Amargadhi", + "Dasharathchand", + "Darchula", +}; +} diff --git a/src/modules/location/data/nepal/NepalStates.h b/src/modules/location/data/nepal/NepalStates.h new file mode 100644 index 000000000..db9c582d6 --- /dev/null +++ b/src/modules/location/data/nepal/NepalStates.h @@ -0,0 +1,17 @@ +#pragma once + +#include +#include + +namespace faker +{ +const std::vector nepalStates = { + "Koshi", + "Madhesh", + "Bagmati", + "Gandaki", + "Lumbini", + "Karnali", + "Sudurpashchim", +}; +} diff --git a/src/modules/location/data/nepal/NepalStreetSuffixes.h b/src/modules/location/data/nepal/NepalStreetSuffixes.h new file mode 100644 index 000000000..550a24c86 --- /dev/null +++ b/src/modules/location/data/nepal/NepalStreetSuffixes.h @@ -0,0 +1,15 @@ +#pragma once + +#include +#include + +namespace faker +{ +const std::vector nepalStreetSuffixes = { + + "Upatyakaa", "Kharka", "Bhanjyang", "Chaur", "Danda", + "Chowk", "Bari", "Ghari", "Bot", "Pur", + "Gadhi" "Dhara", "Pokhari", "Kot", "Dhunga", + "Khola", "Taal", "Lek", "Besi", "Tar", +}; +}