Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added location addresses data from Nepal #529

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/faker-cxx/Location.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ enum class AddressCountry
Finland,
Estonia,
Romania,
Latvia
Latvia,
Nepal
};

class Location
Expand Down
4 changes: 2 additions & 2 deletions src/common/FormatHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <string>
#include <vector>

#if defined(__APPLE__) || defined(__GNUC__) && (__GNUC__ < 12) && !defined(__clang__)
#if defined(__APPLE__) || (defined(__GNUC__) && (__GNUC__ < 12) && !defined(__clang__))
#include <fmt/format.h>
#else
#include <format>
Expand All @@ -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 <typename... Args>
static std::string format(fmt::format_string<Args...> fmt, Args&&... args)
{
Expand Down
5 changes: 4 additions & 1 deletion src/modules/location/Location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -49,7 +50,8 @@ const std::map<AddressCountry, CountryAddresses> countryToCountryAddressesMappin
{AddressCountry::Finland, finlandAddresses},
{AddressCountry::Estonia, estoniaAddresses},
{AddressCountry::Romania, romaniaAddresses},
{AddressCountry::Latvia, latviaAddresses}};
{AddressCountry::Latvia, latviaAddresses},
{AddressCountry::Nepal, nepalAddresses},};

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

Expand Down
34 changes: 34 additions & 0 deletions src/modules/location/LocationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -74,6 +75,7 @@ const std::map<AddressCountry, CountryAddresses> countryToCountryAddressesMappin
{AddressCountry::Estonia, estoniaAddresses},
{AddressCountry::Romania, romaniaAddresses},
{AddressCountry::Latvia, latviaAddresses},
{AddressCountry::Nepal, nepalAddresses},
};

const std::map<AddressCountry, std::string> generatedTestName{
Expand All @@ -94,6 +96,7 @@ const std::map<AddressCountry, std::string> generatedTestName{
{AddressCountry::Estonia, "shouldGenerateEstoniaAddress"},
{AddressCountry::Romania, "shouldGenerateRomaniaAddress"},
{AddressCountry::Latvia, "shouldGenerateLatviaAddress"},
{AddressCountry::Nepal, "shouldGenerateNepalAddress"},
};
}

Expand Down Expand Up @@ -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; }));
}
36 changes: 36 additions & 0 deletions src/modules/location/data/nepal/NepalAddresses.h
Original file line number Diff line number Diff line change
@@ -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<std::string> nepalAddressFormats{"{buildingNumber} {street}"};

const std::vector<std::string> nepalSecondaryAddressFormats{"Apt. ###", "Flat ###"};

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

const std::vector<std::string> nepalStreetFormats{"{firstName} {streetSuffix}", "{lastName} {streetSuffix}"};

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

const CountryAddresses nepalAddresses{nepalZipCodeFormat,
nepalAddressFormats,
nepalSecondaryAddressFormats,
nepalStreetFormats,
{},
{},
nepalStreetSuffixes,
nepalBuildingNumberFormats,
nepalCityFormats,
{},
nepalCities,
{},
nepalStates,
{}};
}
87 changes: 87 additions & 0 deletions src/modules/location/data/nepal/NepalCities.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#pragma once

#include <string>
#include <vector>

namespace faker
{
const std::vector<std::string> 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",
};
}
17 changes: 17 additions & 0 deletions src/modules/location/data/nepal/NepalStates.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include <string>
#include <vector>

namespace faker
{
const std::vector<std::string> nepalStates = {
"Koshi",
"Madhesh",
"Bagmati",
"Gandaki",
"Lumbini",
"Karnali",
"Sudurpashchim",
};
}
15 changes: 15 additions & 0 deletions src/modules/location/data/nepal/NepalStreetSuffixes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include <string>
#include <vector>

namespace faker
{
const std::vector<std::string> nepalStreetSuffixes = {

"Upatyakaa", "Kharka", "Bhanjyang", "Chaur", "Danda",
"Chowk", "Bari", "Ghari", "Bot", "Pur",
"Gadhi" "Dhara", "Pokhari", "Kot", "Dhunga",
"Khola", "Taal", "Lek", "Besi", "Tar",
};
}
Loading