diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a8180747..7bf4ca992 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,7 @@ set(FAKER_SOURCES src/modules/date/Date.cpp src/modules/date/DateData.cpp src/modules/finance/Finance.cpp + src/modules/finance/FinanceData.cpp src/modules/food/Food.cpp src/modules/git/Git.cpp src/modules/hacker/Hacker.cpp diff --git a/include/faker-cxx/Finance.h b/include/faker-cxx/Finance.h index 667f18ae7..27683db99 100644 --- a/include/faker-cxx/Finance.h +++ b/include/faker-cxx/Finance.h @@ -2,6 +2,7 @@ #include #include +#include #include "types/Country.h" #include "types/Precision.h" @@ -10,9 +11,9 @@ namespace faker { struct Currency { - std::string name; - std::string code; - std::string symbol; + std::string_view name; + std::string_view code; + std::string_view symbol; }; class Finance @@ -38,7 +39,7 @@ class Finance * Finance::currencyName() // "US Dollar" * @endcode */ - static std::string currencyName(); + static std::string_view currencyName(); /** * @brief Returns a random currency code. @@ -49,7 +50,7 @@ class Finance * Finance::currencyCode() // "USD" * @endcode */ - static std::string currencyCode(); + static std::string_view currencyCode(); /** * @brief Returns a random currency symbol. @@ -60,7 +61,7 @@ class Finance * Finance::currencySymbol() // "$" * @endcode */ - static std::string currencySymbol(); + static std::string_view currencySymbol(); /** * @brief Returns a random account type. @@ -71,7 +72,7 @@ class Finance * Finance::accountType() // "Savings" * @endcode */ - static std::string accountType(); + static std::string_view accountType(); /** * @brief Generates a random amount between the given bounds (inclusive). @@ -164,7 +165,7 @@ class Finance * Finance::bic(BicCountry::Poland) // "BREXPLPWMUL" * @endcode */ - static std::string bic(std::optional country = std::nullopt); + static std::string_view bic(std::optional country = std::nullopt); /** * Generates a random account number. @@ -290,6 +291,6 @@ class Finance * Finance::creditCardType() // "Visa" * @endcode */ - static std::string creditCardType(); + static std::string_view creditCardType(); }; } diff --git a/src/modules/finance/Finance.cpp b/src/modules/finance/Finance.cpp index 959cb0347..514e2e9fd 100644 --- a/src/modules/finance/Finance.cpp +++ b/src/modules/finance/Finance.cpp @@ -2,74 +2,38 @@ #include "../../common/FormatHelper.h" #include "../../common/PrecisionMapper.h" -#include "data/AccountTypes.h" -#include "data/BankIndentifiersCodes.h" -#include "data/CreditCardsFormats.h" -#include "data/CreditCardTypeNames.h" -#include "data/Currencies.h" -#include "data/IbanFormats.h" #include "faker-cxx/Date.h" #include "faker-cxx/Helper.h" #include "faker-cxx/Number.h" #include "faker-cxx/String.h" +#include "FinanceData.h" namespace faker { -namespace -{ -const std::vector supportedBicCountries{ - Finance::BicCountry::Poland, Finance::BicCountry::UnitedStates, Finance::BicCountry::UnitedKingdom, - Finance::BicCountry::Germany, Finance::BicCountry::Romania, Finance::BicCountry::France, - Finance::BicCountry::Italy, Finance::BicCountry::Spain, Finance::BicCountry::Netherlands, - Finance::BicCountry::India}; - -const std::vector supportedIbanCountries{ - Finance::IbanCountry::Austria, Finance::IbanCountry::Belgium, Finance::IbanCountry::Bulgaria, - Finance::IbanCountry::Croatia, Finance::IbanCountry::Cyprus, Finance::IbanCountry::Czechia, - Finance::IbanCountry::Denmark, Finance::IbanCountry::Estonia, Finance::IbanCountry::Finland, - Finance::IbanCountry::France, Finance::IbanCountry::Germany, Finance::IbanCountry::Greece, - Finance::IbanCountry::Hungary, Finance::IbanCountry::Ireland, Finance::IbanCountry::Italy, - Finance::IbanCountry::Latvia, Finance::IbanCountry::Lithuania, Finance::IbanCountry::Luxembourg, - Finance::IbanCountry::Malta, Finance::IbanCountry::Netherlands, Finance::IbanCountry::Poland, - Finance::IbanCountry::Portugal, Finance::IbanCountry::Romania, Finance::IbanCountry::Slovakia, - Finance::IbanCountry::Slovenia, Finance::IbanCountry::Spain, Finance::IbanCountry::Sweden, -}; - -const std::unordered_map> creditCardTypeToNumberFormats{ - {Finance::CreditCardType::AmericanExpress, americanExpressCreditCardFormats}, - {Finance::CreditCardType::Discover, discoverCreditCardFormats}, - {Finance::CreditCardType::MasterCard, masterCardCreditCardFormats}, - {Finance::CreditCardType::Visa, visaCreditCardFormats}, -}; - -const std::vector creditCardTypes{ - Finance::CreditCardType::AmericanExpress, Finance::CreditCardType::Discover, Finance::CreditCardType::MasterCard, - Finance::CreditCardType::Visa}; -} Currency Finance::currency() { - return Helper::arrayElement(currencies); + return Helper::arrayElement(currencies); } -std::string Finance::currencyName() +std::string_view Finance::currencyName() { - return Helper::arrayElement(currencies).name; + return Helper::arrayElement(currencies).name; } -std::string Finance::currencyCode() +std::string_view Finance::currencyCode() { - return Helper::arrayElement(currencies).code; + return Helper::arrayElement(currencies).code; } -std::string Finance::currencySymbol() +std::string_view Finance::currencySymbol() { - return Helper::arrayElement(currencies).symbol; + return Helper::arrayElement(currencies).symbol; } -std::string Finance::accountType() +std::string_view Finance::accountType() { - return Helper::arrayElement(accountTypes); + return Helper::arrayElement(accountTypes); } std::string Finance::amount(double min, double max, Precision precision, const std::string& symbol) @@ -89,7 +53,7 @@ std::string Finance::amount(double min, double max, Precision precision, const s std::string Finance::iban(std::optional country) { - const auto ibanCountry = country ? *country : Helper::arrayElement(supportedIbanCountries); + const auto ibanCountry = country ? *country : Helper::arrayElement(ibanCountries); const auto& ibanFormat = ibanFormats.at(ibanCountry); @@ -102,7 +66,8 @@ std::string Finance::iban(std::optional country) const auto& ibanFormatEntry = ibanFormat[i]; const auto ibanFormatEntryDataType = ibanFormatEntry[ibanFormatEntry.size() - 1]; - const auto ibanFormatEntryDataLength = std::stoi(ibanFormatEntry.substr(0, ibanFormatEntry.size() - 1)); + const auto ibanFormatEntryDataLength = + std::stoi(static_cast(ibanFormatEntry.substr(0, ibanFormatEntry.size() - 1))); if (ibanFormatEntryDataType == 'a') { @@ -121,11 +86,11 @@ std::string Finance::iban(std::optional country) return iban; } -std::string Finance::bic(std::optional country) +std::string_view Finance::bic(std::optional country) { - const auto bicCountry = country ? *country : Helper::arrayElement(supportedBicCountries); + const auto bicCountry = country ? *country : Helper::arrayElement(bicCountries); - return Helper::arrayElement(bankIdentifiersCodesMapping.at(bicCountry)); + return Helper::arrayElement(bicCountriesCodes.at(bicCountry)); } std::string Finance::accountNumber(unsigned int length) @@ -145,14 +110,24 @@ std::string Finance::routingNumber() std::string Finance::creditCardNumber(std::optional creditCardType) { - const auto creditCardTargetType = - creditCardType ? *creditCardType : Helper::arrayElement(creditCardTypes); - - const auto& creditCardFormats = creditCardTypeToNumberFormats.at(creditCardTargetType); + const auto creditCardTargetType = creditCardType ? *creditCardType : Helper::arrayElement(creditCardTypes); - const auto creditCardFormat = Helper::arrayElement(creditCardFormats); + switch (creditCardTargetType) + { + case CreditCardType::AmericanExpress: + return Helper::replaceCreditCardSymbols( + static_cast(Helper::arrayElement(americanExpressCreditCardFormats))); + case CreditCardType::Discover: + return Helper::replaceCreditCardSymbols( + static_cast(Helper::arrayElement(discoverCreditCardFormats))); + case CreditCardType::MasterCard: + return Helper::replaceCreditCardSymbols( + static_cast(Helper::arrayElement(masterCardCreditCardFormats))); + case CreditCardType::Visa: + return Helper::replaceCreditCardSymbols(static_cast(Helper::arrayElement(visaCreditCardFormats))); + } - return Helper::replaceCreditCardSymbols(creditCardFormat); + return ""; } std::string Finance::creditCardCvv() @@ -164,7 +139,7 @@ std::string Finance::bitcoinAddress() { const unsigned addressLength = Number::integer(26u, 33u); - auto address = Helper::arrayElement(std::vector{"1", "3"}); + auto address = Helper::arrayElement(std::vector{"1", "3"}); address += String::alphanumeric(addressLength, StringCasing::Mixed, "0OIl"); @@ -175,7 +150,7 @@ std::string Finance::litecoinAddress() { const unsigned addressLength = Number::integer(26u, 33u); - auto address = Helper::arrayElement(std::vector{"L", "M", "3"}); + auto address = Helper::arrayElement(std::vector{"L", "M", "3"}); address += String::alphanumeric(addressLength, StringCasing::Mixed, "0OIl"); @@ -190,12 +165,13 @@ std::string Finance::ethereumAddress() std::string Finance::creditCardExpirationDate() { const auto expirationDate = Date::futureDate(3); + return expirationDate.substr(5, 2) + "/" + expirationDate.substr(2, 2); } -std::string Finance::creditCardType() +std::string_view Finance::creditCardType() { - return Helper::arrayElement(creditCardTypeNames); + return Helper::arrayElement(creditCardNames); } } diff --git a/src/modules/finance/FinanceData.cpp b/src/modules/finance/FinanceData.cpp new file mode 100644 index 000000000..64196f27c --- /dev/null +++ b/src/modules/finance/FinanceData.cpp @@ -0,0 +1,889 @@ +#include "FinanceData.h" + +namespace faker +{ +const std::array bicCountries{ + Finance::BicCountry::Poland, Finance::BicCountry::UnitedStates, Finance::BicCountry::UnitedKingdom, + Finance::BicCountry::Germany, Finance::BicCountry::Romania, Finance::BicCountry::France, + Finance::BicCountry::Italy, Finance::BicCountry::Spain, Finance::BicCountry::Netherlands, + Finance::BicCountry::India}; + +const std::array ibanCountries{ + Finance::IbanCountry::Austria, Finance::IbanCountry::Belgium, Finance::IbanCountry::Bulgaria, + Finance::IbanCountry::Croatia, Finance::IbanCountry::Cyprus, Finance::IbanCountry::Czechia, + Finance::IbanCountry::Denmark, Finance::IbanCountry::Estonia, Finance::IbanCountry::Finland, + Finance::IbanCountry::France, Finance::IbanCountry::Germany, Finance::IbanCountry::Greece, + Finance::IbanCountry::Hungary, Finance::IbanCountry::Ireland, Finance::IbanCountry::Italy, + Finance::IbanCountry::Latvia, Finance::IbanCountry::Lithuania, Finance::IbanCountry::Luxembourg, + Finance::IbanCountry::Malta, Finance::IbanCountry::Netherlands, Finance::IbanCountry::Poland, + Finance::IbanCountry::Portugal, Finance::IbanCountry::Romania, Finance::IbanCountry::Slovakia, + Finance::IbanCountry::Slovenia, Finance::IbanCountry::Spain, Finance::IbanCountry::Sweden, +}; + +const std::array accountTypes = { + "Checking", "Savings", "Money Market", "Investment", "Home Loan", "Credit Card", "Auto Loan", "Personal Loan", +}; + +const std::unordered_map> bicCountriesCodes = { + {Finance::BicCountry::Poland, + {"BPKOPLPW", "PKOPPLPW", "BREXPLPWMUL", "BNPAPLP", "POLUPLPR", "BIGBPLPW", "WBKPPLPP", "CITIPLPX", "INGBPLPW", + "DEUTPLPK", "DEUTPLP"}}, + {Finance::BicCountry::UnitedStates, + {"BOFAUS3N", "CITIUS33", "WELLSFARGO", "USBKUS44", "CHASUS33", "HSBCUS33", "PNCCUS33"}}, + {Finance::BicCountry::UnitedKingdom, + {"BARCGB22", "HSBCKENW", "LOYDGB21", "NWBKGB2L", "RBOSGB2L", "HSBCGB2L", "DEUTGB2L"}}, + {Finance::BicCountry::Germany, + {"DEUTDEFF", "DRESDEFF", "COBADEFF", "BYLADEM1", "GENODEFF", "HYVEDEMM", "MALADE51", "NOLADE21", "SOLADEST", + "UNCRDEFF"}}, + {Finance::BicCountry::Romania, + {"RNCBROBU", "BRDEROBU", "BTRLRO22", "PIRBROBU", "INGBROBU", "EXIMRO22", "CRDZROBU"}}, + {Finance::BicCountry::France, + {"BNPAFRPP", "CEPAFRPP", "CRLYFRPP", "SOGEFRPP", "AGRIFRPP", "HSBDFRPP", "CCFRFRPP", "BNORDRPP", "CMCIFRPP"}}, + {Finance::BicCountry::Italy, {"UNCRITMM", "BCITITMM", "INTESA", "UBSPITPA", "BLOPIT22", "CITIITMX", "BNLIITRR"}}, + {Finance::BicCountry::Spain, + {"CAIXESBB", "BBVAESMM", "SABSESBB", "BSCHESMM", "POPUESMM", "INGDESMM", "CITIES2X", "BCOEESMM"}}, + {Finance::BicCountry::Netherlands, + {"ABNANL2A", "INGBNL2A", "RABONL2U", "TRIONL2U", "KNABNL2H", "SBINNL2X", "DEUTNL2N"}}, + { + Finance::BicCountry::India, + {"HDFCINBB", "ICICINBB", "SBININBB", "PNBAINBB", "UBININBB", "AXISINBB", "KKBKINBB", "YESBINBB", "IDBIINBB"}, + }}; + +const std::array americanExpressCreditCardFormats = { + "34##-######-####L", + "37##-######-####L", +}; + +const std::array discoverCreditCardFormats = { + "6011-####-####-###L", "65##-####-####-###L", "64[4-9]#-####-####-###L", + "6011-62##-####-####-###L", "65##-62##-####-####-###L", "64[4-9]#-62##-####-####-###L", +}; + +const std::array masterCardCreditCardFormats = { + "5[1-5]##-####-####-###L", + "6771-89##-####-###L", +}; + +const std::array visaCreditCardFormats = { + "4###########L", + "4###-####-####-###L", +}; + +const std::array creditCardTypes = { + Finance::CreditCardType::Visa, + Finance::CreditCardType::AmericanExpress, + Finance::CreditCardType::MasterCard, + Finance::CreditCardType::Discover, +}; + +const std::array creditCardNames = { + "Visa", + "American Express", + "MasterCard", + "Discover", +}; + +const std::array currencies = {{{ + "UAE Dirham", + "AED", + "", + }, + { + "Afghani", + "AFN", + "؋", + }, + { + "Lek", + "ALL", + "Lek", + }, + { + "Armenian Dram", + "AMD", + "", + }, + { + "Netherlands Antillian Guilder", + "ANG", + "ƒ", + }, + { + "Kwanza", + "AOA", + "", + }, + { + "Argentine Peso", + "ARS", + "$", + }, + { + "Australian Dollar", + "AUD", + "$", + }, + { + "Aruban Guilder", + "AWG", + "ƒ", + }, + { + "Azerbaijanian Manat", + "AZN", + "ман", + }, + { + "Convertible Marks", + "BAM", + "KM", + }, + { + "Barbados Dollar", + "BBD", + "$", + }, + { + "Taka", + "BDT", + "", + }, + { + "Bulgarian Lev", + "BGN", + "лв", + }, + { + "Bahraini Dinar", + "BHD", + "", + }, + { + "Burundi Franc", + "BIF", + "", + }, + { + "Bermudian Dollar (customarily known as Bermuda Dollar)", + "BMD", + "$", + }, + { + "Brunei Dollar", + "BND", + "$", + }, + { + "Boliviano boliviano", + "BOB", + "Bs", + }, + { + "Brazilian Real", + "BRL", + "R$", + }, + { + "Bahamian Dollar", + "BSD", + "$", + }, + { + "Pula", + "BWP", + "P", + }, + { + "Belarusian Ruble", + "BYN", + "Rbl", + }, + { + "Belize Dollar", + "BZD", + "BZ$", + }, + { + "Canadian Dollar", + "CAD", + "$", + }, + { + "Congolese Franc", + "CDF", + "", + }, + { + "Swiss Franc", + "CHF", + "CHF", + }, + { + "Chilean Peso", + "CLP", + "$", + }, + { + "Yuan Renminbi", + "CNY", + "¥", + }, + { + "Colombian Peso", + "COP", + "$", + }, + { + "Costa Rican Colon", + "CRC", + "₡", + }, + { + "Cuban Peso", + "CUP", + "₱", + }, + { + "Cape Verde Escudo", + "CVE", + "", + }, + { + "Czech Koruna", + "CZK", + "Kč", + }, + { + "Djibouti Franc", + "DJF", + "", + }, + { + "Danish Krone", + "DKK", + "kr", + }, + { + "Dominican Peso", + "DOP", + "RD$", + }, + { + "Algerian Dinar", + "DZD", + "", + }, + { + "Egyptian Pound", + "EGP", + "£", + }, + { + "Nakfa", + "ERN", + "", + }, + { + "Ethiopian Birr", + "ETB", + "", + }, + { + "Euro", + "EUR", + "€", + }, + { + "Fiji Dollar", + "FJD", + "$", + }, + { + "Falkland Islands Pound", + "FKP", + "£", + }, + { + "Pound Sterling", + "GBP", + "£", + }, + { + "Lari", + "GEL", + "", + }, + { + "Cedi", + "GHS", + "", + }, + { + "Gibraltar Pound", + "GIP", + "£", + }, + { + "Dalasi", + "GMD", + "", + }, + { + "Guinea Franc", + "GNF", + "", + }, + { + "Quetzal", + "GTQ", + "Q", + }, + { + "Guyana Dollar", + "GYD", + "$", + }, + { + "Hong Kong Dollar", + "HKD", + "$", + }, + { + "Lempira", + "HNL", + "L", + }, + { + "Gourde", + "HTG", + "", + }, + { + "Forint", + "HUF", + "Ft", + }, + { + "Rupiah", + "IDR", + "Rp", + }, + { + "New Israeli Sheqel", + "ILS", + "₪", + }, + { + "Bhutanese Ngultrum", + "BTN", + "Nu", + }, + { + "Indian Rupee", + "INR", + "₹", + }, + { + "Iraqi Dinar", + "IQD", + "", + }, + { + "Iranian Rial", + "IRR", + "﷼", + }, + { + "Iceland Krona", + "ISK", + "kr", + }, + { + "Jamaican Dollar", + "JMD", + "J$", + }, + { + "Jordanian Dinar", + "JOD", + "", + }, + { + "Yen", + "JPY", + "¥", + }, + { + "Kenyan Shilling", + "KES", + "", + }, + { + "Som", + "KGS", + "лв", + }, + { + "Riel", + "KHR", + "៛", + }, + { + "Comoro Franc", + "KMF", + "", + }, + { + "North Korean Won", + "KPW", + "₩", + }, + { + "Won", + "KRW", + "₩", + }, + { + "Kuwaiti Dinar", + "KWD", + "", + }, + { + "Cayman Islands Dollar", + "KYD", + "$", + }, + { + "Tenge", + "KZT", + "лв", + }, + { + "Kip", + "LAK", + "₭", + }, + { + "Lebanese Pound", + "LBP", + "£", + }, + { + "Sri Lanka Rupee", + "LKR", + "₨", + }, + { + "Liberian Dollar", + "LRD", + "$", + }, + { + "Libyan Dinar", + "LYD", + "", + }, + { + "Moroccan Dirham", + "MAD", + "", + }, + { + "Moldovan Leu", + "MDL", + "", + }, + { + "Malagasy Ariary", + "MGA", + "", + }, + { + "Denar", + "MKD", + "ден", + }, + { + "Kyat", + "MMK", + "", + }, + { + "Tugrik", + "MNT", + "₮", + }, + { + "Pataca", + "MOP", + "", + }, + { + "Ouguiya", + "MRU", + "", + }, + { + "Mauritius Rupee", + "MUR", + "₨", + }, + { + "Rufiyaa", + "MVR", + "", + }, + { + "Kwacha", + "MWK", + "", + }, + { + "Mexican Peso", + "MXN", + "$", + }, + { + "Malaysian Ringgit", + "MYR", + "RM", + }, + { + "Metical", + "MZN", + "MT", + }, + { + "Naira", + "NGN", + "₦", + }, + { + "Cordoba Oro", + "NIO", + "C$", + }, + { + "Norwegian Krone", + "NOK", + "kr", + }, + { + "Nepalese Rupee", + "NPR", + "₨", + }, + { + "New Zealand Dollar", + "NZD", + "$", + }, + { + "Rial Omani", + "OMR", + "﷼", + }, + { + "Balboa", + "PAB", + "B/.", + }, + { + "Nuevo Sol", + "PEN", + "S/.", + }, + { + "Kina", + "PGK", + "", + }, + { + "Philippine Peso", + "PHP", + "Php", + }, + { + "Pakistan Rupee", + "PKR", + "₨", + }, + { + "Zloty", + "PLN", + "zł", + }, + { + "Guarani", + "PYG", + "Gs", + }, + { + "Qatari Rial", + "QAR", + "﷼", + }, + { + "New Leu", + "RON", + "lei", + }, + { + "Serbian Dinar", + "RSD", + "Дин.", + }, + { + "Russian Ruble", + "RUB", + "руб", + }, + { + "Rwanda Franc", + "RWF", + "", + }, + { + "Saudi Riyal", + "SAR", + "﷼", + }, + { + "Solomon Islands Dollar", + "SBD", + "$", + }, + { + "Seychelles Rupee", + "SCR", + "₨", + }, + { + "Sudanese Pound", + "SDG", + "", + }, + { + "Swedish Krona", + "SEK", + "kr", + }, + { + "Singapore Dollar", + "SGD", + "$", + }, + { + "Saint Helena Pound", + "SHP", + "£", + }, + { + "Leone", + "SLE", + "", + }, + { + "Somali Shilling", + "SOS", + "S", + }, + { + "Surinam Dollar", + "SRD", + "$", + }, + { + "South Sudanese pound", + "SSP", + "", + }, + { + "Dobra", + "STN", + "Db", + }, + { + "Syrian Pound", + "SYP", + "£", + }, + { + "Lilangeni", + "SZL", + "", + }, + { + "Baht", + "THB", + "฿", + }, + { + "Somoni", + "TJS", + "", + }, + { + "Manat", + "TMT", + "", + }, + { + "Tunisian Dinar", + "TND", + "", + }, + { + "Pa' anga ", + "TOP", + "", + }, + { + "Turkish Lira", + "TRY", + "₺", + }, + { + "Trinidad and Tobago Dollar", + "TTD", + "TT$", + }, + { + "New Taiwan Dollar", + "TWD", + "NT$", + }, + { + "Tanzanian Shilling", + "TZS", + "", + }, + { + "Hryvnia", + "UAH", + "₴", + }, + { + "Uganda Shilling", + "UGX", + "", + }, + { + "US Dollar", + "USD", + "$", + }, + { + "Peso Uruguayo", + "UYU", + "$U", + }, + { + "Uzbekistan Sum", + "UZS", + "лв", + }, + { + "Venezuelan bolívar", + "VES", + "Bs", + }, + { + "Dong", + "VND", + "₫", + }, + { + "Vatu", + "VUV", + "", + }, + { + "Tala", + "WST", + "", + }, + { + "CFA Franc BEAC", + "XAF", + "", + }, + { + "East Caribbean Dollar", + "XCD", + "$", + }, + { + "CFA Franc BCEAO", + "XOF", + "", + }, + { + "CFP Franc", + "XPF", + "", + }, + { + "Yemeni Rial", + "YER", + "﷼", + }, + { + "Rand", + "ZAR", + "R", + }, + { + "Lesotho Loti", + "LSL", + "", + }, + { + "Namibia Dollar", + "NAD", + "N$", + }, + { + "Zambian Kwacha", + "ZMW", + "K", + }, + { + "Zimbabwe Dollar", + "ZWL", + "", + }}}; + +// Iban format structure from https://bank.codes/iban/structure/ +// Note: a - alphabets (letters only), c - characters (letters & numbers), n - numbers (numbers only) +const std::unordered_map> ibanFormats{ + {Finance::IbanCountry::Austria, {"AT", "2n", "5n", "11n"}}, + {Finance::IbanCountry::Belgium, {"BE", "2n", "3n", "7n", "2n"}}, + {Finance::IbanCountry::Bulgaria, {"BG", "2n", "4a", "4n", "2n", "8c"}}, + {Finance::IbanCountry::Croatia, {"HR", "2n", "7n", "10n"}}, + {Finance::IbanCountry::Cyprus, {"CY", "2n", "3n", "5n", "16c"}}, + {Finance::IbanCountry::Czechia, {"CZ", "2n", "4n", "6n", "10n"}}, + {Finance::IbanCountry::Denmark, {"DK", "2n", "4n", "9n", "1n"}}, + {Finance::IbanCountry::Estonia, {"EE", "2n", "2n", "2n", "11n", "1n"}}, + {Finance::IbanCountry::Finland, {"FI", "2n", "6n", "7n", "1n"}}, + {Finance::IbanCountry::France, {"FR", "2n", "5n", "5n", "11c", "2n"}}, + {Finance::IbanCountry::Germany, {"DE", "2n", "8n", "10n"}}, + {Finance::IbanCountry::Greece, {"GR", "2n", "3n", "4n", "16c"}}, + {Finance::IbanCountry::Hungary, {"HU", "2n", "3n", "4n", "1n", "15n", "1n"}}, + {Finance::IbanCountry::Ireland, {"IE", "2n", "4a", "6n", "8n"}}, + {Finance::IbanCountry::Italy, {"IT", "2n", "1a", "5n", "5n", "12c"}}, + {Finance::IbanCountry::Latvia, {"LV", "2n", "4a", "13n"}}, + {Finance::IbanCountry::Lithuania, {"LT", "2n", "5n", "11n"}}, + {Finance::IbanCountry::Luxembourg, {"LU", "2n", "3n", "13c"}}, + {Finance::IbanCountry::Malta, {"MT", "2n", "4a", "5n", "18c"}}, + {Finance::IbanCountry::Netherlands, {"NL", "2n", "4a", "10n"}}, + {Finance::IbanCountry::Poland, {"PL", "2n", "3n", "4n", "1n", "16n"}}, + {Finance::IbanCountry::Portugal, {"PT", "2n", "4n", "4n", "11n", "2n"}}, + {Finance::IbanCountry::Romania, {"RO", "2n", "4a", "16c"}}, + {Finance::IbanCountry::Slovakia, {"SK", "2n", "4n", "6n", "10n"}}, + {Finance::IbanCountry::Slovenia, {"SI", "2n", "2n", "3n", "8n", "2n"}}, + {Finance::IbanCountry::Spain, {"ES", "2n", "4n", "4n", "2n", "10n"}}, + {Finance::IbanCountry::Sweden, {"SE", "2n", "3n", "16n", "1n"}}, +}; + +} diff --git a/src/modules/finance/FinanceData.h b/src/modules/finance/FinanceData.h new file mode 100644 index 000000000..85a14fbfa --- /dev/null +++ b/src/modules/finance/FinanceData.h @@ -0,0 +1,24 @@ +#pragma once + +#include +#include +#include +#include + +#include "faker-cxx/Finance.h" + +namespace faker +{ +extern const std::array bicCountries; +extern const std::array ibanCountries; +extern const std::array accountTypes; +extern const std::unordered_map> bicCountriesCodes; +extern const std::array creditCardTypes; +extern const std::array creditCardNames; +extern const std::array americanExpressCreditCardFormats; +extern const std::array discoverCreditCardFormats; +extern const std::array masterCardCreditCardFormats; +extern const std::array visaCreditCardFormats; +extern const std::array currencies; +extern const std::unordered_map> ibanFormats; +} diff --git a/src/modules/finance/data/AccountTypes.h b/src/modules/finance/data/AccountTypes.h deleted file mode 100644 index 6a865fcd3..000000000 --- a/src/modules/finance/data/AccountTypes.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include -#include - -namespace faker -{ -const std::vector accountTypes = { - "Checking", "Savings", "Money Market", "Investment", "Home Loan", "Credit Card", "Auto Loan", "Personal Loan", -}; -} diff --git a/src/modules/finance/data/BankIndentifiersCodes.h b/src/modules/finance/data/BankIndentifiersCodes.h deleted file mode 100644 index 64f70ba8c..000000000 --- a/src/modules/finance/data/BankIndentifiersCodes.h +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include -#include -#include - -#include "faker-cxx/Finance.h" - -namespace faker -{ -const std::unordered_map> bankIdentifiersCodesMapping = { - {Finance::BicCountry::Poland, - {"BPKOPLPW", "PKOPPLPW", "BREXPLPWMUL", "BNPAPLP", "POLUPLPR", "BIGBPLPW", "WBKPPLPP", "CITIPLPX", "INGBPLPW", - "DEUTPLPK", "DEUTPLP"}}, - {Finance::BicCountry::UnitedStates, - {"BOFAUS3N", "CITIUS33", "WELLSFARGO", "USBKUS44", "CHASUS33", "HSBCUS33", "PNCCUS33"}}, - {Finance::BicCountry::UnitedKingdom, - {"BARCGB22", "HSBCKENW", "LOYDGB21", "NWBKGB2L", "RBOSGB2L", "HSBCGB2L", "DEUTGB2L"}}, - {Finance::BicCountry::Germany, - {"DEUTDEFF", "DRESDEFF", "COBADEFF", "BYLADEM1", "GENODEFF", "HYVEDEMM", "MALADE51", "NOLADE21", "SOLADEST", - "UNCRDEFF"}}, - {Finance::BicCountry::Romania, - {"RNCBROBU", "BRDEROBU", "BTRLRO22", "PIRBROBU", "INGBROBU", "EXIMRO22", "CRDZROBU"}}, - {Finance::BicCountry::France, - {"BNPAFRPP", "CEPAFRPP", "CRLYFRPP", "SOGEFRPP", "AGRIFRPP", "HSBDFRPP", "CCFRFRPP", "BNORDRPP", "CMCIFRPP"}}, - {Finance::BicCountry::Italy, {"UNCRITMM", "BCITITMM", "INTESA", "UBSPITPA", "BLOPIT22", "CITIITMX", "BNLIITRR"}}, - {Finance::BicCountry::Spain, - {"CAIXESBB", "BBVAESMM", "SABSESBB", "BSCHESMM", "POPUESMM", "INGDESMM", "CITIES2X", "BCOEESMM"}}, - {Finance::BicCountry::Netherlands, - {"ABNANL2A", "INGBNL2A", "RABONL2U", "TRIONL2U", "KNABNL2H", "SBINNL2X", "DEUTNL2N"}}, - {Finance::BicCountry::India, - {"HDFCINBB", "ICICINBB", "SBININBB", "PNBAINBB", "UBININBB", "AXISINBB", "KKBKINBB", "YESBINBB", "IDBIINBB"}}}; -} diff --git a/src/modules/finance/data/CreditCardTypeNames.h b/src/modules/finance/data/CreditCardTypeNames.h deleted file mode 100644 index 97e94549e..000000000 --- a/src/modules/finance/data/CreditCardTypeNames.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#include -#include - -namespace faker -{ -const std::vector creditCardTypeNames = {"Visa", "AmericanExpress", "MasterCard", "Discover"}; -} diff --git a/src/modules/finance/data/CreditCardsFormats.h b/src/modules/finance/data/CreditCardsFormats.h deleted file mode 100644 index 0101cbc87..000000000 --- a/src/modules/finance/data/CreditCardsFormats.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include -#include - -namespace faker -{ -const std::vector americanExpressCreditCardFormats = {"34##-######-####L", "37##-######-####L"}; - -const std::vector discoverCreditCardFormats = {"6011-####-####-###L", "65##-####-####-###L", - "64[4-9]#-####-####-###L", "6011-62##-####-####-###L", - "65##-62##-####-####-###L", "64[4-9]#-62##-####-####-###L"}; - -const std::vector masterCardCreditCardFormats = {"5[1-5]##-####-####-###L", "6771-89##-####-###L"}; - -const std::vector visaCreditCardFormats = {"4###########L", "4###-####-####-###L"}; -} diff --git a/src/modules/finance/data/Currencies.h b/src/modules/finance/data/Currencies.h deleted file mode 100644 index 691854af2..000000000 --- a/src/modules/finance/data/Currencies.h +++ /dev/null @@ -1,780 +0,0 @@ -#pragma once - -#include -#include - -#include "faker-cxx/Finance.h" - -namespace faker -{ -const std::vector currencies = {{ - "UAE Dirham", - "AED", - "", - }, - { - "Afghani", - "AFN", - "؋", - }, - { - "Lek", - "ALL", - "Lek", - }, - { - "Armenian Dram", - "AMD", - "", - }, - { - "Netherlands Antillian Guilder", - "ANG", - "ƒ", - }, - { - "Kwanza", - "AOA", - "", - }, - { - "Argentine Peso", - "ARS", - "$", - }, - { - "Australian Dollar", - "AUD", - "$", - }, - { - "Aruban Guilder", - "AWG", - "ƒ", - }, - { - "Azerbaijanian Manat", - "AZN", - "ман", - }, - { - "Convertible Marks", - "BAM", - "KM", - }, - { - "Barbados Dollar", - "BBD", - "$", - }, - { - "Taka", - "BDT", - "", - }, - { - "Bulgarian Lev", - "BGN", - "лв", - }, - { - "Bahraini Dinar", - "BHD", - "", - }, - { - "Burundi Franc", - "BIF", - "", - }, - { - "Bermudian Dollar (customarily known as Bermuda Dollar)", - "BMD", - "$", - }, - { - "Brunei Dollar", - "BND", - "$", - }, - { - "Boliviano boliviano", - "BOB", - "Bs", - }, - { - "Brazilian Real", - "BRL", - "R$", - }, - { - "Bahamian Dollar", - "BSD", - "$", - }, - { - "Pula", - "BWP", - "P", - }, - { - "Belarusian Ruble", - "BYN", - "Rbl", - }, - { - "Belize Dollar", - "BZD", - "BZ$", - }, - { - "Canadian Dollar", - "CAD", - "$", - }, - { - "Congolese Franc", - "CDF", - "", - }, - { - "Swiss Franc", - "CHF", - "CHF", - }, - { - "Chilean Peso", - "CLP", - "$", - }, - { - "Yuan Renminbi", - "CNY", - "¥", - }, - { - "Colombian Peso", - "COP", - "$", - }, - { - "Costa Rican Colon", - "CRC", - "₡", - }, - { - "Cuban Peso", - "CUP", - "₱", - }, - { - "Cape Verde Escudo", - "CVE", - "", - }, - { - "Czech Koruna", - "CZK", - "Kč", - }, - { - "Djibouti Franc", - "DJF", - "", - }, - { - "Danish Krone", - "DKK", - "kr", - }, - { - "Dominican Peso", - "DOP", - "RD$", - }, - { - "Algerian Dinar", - "DZD", - "", - }, - { - "Egyptian Pound", - "EGP", - "£", - }, - { - "Nakfa", - "ERN", - "", - }, - { - "Ethiopian Birr", - "ETB", - "", - }, - { - "Euro", - "EUR", - "€", - }, - { - "Fiji Dollar", - "FJD", - "$", - }, - { - "Falkland Islands Pound", - "FKP", - "£", - }, - { - "Pound Sterling", - "GBP", - "£", - }, - { - "Lari", - "GEL", - "", - }, - { - "Cedi", - "GHS", - "", - }, - { - "Gibraltar Pound", - "GIP", - "£", - }, - { - "Dalasi", - "GMD", - "", - }, - { - "Guinea Franc", - "GNF", - "", - }, - { - "Quetzal", - "GTQ", - "Q", - }, - { - "Guyana Dollar", - "GYD", - "$", - }, - { - "Hong Kong Dollar", - "HKD", - "$", - }, - { - "Lempira", - "HNL", - "L", - }, - { - "Gourde", - "HTG", - "", - }, - { - "Forint", - "HUF", - "Ft", - }, - { - "Rupiah", - "IDR", - "Rp", - }, - { - "New Israeli Sheqel", - "ILS", - "₪", - }, - { - "Bhutanese Ngultrum", - "BTN", - "Nu", - }, - { - "Indian Rupee", - "INR", - "₹", - }, - { - "Iraqi Dinar", - "IQD", - "", - }, - { - "Iranian Rial", - "IRR", - "﷼", - }, - { - "Iceland Krona", - "ISK", - "kr", - }, - { - "Jamaican Dollar", - "JMD", - "J$", - }, - { - "Jordanian Dinar", - "JOD", - "", - }, - { - "Yen", - "JPY", - "¥", - }, - { - "Kenyan Shilling", - "KES", - "", - }, - { - "Som", - "KGS", - "лв", - }, - { - "Riel", - "KHR", - "៛", - }, - { - "Comoro Franc", - "KMF", - "", - }, - { - "North Korean Won", - "KPW", - "₩", - }, - { - "Won", - "KRW", - "₩", - }, - { - "Kuwaiti Dinar", - "KWD", - "", - }, - { - "Cayman Islands Dollar", - "KYD", - "$", - }, - { - "Tenge", - "KZT", - "лв", - }, - { - "Kip", - "LAK", - "₭", - }, - { - "Lebanese Pound", - "LBP", - "£", - }, - { - "Sri Lanka Rupee", - "LKR", - "₨", - }, - { - "Liberian Dollar", - "LRD", - "$", - }, - { - "Libyan Dinar", - "LYD", - "", - }, - { - "Moroccan Dirham", - "MAD", - "", - }, - { - "Moldovan Leu", - "MDL", - "", - }, - { - "Malagasy Ariary", - "MGA", - "", - }, - { - "Denar", - "MKD", - "ден", - }, - { - "Kyat", - "MMK", - "", - }, - { - "Tugrik", - "MNT", - "₮", - }, - { - "Pataca", - "MOP", - "", - }, - { - "Ouguiya", - "MRU", - "", - }, - { - "Mauritius Rupee", - "MUR", - "₨", - }, - { - "Rufiyaa", - "MVR", - "", - }, - { - "Kwacha", - "MWK", - "", - }, - { - "Mexican Peso", - "MXN", - "$", - }, - { - "Malaysian Ringgit", - "MYR", - "RM", - }, - { - "Metical", - "MZN", - "MT", - }, - { - "Naira", - "NGN", - "₦", - }, - { - "Cordoba Oro", - "NIO", - "C$", - }, - { - "Norwegian Krone", - "NOK", - "kr", - }, - { - "Nepalese Rupee", - "NPR", - "₨", - }, - { - "New Zealand Dollar", - "NZD", - "$", - }, - { - "Rial Omani", - "OMR", - "﷼", - }, - { - "Balboa", - "PAB", - "B/.", - }, - { - "Nuevo Sol", - "PEN", - "S/.", - }, - { - "Kina", - "PGK", - "", - }, - { - "Philippine Peso", - "PHP", - "Php", - }, - { - "Pakistan Rupee", - "PKR", - "₨", - }, - { - "Zloty", - "PLN", - "zł", - }, - { - "Guarani", - "PYG", - "Gs", - }, - { - "Qatari Rial", - "QAR", - "﷼", - }, - { - "New Leu", - "RON", - "lei", - }, - { - "Serbian Dinar", - "RSD", - "Дин.", - }, - { - "Russian Ruble", - "RUB", - "руб", - }, - { - "Rwanda Franc", - "RWF", - "", - }, - { - "Saudi Riyal", - "SAR", - "﷼", - }, - { - "Solomon Islands Dollar", - "SBD", - "$", - }, - { - "Seychelles Rupee", - "SCR", - "₨", - }, - { - "Sudanese Pound", - "SDG", - "", - }, - { - "Swedish Krona", - "SEK", - "kr", - }, - { - "Singapore Dollar", - "SGD", - "$", - }, - { - "Saint Helena Pound", - "SHP", - "£", - }, - { - "Leone", - "SLE", - "", - }, - { - "Somali Shilling", - "SOS", - "S", - }, - { - "Surinam Dollar", - "SRD", - "$", - }, - { - "South Sudanese pound", - "SSP", - "", - }, - { - "Dobra", - "STN", - "Db", - }, - { - "Syrian Pound", - "SYP", - "£", - }, - { - "Lilangeni", - "SZL", - "", - }, - { - "Baht", - "THB", - "฿", - }, - { - "Somoni", - "TJS", - "", - }, - { - "Manat", - "TMT", - "", - }, - { - "Tunisian Dinar", - "TND", - "", - }, - { - "Pa' anga ", - "TOP", - "", - }, - { - "Turkish Lira", - "TRY", - "₺", - }, - { - "Trinidad and Tobago Dollar", - "TTD", - "TT$", - }, - { - "New Taiwan Dollar", - "TWD", - "NT$", - }, - { - "Tanzanian Shilling", - "TZS", - "", - }, - { - "Hryvnia", - "UAH", - "₴", - }, - { - "Uganda Shilling", - "UGX", - "", - }, - { - "US Dollar", - "USD", - "$", - }, - { - "Peso Uruguayo", - "UYU", - "$U", - }, - { - "Uzbekistan Sum", - "UZS", - "лв", - }, - { - "Venezuelan bolívar", - "VES", - "Bs", - }, - { - "Dong", - "VND", - "₫", - }, - { - "Vatu", - "VUV", - "", - }, - { - "Tala", - "WST", - "", - }, - { - "CFA Franc BEAC", - "XAF", - "", - }, - { - "East Caribbean Dollar", - "XCD", - "$", - }, - { - "CFA Franc BCEAO", - "XOF", - "", - }, - { - "CFP Franc", - "XPF", - "", - }, - { - "Yemeni Rial", - "YER", - "﷼", - }, - { - "Rand", - "ZAR", - "R", - }, - { - "Lesotho Loti", - "LSL", - "", - }, - { - "Namibia Dollar", - "NAD", - "N$", - }, - { - "Zambian Kwacha", - "ZMW", - "K", - }, - { - "Zimbabwe Dollar", - "ZWL", - "", - }}; -} diff --git a/src/modules/finance/data/IbanFormats.h b/src/modules/finance/data/IbanFormats.h deleted file mode 100644 index c55f3fe67..000000000 --- a/src/modules/finance/data/IbanFormats.h +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once - -#include -#include -#include - -#include "faker-cxx/Finance.h" - -namespace faker -{ -// Iban format structure from https://bank.codes/iban/structure/ -// Note: a - alphabets (letters only), c - characters (letters & numbers), n - numbers (numbers only) -const std::unordered_map> ibanFormats{ - {Finance::IbanCountry::Austria, {"AT", "2n", "5n", "11n"}}, - {Finance::IbanCountry::Belgium, {"BE", "2n", "3n", "7n", "2n"}}, - {Finance::IbanCountry::Bulgaria, {"BG", "2n", "4a", "4n", "2n", "8c"}}, - {Finance::IbanCountry::Croatia, {"HR", "2n", "7n", "10n"}}, - {Finance::IbanCountry::Cyprus, {"CY", "2n", "3n", "5n", "16c"}}, - {Finance::IbanCountry::Czechia, {"CZ", "2n", "4n", "6n", "10n"}}, - {Finance::IbanCountry::Denmark, {"DK", "2n", "4n", "9n", "1n"}}, - {Finance::IbanCountry::Estonia, {"EE", "2n", "2n", "2n", "11n", "1n"}}, - {Finance::IbanCountry::Finland, {"FI", "2n", "6n", "7n", "1n"}}, - {Finance::IbanCountry::France, {"FR", "2n", "5n", "5n", "11c", "2n"}}, - {Finance::IbanCountry::Germany, {"DE", "2n", "8n", "10n"}}, - {Finance::IbanCountry::Greece, {"GR", "2n", "3n", "4n", "16c"}}, - {Finance::IbanCountry::Hungary, {"HU", "2n", "3n", "4n", "1n", "15n", "1n"}}, - {Finance::IbanCountry::Ireland, {"IE", "2n", "4a", "6n", "8n"}}, - {Finance::IbanCountry::Italy, {"IT", "2n", "1a", "5n", "5n", "12c"}}, - {Finance::IbanCountry::Latvia, {"LV", "2n", "4a", "13n"}}, - {Finance::IbanCountry::Lithuania, {"LT", "2n", "5n", "11n"}}, - {Finance::IbanCountry::Luxembourg, {"LU", "2n", "3n", "13c"}}, - {Finance::IbanCountry::Malta, {"MT", "2n", "4a", "5n", "18c"}}, - {Finance::IbanCountry::Netherlands, {"NL", "2n", "4a", "10n"}}, - {Finance::IbanCountry::Poland, {"PL", "2n", "3n", "4n", "1n", "16n"}}, - {Finance::IbanCountry::Portugal, {"PT", "2n", "4n", "4n", "11n", "2n"}}, - {Finance::IbanCountry::Romania, {"RO", "2n", "4a", "16c"}}, - {Finance::IbanCountry::Slovakia, {"SK", "2n", "4n", "6n", "10n"}}, - {Finance::IbanCountry::Slovenia, {"SI", "2n", "2n", "3n", "8n", "2n"}}, - {Finance::IbanCountry::Spain, {"ES", "2n", "4n", "4n", "2n", "10n"}}, - {Finance::IbanCountry::Sweden, {"SE", "2n", "3n", "16n", "1n"}}, -}; -} diff --git a/tests/modules/finance/FinanceTest.cpp b/tests/modules/finance/FinanceTest.cpp index cb9b37097..d96c65dd9 100644 --- a/tests/modules/finance/FinanceTest.cpp +++ b/tests/modules/finance/FinanceTest.cpp @@ -9,10 +9,7 @@ #include "common/LuhnCheck.h" #include "common/StringHelper.h" -#include "finance/data/AccountTypes.h" -#include "finance/data/BankIndentifiersCodes.h" -#include "finance/data/CreditCardTypeNames.h" -#include "finance/data/Currencies.h" +#include "finance/FinanceData.h" #include "gmock/gmock.h" #include "string/data/Characters.h" @@ -164,7 +161,7 @@ TEST_F(FinanceTest, shouldGenerateAccountType) { const auto generatedAccountType = Finance::accountType(); - ASSERT_TRUE(std::ranges::any_of(accountTypes, [generatedAccountType](const std::string& accountType) + ASSERT_TRUE(std::ranges::any_of(accountTypes, [generatedAccountType](const std::string_view& accountType) { return accountType == generatedAccountType; })); } @@ -404,8 +401,8 @@ TEST_F(FinanceTest, shouldGenerateExpirationDate) TEST_F(FinanceTest, shouldGenerateRandomCreditCardTypeName) { const auto creditCardTypeName = Finance::creditCardType(); - ASSERT_TRUE(std::find(faker::creditCardTypeNames.begin(), faker::creditCardTypeNames.end(), creditCardTypeName) != - faker::creditCardTypeNames.end()); + + ASSERT_TRUE(std::find(creditCardNames.begin(), creditCardNames.end(), creditCardTypeName) != creditCardNames.end()); } class FinanceBicTest : public TestWithParam @@ -418,9 +415,9 @@ TEST_P(FinanceBicTest, CheckBicGenerator) const auto bic = Finance::bic(country); - const auto& bankIdentifiersCodes = bankIdentifiersCodesMapping.at(country); + const auto& bankIdentifiersCodes = bicCountriesCodes.at(country); - ASSERT_TRUE(std::ranges::any_of(bankIdentifiersCodes, [bic](const std::string& bankIdentifierCode) + ASSERT_TRUE(std::ranges::any_of(bankIdentifiersCodes, [bic](const std::string_view& bankIdentifierCode) { return bic == bankIdentifierCode; })); }