diff --git a/examples/basic/main.cpp b/examples/basic/main.cpp index 667c806e..d911f0d2 100644 --- a/examples/basic/main.cpp +++ b/examples/basic/main.cpp @@ -8,7 +8,7 @@ int main() { - const auto id = faker::String::uuid(); + const auto id = faker::string::uuid(); const auto email = faker::internet::email(); const auto password = faker::internet::password(); const auto city = faker::location::city(); diff --git a/include/faker-cxx/String.h b/include/faker-cxx/String.h index 9940aa54..058d2c0d 100644 --- a/include/faker-cxx/String.h +++ b/include/faker-cxx/String.h @@ -10,7 +10,7 @@ #include "RandomGenerator.h" #include "types/Hex.h" -namespace faker +namespace faker::string { enum class StringCasing { @@ -43,7 +43,7 @@ using GuaranteeMap = std::map; * GuaranteeMap guarantee = {{'0',{5,10}},{'1',{6,10}}}; * std::string targetCharacters = "01"; * unsigned int length = 10; - * faker::isValidGuarantee(guarantee,targetCharacters,length) // false + * faker::string::isValidGuarantee(guarantee,targetCharacters,length) // false * @endcode */ bool isValidGuarantee(GuaranteeMap& guarantee, std::set& targetCharacters, unsigned int length); @@ -57,18 +57,15 @@ bool isValidGuarantee(GuaranteeMap& guarantee, std::set& targetCharacters, * * @code * GuaranteeMap guarantee { {'0',{3,10}},{'a',{6,8}} }; // "000aaaaaa" - * faker::generateAtLeastString(guarantee); + * faker::string::generateAtLeastString(guarantee); * @endcode */ std::string generateAtLeastString(const GuaranteeMap& guarantee); -class String -{ -private: - static std::string generateStringWithGuarantee(GuaranteeMap& guarantee, std::set& targetCharacters, - unsigned int length); - -public: + // namespace { + // std::string generateStringWithGuarantee(GuaranteeMap& guarantee, std::set& targetCharacters, + // unsigned int length); + // } /** * @brief Generates an Universally Unique Identifier with version 4. * @@ -77,11 +74,11 @@ class String * @param gen A random number generator (type RandomGenerator) * * @code - * String::uuid() // "27666229-cedb-4a45-8018-98b1e1d921e2" + * string::uuid() // "27666229-cedb-4a45-8018-98b1e1d921e2" * @endcode */ template - static std::string uuid(RandomGenerator gen = RandomGenerator{}) + std::string uuid(RandomGenerator gen = RandomGenerator{}) { static std::uniform_int_distribution<> dist(0, 15); static std::uniform_int_distribution<> dist2(8, 11); @@ -133,11 +130,11 @@ class String * @returns Sample string. * * @code - * String::sample() // "Zo!.:*e>wR" - * String::sample(5) // "6Bye8" + * string::sample() // "Zo!.:*e>wR" + * string::sample(5) // "6Bye8" * @endcode */ - static std::string sample(unsigned length = 10); + std::string sample(unsigned length = 10); /** * @brief Returns a string containing UTF-16 chars between 33 and 125 (`!` to `}`). @@ -148,11 +145,11 @@ class String * @returns Sample string. * * @code - * String::sample({}) // "Zo!.:*e>wR" - * String::sample({{'|' ,{2,2}},{'^',{0,0}},{':',{1,8}}}, 8) // "|6Bye8:|" + * string::sample({}) // "Zo!.:*e>wR" + * string::sample({{'|' ,{2,2}},{'^',{0,0}},{':',{1,8}}}, 8) // "|6Bye8:|" * @endcode */ - static std::string sample(GuaranteeMap&& guarantee, unsigned length = 10); + std::string sample(GuaranteeMap&& guarantee, unsigned length = 10); /** * @brief Generates a string consisting of given characters. @@ -163,11 +160,11 @@ class String * @returns String from characters. * * @code - * String::fromCharacters("abc") // "b" - * String::fromCharacters("qwerty", 5) // "qrwqt" + * string::fromCharacters("abc") // "b" + * string::fromCharacters("qwerty", 5) // "qrwqt" * @endcode */ - static std::string fromCharacters(const std::string& characters, unsigned length = 1); + std::string fromCharacters(const std::string& characters, unsigned length = 1); /** * @brief Generates a string consisting of given characters. @@ -179,11 +176,11 @@ class String * @returns String from characters. * * @code - * String::fromCharacters({}, "abc") // "b" - * String::fromCharacters({{'q',{2,2}},{'e',{1,5}}}, "qwerty", 8) // "yqreqety" + * string::fromCharacters({}, "abc") // "b" + * string::fromCharacters({{'q',{2,2}},{'e',{1,5}}}, "qwerty", 8) // "yqreqety" * @endcode */ - static std::string fromCharacters(GuaranteeMap&& guarantee, const std::string& characters, unsigned length = 1); + std::string fromCharacters(GuaranteeMap&& guarantee, const std::string& characters, unsigned length = 1); /** * @brief Generates a string consisting of letters in the English alphabet. @@ -196,12 +193,12 @@ class String * @returns Alpha string. * * @code - * String::alpha() // "b" - * String::alpha(5, StringCasing::Upper) // "DTCIC" - * String::alpha(4, StringCasing::Lower) // "brpt" + * string::alpha() // "b" + * string::alpha(5, StringCasing::Upper) // "DTCIC" + * string::alpha(4, StringCasing::Lower) // "brpt" * @endcode */ - static std::string alpha(unsigned length = 1, StringCasing casing = StringCasing::Mixed, + std::string alpha(unsigned length = 1, StringCasing casing = StringCasing::Mixed, const std::string& excludeCharacters = ""); /** @@ -214,12 +211,12 @@ class String * @returns Alpha string. * * @code - * String::alpha({}) // "b" - * String::alpha({{'A',{2,2}}, 5, StringCasing::Upper) // "DACAC" - * String::alpha({{'a',{0,0}},{'b',{3,3}},{'c', {0,2}}}, 10, StringCasing::Lower) // "bicnmmkbbp" + * string::alpha({}) // "b" + * string::alpha({{'A',{2,2}}, 5, StringCasing::Upper) // "DACAC" + * string::alpha({{'a',{0,0}},{'b',{3,3}},{'c', {0,2}}}, 10, StringCasing::Lower) // "bicnmmkbbp" * @endcode */ - static std::string alpha(GuaranteeMap&& guarantee, unsigned length = 1, StringCasing casing = StringCasing::Mixed); + std::string alpha(GuaranteeMap&& guarantee, unsigned length = 1, StringCasing casing = StringCasing::Mixed); /** * @brief Generates a string consisting of alpha characters and digits. @@ -232,12 +229,12 @@ class String * @returns Alphanumeric string. * * @code - * String::alphanumeric() // "4" - * String::alphanumeric(5, StringCasing::Upper) // "3e5V7" - * String::alphanumeric(4, StringCasing::Lower) // "1nrq" + * string::alphanumeric() // "4" + * string::alphanumeric(5, StringCasing::Upper) // "3e5V7" + * string::alphanumeric(4, StringCasing::Lower) // "1nrq" * @endcode */ - static std::string alphanumeric(unsigned length = 1, StringCasing casing = StringCasing::Mixed, + std::string alphanumeric(unsigned length = 1, StringCasing casing = StringCasing::Mixed, const std::string& excludeCharacters = ""); /** @@ -250,12 +247,12 @@ class String * @returns Alphanumeric string. * * @code - * String::alphanumeric({}) // "4" - * String::alphanumeric({{'A', {3,6}},{'1', {1,1}}, 5, StringCasing::Upper) // "1EAAA" - * String::alphanumeric({{'a',{0,2}},{'2',{0,3}},{'z',{3,5}}}, 10, StringCasing::Lower) // "z1naazrqz0" + * string::alphanumeric({}) // "4" + * string::alphanumeric({{'A', {3,6}},{'1', {1,1}}, 5, StringCasing::Upper) // "1EAAA" + * string::alphanumeric({{'a',{0,2}},{'2',{0,3}},{'z',{3,5}}}, 10, StringCasing::Lower) // "z1naazrqz0" * @endcode */ - static std::string alphanumeric(GuaranteeMap&& guarantee, unsigned length = 1, + std::string alphanumeric(GuaranteeMap&& guarantee, unsigned length = 1, StringCasing casing = StringCasing::Mixed); /** @@ -267,12 +264,12 @@ class String * @returns Numeric string. * * @code - * String::numeric() // "1" - * String::numeric(6) // "035742" - * String::numeric(6, false) // "254429" + * string::numeric() // "1" + * string::numeric(6) // "035742" + * string::numeric(6, false) // "254429" * @endcode */ - static std::string numeric(unsigned length = 1, bool allowLeadingZeros = true); + std::string numeric(unsigned length = 1, bool allowLeadingZeros = true); /** * @brief Generates a given length string of digits. @@ -284,12 +281,12 @@ class String * @returns Numeric string. * * @code - * String::numeric({}) // "1" - * String::numeric({'5',{3,6}}, 6) // "055542" - * String::numeric({'0',{0,0}}, {'4',{1,1}}, 6, false) // "854829" + * string::numeric({}) // "1" + * string::numeric({'5',{3,6}}, 6) // "055542" + * string::numeric({'0',{0,0}}, {'4',{1,1}}, 6, false) // "854829" * @endcode */ - static std::string numeric(GuaranteeMap&& guarantee, unsigned length = 1, bool allowLeadingZeros = true); + std::string numeric(GuaranteeMap&& guarantee, unsigned length = 1, bool allowLeadingZeros = true); /** * @brief Generates a hexadecimal string. @@ -301,13 +298,13 @@ class String * @returns Hexadecimal string. * * @code - * String::hexadecimal() // "0xb" - * String::hexadecimal(10) // "0xae13d044cb" - * String::hexadecimal(6, HexCasing::Upper, HexPrefix::Hash) // "#E3F380" - * String::hexadecimal(6, HexCasing::Lower, HexPrefix::None) // "e3f380" + * string::hexadecimal() // "0xb" + * string::hexadecimal(10) // "0xae13d044cb" + * string::hexadecimal(6, HexCasing::Upper, HexPrefix::Hash) // "#E3F380" + * string::hexadecimal(6, HexCasing::Lower, HexPrefix::None) // "e3f380" * @endcode */ - static std::string hexadecimal(unsigned length = 1, HexCasing casing = HexCasing::Lower, + std::string hexadecimal(unsigned length = 1, HexCasing casing = HexCasing::Lower, HexPrefix prefix = HexPrefix::ZeroX); /** @@ -319,11 +316,11 @@ class String * @return A lowercase hexadecimal number. * * @code - * String::hexadecimal() // "b" - * String::hexadecimal(0, 255) // "9d" + * string::hexadecimal() // "b" + * string::hexadecimal(0, 255) // "9d" * @endcode */ - static std::string hexadecimal(std::optional min = std::nullopt, std::optional max = std::nullopt); + std::string hexadecimal(std::optional min = std::nullopt, std::optional max = std::nullopt); /** * @brief Generates a hexadecimal string. @@ -336,13 +333,13 @@ class String * @returns Hexadecimal string. * * @code - * String::hexadecimal({}) // "0xb" - * String::hexadecimal({'a',{2,2}}, 10) // "0xae13d04acb" - * String::hexadecimal({'F', {2,4}}, 6, HexCasing::Upper, HexPrefix::Hash) // "#E3FFF0" - * String::hexadecimal({'1', {1,4}, {'2', {1, 4}, {'c', {1,1}}, 6, HexCasing::Lower, HexPrefix::None) // "121a1c" + * string::hexadecimal({}) // "0xb" + * string::hexadecimal({'a',{2,2}}, 10) // "0xae13d04acb" + * string::hexadecimal({'F', {2,4}}, 6, HexCasing::Upper, HexPrefix::Hash) // "#E3FFF0" + * string::hexadecimal({'1', {1,4}, {'2', {1, 4}, {'c', {1,1}}, 6, HexCasing::Lower, HexPrefix::None) // "121a1c" * @endcode */ - static std::string hexadecimal(GuaranteeMap&& guarantee, unsigned length = 1, HexCasing casing = HexCasing::Lower, + std::string hexadecimal(GuaranteeMap&& guarantee, unsigned length = 1, HexCasing casing = HexCasing::Lower, HexPrefix prefix = HexPrefix::ZeroX); /** @@ -353,10 +350,10 @@ class String * @returns Binary string. * * @code - * String::binary(8) // "0b01110101" + * string::binary(8) // "0b01110101" * @endcode */ - static std::string binary(unsigned length = 1); + std::string binary(unsigned length = 1); /** * @brief Generates a binary string. @@ -367,10 +364,10 @@ class String * @returns Binary string. * * @code - * String::binary({'1',{7,8}}, 8) // "0b11110111" + * string::binary({'1',{7,8}}, 8) // "0b11110111" * @endcode */ - static std::string binary(GuaranteeMap&& guarantee, unsigned length = 1); + std::string binary(GuaranteeMap&& guarantee, unsigned length = 1); /** * @brief Generates an octal string. @@ -380,10 +377,10 @@ class String * @returns Octal string. * * @code - * String::octal(8) // "0o52561721" + * string::octal(8) // "0o52561721" * @endcode */ - static std::string octal(unsigned length = 1); + std::string octal(unsigned length = 1); /** * @brief Generates an octal string. @@ -394,9 +391,8 @@ class String * @returns Octal string. * * @code - * String::octal({'4',{4,5}}, 8) // "0o42444041" + * string::octal({'4',{4,5}}, 8) // "0o42444041" * @endcode */ - static std::string octal(GuaranteeMap&& guarantee, unsigned length = 1); -}; + std::string octal(GuaranteeMap&& guarantee, unsigned length = 1); } diff --git a/src/modules/airline/Airline.cpp b/src/modules/airline/Airline.cpp index 5fb9ade0..7f19a0f4 100644 --- a/src/modules/airline/Airline.cpp +++ b/src/modules/airline/Airline.cpp @@ -40,29 +40,29 @@ std::string recordLocator(bool allowNumerics) { if (allowNumerics) { - return String::alphanumeric(6, StringCasing::Upper); + return string::alphanumeric(6, string::StringCasing::Upper); } - return String::alpha(6, StringCasing::Upper); + return string::alpha(6, string::StringCasing::Upper); } std::string flightNumber(bool addLeadingZeros, unsigned int length) { if (addLeadingZeros) { - return String::numeric(length, true); + return string::numeric(length, true); } - return String::numeric(length, false); + return string::numeric(length, false); } std::string flightNumberByRange(bool addLeadingZeros, Range length) { if (addLeadingZeros) { - return String::numeric(number::integer(length.min, length.max), true); + return string::numeric(number::integer(length.min, length.max), true); } - return String::numeric(number::integer(length.min, length.max), false); + return string::numeric(number::integer(length.min, length.max), false); } } diff --git a/src/modules/color/Color.cpp b/src/modules/color/Color.cpp index 166d5e84..667bb8a7 100644 --- a/src/modules/color/Color.cpp +++ b/src/modules/color/Color.cpp @@ -35,7 +35,7 @@ std::string rgb(bool includeAlpha) std::string hex(HexCasing casing, HexPrefix prefix, bool includeAlpha) { - return String::hexadecimal(includeAlpha ? 8 : 6, casing, prefix); + return string::hexadecimal(includeAlpha ? 8 : 6, casing, prefix); } std::string hsl(bool include_alpha) diff --git a/src/modules/commerce/Commerce.cpp b/src/modules/commerce/Commerce.cpp index 31ec3cc3..2f94471f 100644 --- a/src/modules/commerce/Commerce.cpp +++ b/src/modules/commerce/Commerce.cpp @@ -17,7 +17,7 @@ std::string_view department() std::string sku(unsigned int length) { - return String::numeric(length, false); + return string::numeric(length, false); } std::string_view productAdjective() @@ -42,7 +42,7 @@ std::string productFullName() std::string EAN13() { - const auto ean13 = String::numeric(12, false); + const auto ean13 = string::numeric(12, false); int sum = 0; @@ -70,7 +70,7 @@ std::string EAN13() std::string EAN8() { - const auto ean8 = String::numeric(7, false); + const auto ean8 = string::numeric(7, false); int sum = 0; @@ -98,7 +98,7 @@ std::string EAN8() std::string ISBN13() { - const auto isbn13 = String::numeric(12, true); + const auto isbn13 = string::numeric(12, true); int sum = 0; @@ -126,7 +126,7 @@ std::string ISBN13() std::string ISBN10() { - const auto isbn10 = String::numeric(9, true); + const auto isbn10 = string::numeric(9, true); int sum = 0, weight = 10; diff --git a/src/modules/database/Database.cpp b/src/modules/database/Database.cpp index 7429fd71..9bfa5ba1 100644 --- a/src/modules/database/Database.cpp +++ b/src/modules/database/Database.cpp @@ -32,6 +32,6 @@ std::string_view engine() std::string mongoDbObjectId() { - return String::hexadecimal(24, HexCasing::Lower, HexPrefix::None); + return string::hexadecimal(24, HexCasing::Lower, HexPrefix::None); } } diff --git a/src/modules/finance/Finance.cpp b/src/modules/finance/Finance.cpp index fa40644d..58351d8a 100644 --- a/src/modules/finance/Finance.cpp +++ b/src/modules/finance/Finance.cpp @@ -74,15 +74,15 @@ std::string iban(std::optional country) if (ibanFormatEntryDataType == 'a') { - iban += String::alpha(static_cast(ibanFormatEntryDataLength), StringCasing::Upper); + iban += string::alpha(static_cast(ibanFormatEntryDataLength), string::StringCasing::Upper); } else if (ibanFormatEntryDataType == 'c') { - iban += String::alphanumeric(static_cast(ibanFormatEntryDataLength), StringCasing::Upper); + iban += string::alphanumeric(static_cast(ibanFormatEntryDataLength), string::StringCasing::Upper); } else if (ibanFormatEntryDataType == 'n') { - iban += String::numeric(static_cast(ibanFormatEntryDataLength)); + iban += string::numeric(static_cast(ibanFormatEntryDataLength)); } } @@ -98,17 +98,17 @@ std::string_view bic(std::optional country) std::string accountNumber(unsigned int length) { - return String::numeric(length, true); + return string::numeric(length, true); } std::string pin(unsigned int length) { - return String::numeric(length, true); + return string::numeric(length, true); } std::string routingNumber() { - return String::numeric(9, true); + return string::numeric(9, true); } std::string creditCardNumber(std::optional creditCardType) @@ -135,7 +135,7 @@ std::string creditCardNumber(std::optional creditCardType) std::string creditCardCvv() { - return String::numeric(3, true); + return string::numeric(3, true); } std::string bitcoinAddress() @@ -144,7 +144,7 @@ std::string bitcoinAddress() auto address = Helper::arrayElement(std::vector{"1", "3"}); - address += String::alphanumeric(addressLength, StringCasing::Mixed, "0OIl"); + address += string::alphanumeric(addressLength, string::StringCasing::Mixed, "0OIl"); return address; } @@ -155,14 +155,14 @@ std::string litecoinAddress() auto address = Helper::arrayElement(std::vector{"L", "M", "3"}); - address += String::alphanumeric(addressLength, StringCasing::Mixed, "0OIl"); + address += string::alphanumeric(addressLength, string::StringCasing::Mixed, "0OIl"); return address; } std::string ethereumAddress() { - return String::hexadecimal(40, HexCasing::Lower); + return string::hexadecimal(40, HexCasing::Lower); } std::string creditCardExpirationDate() diff --git a/src/modules/git/Git.cpp b/src/modules/git/Git.cpp index c90a94ee..8c0fed8e 100644 --- a/src/modules/git/Git.cpp +++ b/src/modules/git/Git.cpp @@ -127,7 +127,7 @@ std::string commitMessage() std::string commitSha(unsigned length) { - return faker::String::hexadecimal(length, HexCasing::Lower, HexPrefix::None); + return faker::string::hexadecimal(length, HexCasing::Lower, HexPrefix::None); } } diff --git a/src/modules/internet/Internet.cpp b/src/modules/internet/Internet.cpp index 46c79ae6..9a71e07b 100644 --- a/src/modules/internet/Internet.cpp +++ b/src/modules/internet/Internet.cpp @@ -131,22 +131,22 @@ std::string password(int length, const PasswordOptions& options) if (options.upperLetters) { - characters += upperCharacters; + characters += string::upperCharacters; } if (options.lowerLetters) { - characters += lowerCharacters; + characters += string::lowerCharacters; } if (options.numbers) { - characters += numericCharacters; + characters += string::numericCharacters; } if (options.symbols) { - characters += symbolCharacters; + characters += string::symbolCharacters; } std::string password; @@ -279,7 +279,7 @@ std::string ipv6() for (int i = 0; i < 8; i++) { - ipv6Parts.push_back(String::hexadecimal(4, HexCasing::Lower, HexPrefix::None)); + ipv6Parts.push_back(string::hexadecimal(4, HexCasing::Lower, HexPrefix::None)); } return StringHelper::joinString(ipv6Parts, ":"); @@ -298,7 +298,7 @@ std::string mac(const std::string& sep) for (int i = 0; i < 12; i++) { - mac += String::hexadecimal(0, 15); + mac += string::hexadecimal(0, 15); if (i % 2 == 1 && i != 11) { diff --git a/src/modules/person/Person.cpp b/src/modules/person/Person.cpp index 212c44b9..04073605 100644 --- a/src/modules/person/Person.cpp +++ b/src/modules/person/Person.cpp @@ -407,11 +407,11 @@ std::string Person::ssn(std::optional country) { if (ssnFormatCharacter == 'L') { - ssn += String::alpha(1, StringCasing::Upper); + ssn += string::alpha(1, string::StringCasing::Upper); } else if (ssnFormatCharacter == 'F') { - ssn += String::alphanumeric(1, StringCasing::Upper); + ssn += string::alphanumeric(1, string::StringCasing::Upper); } else if (ssnFormatCharacter == '#') { @@ -448,12 +448,12 @@ std::string Person::passport(std::optional countryOpt) { if (c == 'A') { - passportNumber += String::alpha(1, StringCasing::Upper); + passportNumber += string::alpha(1, string::StringCasing::Upper); } else if (c == '0') { - passportNumber += String::numeric(1); + passportNumber += string::numeric(1); } } diff --git a/src/modules/string/String.cpp b/src/modules/string/String.cpp index be360709..f6c0c83c 100644 --- a/src/modules/string/String.cpp +++ b/src/modules/string/String.cpp @@ -14,7 +14,7 @@ #include "faker-cxx/types/Hex.h" #include "StringData.h" -namespace faker +namespace faker::string { namespace { @@ -48,41 +48,8 @@ const std::map> hexCasingToCharSetMapping{ {HexCasing::Lower, hexLowerCharSet}, {HexCasing::Upper, hexUpperCharSet}, }; -} - -bool isValidGuarantee(GuaranteeMap& guarantee, std::set& targetCharacters, unsigned int length) -{ - unsigned int atleastCountSum{}; - unsigned int atmostCountSum{}; - for (auto& it : guarantee) - { - // if a char in guarantee is not in char set, it is an invalid guarantee - if (std::find(targetCharacters.begin(), targetCharacters.end(), it.first) == targetCharacters.end()) - { - return false; - } - atleastCountSum += it.second.atLeastCount; - atmostCountSum += it.second.atMostCount; - } - // if atleastCount sums up greater than total length of string, it is an invalid guarantee - // if all chars in targetCharacters are mapped in guarantee, we need to check for validity of atmostCount - // if atmostCount sumps up less than total length of string, it in an invalid guarantee - if (atleastCountSum > length || (guarantee.size() == targetCharacters.size() && atmostCountSum < length)) - return false; - return true; -} - -std::string generateAtLeastString(const GuaranteeMap& guarantee) -{ - std::string result; - for (auto& it : guarantee) - { - result += std::string(it.second.atLeastCount, it.first); - } - return result; -} -std::string String::generateStringWithGuarantee(GuaranteeMap& guarantee, std::set& targetCharacters, +std::string generateStringWithGuarantee(GuaranteeMap& guarantee, std::set& targetCharacters, unsigned int length) { std::string output{}; @@ -123,8 +90,41 @@ std::string String::generateStringWithGuarantee(GuaranteeMap& guarantee, std::se output = Helper::shuffleString(output); return output; } +} + +bool isValidGuarantee(GuaranteeMap& guarantee, std::set& targetCharacters, unsigned int length) +{ + unsigned int atleastCountSum{}; + unsigned int atmostCountSum{}; + for (auto& it : guarantee) + { + // if a char in guarantee is not in char set, it is an invalid guarantee + if (std::find(targetCharacters.begin(), targetCharacters.end(), it.first) == targetCharacters.end()) + { + return false; + } + atleastCountSum += it.second.atLeastCount; + atmostCountSum += it.second.atMostCount; + } + // if atleastCount sums up greater than total length of string, it is an invalid guarantee + // if all chars in targetCharacters are mapped in guarantee, we need to check for validity of atmostCount + // if atmostCount sumps up less than total length of string, it in an invalid guarantee + if (atleastCountSum > length || (guarantee.size() == targetCharacters.size() && atmostCountSum < length)) + return false; + return true; +} + +std::string generateAtLeastString(const GuaranteeMap& guarantee) +{ + std::string result; + for (auto& it : guarantee) + { + result += std::string(it.second.atLeastCount, it.first); + } + return result; +} -std::string String::sample(unsigned int length) +std::string sample(unsigned int length) { std::string sample; @@ -136,7 +136,7 @@ std::string String::sample(unsigned int length) return sample; } -std::string String::sample(GuaranteeMap&& guarantee, unsigned int length) +std::string sample(GuaranteeMap&& guarantee, unsigned int length) { auto targetCharacters = utf16CharSet; // throw if guarantee is invalid @@ -147,7 +147,7 @@ std::string String::sample(GuaranteeMap&& guarantee, unsigned int length) return generateStringWithGuarantee(guarantee, targetCharacters, length); } -std::string String::fromCharacters(const std::string& characters, unsigned int length) +std::string fromCharacters(const std::string& characters, unsigned int length) { std::string result; @@ -159,7 +159,7 @@ std::string String::fromCharacters(const std::string& characters, unsigned int l return result; } -std::string String::fromCharacters(GuaranteeMap&& guarantee, const std::string& characters, unsigned length) +std::string fromCharacters(GuaranteeMap&& guarantee, const std::string& characters, unsigned length) { std::set targetCharacters; for (auto character : characters) @@ -174,7 +174,7 @@ std::string String::fromCharacters(GuaranteeMap&& guarantee, const std::string& return generateStringWithGuarantee(guarantee, targetCharacters, length); } -std::string String::alpha(unsigned length, StringCasing casing, const std::string& excludeCharacters) +std::string alpha(unsigned length, StringCasing casing, const std::string& excludeCharacters) { const auto& alphaCharacters = stringCasingToAlphaCharactersMapping.at(casing); @@ -198,7 +198,7 @@ std::string String::alpha(unsigned length, StringCasing casing, const std::strin return alpha; } -std::string String::alpha(GuaranteeMap&& guarantee, unsigned int length, StringCasing casing) +std::string alpha(GuaranteeMap&& guarantee, unsigned int length, StringCasing casing) { auto targetCharacters = stringCasingToAlphaCharSetMapping.at(casing); // throw if guarantee is invalid @@ -209,7 +209,7 @@ std::string String::alpha(GuaranteeMap&& guarantee, unsigned int length, StringC return generateStringWithGuarantee(guarantee, targetCharacters, length); } -std::string String::alphanumeric(unsigned int length, StringCasing casing, const std::string& excludeCharacters) +std::string alphanumeric(unsigned int length, StringCasing casing, const std::string& excludeCharacters) { const auto& alphanumericCharacters = stringCasingToAlphanumericCharactersMapping.at(casing); @@ -233,7 +233,7 @@ std::string String::alphanumeric(unsigned int length, StringCasing casing, const return alphanumeric; } -std::string String::alphanumeric(GuaranteeMap&& guarantee, unsigned length, StringCasing casing) +std::string alphanumeric(GuaranteeMap&& guarantee, unsigned length, StringCasing casing) { auto targetCharacters = digitSet; auto charSet = stringCasingToAlphaCharSetMapping.at(casing); @@ -246,7 +246,7 @@ std::string String::alphanumeric(GuaranteeMap&& guarantee, unsigned length, Stri return generateStringWithGuarantee(guarantee, targetCharacters, length); } -std::string String::numeric(unsigned int length, bool allowLeadingZeros) +std::string numeric(unsigned int length, bool allowLeadingZeros) { std::string alphanumeric; @@ -265,7 +265,7 @@ std::string String::numeric(unsigned int length, bool allowLeadingZeros) return alphanumeric; } -std::string String::numeric(GuaranteeMap&& guarantee, const unsigned length, bool allowLeadingZeros) +std::string numeric(GuaranteeMap&& guarantee, const unsigned length, bool allowLeadingZeros) { // if leading zero not allowed, atleastCount of '0' cannot be equal to length if (!allowLeadingZeros) @@ -298,7 +298,7 @@ std::string String::numeric(GuaranteeMap&& guarantee, const unsigned length, boo } } -std::string String::hexadecimal(unsigned int length, HexCasing casing, HexPrefix prefix) +std::string hexadecimal(unsigned int length, HexCasing casing, HexPrefix prefix) { const auto& hexadecimalCharacters = hexCasingToCharactersMapping.at(casing); @@ -314,7 +314,7 @@ std::string String::hexadecimal(unsigned int length, HexCasing casing, HexPrefix return hexadecimal; } -std::string String::hexadecimal(std::optional min, std::optional max) +std::string hexadecimal(std::optional min, std::optional max) { int defaultMin = 0; int defaultMax = 15; @@ -332,7 +332,7 @@ std::string String::hexadecimal(std::optional min, std::optional max) return FormatHelper::format("{:x}", number::integer(defaultMin, defaultMax)); } -std::string String::hexadecimal(GuaranteeMap&& guarantee, unsigned int length, HexCasing casing, HexPrefix prefix) +std::string hexadecimal(GuaranteeMap&& guarantee, unsigned int length, HexCasing casing, HexPrefix prefix) { std::set targetCharacters = hexCasingToCharSetMapping.at(casing); // throw if guarantee is invalid @@ -344,7 +344,7 @@ std::string String::hexadecimal(GuaranteeMap&& guarantee, unsigned int length, H return hexadecimalPrefix + generateStringWithGuarantee(guarantee, targetCharacters, length); } -std::string String::binary(unsigned int length) +std::string binary(unsigned int length) { std::string binaryNumber; for (unsigned int i = 0; i < length; ++i) @@ -354,7 +354,7 @@ std::string String::binary(unsigned int length) return "0b" + binaryNumber; } -std::string String::binary(GuaranteeMap&& guarantee, unsigned int length) +std::string binary(GuaranteeMap&& guarantee, unsigned int length) { // numbers used by binary representation std::set targetCharacters{'0', '1'}; @@ -367,7 +367,7 @@ std::string String::binary(GuaranteeMap&& guarantee, unsigned int length) return "0b" + generateStringWithGuarantee(guarantee, targetCharacters, length); } -std::string String::octal(unsigned int length) +std::string octal(unsigned int length) { std::string octalNumber; for (unsigned int i = 0; i < length; ++i) @@ -377,7 +377,7 @@ std::string String::octal(unsigned int length) return "0o" + octalNumber; } -std::string String::octal(GuaranteeMap&& guarantee, unsigned int length) +std::string octal(GuaranteeMap&& guarantee, unsigned int length) { // numbers used by octal representation std::set targetCharacters{'0', '1', '2', '3', '4', '5', '6', '7'}; diff --git a/src/modules/string/StringData.h b/src/modules/string/StringData.h index 1e307c53..6feef2ef 100644 --- a/src/modules/string/StringData.h +++ b/src/modules/string/StringData.h @@ -3,45 +3,45 @@ #include #include -namespace faker +namespace faker::string { -static const std::string upperCharacters{"ABCDEFGHIJKLMNOPQRSTUVWXYZ"}; -static const std::string lowerCharacters{"abcdefghijklmnopqrstuvwxyz"}; -static const std::string numericCharactersWithoutZero{"123456789"}; -static const std::string numericCharacters{"0123456789"}; -static const std::string mixedAlphaCharacters{upperCharacters + lowerCharacters}; -static const std::string lowerAlphanumericCharacters{lowerCharacters + numericCharacters}; -static const std::string upperAlphanumericCharacters{upperCharacters + numericCharacters}; -static const std::string mixedAlphanumericCharacters{upperCharacters + lowerCharacters + numericCharacters}; -static const std::string hexUpperCharacters{"0123456789ABCDEF"}; -static const std::string hexLowerCharacters{"0123456789abcdef"}; -static const std::string symbolCharacters{"~`!@#$%^&*()_-+={[}]|:;\"'<,>.?/"}; - -static const std::set lowerCharSet{ + const std::string upperCharacters{"ABCDEFGHIJKLMNOPQRSTUVWXYZ"}; + const std::string lowerCharacters{"abcdefghijklmnopqrstuvwxyz"}; + const std::string numericCharactersWithoutZero{"123456789"}; + const std::string numericCharacters{"0123456789"}; + const std::string mixedAlphaCharacters{upperCharacters + lowerCharacters}; + const std::string lowerAlphanumericCharacters{lowerCharacters + numericCharacters}; + const std::string upperAlphanumericCharacters{upperCharacters + numericCharacters}; + const std::string mixedAlphanumericCharacters{upperCharacters + lowerCharacters + numericCharacters}; + const std::string hexUpperCharacters{"0123456789ABCDEF"}; + const std::string hexLowerCharacters{"0123456789abcdef"}; + const std::string symbolCharacters{"~`!@#$%^&*()_-+={[}]|:;\"'<,>.?/"}; + + const std::set lowerCharSet{ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', }; -static const std::set upperCharSet{ + const std::set upperCharSet{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', }; -static const std::set mixedAlphaCharSet{ + const std::set mixedAlphaCharSet{ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', }; -static const std::set hexUpperCharSet{'A', 'B', 'C', 'D', 'E', 'F', '0', '1', + const std::set hexUpperCharSet{'A', 'B', 'C', 'D', 'E', 'F', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; -static const std::set hexLowerCharSet{'a', 'b', 'c', 'd', 'e', 'f', '0', '1', + const std::set hexLowerCharSet{'a', 'b', 'c', 'd', 'e', 'f', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; -static const std::set digitSet{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; + const std::set digitSet{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; -static const std::set utf16CharSet{ + const std::set utf16CharSet{ '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', diff --git a/src/modules/system/System.cpp b/src/modules/system/System.cpp index b2f198f6..b9c8d15d 100644 --- a/src/modules/system/System.cpp +++ b/src/modules/system/System.cpp @@ -203,7 +203,7 @@ std::string networkInterface(const std::optional& optio std::string suffix; std::string prefix; - auto digit = []() { return String::numeric(); }; + auto digit = []() { return string::numeric(); }; if (interfaceSchema == "index") { diff --git a/src/modules/vehicle/Vehicle.cpp b/src/modules/vehicle/Vehicle.cpp index 0fdf833d..0eb5ffec 100644 --- a/src/modules/vehicle/Vehicle.cpp +++ b/src/modules/vehicle/Vehicle.cpp @@ -51,16 +51,16 @@ std::string vin() { std::string exclude_characters{"oiqOIQ"}; - return FormatHelper::format("{}{}{}{}", String::alphanumeric(10, StringCasing::Upper, exclude_characters), - String::alpha(1, StringCasing::Upper, exclude_characters), - String::alphanumeric(1, StringCasing::Upper, exclude_characters), + return FormatHelper::format("{}{}{}{}", string::alphanumeric(10, string::StringCasing::Upper, exclude_characters), + string::alpha(1, string::StringCasing::Upper, exclude_characters), + string::alphanumeric(1, string::StringCasing::Upper, exclude_characters), number::integer(10000, 99999)); } std::string vrm() { - return FormatHelper::format("{}{}{}", String::alpha(2, StringCasing::Upper), String::numeric(2, true), - String::alpha(3, StringCasing::Upper)); + return FormatHelper::format("{}{}{}", string::alpha(2, string::StringCasing::Upper), string::numeric(2, true), + string::alpha(3, string::StringCasing::Upper)); } } diff --git a/tests/modules/color/ColorTest.cpp b/tests/modules/color/ColorTest.cpp index 93a2c9fe..a7dfcf3c 100644 --- a/tests/modules/color/ColorTest.cpp +++ b/tests/modules/color/ColorTest.cpp @@ -77,7 +77,7 @@ TEST_F(ColorTest, shouldGenerateHexColorWithoutAlpha) ASSERT_EQ(hexadecimal.size(), 7); ASSERT_EQ(prefix, "#"); ASSERT_TRUE(std::ranges::any_of(hexNumber, [hexNumber](char hexNumberCharacter) - { return hexLowerCharacters.find(hexNumberCharacter) != std::string::npos; })); + { return string::hexLowerCharacters.find(hexNumberCharacter) != std::string::npos; })); } TEST_F(ColorTest, shouldGenerateHexColorWithAlpha) @@ -90,7 +90,7 @@ TEST_F(ColorTest, shouldGenerateHexColorWithAlpha) ASSERT_EQ(hexadecimal.size(), 10); ASSERT_EQ(prefix, "0x"); ASSERT_TRUE(std::ranges::any_of(hexNumber, [hexNumber](char hexNumberCharacter) - { return hexUpperCharacters.find(hexNumberCharacter) != std::string::npos; })); + { return string::hexUpperCharacters.find(hexNumberCharacter) != std::string::npos; })); } TEST_F(ColorTest, shouldGenerateHslWithoutAlpha) diff --git a/tests/modules/commerce/CommerceTest.cpp b/tests/modules/commerce/CommerceTest.cpp index 52cd699e..d7f80bcf 100644 --- a/tests/modules/commerce/CommerceTest.cpp +++ b/tests/modules/commerce/CommerceTest.cpp @@ -34,7 +34,7 @@ TEST_F(CommerceTest, shouldGenerateSku) ASSERT_TRUE(std::ranges::all_of(generatedSku, [](char skuCharacter) { - return std::ranges::any_of(numericCharacters, + return std::ranges::any_of(string::numericCharacters, [skuCharacter](char numericCharacter) { return skuCharacter == numericCharacter; }); })); @@ -50,7 +50,7 @@ TEST_F(CommerceTest, shouldGenerateSkuWithSpecifiedLength) ASSERT_TRUE(std::ranges::all_of(generatedSku, [](char skuCharacter) { - return std::ranges::any_of(numericCharacters, + return std::ranges::any_of(string::numericCharacters, [skuCharacter](char numericCharacter) { return skuCharacter == numericCharacter; }); })); diff --git a/tests/modules/database/DatabaseTest.cpp b/tests/modules/database/DatabaseTest.cpp index a3fd24b8..677f81fc 100644 --- a/tests/modules/database/DatabaseTest.cpp +++ b/tests/modules/database/DatabaseTest.cpp @@ -55,5 +55,5 @@ TEST_F(DatabaseTest, shouldGenerateMongoDbObjectId) ASSERT_EQ(generatedMongoDbObjectId.size(), 24); ASSERT_TRUE(std::ranges::any_of(generatedMongoDbObjectId, [](char hexNumberCharacter) - { return hexLowerCharacters.find(hexNumberCharacter) != std::string::npos; })); + { return string::hexLowerCharacters.find(hexNumberCharacter) != std::string::npos; })); } diff --git a/tests/modules/finance/FinanceTest.cpp b/tests/modules/finance/FinanceTest.cpp index 8f4751e8..7a769ffc 100644 --- a/tests/modules/finance/FinanceTest.cpp +++ b/tests/modules/finance/FinanceTest.cpp @@ -105,7 +105,7 @@ class FinanceTest : public TestWithParam return std::ranges::all_of(data, [](char dataCharacter) { - return std::ranges::any_of(numericCharacters, + return std::ranges::any_of(string::numericCharacters, [dataCharacter](char numericCharacter) { return numericCharacter == dataCharacter; }); }); @@ -392,7 +392,7 @@ TEST_F(FinanceTest, shouldGenerateEthereumAddress) ASSERT_EQ(generatedEthereumAddress.size(), 42); ASSERT_EQ(prefix, "0x"); ASSERT_TRUE(std::ranges::any_of(hexNumber, [hexNumber](char hexNumberCharacter) - { return hexLowerCharacters.find(hexNumberCharacter) != std::string::npos; })); + { return string::hexLowerCharacters.find(hexNumberCharacter) != std::string::npos; })); } TEST_F(FinanceTest, shouldGenerateExpirationDate) diff --git a/tests/modules/internet/InternetTest.cpp b/tests/modules/internet/InternetTest.cpp index 88d368aa..db62cd34 100644 --- a/tests/modules/internet/InternetTest.cpp +++ b/tests/modules/internet/InternetTest.cpp @@ -633,7 +633,7 @@ TEST_F(InternetTest, shouldGenerateIpv6) { return std::ranges::all_of( generatedIpv6Part, [](char hexCharacter) - { return hexLowerCharacters.find(hexCharacter) != std::string::npos; }); + { return string::hexLowerCharacters.find(hexCharacter) != std::string::npos; }); })); } diff --git a/tests/modules/location/LocationTest.cpp b/tests/modules/location/LocationTest.cpp index b5b37c80..172d1345 100644 --- a/tests/modules/location/LocationTest.cpp +++ b/tests/modules/location/LocationTest.cpp @@ -106,7 +106,7 @@ class LocationTest : public TestWithParam return std::ranges::all_of(data, [](char dataCharacter) { - return std::ranges::any_of(numericCharacters, + return std::ranges::any_of(string::numericCharacters, [dataCharacter](char numericCharacter) { return numericCharacter == dataCharacter; }); }); @@ -114,7 +114,7 @@ class LocationTest : public TestWithParam static bool checkIfCharacterIsNumeric(char character) { - return std::ranges::any_of(numericCharacters, + return std::ranges::any_of(string::numericCharacters, [character](char numericCharacter) { return numericCharacter == character; }); } }; diff --git a/tests/modules/string/StringTest.cpp b/tests/modules/string/StringTest.cpp index 04529832..66c0564e 100644 --- a/tests/modules/string/StringTest.cpp +++ b/tests/modules/string/StringTest.cpp @@ -15,6 +15,7 @@ using namespace ::testing; using namespace faker; +using namespace faker::string; class StringTest : public Test { @@ -25,124 +26,124 @@ class StringTest : public Test TEST_F(StringTest, shouldUseCustomRandomGeneratorForUuid4) { RandomGenerator gen1{}; - const auto uuid1 = String::uuid(gen1); + const auto generatedUuid1 = uuid(gen1); - ASSERT_EQ(uuid1[8], '-'); - ASSERT_EQ(uuid1[13], '-'); - ASSERT_EQ(uuid1[14], '4'); - ASSERT_EQ(uuid1[18], '-'); - ASSERT_EQ(uuid1[23], '-'); + ASSERT_EQ(generatedUuid1[8], '-'); + ASSERT_EQ(generatedUuid1[13], '-'); + ASSERT_EQ(generatedUuid1[14], '4'); + ASSERT_EQ(generatedUuid1[18], '-'); + ASSERT_EQ(generatedUuid1[23], '-'); RandomGenerator gen2{}; - const auto uuid2 = String::uuid(gen2); + const auto generatedUuid2 = uuid(gen2); - ASSERT_EQ(uuid2[8], '-'); - ASSERT_EQ(uuid2[13], '-'); - ASSERT_EQ(uuid2[14], '4'); - ASSERT_EQ(uuid2[18], '-'); - ASSERT_EQ(uuid2[23], '-'); + ASSERT_EQ(generatedUuid2[8], '-'); + ASSERT_EQ(generatedUuid2[13], '-'); + ASSERT_EQ(generatedUuid2[14], '4'); + ASSERT_EQ(generatedUuid2[18], '-'); + ASSERT_EQ(generatedUuid2[23], '-'); RandomGenerator gen3{}; - const auto uuid3 = String::uuid(gen3); + const auto generatedUuid3 = uuid(gen3); - ASSERT_EQ(uuid3[8], '-'); - ASSERT_EQ(uuid3[13], '-'); - ASSERT_EQ(uuid3[14], '4'); - ASSERT_EQ(uuid3[18], '-'); - ASSERT_EQ(uuid3[23], '-'); + ASSERT_EQ(generatedUuid3[8], '-'); + ASSERT_EQ(generatedUuid3[13], '-'); + ASSERT_EQ(generatedUuid3[14], '4'); + ASSERT_EQ(generatedUuid3[18], '-'); + ASSERT_EQ(generatedUuid3[23], '-'); RandomGenerator gen4{}; - const auto uuid4 = String::uuid(gen4); + const auto generatedUuid4 = uuid(gen4); - ASSERT_EQ(uuid4[8], '-'); - ASSERT_EQ(uuid4[13], '-'); - ASSERT_EQ(uuid4[14], '4'); - ASSERT_EQ(uuid4[18], '-'); - ASSERT_EQ(uuid4[23], '-'); + ASSERT_EQ(generatedUuid4[8], '-'); + ASSERT_EQ(generatedUuid4[13], '-'); + ASSERT_EQ(generatedUuid4[14], '4'); + ASSERT_EQ(generatedUuid4[18], '-'); + ASSERT_EQ(generatedUuid4[23], '-'); RandomGenerator gen5{}; - const auto uuid5 = String::uuid(gen5); + const auto generatedUuid5 = uuid(gen5); - ASSERT_EQ(uuid5[8], '-'); - ASSERT_EQ(uuid5[13], '-'); - ASSERT_EQ(uuid5[14], '4'); - ASSERT_EQ(uuid5[18], '-'); - ASSERT_EQ(uuid5[23], '-'); + ASSERT_EQ(generatedUuid5[8], '-'); + ASSERT_EQ(generatedUuid5[13], '-'); + ASSERT_EQ(generatedUuid5[14], '4'); + ASSERT_EQ(generatedUuid5[18], '-'); + ASSERT_EQ(generatedUuid5[23], '-'); RandomGenerator gen6{}; - const auto uuid6 = String::uuid(gen6); + const auto generatedUuid6 = uuid(gen6); - ASSERT_EQ(uuid6[8], '-'); - ASSERT_EQ(uuid6[13], '-'); - ASSERT_EQ(uuid6[14], '4'); - ASSERT_EQ(uuid6[18], '-'); - ASSERT_EQ(uuid6[23], '-'); + ASSERT_EQ(generatedUuid6[8], '-'); + ASSERT_EQ(generatedUuid6[13], '-'); + ASSERT_EQ(generatedUuid6[14], '4'); + ASSERT_EQ(generatedUuid6[18], '-'); + ASSERT_EQ(generatedUuid6[23], '-'); RandomGenerator gen7{}; - const auto uuid7 = String::uuid(gen7); + const auto generatedUuid7 = uuid(gen7); - ASSERT_EQ(uuid7[8], '-'); - ASSERT_EQ(uuid7[13], '-'); - ASSERT_EQ(uuid7[14], '4'); - ASSERT_EQ(uuid7[18], '-'); - ASSERT_EQ(uuid7[23], '-'); + ASSERT_EQ(generatedUuid7[8], '-'); + ASSERT_EQ(generatedUuid7[13], '-'); + ASSERT_EQ(generatedUuid7[14], '4'); + ASSERT_EQ(generatedUuid7[18], '-'); + ASSERT_EQ(generatedUuid7[23], '-'); RandomGenerator gen8{}; - const auto uuid8 = String::uuid(gen8); + const auto generatedUuid8 = uuid(gen8); - ASSERT_EQ(uuid8[8], '-'); - ASSERT_EQ(uuid8[13], '-'); - ASSERT_EQ(uuid8[14], '4'); - ASSERT_EQ(uuid8[18], '-'); - ASSERT_EQ(uuid8[23], '-'); + ASSERT_EQ(generatedUuid8[8], '-'); + ASSERT_EQ(generatedUuid8[13], '-'); + ASSERT_EQ(generatedUuid8[14], '4'); + ASSERT_EQ(generatedUuid8[18], '-'); + ASSERT_EQ(generatedUuid8[23], '-'); RandomGenerator gen9{}; - const auto uuid9 = String::uuid(gen9); + const auto generatedUuid9 = uuid(gen9); - ASSERT_EQ(uuid9[8], '-'); - ASSERT_EQ(uuid9[13], '-'); - ASSERT_EQ(uuid9[14], '4'); - ASSERT_EQ(uuid9[18], '-'); - ASSERT_EQ(uuid9[23], '-'); + ASSERT_EQ(generatedUuid9[8], '-'); + ASSERT_EQ(generatedUuid9[13], '-'); + ASSERT_EQ(generatedUuid9[14], '4'); + ASSERT_EQ(generatedUuid9[18], '-'); + ASSERT_EQ(generatedUuid9[23], '-'); RandomGenerator gen10{}; - const auto uuid10 = String::uuid(gen10); + const auto generatedUuid10 = uuid(gen10); - ASSERT_EQ(uuid10[8], '-'); - ASSERT_EQ(uuid10[13], '-'); - ASSERT_EQ(uuid10[14], '4'); - ASSERT_EQ(uuid10[18], '-'); - ASSERT_EQ(uuid10[23], '-'); + ASSERT_EQ(generatedUuid10[8], '-'); + ASSERT_EQ(generatedUuid10[13], '-'); + ASSERT_EQ(generatedUuid10[14], '4'); + ASSERT_EQ(generatedUuid10[18], '-'); + ASSERT_EQ(generatedUuid10[23], '-'); } TEST_F(StringTest, shouldGenerateUuid4) { - const auto uuid = String::uuid(); + const auto generatedUuid = uuid(); - ASSERT_EQ(uuid[8], '-'); - ASSERT_EQ(uuid[13], '-'); - ASSERT_EQ(uuid[14], '4'); - ASSERT_EQ(uuid[18], '-'); - ASSERT_EQ(uuid[23], '-'); + ASSERT_EQ(generatedUuid[8], '-'); + ASSERT_EQ(generatedUuid[13], '-'); + ASSERT_EQ(generatedUuid[14], '4'); + ASSERT_EQ(generatedUuid[18], '-'); + ASSERT_EQ(generatedUuid[23], '-'); } TEST_F(StringTest, shouldGenerateDefaultSampleString) { - const auto sample = String::sample(); + const auto generatedSample = sample(); - ASSERT_EQ(sample.size(), 10); + ASSERT_EQ(generatedSample.size(), 10); ASSERT_TRUE(std::ranges::all_of( - sample, [](char sampleCharacter) + generatedSample, [](char sampleCharacter) { return static_cast(sampleCharacter) >= 33 && static_cast(sampleCharacter) <= 125; })); } TEST_F(StringTest, shouldGenerateSampleString) { - const auto sample = String::sample(5); + const auto generatedSample = sample(5); - ASSERT_EQ(sample.size(), 5); + ASSERT_EQ(generatedSample.size(), 5); ASSERT_TRUE(std::ranges::all_of( - sample, [](char sampleCharacter) + generatedSample, [](char sampleCharacter) { return static_cast(sampleCharacter) >= 33 && static_cast(sampleCharacter) <= 125; })); } @@ -156,16 +157,16 @@ TEST_F(StringTest, shouldGenerateSampleStringWithGuarantee1) for (int i = 0; i < runCount; ++i) { auto copyGuarantee = guarantee; - const auto sample = String::sample(std::move(copyGuarantee), sampleLength); + const auto generatedSample = sample(std::move(copyGuarantee), sampleLength); - ASSERT_EQ(sample.size(), sampleLength); + ASSERT_EQ(generatedSample.size(), sampleLength); ASSERT_TRUE(std::ranges::all_of( - sample, [](char sampleCharacter) + generatedSample, [](char sampleCharacter) { return static_cast(sampleCharacter) >= 33 && static_cast(sampleCharacter) <= 125; })); - auto count_semicolon = std::ranges::count(sample, ';'); - auto count_comma = std::ranges::count(sample, ','); - auto count_a = std::ranges::count(sample, 'a'); + auto count_semicolon = std::ranges::count(generatedSample, ';'); + auto count_comma = std::ranges::count(generatedSample, ','); + auto count_a = std::ranges::count(generatedSample, 'a'); ASSERT_TRUE(count_semicolon >= 1 && count_semicolon <= 3); ASSERT_TRUE(count_comma >= 3 && count_comma <= 4); @@ -183,17 +184,17 @@ TEST_F(StringTest, shouldGenerateSampleStringWithGuarantee2) for (int i = 0; i < runCount; ++i) { auto copyGuarantee = guarantee; - const auto sample = String::sample(std::move(copyGuarantee), sampleLength); + const auto generatedSample = sample(std::move(copyGuarantee), sampleLength); - ASSERT_EQ(sample.size(), sampleLength); + ASSERT_EQ(generatedSample.size(), sampleLength); ASSERT_TRUE(std::ranges::all_of( - sample, [](char sampleCharacter) + generatedSample, [](char sampleCharacter) { return static_cast(sampleCharacter) >= 33 && static_cast(sampleCharacter) <= 125; })); - auto count_4 = std::ranges::count(sample, '4'); - auto count_5 = std::ranges::count(sample, '5'); - auto count_a = std::ranges::count(sample, 'a'); - auto count_at = std::ranges::count(sample, '@'); + auto count_4 = std::ranges::count(generatedSample, '4'); + auto count_5 = std::ranges::count(generatedSample, '5'); + auto count_a = std::ranges::count(generatedSample, 'a'); + auto count_at = std::ranges::count(generatedSample, '@'); ASSERT_TRUE(count_4 <= 1); ASSERT_TRUE(count_5 <= 2); @@ -211,17 +212,17 @@ TEST_F(StringTest, shouldGenerateSampleStringWithGuarantee3) for (int i = 0; i < runCount; ++i) { auto copyGuarantee = guarantee; - const auto sample = String::sample(std::move(copyGuarantee), sampleLength); + const auto generatedSample = sample(std::move(copyGuarantee), sampleLength); - ASSERT_EQ(sample.size(), sampleLength); + ASSERT_EQ(generatedSample.size(), sampleLength); ASSERT_TRUE(std::ranges::all_of( - sample, [](char sampleCharacter) + generatedSample, [](char sampleCharacter) { return static_cast(sampleCharacter) >= 33 && static_cast(sampleCharacter) <= 125; })); - auto count_leftBracket = std::ranges::count(sample, '('); - auto count_leftBrace = std::ranges::count(sample, '{'); - auto count_backSlash = std::ranges::count(sample, '\\'); - auto count_forwardSlash = std::ranges::count(sample, '/'); + auto count_leftBracket = std::ranges::count(generatedSample, '('); + auto count_leftBrace = std::ranges::count(generatedSample, '{'); + auto count_backSlash = std::ranges::count(generatedSample, '\\'); + auto count_forwardSlash = std::ranges::count(generatedSample, '/'); ASSERT_TRUE(count_leftBracket <= 4); ASSERT_TRUE(count_leftBrace <= 2); @@ -236,7 +237,7 @@ TEST_F(StringTest, invalidGuaranteeForSample1) // atleast 5 '3' - 6 ':' - 10 'A' // invalid // string will be atleast 21 which is wrong // atmost 6 '3' GuaranteeMap guarantee = {{'3', {5, 6}}, {':', {6}}, {'A', {10}}}; - ASSERT_THROW(String::sample(std::move(guarantee), sampleLength), std::invalid_argument); + ASSERT_THROW(sample(std::move(guarantee), sampleLength), std::invalid_argument); } TEST_F(StringTest, invalidGuaranteeForSample2) @@ -244,17 +245,17 @@ TEST_F(StringTest, invalidGuaranteeForSample2) const auto sampleLength{20}; // exactly 2 '~' // invalid // not in char set GuaranteeMap guarantee = {{'a', {3}}, {'A', {10}}, {'~', {2, 2}}}; - ASSERT_THROW(String::sample(std::move(guarantee), sampleLength), std::invalid_argument); + ASSERT_THROW(sample(std::move(guarantee), sampleLength), std::invalid_argument); } TEST_F(StringTest, shouldGenerateDefaultStringFromCharaters) { const std::string characters{"abc"}; - const auto fromCharacters = String::fromCharacters(characters); + const auto generatedFromCharacters = fromCharacters(characters); - ASSERT_EQ(fromCharacters.size(), 1); - ASSERT_TRUE(std::ranges::all_of(fromCharacters, [&characters](char sampleCharacter) + ASSERT_EQ(generatedFromCharacters.size(), 1); + ASSERT_TRUE(std::ranges::all_of(generatedFromCharacters, [&characters](char sampleCharacter) { return characters.find(sampleCharacter) != std::string::npos; })); } @@ -262,10 +263,10 @@ TEST_F(StringTest, shouldGenerateStringFromCharaters) { const std::string characters{"iosjdaijqw"}; - const auto fromCharacters = String::fromCharacters(characters, 6); + const auto generatedFromCharacters = fromCharacters(characters, 6); - ASSERT_EQ(fromCharacters.size(), 6); - ASSERT_TRUE(std::ranges::all_of(fromCharacters, [&characters](char sampleCharacter) + ASSERT_EQ(generatedFromCharacters.size(), 6); + ASSERT_TRUE(std::ranges::all_of(generatedFromCharacters, [&characters](char sampleCharacter) { return characters.find(sampleCharacter) != std::string::npos; })); } @@ -280,15 +281,15 @@ TEST_F(StringTest, shouldGenerateStringFromCharatersWithGuarantee1) for (int i = 0; i < runCount; ++i) { auto copyGuarantee = guarantee; - const auto fromCharacters = String::fromCharacters(std::move(copyGuarantee), characters, 6); + const auto generatedFromCharacters = fromCharacters(std::move(copyGuarantee), characters, 6); - ASSERT_EQ(fromCharacters.size(), 6); - ASSERT_TRUE(std::ranges::all_of(fromCharacters, [&characters](char sampleCharacter) + ASSERT_EQ(generatedFromCharacters.size(), 6); + ASSERT_TRUE(std::ranges::all_of(generatedFromCharacters, [&characters](char sampleCharacter) { return characters.find(sampleCharacter) != std::string::npos; })); - auto count_s = std::ranges::count(fromCharacters, 's'); - auto count_w = std::ranges::count(fromCharacters, 'w'); - auto count_a = std::ranges::count(fromCharacters, 'a'); + auto count_s = std::ranges::count(generatedFromCharacters, 's'); + auto count_w = std::ranges::count(generatedFromCharacters, 'w'); + auto count_a = std::ranges::count(generatedFromCharacters, 'a'); ASSERT_TRUE(count_s == 1); ASSERT_TRUE(count_w >= 2); @@ -308,16 +309,16 @@ TEST_F(StringTest, shouldGenerateStringFromCharatersWithGuarantee2) for (int i = 0; i < runCount; ++i) { auto copyGuarantee = guarantee; - const auto fromCharacters = String::fromCharacters(std::move(copyGuarantee), characters, fromCharactersLength); + const auto generatedFromCharacters = fromCharacters(std::move(copyGuarantee), characters, fromCharactersLength); - ASSERT_EQ(fromCharacters.size(), fromCharactersLength); - ASSERT_TRUE(std::ranges::all_of(fromCharacters, [&characters](char sampleCharacter) + ASSERT_EQ(generatedFromCharacters.size(), fromCharactersLength); + ASSERT_TRUE(std::ranges::all_of(generatedFromCharacters, [&characters](char sampleCharacter) { return characters.find(sampleCharacter) != std::string::npos; })); - auto count_underscore = std::ranges::count(fromCharacters, '_'); - auto count_hash = std::ranges::count(fromCharacters, '#'); - auto count_8 = std::ranges::count(fromCharacters, '8'); - auto count_equal = std::ranges::count(fromCharacters, '='); + auto count_underscore = std::ranges::count(generatedFromCharacters, '_'); + auto count_hash = std::ranges::count(generatedFromCharacters, '#'); + auto count_8 = std::ranges::count(generatedFromCharacters, '8'); + auto count_equal = std::ranges::count(generatedFromCharacters, '='); ASSERT_TRUE(count_underscore >= 3); ASSERT_TRUE(count_hash == 5); @@ -337,15 +338,15 @@ TEST_F(StringTest, shouldGenerateStringFromCharatersWithGuarantee3) for (int i = 0; i < runCount; ++i) { auto copyGuarantee = guarantee; - const auto fromCharacters = String::fromCharacters(std::move(copyGuarantee), characters, fromCharactersLength); + const auto generatedFromCharacters = fromCharacters(std::move(copyGuarantee), characters, fromCharactersLength); - ASSERT_EQ(fromCharacters.size(), fromCharactersLength); - ASSERT_TRUE(std::ranges::all_of(fromCharacters, [&characters](char sampleCharacter) + ASSERT_EQ(generatedFromCharacters.size(), fromCharactersLength); + ASSERT_TRUE(std::ranges::all_of(generatedFromCharacters, [&characters](char sampleCharacter) { return characters.find(sampleCharacter) != std::string::npos; })); - auto count_B = std::ranges::count(fromCharacters, 'B'); - auto count_asterisk = std::ranges::count(fromCharacters, '*'); - auto count_minus = std::ranges::count(fromCharacters, '-'); + auto count_B = std::ranges::count(generatedFromCharacters, 'B'); + auto count_asterisk = std::ranges::count(generatedFromCharacters, '*'); + auto count_minus = std::ranges::count(generatedFromCharacters, '-'); ASSERT_TRUE(count_B == 10); ASSERT_TRUE(count_asterisk == 1); @@ -360,7 +361,7 @@ TEST_F(StringTest, invalidGuaranteeForFromCharacters1) // atleast 10 '&' - 5 '*' - 5 'm' - 1 'b' // invalid // string size will be atleast 21 which is invalid // atmost 10 'b' GuaranteeMap guarantee{{'&', {10}}, {'*', {5}}, {'m', {5}}, {'b', {1, 10}}}; - ASSERT_THROW(String::fromCharacters(std::move(guarantee), characters, fromCharactersLength), std::invalid_argument); + ASSERT_THROW(fromCharacters(std::move(guarantee), characters, fromCharactersLength), std::invalid_argument); } TEST_F(StringTest, invalidGuaranteeForFromCharacters2) @@ -370,7 +371,7 @@ TEST_F(StringTest, invalidGuaranteeForFromCharacters2) // atleast 6 '1' // atmost 3 'a' - 5 'b' - 8 '1' // invalid // string size wont exceed 16 which is invalid GuaranteeMap guarantee{{'a', {0, 3}}, {'b', {0, 5}}, {'1', {6, 8}}}; - ASSERT_THROW(String::fromCharacters(std::move(guarantee), characters, fromCharactersLength), std::invalid_argument); + ASSERT_THROW(fromCharacters(std::move(guarantee), characters, fromCharactersLength), std::invalid_argument); } TEST_F(StringTest, invalidGuaranteeForFromCharacters3) @@ -379,26 +380,26 @@ TEST_F(StringTest, invalidGuaranteeForFromCharacters3) const std::string characters{"67bnmM"}; // exactly 2 '1' // invalid // '1' not in `characters` GuaranteeMap guarantee{{'1', {2, 2}}, {'M', {2, 2}}, {'m', {2, 2}}}; - ASSERT_THROW(String::fromCharacters(std::move(guarantee), characters, fromCharactersLength), std::invalid_argument); + ASSERT_THROW(fromCharacters(std::move(guarantee), characters, fromCharactersLength), std::invalid_argument); } TEST_F(StringTest, shouldGenerateDefaultApha) { - const auto alpha = String::alpha(); + const auto generatedAlpha = alpha(); - ASSERT_EQ(alpha.size(), 1); + ASSERT_EQ(generatedAlpha.size(), 1); ASSERT_TRUE( - std::ranges::any_of(mixedAlphaCharacters, [alpha](char mixedCharacter) { return alpha[0] == mixedCharacter; })); + std::ranges::any_of(mixedAlphaCharacters, [generatedAlpha](char mixedCharacter) { return generatedAlpha[0] == mixedCharacter; })); } TEST_F(StringTest, shouldGenerateMixedAlpha) { const auto alphaLength = 10; - const auto alpha = String::alpha(alphaLength); + const auto generatedAlpha = alpha(alphaLength); - ASSERT_EQ(alpha.size(), alphaLength); - ASSERT_TRUE(std::ranges::all_of(alpha, + ASSERT_EQ(generatedAlpha.size(), alphaLength); + ASSERT_TRUE(std::ranges::all_of(generatedAlpha, [](char alphaCharacter) { return std::ranges::any_of(mixedAlphaCharacters, @@ -411,10 +412,10 @@ TEST_F(StringTest, shouldGenerateUpperAlpha) { const auto alphaLength = 15; - const auto alpha = String::alpha(alphaLength, StringCasing::Upper); + const auto generatedAlpha = alpha(alphaLength, StringCasing::Upper); - ASSERT_EQ(alpha.size(), alphaLength); - ASSERT_TRUE(std::ranges::all_of(alpha, + ASSERT_EQ(generatedAlpha.size(), alphaLength); + ASSERT_TRUE(std::ranges::all_of(generatedAlpha, [](char alphaCharacter) { return std::ranges::any_of(upperCharacters, @@ -427,10 +428,10 @@ TEST_F(StringTest, shouldGenerateLowerAlpha) { const auto alphaLength = 7; - const auto alpha = String::alpha(alphaLength, StringCasing::Lower); + const auto generatedAlpha = alpha(alphaLength, StringCasing::Lower); - ASSERT_EQ(alpha.size(), alphaLength); - ASSERT_TRUE(std::ranges::all_of(alpha, + ASSERT_EQ(generatedAlpha.size(), alphaLength); + ASSERT_TRUE(std::ranges::all_of(generatedAlpha, [](char alphaCharacter) { return std::ranges::any_of(lowerCharacters, @@ -450,20 +451,20 @@ TEST_F(StringTest, shouldGenerateMixedAlphaWithGuarantee) for (int i = 0; i < runCount; ++i) { auto copyGuarantee = guarantee; - const auto alpha = String::alpha(std::move(copyGuarantee), alphaLength); + const auto generatedAlpha = alpha(std::move(copyGuarantee), alphaLength); - ASSERT_EQ(alpha.size(), alphaLength); - ASSERT_TRUE(std::ranges::all_of(alpha, + ASSERT_EQ(generatedAlpha.size(), alphaLength); + ASSERT_TRUE(std::ranges::all_of(generatedAlpha, [](char alphaCharacter) { return std::ranges::any_of(mixedAlphaCharacters, [alphaCharacter](char mixedCharacter) { return mixedCharacter == alphaCharacter; }); })); - auto count_A = std::ranges::count(alpha, 'A'); - auto count_B = std::ranges::count(alpha, 'B'); - auto count_a = std::ranges::count(alpha, 'a'); - auto count_z = std::ranges::count(alpha, 'z'); + auto count_A = std::ranges::count(generatedAlpha, 'A'); + auto count_B = std::ranges::count(generatedAlpha, 'B'); + auto count_a = std::ranges::count(generatedAlpha, 'a'); + auto count_z = std::ranges::count(generatedAlpha, 'z'); ASSERT_TRUE(count_A >= 5 && count_A <= 20); ASSERT_TRUE(count_B >= 3 && count_B <= 20); @@ -483,20 +484,20 @@ TEST_F(StringTest, shouldGenerateLowerAlphaWithGuarantee) for (int i = 0; i < runCount; ++i) { auto copyGuarantee = guarantee; - const auto alpha = String::alpha(std::move(copyGuarantee), alphaLength, StringCasing::Lower); + const auto generatedAlpha = alpha(std::move(copyGuarantee), alphaLength, StringCasing::Lower); - ASSERT_EQ(alpha.size(), alphaLength); - ASSERT_TRUE(std::ranges::all_of(alpha, + ASSERT_EQ(generatedAlpha.size(), alphaLength); + ASSERT_TRUE(std::ranges::all_of(generatedAlpha, [](char alphaCharacter) { return std::ranges::any_of(lowerCharSet, [alphaCharacter](char lowerCharacter) { return lowerCharacter == alphaCharacter; }); })); - auto count_k = std::ranges::count(alpha, 'k'); - auto count_o = std::ranges::count(alpha, 'o'); - auto count_a = std::ranges::count(alpha, 'a'); - auto count_z = std::ranges::count(alpha, 'z'); + auto count_k = std::ranges::count(generatedAlpha, 'k'); + auto count_o = std::ranges::count(generatedAlpha, 'o'); + auto count_a = std::ranges::count(generatedAlpha, 'a'); + auto count_z = std::ranges::count(generatedAlpha, 'z'); ASSERT_TRUE(count_k >= 5 && count_k <= 20); ASSERT_TRUE(count_o >= 3 && count_o <= 20); @@ -516,20 +517,20 @@ TEST_F(StringTest, shouldGenerateUpperAlphaWithGuarantee) for (int i = 0; i < runCount; ++i) { auto copyGuarantee = guarantee; - const auto alpha = String::alpha(std::move(copyGuarantee), alphaLength, StringCasing::Upper); + const auto generatedAlpha = alpha(std::move(copyGuarantee), alphaLength, StringCasing::Upper); - ASSERT_EQ(alpha.size(), alphaLength); - ASSERT_TRUE(std::ranges::all_of(alpha, + ASSERT_EQ(generatedAlpha.size(), alphaLength); + ASSERT_TRUE(std::ranges::all_of(generatedAlpha, [](char alphaCharacter) { return std::ranges::any_of(upperCharSet, [alphaCharacter](char lowerCharacter) { return lowerCharacter == alphaCharacter; }); })); - auto count_K = std::ranges::count(alpha, 'K'); - auto count_O = std::ranges::count(alpha, 'O'); - auto count_A = std::ranges::count(alpha, 'A'); - auto count_Z = std::ranges::count(alpha, 'Z'); + auto count_K = std::ranges::count(generatedAlpha, 'K'); + auto count_O = std::ranges::count(generatedAlpha, 'O'); + auto count_A = std::ranges::count(generatedAlpha, 'A'); + auto count_Z = std::ranges::count(generatedAlpha, 'Z'); ASSERT_TRUE(count_K >= 5 && count_K <= 20); ASSERT_TRUE(count_O >= 3 && count_O <= 20); @@ -545,7 +546,7 @@ TEST_F(StringTest, invalidGuaranteeForAlpha1) // atleast 8 'A' - 10 'B' 1 'Y' // invalid // string size will be atleast 22 which is invalid // atmost 10 'A','Y' - 15 'B' GuaranteeMap guarantee = {{'A', {8, 10}}, {'B', {10, 15}}, {'Y', {1, 10}}, {'Z', {3, 3}}}; - ASSERT_THROW(String::alpha(std::move(guarantee), alphaLength), std::invalid_argument); + ASSERT_THROW(alpha(std::move(guarantee), alphaLength), std::invalid_argument); } TEST_F(StringTest, invalidGuaranteeForAlpha2) @@ -560,7 +561,7 @@ TEST_F(StringTest, invalidGuaranteeForAlpha2) {'O', {0, 1}}, {'P', {0, 1}}, {'Q', {0, 1}}, {'R', {0, 1}}, {'S', {0, 1}}, {'T', {0, 1}}, {'U', {0, 1}}, {'V', {0, 1}}, {'W', {0, 1}}, {'X', {0, 1}}, {'Y', {0, 1}}, {'Z', {0, 1}}, }; - ASSERT_THROW(String::alpha(std::move(guarantee), alphaLength, StringCasing::Upper), std::invalid_argument); + ASSERT_THROW(alpha(std::move(guarantee), alphaLength, StringCasing::Upper), std::invalid_argument); } TEST_F(StringTest, invalidGuaranteeForAlpha3) @@ -568,7 +569,7 @@ TEST_F(StringTest, invalidGuaranteeForAlpha3) const auto alphaLength = 20; // atleast 4 '5' // invalid // alpha can't have digits GuaranteeMap guarantee = {{'a', {4, 10}}, {'B', {4, 10}}, {'5', {4, 6}}}; - ASSERT_THROW(String::alpha(std::move(guarantee), alphaLength), std::invalid_argument); + ASSERT_THROW(alpha(std::move(guarantee), alphaLength), std::invalid_argument); } TEST_F(StringTest, invalidGuaranteeForAlpha4) @@ -576,7 +577,7 @@ TEST_F(StringTest, invalidGuaranteeForAlpha4) const auto alphaLength = 20; // atleast 4 'a' // invalid // Can't have lower case characters when string casing is set to StringCasing::Upper GuaranteeMap guarantee = {{'a', {4, 10}}, {'B', {4, 10}}}; - ASSERT_THROW(String::alpha(std::move(guarantee), alphaLength, StringCasing::Upper), std::invalid_argument); + ASSERT_THROW(alpha(std::move(guarantee), alphaLength, StringCasing::Upper), std::invalid_argument); } TEST_F(StringTest, invalidGuaranteeForAlpha5) @@ -584,26 +585,26 @@ TEST_F(StringTest, invalidGuaranteeForAlpha5) const auto alphaLength = 20; // atleast 4 'B' // invalid // Can't have upper case characters when string casing is set to StringCasing::Lower GuaranteeMap guarantee = {{'a', {4, 10}}, {'B', {4, 10}}}; - ASSERT_THROW(String::alpha(std::move(guarantee), alphaLength, StringCasing::Lower), std::invalid_argument); + ASSERT_THROW(alpha(std::move(guarantee), alphaLength, StringCasing::Lower), std::invalid_argument); } TEST_F(StringTest, shouldGenerateDefaultAphanumeric) { - const auto alphanumeric = String::alphanumeric(); + const auto generatedAlphanumeric = alphanumeric(); - ASSERT_EQ(alphanumeric.size(), 1); + ASSERT_EQ(generatedAlphanumeric.size(), 1); ASSERT_TRUE(std::ranges::any_of(mixedAlphanumericCharacters, - [alphanumeric](char mixedCharacter) { return alphanumeric[0] == mixedCharacter; })); + [generatedAlphanumeric](char mixedCharacter) { return generatedAlphanumeric[0] == mixedCharacter; })); } TEST_F(StringTest, shouldGenerateMixedAlphanumeric) { const auto alphanumericLength = 10; - const auto alphanumeric = String::alphanumeric(alphanumericLength); + const auto generatedAlphanumeric = alphanumeric(alphanumericLength); - ASSERT_EQ(alphanumeric.size(), alphanumericLength); - ASSERT_TRUE(std::ranges::all_of(alphanumeric, + ASSERT_EQ(generatedAlphanumeric.size(), alphanumericLength); + ASSERT_TRUE(std::ranges::all_of(generatedAlphanumeric, [](char alphanumericCharacter) { return std::ranges::any_of( @@ -617,10 +618,10 @@ TEST_F(StringTest, shouldGenerateUpperAlphanumeric) { const auto alphanumericLength = 15; - const auto alphanumeric = String::alphanumeric(alphanumericLength, StringCasing::Upper); + const auto generatedAlphanumeric = alphanumeric(alphanumericLength, StringCasing::Upper); - ASSERT_EQ(alphanumeric.size(), alphanumericLength); - ASSERT_TRUE(std::ranges::all_of(alphanumeric, + ASSERT_EQ(generatedAlphanumeric.size(), alphanumericLength); + ASSERT_TRUE(std::ranges::all_of(generatedAlphanumeric, [](char alphanumericCharacter) { return std::ranges::any_of( @@ -634,10 +635,10 @@ TEST_F(StringTest, shouldGenerateLowerAlphanumeric) { const auto alphanumericLength = 7; - const auto alphanumeric = String::alphanumeric(alphanumericLength, StringCasing::Lower); + const auto generatedAlphanumeric = alphanumeric(alphanumericLength, StringCasing::Lower); - ASSERT_EQ(alphanumeric.size(), alphanumericLength); - ASSERT_TRUE(std::ranges::all_of(alphanumeric, + ASSERT_EQ(generatedAlphanumeric.size(), alphanumericLength); + ASSERT_TRUE(std::ranges::all_of(generatedAlphanumeric, [](char alphanumericCharacter) { return std::ranges::any_of( @@ -658,20 +659,20 @@ TEST_F(StringTest, shouldGenerateMixedAlphanumericWithGuarantee) for (int i = 0; i < runCount; ++i) { auto copyGuarantee = guarantee; - const auto alphanumeric = String::alphanumeric(std::move(copyGuarantee), alphanumericLength); + const auto generatedAlphanumeric = alphanumeric(std::move(copyGuarantee), alphanumericLength); - ASSERT_EQ(alphanumeric.size(), alphanumericLength); + ASSERT_EQ(generatedAlphanumeric.size(), alphanumericLength); ASSERT_TRUE(std::ranges::all_of( - alphanumeric, + generatedAlphanumeric, [](char alphanumericCharacter) { return std::ranges::any_of(mixedAlphanumericCharacters, [alphanumericCharacter](char mixedCharacter) { return mixedCharacter == alphanumericCharacter; }); })); - auto count_1 = std::ranges::count(alphanumeric, '1'); - auto count_B = std::ranges::count(alphanumeric, 'B'); - auto count_a = std::ranges::count(alphanumeric, 'a'); - auto count_z = std::ranges::count(alphanumeric, 'z'); + auto count_1 = std::ranges::count(generatedAlphanumeric, '1'); + auto count_B = std::ranges::count(generatedAlphanumeric, 'B'); + auto count_a = std::ranges::count(generatedAlphanumeric, 'a'); + auto count_z = std::ranges::count(generatedAlphanumeric, 'z'); ASSERT_TRUE(count_1 >= 5 && count_1 <= 20); ASSERT_TRUE(count_B >= 3 && count_B <= 20); @@ -691,21 +692,21 @@ TEST_F(StringTest, shouldGenerateLowerAlphanumericWithGuarantee) for (int i = 0; i < runCount; ++i) { auto copyGuarantee = guarantee; - const auto alphanumeric = - String::alphanumeric(std::move(copyGuarantee), alphanumericLength, StringCasing::Lower); + const auto generatedAlphanumeric = + alphanumeric(std::move(copyGuarantee), alphanumericLength, StringCasing::Lower); - ASSERT_EQ(alphanumeric.size(), alphanumericLength); + ASSERT_EQ(generatedAlphanumeric.size(), alphanumericLength); ASSERT_TRUE(std::ranges::all_of( - alphanumeric, + generatedAlphanumeric, [](char alphanumericCharacter) { return std::ranges::any_of(lowerAlphanumericCharacters, [alphanumericCharacter](char lowerCharacter) { return lowerCharacter == alphanumericCharacter; }); })); - auto count_k = std::ranges::count(alphanumeric, 'k'); - auto count_o = std::ranges::count(alphanumeric, 'o'); - auto count_a = std::ranges::count(alphanumeric, 'a'); - auto count_0 = std::ranges::count(alphanumeric, '0'); + auto count_k = std::ranges::count(generatedAlphanumeric, 'k'); + auto count_o = std::ranges::count(generatedAlphanumeric, 'o'); + auto count_a = std::ranges::count(generatedAlphanumeric, 'a'); + auto count_0 = std::ranges::count(generatedAlphanumeric, '0'); ASSERT_TRUE(count_k >= 5 && count_k <= 20); ASSERT_TRUE(count_o >= 3 && count_o <= 20); @@ -725,21 +726,21 @@ TEST_F(StringTest, shouldGenerateUpperAlphanumericWithGuarantee) for (int i = 0; i < runCount; ++i) { auto copyGuarantee = guarantee; - const auto alphanumeric = - String::alphanumeric(std::move(copyGuarantee), alphanumericLength, StringCasing::Upper); + const auto generatedAlphanumeric = + alphanumeric(std::move(copyGuarantee), alphanumericLength, StringCasing::Upper); - ASSERT_EQ(alphanumeric.size(), alphanumericLength); + ASSERT_EQ(generatedAlphanumeric.size(), alphanumericLength); ASSERT_TRUE(std::ranges::all_of( - alphanumeric, + generatedAlphanumeric, [](char alphanumericCharacter) { return std::ranges::any_of(upperAlphanumericCharacters, [alphanumericCharacter](char lowerCharacter) { return lowerCharacter == alphanumericCharacter; }); })); - auto count_7 = std::ranges::count(alphanumeric, '7'); - auto count_O = std::ranges::count(alphanumeric, 'O'); - auto count_A = std::ranges::count(alphanumeric, 'A'); - auto count_Z = std::ranges::count(alphanumeric, 'Z'); + auto count_7 = std::ranges::count(generatedAlphanumeric, '7'); + auto count_O = std::ranges::count(generatedAlphanumeric, 'O'); + auto count_A = std::ranges::count(generatedAlphanumeric, 'A'); + auto count_Z = std::ranges::count(generatedAlphanumeric, 'Z'); ASSERT_TRUE(count_7 >= 5 && count_7 <= 20); ASSERT_TRUE(count_O >= 3 && count_O <= 20); @@ -755,7 +756,7 @@ TEST_F(StringTest, invalidGuaranteeForAlphanumeric1) // atleast 8 'A' - 10 'b' 1 'Y' // invalid // string size will be atleast 22 which is invalid // atmost 10 'A','Y' - 15 'b' GuaranteeMap guarantee = {{'A', {8, 10}}, {'b', {10, 15}}, {'Y', {1, 10}}, {'8', {3, 3}}}; - ASSERT_THROW(String::alphanumeric(std::move(guarantee), alphanumericLength), std::invalid_argument); + ASSERT_THROW(alphanumeric(std::move(guarantee), alphanumericLength), std::invalid_argument); } TEST_F(StringTest, invalidGuaranteeForAlphanumeric2) @@ -773,7 +774,7 @@ TEST_F(StringTest, invalidGuaranteeForAlphanumeric2) {'Y', {0, 1}}, {'Z', {0, 1}}, {'0', {0, 1}}, {'1', {0, 1}}, {'2', {0, 1}}, {'3', {0, 1}}, {'4', {0, 1}}, {'5', {0, 1}}, {'6', {0, 1}}, {'7', {0, 1}}, {'8', {0, 1}}, {'9', {0, 1}}, }; - ASSERT_THROW(String::alphanumeric(std::move(guarantee), alphanumericLength, StringCasing::Upper), + ASSERT_THROW(alphanumeric(std::move(guarantee), alphanumericLength, StringCasing::Upper), std::invalid_argument); } @@ -782,7 +783,7 @@ TEST_F(StringTest, invalidGuaranteeForAlphanumeric3) const auto alphanumericLength = 20; // atleast 4 '#' // invalid // alphanumeric can't have symbols GuaranteeMap guarantee = {{'a', {4, 10}}, {'B', {4, 10}}, {'5', {4, 6}}, {'#', {4}}}; - ASSERT_THROW(String::alphanumeric(std::move(guarantee), alphanumericLength), std::invalid_argument); + ASSERT_THROW(alphanumeric(std::move(guarantee), alphanumericLength), std::invalid_argument); } TEST_F(StringTest, invalidGuaranteeForAlphanumeric4) @@ -790,7 +791,7 @@ TEST_F(StringTest, invalidGuaranteeForAlphanumeric4) const auto alphanumericLength = 20; // atleast 4 'a' // invalid // Can't have lower case characters when string casing is set to StringCasing::Upper GuaranteeMap guarantee = {{'a', {4, 10}}, {'B', {4, 10}}, {'2', {1}}}; - ASSERT_THROW(String::alphanumeric(std::move(guarantee), alphanumericLength, StringCasing::Upper), + ASSERT_THROW(alphanumeric(std::move(guarantee), alphanumericLength, StringCasing::Upper), std::invalid_argument); } @@ -799,29 +800,29 @@ TEST_F(StringTest, invalidGuaranteeForAlphanumeric5) const auto alphanumericLength = 20; // atleast 4 'B' // invalid // Can't have upper case characters when string casing is set to StringCasing::Lower GuaranteeMap guarantee = {{'a', {4, 10}}, {'B', {4, 10}}, {'8', {8, 10}}}; - ASSERT_THROW(String::alphanumeric(std::move(guarantee), alphanumericLength, StringCasing::Lower), + ASSERT_THROW(alphanumeric(std::move(guarantee), alphanumericLength, StringCasing::Lower), std::invalid_argument); } TEST_F(StringTest, shouldGenerateNumeric) { - const auto numeric = String::numeric(); + const auto generatedNumeric = numeric(); - ASSERT_EQ(numeric.size(), 1); + ASSERT_EQ(generatedNumeric.size(), 1); ASSERT_TRUE( - std::ranges::any_of(numeric, [numeric](char numericCharacter) { return numeric[0] == numericCharacter; })); + std::ranges::any_of(generatedNumeric, [generatedNumeric](char numericCharacter) { return generatedNumeric[0] == numericCharacter; })); } TEST_F(StringTest, shouldGenerateNumericWithoutLeadingZeros) { const auto numericLength = 13; - const auto numeric = String::numeric(numericLength, false); + const auto generatedNumeric = numeric(numericLength, false); - const auto nonZeroCharacter = numeric[0]; - const auto numericWithPossibleZeroCharacters = numeric.substr(1); + const auto nonZeroCharacter = generatedNumeric[0]; + const auto numericWithPossibleZeroCharacters = generatedNumeric.substr(1); - ASSERT_EQ(numeric.size(), numericLength); + ASSERT_EQ(generatedNumeric.size(), numericLength); ASSERT_TRUE(std::ranges::any_of(numericCharactersWithoutZero, [nonZeroCharacter](char numericCharacter) { return nonZeroCharacter == numericCharacter; })); ASSERT_TRUE(std::ranges::all_of(numericWithPossibleZeroCharacters, @@ -843,14 +844,14 @@ TEST_F(StringTest, shouldGenerateNumericWithGuarantee1) for (int i = 0; i < runCount; ++i) { auto copyGuarantee = guarantee; - const auto numeric = String::numeric(std::move(copyGuarantee), numericLength); + const auto generatedNumeric = numeric(std::move(copyGuarantee), numericLength); - ASSERT_EQ(numeric.size(), numericLength); + ASSERT_EQ(generatedNumeric.size(), numericLength); ASSERT_TRUE( - std::ranges::any_of(numeric, [numeric](char numericCharacter) { return numeric[0] == numericCharacter; })); + std::ranges::any_of(generatedNumeric, [generatedNumeric](char numericCharacter) { return generatedNumeric[0] == numericCharacter; })); - auto count_0 = std::ranges::count(numeric, '0'); - auto count_9 = std::ranges::count(numeric, '9'); + auto count_0 = std::ranges::count(generatedNumeric, '0'); + auto count_9 = std::ranges::count(generatedNumeric, '9'); ASSERT_TRUE(count_0 >= 10 && count_0 <= 15); ASSERT_TRUE(count_9 >= 5 && count_9 <= 10); @@ -868,16 +869,16 @@ TEST_F(StringTest, shouldGenerateNumericWithGuarantee2) for (int i = 0; i < runCount; ++i) { auto copyGuarantee = guarantee; - const auto numeric = String::numeric(std::move(copyGuarantee), numericLength); + const auto generatedNumeric = numeric(std::move(copyGuarantee), numericLength); - ASSERT_EQ(numeric.size(), numericLength); + ASSERT_EQ(generatedNumeric.size(), numericLength); ASSERT_TRUE( - std::ranges::any_of(numeric, [numeric](char numericCharacter) { return numeric[0] == numericCharacter; })); + std::ranges::any_of(generatedNumeric, [generatedNumeric](char numericCharacter) { return generatedNumeric[0] == numericCharacter; })); - auto count_1 = std::ranges::count(numeric, '1'); - auto count_2 = std::ranges::count(numeric, '2'); - auto count_8 = std::ranges::count(numeric, '8'); - auto count_9 = std::ranges::count(numeric, '9'); + auto count_1 = std::ranges::count(generatedNumeric, '1'); + auto count_2 = std::ranges::count(generatedNumeric, '2'); + auto count_8 = std::ranges::count(generatedNumeric, '8'); + auto count_9 = std::ranges::count(generatedNumeric, '9'); ASSERT_TRUE(count_1 == 0); ASSERT_TRUE(count_2 >= 5 && count_2 <= 20); @@ -895,12 +896,12 @@ TEST_F(StringTest, shouldGenerateNumericWithoutLeadingZerosWithGuarantee1) for (int i = 0; i < runCount; ++i) { auto copyGuarantee = guarantee; - const auto numeric = String::numeric(std::move(copyGuarantee), numericLength, false); + const auto generatedNumeric = numeric(std::move(copyGuarantee), numericLength, false); - const auto nonZeroCharacter = numeric[0]; - const auto numericWithPossibleZeroCharacters = numeric.substr(1); + const auto nonZeroCharacter = generatedNumeric[0]; + const auto numericWithPossibleZeroCharacters = generatedNumeric.substr(1); - ASSERT_EQ(numeric.size(), numericLength); + ASSERT_EQ(generatedNumeric.size(), numericLength); ASSERT_TRUE(std::ranges::any_of(numericCharactersWithoutZero, [nonZeroCharacter](char numericCharacter) { return nonZeroCharacter == numericCharacter; })); ASSERT_TRUE(std::ranges::all_of( @@ -910,7 +911,7 @@ TEST_F(StringTest, shouldGenerateNumericWithoutLeadingZerosWithGuarantee1) return std::ranges::any_of(numericCharacters, [numericCharacterWithPossibleZero](char numericCharacter) { return numericCharacterWithPossibleZero == numericCharacter; }); })); - auto count_0 = std::ranges::count(numeric, '0'); + auto count_0 = std::ranges::count(generatedNumeric, '0'); ASSERT_TRUE(count_0 >= 19); } @@ -926,12 +927,12 @@ TEST_F(StringTest, shouldGenerateNumericWithoutLeadingZerosWithGuarantee2) for (int i = 0; i < runCount; ++i) { auto copyGuarantee = guarantee; - const auto numeric = String::numeric(std::move(copyGuarantee), numericLength, false); + const auto generatedNumeric = numeric(std::move(copyGuarantee), numericLength, false); - const auto nonZeroCharacter = numeric[0]; - const auto numericWithPossibleZeroCharacters = numeric.substr(1); + const auto nonZeroCharacter = generatedNumeric[0]; + const auto numericWithPossibleZeroCharacters = generatedNumeric.substr(1); - ASSERT_EQ(numeric.size(), numericLength); + ASSERT_EQ(generatedNumeric.size(), numericLength); ASSERT_TRUE(std::ranges::any_of(numericCharactersWithoutZero, [nonZeroCharacter](char numericCharacter) { return nonZeroCharacter == numericCharacter; })); ASSERT_TRUE(std::ranges::all_of( @@ -941,9 +942,9 @@ TEST_F(StringTest, shouldGenerateNumericWithoutLeadingZerosWithGuarantee2) return std::ranges::any_of(numericCharacters, [numericCharacterWithPossibleZero](char numericCharacter) { return numericCharacterWithPossibleZero == numericCharacter; }); })); - auto count_0 = std::ranges::count(numeric, '0'); - auto count_1 = std::ranges::count(numeric, '1'); - auto count_3 = std::ranges::count(numeric, '3'); + auto count_0 = std::ranges::count(generatedNumeric, '0'); + auto count_1 = std::ranges::count(generatedNumeric, '1'); + auto count_3 = std::ranges::count(generatedNumeric, '3'); ASSERT_TRUE(count_0 >= 10); ASSERT_TRUE(count_1 >= 3 && count_1 <= 4); @@ -957,7 +958,7 @@ TEST_F(StringTest, invalidGuaranteeForNumeric1) // atleast 10 '0' - 3 '1' - 8 '3' // invalid // string size will be atleast 21 which is wrong // atmost 4 '1' - 10 '3' GuaranteeMap guarantee = {{'0', {10}}, {'1', {3, 4}}, {'3', {8, 10}}}; - ASSERT_THROW(String::numeric(std::move(guarantee), numericLength), std::invalid_argument); + ASSERT_THROW(numeric(std::move(guarantee), numericLength), std::invalid_argument); } TEST_F(StringTest, invalidGuaranteeForNumeric2) @@ -968,7 +969,7 @@ TEST_F(StringTest, invalidGuaranteeForNumeric2) {'1', {0, 1}}, {'2', {0, 1}}, {'3', {0, 1}}, {'4', {0, 1}}, {'5', {0, 1}}, {'6', {0, 1}}, {'7', {0, 1}}, {'8', {0, 1}}, {'9', {0, 1}}, {'0', {0, 1}}, }; - ASSERT_THROW(String::numeric(std::move(guarantee), numericLength), std::invalid_argument); + ASSERT_THROW(numeric(std::move(guarantee), numericLength), std::invalid_argument); } TEST_F(StringTest, invalidGuaranteeForNumeric3) @@ -976,7 +977,7 @@ TEST_F(StringTest, invalidGuaranteeForNumeric3) const auto numericLength = 20; // exactly 5 'a' // invalid // numeric string can't have alphabets GuaranteeMap guarantee = {{'0', {10}}, {'1', {3, 4}}, {'3', {2, 4}}, {'a', {5, 5}}}; - ASSERT_THROW(String::numeric(std::move(guarantee), numericLength), std::invalid_argument); + ASSERT_THROW(numeric(std::move(guarantee), numericLength), std::invalid_argument); } TEST_F(StringTest, invalidGuaranteeForNumeric4) @@ -984,19 +985,19 @@ TEST_F(StringTest, invalidGuaranteeForNumeric4) const auto numericLength = 5; // atleast 5 '0' // invalid // leading zeros not allowed so '0' count should be less than numericLength i.e 5 GuaranteeMap guarantee = {{'0', {5}}}; - ASSERT_THROW(String::numeric(std::move(guarantee), numericLength, false), std::invalid_argument); + ASSERT_THROW(numeric(std::move(guarantee), numericLength, false), std::invalid_argument); } TEST_F(StringTest, shouldGenerateHexadecimal) { const auto hexadecimalLength = 8; - const auto hexadecimal = String::hexadecimal(hexadecimalLength); + const auto generatedHexadecimal = hexadecimal(hexadecimalLength); - const auto prefix = hexadecimal.substr(0, 2); - const auto hexNumber = hexadecimal.substr(2); + const auto prefix = generatedHexadecimal.substr(0, 2); + const auto hexNumber = generatedHexadecimal.substr(2); - ASSERT_EQ(hexadecimal.size(), hexadecimalLength + 2); + ASSERT_EQ(generatedHexadecimal.size(), hexadecimalLength + 2); ASSERT_EQ(prefix, "0x"); ASSERT_TRUE(std::ranges::any_of(hexNumber, [hexNumber](char hexNumberCharacter) { return hexLowerCharacters.find(hexNumberCharacter) != std::string::npos; })); @@ -1006,12 +1007,12 @@ TEST_F(StringTest, shouldGenerateHexadecimalWithHashPrefix) { const auto hexadecimalLength = 8; - const auto hexadecimal = String::hexadecimal(hexadecimalLength, HexCasing::Upper, HexPrefix::Hash); + const auto generatedHexadecimal = hexadecimal(hexadecimalLength, HexCasing::Upper, HexPrefix::Hash); - const auto prefix = hexadecimal.substr(0, 1); - const auto hexNumber = hexadecimal.substr(1); + const auto prefix = generatedHexadecimal.substr(0, 1); + const auto hexNumber = generatedHexadecimal.substr(1); - ASSERT_EQ(hexadecimal.size(), hexadecimalLength + 1); + ASSERT_EQ(generatedHexadecimal.size(), hexadecimalLength + 1); ASSERT_EQ(prefix, "#"); ASSERT_TRUE(std::ranges::any_of(hexNumber, [](char hexNumberCharacter) { return hexUpperCharacters.find(hexNumberCharacter) != std::string::npos; })); @@ -1021,10 +1022,10 @@ TEST_F(StringTest, shouldGenerateHexadecimalWithoutPrefix) { const auto hexadecimalLength = 8; - const auto hexadecimal = String::hexadecimal(hexadecimalLength, HexCasing::Upper, HexPrefix::None); + const auto generatedHexadecimal = hexadecimal(hexadecimalLength, HexCasing::Upper, HexPrefix::None); - ASSERT_EQ(hexadecimal.size(), hexadecimalLength); - ASSERT_TRUE(std::ranges::any_of(hexadecimal, [](char hexNumberCharacter) + ASSERT_EQ(generatedHexadecimal.size(), hexadecimalLength); + ASSERT_TRUE(std::ranges::any_of(generatedHexadecimal, [](char hexNumberCharacter) { return hexUpperCharacters.find(hexNumberCharacter) != std::string::npos; })); } @@ -1034,14 +1035,14 @@ TEST_F(StringTest, shouldGenerateHexadecimalWithGuarantee1) // exactly 4 'a' // atleast 3 'f' // atmost 10 'f' - faker::GuaranteeMap guarantee{{'a', {4, 4}}, {'f', {3, 10}}}; + GuaranteeMap guarantee{{'a', {4, 4}}, {'f', {3, 10}}}; // it is a random function so lets test for 20 random generations for (int i = 0; i < runCount; ++i) { auto copyGuarantee = guarantee; - const auto hexadecimal = String::hexadecimal(std::move(copyGuarantee), hexadecimalLength); - const auto prefix = hexadecimal.substr(0, 2); - const auto hexNumber = hexadecimal.substr(2); + const auto generatedHexadecimal = hexadecimal(std::move(copyGuarantee), hexadecimalLength); + const auto prefix = generatedHexadecimal.substr(0, 2); + const auto hexNumber = generatedHexadecimal.substr(2); ASSERT_EQ(hexNumber.size(), hexadecimalLength); ASSERT_EQ(prefix, "0x"); @@ -1060,14 +1061,14 @@ TEST_F(StringTest, shouldGenerateHexadecimalWithGuarantee2) const auto hexadecimalLength = 20; // exactly 10 'F' - 0 'A' // atleast 5 '0' - faker::GuaranteeMap guarantee{{'A', {0, 0}}, {'F', {10, 10}}, {'0', {5}}}; + GuaranteeMap guarantee{{'A', {0, 0}}, {'F', {10, 10}}, {'0', {5}}}; // it is a random function so lets test for 20 random generations for (int i = 0; i < runCount; ++i) { auto copyGuarantee = guarantee; - const auto hexadecimal = String::hexadecimal(std::move(copyGuarantee), hexadecimalLength, HexCasing::Upper); - const auto prefix = hexadecimal.substr(0, 2); - const auto hexNumber = hexadecimal.substr(2); + const auto generatedHexadecimal = hexadecimal(std::move(copyGuarantee), hexadecimalLength, HexCasing::Upper); + const auto prefix = generatedHexadecimal.substr(0, 2); + const auto hexNumber = generatedHexadecimal.substr(2); ASSERT_EQ(hexNumber.size(), hexadecimalLength); ASSERT_EQ(prefix, "0x"); @@ -1087,7 +1088,7 @@ TEST_F(StringTest, shouldGenerateHexadecimalWithGuarantee3) { const auto hexadecimalLength = 20; // exactly 0 '0' '1' '2' '3' '4' '5' '6' '7' - faker::GuaranteeMap guarantee{ + GuaranteeMap guarantee{ {'0', {0, 0}}, {'1', {0, 0}}, {'2', {0, 0}}, {'3', {0, 0}}, {'4', {0, 0}}, {'5', {0, 0}}, {'6', {0, 0}}, {'7', {0, 0}}, }; @@ -1095,9 +1096,9 @@ TEST_F(StringTest, shouldGenerateHexadecimalWithGuarantee3) for (int i = 0; i < runCount; ++i) { auto copyGuarantee = guarantee; - const auto hexadecimal = String::hexadecimal(std::move(copyGuarantee), hexadecimalLength, HexCasing::Upper); - const auto prefix = hexadecimal.substr(0, 2); - const auto hexNumber = hexadecimal.substr(2); + const auto generatedHexadecimal = hexadecimal(std::move(copyGuarantee), hexadecimalLength, HexCasing::Upper); + const auto prefix = generatedHexadecimal.substr(0, 2); + const auto hexNumber = generatedHexadecimal.substr(2); ASSERT_EQ(hexNumber.size(), hexadecimalLength); ASSERT_EQ(prefix, "0x"); @@ -1127,24 +1128,24 @@ TEST_F(StringTest, invalidGuaranteeForHexadecimal1) { const auto hexadecimalLength = 20; // atleast 5 'G' // invalid // 'G' is not a valid char for hexadecimal numbers - faker::GuaranteeMap guarantee{{'A', {0, 0}}, {'F', {10, 10}}, {'G', {5}}}; - ASSERT_THROW(String::hexadecimal(std::move(guarantee), hexadecimalLength, HexCasing::Upper), std::invalid_argument); + GuaranteeMap guarantee{{'A', {0, 0}}, {'F', {10, 10}}, {'G', {5}}}; + ASSERT_THROW(hexadecimal(std::move(guarantee), hexadecimalLength, HexCasing::Upper), std::invalid_argument); } TEST_F(StringTest, invalidGuaranteeForHexadecimal2) { const auto hexadecimalLength = 20; // atleast 5 'F' // invalid // 'F' is not a valid char for hexadecimal numbers with HexCasing::Lower - faker::GuaranteeMap guarantee{{'a', {0, 0}}, {'F', {10, 10}}, {'1', {5}}}; - ASSERT_THROW(String::hexadecimal(std::move(guarantee), hexadecimalLength), std::invalid_argument); + GuaranteeMap guarantee{{'a', {0, 0}}, {'F', {10, 10}}, {'1', {5}}}; + ASSERT_THROW(hexadecimal(std::move(guarantee), hexadecimalLength), std::invalid_argument); } TEST_F(StringTest, invalidGuaranteeForHexadecimal3) { const auto hexadecimalLength = 20; // atleast 5 'F' // invalid // 'F' is not a valid char for hexadecimal numbers with HexCasing::Lower - faker::GuaranteeMap guarantee{{'a', {0, 0}}, {'F', {10, 10}}, {'1', {5}}}; - ASSERT_THROW(String::hexadecimal(std::move(guarantee), hexadecimalLength), std::invalid_argument); + GuaranteeMap guarantee{{'a', {0, 0}}, {'F', {10, 10}}, {'1', {5}}}; + ASSERT_THROW(hexadecimal(std::move(guarantee), hexadecimalLength), std::invalid_argument); } TEST_F(StringTest, invalidGuaranteeForHexadecimal4) @@ -1152,8 +1153,8 @@ TEST_F(StringTest, invalidGuaranteeForHexadecimal4) const auto hexadecimalLength = 10; // atleast 5 'a' - 8 'b' // invalid // string size will be atleast 13 which is wrong // atmost 10 'b' - 3 '1' - faker::GuaranteeMap guarantee{{'a', {5}}, {'b', {8, 10}}, {'1', {0, 3}}}; - ASSERT_THROW(String::hexadecimal(std::move(guarantee), hexadecimalLength), std::invalid_argument); + GuaranteeMap guarantee{{'a', {5}}, {'b', {8, 10}}, {'1', {0, 3}}}; + ASSERT_THROW(hexadecimal(std::move(guarantee), hexadecimalLength), std::invalid_argument); } TEST_F(StringTest, invalidGuaranteeForHexadecimal5) @@ -1161,26 +1162,26 @@ TEST_F(StringTest, invalidGuaranteeForHexadecimal5) const auto hexadecimalLength = 20; // atmost 1 '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f' // invalid // string size wont // exceed 16 which is wrong - faker::GuaranteeMap guarantee{ + GuaranteeMap guarantee{ {'0', {0, 1}}, {'1', {0, 1}}, {'2', {0, 1}}, {'3', {0, 1}}, {'4', {0, 1}}, {'5', {0, 1}}, {'6', {0, 1}}, {'7', {0, 1}}, {'8', {0, 1}}, {'9', {0, 1}}, {'a', {0, 1}}, {'b', {0, 1}}, {'c', {0, 1}}, {'d', {0, 1}}, {'e', {0, 1}}, {'f', {0, 1}}, }; - ASSERT_THROW(String::hexadecimal(std::move(guarantee), hexadecimalLength), std::invalid_argument); + ASSERT_THROW(hexadecimal(std::move(guarantee), hexadecimalLength), std::invalid_argument); } TEST_F(StringTest, shouldGenerateHexNumber) { - auto result = String::hexadecimal(100, 255); + auto result = hexadecimal(100, 255); ASSERT_EQ(result.size(), 2); ASSERT_TRUE(std::isxdigit(result[0])); ASSERT_TRUE(std::isxdigit(result[1])); - result = String::hexadecimal(10, 15); + result = hexadecimal(10, 15); ASSERT_EQ(result.size(), 1); ASSERT_TRUE(std::isxdigit(result[0])); - result = String::hexadecimal(30, 40); + result = hexadecimal(30, 40); ASSERT_EQ(result.size(), 2); ASSERT_TRUE(std::isxdigit(result[0])); ASSERT_TRUE(std::isxdigit(result[1])); @@ -1190,14 +1191,14 @@ TEST_F(StringTest, shouldGenerateBinary) { const auto binaryLength = 8; - const auto binary = String::binary(binaryLength); + const auto generatedBinary = binary(binaryLength); - const auto prefix = binary.substr(0, 2); - const auto binaryNumber = binary.substr(2); + const auto prefix = generatedBinary.substr(0, 2); + const auto binaryNumber = generatedBinary.substr(2); - ASSERT_EQ(binary.size(), binaryLength + 2); + ASSERT_EQ(generatedBinary.size(), binaryLength + 2); ASSERT_EQ(prefix, "0b"); - ASSERT_TRUE(std::ranges::any_of(binary, [](char binaryNumberCharacter) + ASSERT_TRUE(std::ranges::any_of(generatedBinary, [](char binaryNumberCharacter) { return std::string("01").find(binaryNumberCharacter) != std::string::npos; })); } @@ -1207,15 +1208,15 @@ TEST_F(StringTest, shouldGenerateBinaryWithGuarantee1) // atleast 3 '0' and 2 '1' // atmost 7 '0' and 7 '1' - faker::GuaranteeMap guarantee{{'0', {3, 7}}, {'1', {2, 7}}}; + GuaranteeMap guarantee{{'0', {3, 7}}, {'1', {2, 7}}}; // it is a random function so lets test for 20 random generations for (int i = 0; i < runCount; ++i) { auto copyGuarantee = guarantee; - const auto binary = String::binary(std::move(copyGuarantee), binaryLength); + const auto generatedBinary = binary(std::move(copyGuarantee), binaryLength); - const auto prefix = binary.substr(0, 2); - const auto binaryNumber = binary.substr(2); + const auto prefix = generatedBinary.substr(0, 2); + const auto binaryNumber = generatedBinary.substr(2); ASSERT_EQ(binaryNumber.size(), binaryLength); ASSERT_EQ(prefix, "0b"); @@ -1234,15 +1235,15 @@ TEST_F(StringTest, shouldGenerateBinaryWithGuarantee2) const auto binaryLength = 10; // exactly 8 '0' and 2 '1' - faker::GuaranteeMap guarantee{{'0', {8, 8}}, {'1', {2, 2}}}; + GuaranteeMap guarantee{{'0', {8, 8}}, {'1', {2, 2}}}; // it is a random function so lets test for 20 random generations for (int i = 0; i < runCount; ++i) { auto copyGuarantee = guarantee; - const auto binary = String::binary(std::move(copyGuarantee), binaryLength); + const auto generatedBinary = binary(std::move(copyGuarantee), binaryLength); - const auto prefix = binary.substr(0, 2); - const auto binaryNumber = binary.substr(2); + const auto prefix = generatedBinary.substr(0, 2); + const auto binaryNumber = generatedBinary.substr(2); ASSERT_EQ(binaryNumber.size(), binaryLength); ASSERT_EQ(prefix, "0b"); @@ -1261,15 +1262,15 @@ TEST_F(StringTest, shouldGenerateBinaryWithGuarantee3) const auto binaryLength = 10; // atleast 10 '0' - faker::GuaranteeMap guarantee{{'0', {10}}}; + GuaranteeMap guarantee{{'0', {10}}}; // it is a random function so lets test for 20 random generations for (int i = 0; i < runCount; ++i) { auto copyGuarantee = guarantee; - const auto binary = String::binary(std::move(copyGuarantee), binaryLength); + const auto generatedBinary = binary(std::move(copyGuarantee), binaryLength); - const auto prefix = binary.substr(0, 2); - const auto binaryNumber = binary.substr(2); + const auto prefix = generatedBinary.substr(0, 2); + const auto binaryNumber = generatedBinary.substr(2); ASSERT_EQ(binaryNumber.size(), binaryLength); ASSERT_EQ(prefix, "0b"); @@ -1286,15 +1287,15 @@ TEST_F(StringTest, shouldGenerateBinaryWithGuarantee4) const auto binaryLength = 10; // atmost 0 '0' - faker::GuaranteeMap guarantee{{'0', {0, 0}}}; + GuaranteeMap guarantee{{'0', {0, 0}}}; // it is a random function so lets test for 20 random generations for (int i = 0; i < runCount; ++i) { auto copyGuarantee = guarantee; - const auto binary = String::binary(std::move(copyGuarantee), binaryLength); + const auto generatedBinary = binary(std::move(copyGuarantee), binaryLength); - const auto prefix = binary.substr(0, 2); - const auto binaryNumber = binary.substr(2); + const auto prefix = generatedBinary.substr(0, 2); + const auto binaryNumber = generatedBinary.substr(2); ASSERT_EQ(binaryNumber.size(), binaryLength); ASSERT_EQ(prefix, "0b"); @@ -1312,8 +1313,8 @@ TEST_F(StringTest, invalidGuaranteeForBinary1) // atleast 6 '0' and 6 '1' // invalid // total string size will be 12 which is wrong // atleast 10 '0' and 10 '1' - faker::GuaranteeMap guarantee{{'0', {6, 10}}, {'1', {6, 10}}}; - EXPECT_THROW(String::binary(std::move(guarantee), binaryLength), std::invalid_argument); + GuaranteeMap guarantee{{'0', {6, 10}}, {'1', {6, 10}}}; + EXPECT_THROW(binary(std::move(guarantee), binaryLength), std::invalid_argument); } TEST_F(StringTest, invalidGuaranteeForBinary2) @@ -1322,31 +1323,31 @@ TEST_F(StringTest, invalidGuaranteeForBinary2) // atleast 6 '0' and 6 '1' // atleast 10 '0' and 8 '1' // invalid // total string size won't exceed 18 which is wrong - faker::GuaranteeMap guarantee{{'0', {6, 10}}, {'1', {6, 8}}}; - EXPECT_THROW(String::binary(std::move(guarantee), binaryLength), std::invalid_argument); + GuaranteeMap guarantee{{'0', {6, 10}}, {'1', {6, 8}}}; + EXPECT_THROW(binary(std::move(guarantee), binaryLength), std::invalid_argument); } TEST_F(StringTest, invalidGuaranteeForBinary3) { const auto binaryLength = 10; // atleast 4 '0' and 3 'a' // invalid // binary string should consist of only '0' and '1' - faker::GuaranteeMap guarantee{{'0', {4}}, {'a', {3}}}; - EXPECT_THROW(String::binary(std::move(guarantee), binaryLength), std::invalid_argument); + GuaranteeMap guarantee{{'0', {4}}, {'a', {3}}}; + EXPECT_THROW(binary(std::move(guarantee), binaryLength), std::invalid_argument); } TEST_F(StringTest, shouldGenerateOctalWithPrefix) { const auto octalLength = 8; - const auto octal = String::octal(octalLength); + const auto generatedOctal = octal(octalLength); - const auto prefix = octal.substr(0, 2); - const auto octalNumber = octal.substr(2); + const auto prefix = generatedOctal.substr(0, 2); + const auto octalNumber = generatedOctal.substr(2); - ASSERT_EQ(octal.size(), octalLength + 2); + ASSERT_EQ(generatedOctal.size(), octalLength + 2); ASSERT_EQ(prefix, "0o"); ASSERT_TRUE( - std::ranges::any_of(octal, [](char octalNumberCharacter) + std::ranges::any_of(generatedOctal, [](char octalNumberCharacter) { return std::string("01234567").find(octalNumberCharacter) != std::string::npos; })); } @@ -1361,15 +1362,15 @@ TEST_F(StringTest, shouldGenerateOctalWithGuarantee1) for (int i = 0; i < runCount; ++i) { auto copyGuarantee = guarantee; - const auto octal = String::octal(std::move(copyGuarantee), octalLength); + const auto generatedOctal = octal(std::move(copyGuarantee), octalLength); - const auto prefix = octal.substr(0, 2); - const auto octalNumber = octal.substr(2); + const auto prefix = generatedOctal.substr(0, 2); + const auto octalNumber = generatedOctal.substr(2); ASSERT_EQ(octalNumber.size(), octalLength); ASSERT_EQ(prefix, "0o"); ASSERT_TRUE( - std::ranges::any_of(octal, [](char octalNumberCharacter) + std::ranges::any_of(generatedOctal, [](char octalNumberCharacter) { return std::string("01234567").find(octalNumberCharacter) != std::string::npos; })); auto count_0 = std::ranges::count(octalNumber, '0'); auto count_3 = std::ranges::count(octalNumber, '3'); @@ -1395,15 +1396,15 @@ TEST_F(StringTest, shouldGenerateOctalWithGuarantee2) for (int i = 0; i < runCount; ++i) { auto copyGuarantee = guarantee; - const auto octal = String::octal(std::move(copyGuarantee), octalLength); + const auto generatedOctal = octal(std::move(copyGuarantee), octalLength); - const auto prefix = octal.substr(0, 2); - const auto octalNumber = octal.substr(2); + const auto prefix = generatedOctal.substr(0, 2); + const auto octalNumber = generatedOctal.substr(2); ASSERT_EQ(octalNumber.size(), octalLength); ASSERT_EQ(prefix, "0o"); ASSERT_TRUE( - std::ranges::any_of(octal, [](char octalNumberCharacter) + std::ranges::any_of(generatedOctal, [](char octalNumberCharacter) { return std::string("01234567").find(octalNumberCharacter) != std::string::npos; })); auto count_0 = std::ranges::count(octalNumber, '0'); auto count_2 = std::ranges::count(octalNumber, '2'); @@ -1430,7 +1431,7 @@ TEST_F(StringTest, invalidGuaranteeForOctal1) // atleast 8 '0' - 9 '2' 9 '3' // invalid // total string size will be atleast 26 which is wrong // atmost GuaranteeMap guarantee{{'0', {8}}, {'2', {9}}, {'3', {9}}, {'4', {0, 0}}}; - ASSERT_THROW(String::octal(std::move(guarantee), octalLength), std::invalid_argument); + ASSERT_THROW(octal(std::move(guarantee), octalLength), std::invalid_argument); } TEST_F(StringTest, invalidGuaranteeForOctal2) @@ -1439,7 +1440,7 @@ TEST_F(StringTest, invalidGuaranteeForOctal2) // atmost 2 '0' '1' '2' '3' '4' '5' '6' '7' // invalid // octal string won't exceed 16 which is wrong GuaranteeMap guarantee{{'0', {0, 2}}, {'1', {0, 2}}, {'2', {0, 2}}, {'3', {0, 2}}, {'4', {0, 2}}, {'5', {0, 2}}, {'6', {0, 2}}, {'7', {0, 2}}}; - ASSERT_THROW(String::octal(std::move(guarantee), octalLength), std::invalid_argument); + ASSERT_THROW(octal(std::move(guarantee), octalLength), std::invalid_argument); } TEST_F(StringTest, invalidGuaranteeForOctal3) @@ -1449,5 +1450,5 @@ TEST_F(StringTest, invalidGuaranteeForOctal3) // atleast 2 '8' // invalid // octal numbers cannot have '8' // atmost 3 '8' GuaranteeMap guarantee{{'0', {0, 2}}, {'1', {0, 2}}, {'8', {2, 3}}, {'2', {0, 2}}, {'3', {0, 2}}}; - ASSERT_THROW(String::octal(std::move(guarantee), octalLength), std::invalid_argument); + ASSERT_THROW(octal(std::move(guarantee), octalLength), std::invalid_argument); }