diff --git a/include/faker-cxx/Helper.h b/include/faker-cxx/Helper.h index 54e7beb91..896ae5d18 100644 --- a/include/faker-cxx/Helper.h +++ b/include/faker-cxx/Helper.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -12,367 +13,360 @@ #include "Datatype.h" #include "Number.h" -namespace faker +namespace faker::helper { -class Helper +/** + * @brief Get a random element from an STL container. + * + * @tparam T an element type of the container. + * + * @param data The container. + * + * @return T a random element from the container. + * + * @code + * helper::arrayElement(std::string{"abcd"}) // "b" + * helper::arrayElement(std::vector{{"hello"}, {"world"}}) // "hello" + * @endcode + */ +template +T arrayElement(std::span data) { -public: - /** - * @brief Get a random element from an STL container. - * - * @tparam T an element type of the container. - * - * @param data The container. - * - * @return T a random element from the container. - * - * @code - * Helper::arrayElement(std::string{"abcd"}) // "b" - * Helper::arrayElement(std::vector{{"hello"}, {"world"}}) // "hello" - * @endcode - */ - template - static T arrayElement(std::span data) + if (data.empty()) { - if (data.empty()) - { - throw std::invalid_argument{"Data is empty."}; - } - - const auto index = number::integer(data.size() - 1); - - return data[index]; + throw std::invalid_argument{"Data is empty."}; } - template - static T arrayElement(const std::array& data) - { - if (data.empty()) - { - throw std::invalid_argument{"Data is empty."}; - } - - const auto index = number::integer(data.size() - 1); + const auto index = number::integer(data.size() - 1); - return data[index]; - } + return data[index]; +} - template - static auto arrayElement(It start, It end) -> decltype(*::std::declval()) +template +T arrayElement(const std::array& data) +{ + if (data.empty()) { - auto size = static_cast(end - start); + throw std::invalid_argument{"Data is empty."}; + } - if (size == 0) - { - throw std::invalid_argument{"Range [start,end) is empty."}; - } + const auto index = number::integer(data.size() - 1); - const std::integral auto index = number::integer(size - 1); + return data[index]; +} - return start[index]; - } +template +auto arrayElement(It start, It end) -> decltype(*::std::declval()) +{ + auto size = static_cast(end - start); - /** - * @brief Get a random element from a vector. - * - * @tparam T an element type of the vector. - * - * @param data vector of elements. - * - * @return T a random element from the vector. - * - * @code - * Helper::arrayElement(std::vector{{"hello"}, {"world"}}) // "hello" - * @endcode - */ - template - static T arrayElement(const std::vector& data) + if (size == 0) { - if (data.empty()) - { - throw std::invalid_argument{"Data is empty."}; - } + throw std::invalid_argument{"Range [start,end) is empty."}; + } - const auto index = number::integer(data.size() - 1); + const std::integral auto index = number::integer(size - 1); - return data[index]; - } + return start[index]; +} - /** - * @brief Get a random element from an initializer list. - * - * @tparam T an element type of the initializer list. - * - * @param data initializer list of elements. - * - * @return T a random element from the initializer list. - * - * @code - * Helper::arrayElement(std::initializer_list{{"hello"}, {"world"}}) // "hello" - * @endcode - */ - template - static T arrayElement(const std::initializer_list& data) +/** + * @brief Get a random element from a vector. + * + * @tparam T an element type of the vector. + * + * @param data vector of elements. + * + * @return T a random element from the vector. + * + * @code + * helper::arrayElement(std::vector{{"hello"}, {"world"}}) // "hello" + * @endcode + */ +template +T arrayElement(const std::vector& data) +{ + if (data.empty()) { - if (data.size() == 0) - { - throw std::invalid_argument{"Data is empty."}; - } + throw std::invalid_argument{"Data is empty."}; + } - const auto index = number::integer(data.size() - 1); + const auto index = number::integer(data.size() - 1); - return *(data.begin() + index); - } + return data[index]; +} - /** - * @brief Get a random element from a std::set. - * - * @tparam T an element type of the std::set. - * - * @param std::set of elements. - * - * @return T a random element from the std::set. - * - * @code - * std::set chars{'a', 'b', 'c', 'd', 'e'}; - * Helper::setElement(chars) // 'd' - * @endcode - */ - template - static T setElement(const std::set& data) +/** + * @brief Get a random element from an initializer list. + * + * @tparam T an element type of the initializer list. + * + * @param data initializer list of elements. + * + * @return T a random element from the initializer list. + * + * @code + * helper::arrayElement(std::initializer_list{{"hello"}, {"world"}}) // "hello" + * @endcode + */ +template +T arrayElement(const std::initializer_list& data) +{ + if (data.size() == 0) { - if (data.empty()) - { - throw std::invalid_argument{"Data is empty."}; - } + throw std::invalid_argument{"Data is empty."}; + } - T item; + const auto index = number::integer(data.size() - 1); - std::sample(data.begin(), data.end(), &item, 1, pseudoRandomGenerator); + return *(data.begin() + index); +} - return item; +/** + * @brief Get a random element from a std::set. + * + * @tparam T an element type of the std::set. + * + * @param std::set of elements. + * + * @return T a random element from the std::set. + * + * @code + * std::set chars{'a', 'b', 'c', 'd', 'e'}; + * helper::setElement(chars) // 'd' + * @endcode + */ +template +T setElement(const std::set& data) +{ + if (data.empty()) + { + throw std::invalid_argument{"Data is empty."}; } - template - struct WeightedElement - { - unsigned weight; - T value; - }; - - /** - * @brief Get a random element by weight from a vector. - * - * @tparam T an element type of the weighted element. - * - * @param data vector of weighted elements. - * - * @return T a weighted element value from the vector. - * - * @code - * Helper::weightedArrayElement(std::vector>{{1, "value1"}, {10, - * "value2"}}) // "hello2" - * @endcode - */ - template - static T weightedArrayElement(const std::vector>& data) - { - if (data.empty()) - { - throw std::invalid_argument{"Data is empty."}; - } + T item; - const auto sumOfWeights = - std::accumulate(data.begin(), data.end(), 0u, - [](unsigned sum, const WeightedElement& element) { return sum + element.weight; }); + static std::mt19937 pseudoRandomGenerator(std::random_device{}()); - if (sumOfWeights == 0u) - { - throw std::invalid_argument{"Sum of weights is zero."}; - } + std::sample(data.begin(), data.end(), &item, 1, pseudoRandomGenerator); - const std::integral auto targetWeightValue = number::integer(1, sumOfWeights); + return item; +} - unsigned currentSum = 0; +template +struct WeightedElement +{ + unsigned weight; + T value; +}; - size_t currentIdx = 0; +/** + * @brief Get a random element by weight from a vector. + * + * @tparam T an element type of the weighted element. + * + * @param data vector of weighted elements. + * + * @return T a weighted element value from the vector. + * + * @code + * helper::weightedArrayElement(std::vector>{{1, "value1"}, {10, + * "value2"}}) // "hello2" + * @endcode + */ +template +T weightedArrayElement(const std::vector>& data) +{ + if (data.empty()) + { + throw std::invalid_argument{"Data is empty."}; + } - while (currentIdx < data.size()) - { - currentSum += data[currentIdx].weight; + const auto sumOfWeights = + std::accumulate(data.begin(), data.end(), 0u, + [](unsigned sum, const WeightedElement& element) { return sum + element.weight; }); - if (currentSum >= targetWeightValue) - { - break; - } + if (sumOfWeights == 0u) + { + throw std::invalid_argument{"Sum of weights is zero."}; + } - currentIdx++; - } + const std::integral auto targetWeightValue = number::integer(1, sumOfWeights); - return data.at(currentIdx).value; - } + unsigned currentSum = 0; - /** - * @brief Returns shuffled std::string - * - * @param data String to be shuffled - * - * @return std::string with shuffled chars - * - * @code - * Helper::shuffleString("hello") // "eollh" - * @endcode - */ - static std::string shuffleString(std::string data); - - /** - * @brief Returns a random key from given object. - * - * @tparam T The type of the object to select from. - * - * @param object The object to be used. - * - * @throws If the given object is empty - * - * @return A random key from given object. - * - * @code - * std::unordered_map testMap = { - * {1, "one"}, - * {2, "two"}, - * {3, "three"} - * }; - * Helper::objectKey(testMap) // "2" - * @endcode - */ - template - static typename T::key_type objectKey(const T& object) - { - if (object.empty()) - { - throw std::runtime_error("Object is empty."); - } + size_t currentIdx = 0; - std::vector keys; + while (currentIdx < data.size()) + { + currentSum += data[currentIdx].weight; - for (const auto& entry : object) + if (currentSum >= targetWeightValue) { - keys.push_back(entry.first); + break; } - return arrayElement(keys); + currentIdx++; } - /** - * @brief Returns the result of the callback if the probability check was successful, otherwise empty string. - * - * - * @tparam TResult The type of result of the given callback. - * - * @param callback The callback to that will be invoked if the probability check was successful. - * @param probability The probability (`[0.00, 1.00]`) of the callback being invoked. Defaults to `0.5`. - * - * @return The result of the callback if the probability check was successful, otherwise empty string. - * - * @code - * Helper::maybe([]() { return "Hello World!"; }) // "" - * Helper::maybe([]() { return 42; }, 0.9) // "42" - * @endcode - */ - template - static TResult maybe(std::function callback, double probability = 0.5) + return data.at(currentIdx).value; +} + +/** + * @brief Returns shuffled std::string + * + * @param data String to be shuffled + * + * @return std::string with shuffled chars + * + * @code + * helper::shuffleString("hello") // "eollh" + * @endcode + */ +std::string shuffleString(std::string data); + +/** + * @brief Returns a random key from given object. + * + * @tparam T The type of the object to select from. + * + * @param object The object to be used. + * + * @throws If the given object is empty + * + * @return A random key from given object. + * + * @code + * std::unordered_map testMap = { + * {1, "one"}, + * {2, "two"}, + * {3, "three"} + * }; + * helper::objectKey(testMap) // "2" + * @endcode + */ +template +typename T::key_type objectKey(const T& object) +{ + if (object.empty()) { - if (datatype::boolean(probability)) - { - return callback(); - } + throw std::runtime_error("Object is empty."); + } - return TResult(); + std::vector keys; + + for (const auto& entry : object) + { + keys.push_back(entry.first); } - /** - * @brief Returns a vector equivalent to the given array. - * - * @tparam T The type of the array. - * @tparam N The size of the array. - * - * @param arr The array to convert. - * - * @return The same array as a vector. - * - * @code - * Helper::toVector(std::array{1, 2, 3}) // {1, 2, 3} - * @endcode - */ - template - static std::vector toVector(const std::array& arr) + return arrayElement(keys); +} + +/** + * @brief Returns the result of the callback if the probability check was successful, otherwise empty string. + * + * + * @tparam TResult The type of result of the given callback. + * + * @param callback The callback to that will be invoked if the probability check was successful. + * @param probability The probability (`[0.00, 1.00]`) of the callback being invoked. Defaults to `0.5`. + * + * @return The result of the callback if the probability check was successful, otherwise empty string. + * + * @code + * helper::maybe([]() { return "Hello World!"; }) // "" + * helper::maybe([]() { return 42; }, 0.9) // "42" + * @endcode + */ +template +TResult maybe(std::function callback, double probability = 0.5) +{ + if (datatype::boolean(probability)) { - std::vector vec; - vec.reserve(N); - vec.insert(vec.end(), arr.begin(), arr.end()); - return vec; + return callback(); } - /** - * @brief Returns the given string parsed symbol by symbol and replaced the placeholders with digits ("0" - "9"). - * "!" will be replaced by digits >=2 ("2" - "9"). - * - * @param str The template to parse string. - * @param symbol The symbol to replace with digits. Defaults to '#'. - * - * @return The string replaced symbols with digits. - * - * @code - * Helper::replaceSymbolWithNumber() // "" - * Helper::replaceSymbolWithNumber("#####") // "04812" - * Helper::replaceSymbolWithNumber("!####") // "27378" - * Helper::replaceSymbolWithNumber("Your pin is: !####") // "29841" - * @endcode - */ - static std::string replaceSymbolWithNumber(const std::string& str, const char& symbol = '#'); - - /** - * @brief Returns credit card schema with replaced symbols and patterns in a credit card including Luhn checksum - * This method supports both range patterns `[4-9]` as well as the patterns used by `replaceSymbolWithNumber()`. - * `L` will be replaced with the appropriate Luhn checksum. - * - * @param inputString TThe credit card format pattern. Defaults to "6453-####-####-####-###L". - * @param symbol The symbol to replace with a digit. Defaults to '#'. - * - * @return The string replaced symbols with digits. - * - * @code - * Helper::replaceCreditCardSymbols() // "6453-4876-8626-8995-3771" - * Helper::replaceCreditCardSymbols("1234-[4-9]-##!!-L") // "1234-9-5298-2" - * @endcode - */ - static std::string replaceCreditCardSymbols(const std::string& inputString = "6453-####-####-####-###L", - char symbol = '#'); - - /** - * @brief Returns the replaced regex-like expression in the string with matching values. - * - * Supported patterns: - * - `.{times}` => Repeat the character exactly `times` times. - * - `.{min,max}` => Repeat the character `min` to `max` times. - * - `[min-max]` => Generate a number between min and max (inclusive). - * - * @param input The template string to to parse. - * - * @return The replaced regex-like expression in the string with matching values. - * - * @code - * Helper::regexpStyleStringParse() // "" - * Helper::regexpStyleStringParse("#{5}") // "#####" - * Helper::regexpStyleStringParse("#{2,9}") // "#######" - * Helper::regexpStyleStringParse("[500-15000]") // "8375" - * Helper::regexpStyleStringParse("#{3}test[1-5]") // "###test3" - * @endcode - */ - static std::string regexpStyleStringParse(const std::string& input); - -private: - static std::random_device randomDevice; - static std::mt19937 pseudoRandomGenerator; -}; + return TResult(); +} + +/** + * @brief Returns a vector equivalent to the given array. + * + * @tparam T The type of the array. + * @tparam N The size of the array. + * + * @param arr The array to convert. + * + * @return The same array as a vector. + * + * @code + * helper::toVector(std::array{1, 2, 3}) // {1, 2, 3} + * @endcode + */ +template +std::vector toVector(const std::array& arr) +{ + std::vector vec; + vec.reserve(N); + vec.insert(vec.end(), arr.begin(), arr.end()); + return vec; +} + +/** + * @brief Returns the given string parsed symbol by symbol and replaced the placeholders with digits ("0" - "9"). + * "!" will be replaced by digits >=2 ("2" - "9"). + * + * @param str The template to parse string. + * @param symbol The symbol to replace with digits. Defaults to '#'. + * + * @return The string replaced symbols with digits. + * + * @code + * helper::replaceSymbolWithNumber() // "" + * helper::replaceSymbolWithNumber("#####") // "04812" + * helper::replaceSymbolWithNumber("!####") // "27378" + * helper::replaceSymbolWithNumber("Your pin is: !####") // "29841" + * @endcode + */ +std::string replaceSymbolWithNumber(const std::string& str, const char& symbol = '#'); + +/** + * @brief Returns credit card schema with replaced symbols and patterns in a credit card including Luhn checksum + * This method supports both range patterns `[4-9]` as well as the patterns used by `replaceSymbolWithNumber()`. + * `L` will be replaced with the appropriate Luhn checksum. + * + * @param inputString TThe credit card format pattern. Defaults to "6453-####-####-####-###L". + * @param symbol The symbol to replace with a digit. Defaults to '#'. + * + * @return The string replaced symbols with digits. + * + * @code + * helper::replaceCreditCardSymbols() // "6453-4876-8626-8995-3771" + * helper::replaceCreditCardSymbols("1234-[4-9]-##!!-L") // "1234-9-5298-2" + * @endcode + */ +std::string replaceCreditCardSymbols(const std::string& inputString = "6453-####-####-####-###L", char symbol = '#'); + +/** + * @brief Returns the replaced regex-like expression in the string with matching values. + * + * Supported patterns: + * - `.{times}` => Repeat the character exactly `times` times. + * - `.{min,max}` => Repeat the character `min` to `max` times. + * - `[min-max]` => Generate a number between min and max (inclusive). + * + * @param input The template string to to parse. + * + * @return The replaced regex-like expression in the string with matching values. + * + * @code + * helper::regexpStyleStringParse() // "" + * helper::regexpStyleStringParse("#{5}") // "#####" + * helper::regexpStyleStringParse("#{2,9}") // "#######" + * helper::regexpStyleStringParse("[500-15000]") // "8375" + * helper::regexpStyleStringParse("#{3}test[1-5]") // "###test3" + * @endcode + */ +std::string regexpStyleStringParse(const std::string& input); } diff --git a/include/faker-cxx/Number.h b/include/faker-cxx/Number.h index edfa8de0e..89831b835 100644 --- a/include/faker-cxx/Number.h +++ b/include/faker-cxx/Number.h @@ -6,92 +6,93 @@ namespace faker::number { - namespace{ - std::mt19937 pseudoRandomGenerator; - } - /** - * @brief Generates a random integer number in the given range, bounds included. - * - * @param min The minimum value of the range. - * @param max The maximum value of the range. - * - * @tparam I the type of the generated number, must be an integral type (int, long, long long, etc.). - * - * @throws std::invalid_argument if min is greater than max. - * - * @return T a random integer number - */ - template - I integer(I min, I max) +/** + * @brief Generates a random integer number in the given range, bounds included. + * + * @param min The minimum value of the range. + * @param max The maximum value of the range. + * + * @tparam I the type of the generated number, must be an integral type (int, long, long long, etc.). + * + * @throws std::invalid_argument if min is greater than max. + * + * @return T a random integer number + */ +template +I integer(I min, I max) +{ + if (min > max) { - if (min > max) - { - throw std::invalid_argument("Minimum value must be smaller than maximum value."); - } + throw std::invalid_argument("Minimum value must be smaller than maximum value."); + } - std::uniform_int_distribution distribution(min, max); + static std::mt19937 pseudoRandomGenerator{std::random_device{}()}; - return distribution(pseudoRandomGenerator); - } + std::uniform_int_distribution distribution(min, max); + + return distribution(pseudoRandomGenerator); +} + +/** + * @brief Generates a random integer between 0 and the given maximum value, bounds included. + * + * @tparam I the type of the generated number, must be an integral type (int, long, long long, etc.). + * @param max the maximum value of the range. + * + * @throws std::invalid_argument if min is greater than max. + * + * @see integer(I, I) + * + * @return T a random integer number + */ +template +I integer(I max) +{ + return integer(static_cast(0), max); +} - /** - * @brief Generates a random integer between 0 and the given maximum value, bounds included. - * - * @tparam I the type of the generated number, must be an integral type (int, long, long long, etc.). - * @param max the maximum value of the range. - * - * @throws std::invalid_argument if min is greater than max. - * - * @see integer(I, I) - * - * @return T a random integer number - */ - template - I integer(I max) +/** + * @brief Generates a random decimal number in the given range, bounds included. + * + * @tparam F the type of the generated number, must be a floating point type (float, double, long double). + * + * @param min The minimum value of the range. + * @param max The maximum value of the range. + * + * @throws std::invalid_argument if min is greater than max. + * + * @return F a random decimal number. + */ +template +F decimal(F min, F max) +{ + if (min > max) { - return integer(static_cast(0), max); + throw std::invalid_argument("Minimum value must be smaller than maximum value."); } - /** - * @brief Generates a random decimal number in the given range, bounds included. - * - * @tparam F the type of the generated number, must be a floating point type (float, double, long double). - * - * @param min The minimum value of the range. - * @param max The maximum value of the range. - * - * @throws std::invalid_argument if min is greater than max. - * - * @return F a random decimal number. - */ - template - F decimal(F min, F max) - { - if (min > max) - { - throw std::invalid_argument("Minimum value must be smaller than maximum value."); - } + static std::mt19937 pseudoRandomGenerator{std::random_device{}()}; - std::uniform_real_distribution distribution(min, max); + std::uniform_real_distribution distribution(min, max); - return distribution(pseudoRandomGenerator); - } + return distribution(pseudoRandomGenerator); +} - /** - * @brief Generates a random decimal number between 0 and the given maximum value, bounds included. - * - * @tparam F The type of the generated number, must be a floating point type (float, double, long double). - * @param max The maximum value of the range. - * - * @throws std::invalid_argument if max is less than 0. - * - * @see decimal(F, F) - * - * @return F, a random decimal number. - */ - template - F decimal(F max) - { - return decimal(static_cast(0.), max); - } +/** + * @brief Generates a random decimal number between 0 and the given maximum value, bounds included. + * + * @tparam F The type of the generated number, must be a floating point type (float, double, long double). + * @param max The maximum value of the range. + * + * @throws std::invalid_argument if max is less than 0. + * + * @see decimal(F, F) + * + * @return F, a random decimal number. + */ +template +F decimal(F max) +{ + return decimal(static_cast(0.), max); +} } diff --git a/src/modules/airline/Airline.cpp b/src/modules/airline/Airline.cpp index 7f19a0f46..700c08442 100644 --- a/src/modules/airline/Airline.cpp +++ b/src/modules/airline/Airline.cpp @@ -12,28 +12,28 @@ namespace faker::airline { std::string_view aircraftType() { - return Helper::arrayElement(aircraftTypes); + return helper::arrayElement(aircraftTypes); } Airplane airplane() { - return Helper::arrayElement(airplanes); + return helper::arrayElement(airplanes); } AirlineInfo airline() { - return Helper::arrayElement(airlines); + return helper::arrayElement(airlines); } Airport airport() { - return Helper::arrayElement(airports); + return helper::arrayElement(airports); } std::string seat(AircraftType aircraftType) { return std::to_string(number::integer(1, aircraftTypeMaxRows.at(aircraftType))) + - Helper::arrayElement(aircraftTypeSeatLetters.at(aircraftType)); + helper::arrayElement(aircraftTypeSeatLetters.at(aircraftType)); } std::string recordLocator(bool allowNumerics) diff --git a/src/modules/animal/Animal.cpp b/src/modules/animal/Animal.cpp index ca4687de5..a92c9f28c 100644 --- a/src/modules/animal/Animal.cpp +++ b/src/modules/animal/Animal.cpp @@ -9,76 +9,76 @@ namespace faker::animal { std::string_view bear() { - return Helper::arrayElement(bears); + return helper::arrayElement(bears); } std::string_view bird() { - return Helper::arrayElement(birds); + return helper::arrayElement(birds); } std::string_view cat() { - return Helper::arrayElement(cats); + return helper::arrayElement(cats); } std::string_view cetacean() { - return Helper::arrayElement(cetaceans); + return helper::arrayElement(cetaceans); } std::string_view cow() { - return Helper::arrayElement(cows); + return helper::arrayElement(cows); } std::string_view crocodile() { - return Helper::arrayElement(crocodiles); + return helper::arrayElement(crocodiles); } std::string_view dog() { - return Helper::arrayElement(dogs); + return helper::arrayElement(dogs); } std::string_view fish() { - return Helper::arrayElement(fishes); + return helper::arrayElement(fishes); } std::string_view horse() { - return Helper::arrayElement(horses); + return helper::arrayElement(horses); } std::string_view insect() { - return Helper::arrayElement(insects); + return helper::arrayElement(insects); } std::string_view lion() { - return Helper::arrayElement(lions); + return helper::arrayElement(lions); } std::string_view rabbit() { - return Helper::arrayElement(rabbits); + return helper::arrayElement(rabbits); } std::string_view rodent() { - return Helper::arrayElement(rodents); + return helper::arrayElement(rodents); } std::string_view snake() { - return Helper::arrayElement(snakes); + return helper::arrayElement(snakes); } std::string_view type() { - return Helper::arrayElement(types); + return helper::arrayElement(types); } } diff --git a/src/modules/book/Book.cpp b/src/modules/book/Book.cpp index 4a2b6aafd..b1c77a731 100644 --- a/src/modules/book/Book.cpp +++ b/src/modules/book/Book.cpp @@ -9,31 +9,31 @@ namespace faker::book { std::string_view title() { - return Helper::arrayElement(titles); + return helper::arrayElement(titles); } std::string_view genre() { - return Helper::arrayElement(bookGenres); + return helper::arrayElement(bookGenres); } std::string_view author() { - return Helper::arrayElement(authors); + return helper::arrayElement(authors); } std::string_view publisher() { - return Helper::arrayElement(publishers); + return helper::arrayElement(publishers); } std::string_view format() { - return Helper::arrayElement(bookFormats); + return helper::arrayElement(bookFormats); } std::string_view series() { - return Helper::arrayElement(bookSeries); + return helper::arrayElement(bookSeries); } } diff --git a/src/modules/color/Color.cpp b/src/modules/color/Color.cpp index 667bb8a7a..01d11a19a 100644 --- a/src/modules/color/Color.cpp +++ b/src/modules/color/Color.cpp @@ -14,7 +14,7 @@ namespace faker::color { std::string_view name() { - return Helper::arrayElement(colors); + return helper::arrayElement(colors); } std::string rgb(bool includeAlpha) diff --git a/src/modules/commerce/Commerce.cpp b/src/modules/commerce/Commerce.cpp index 2f94471f5..d0240de77 100644 --- a/src/modules/commerce/Commerce.cpp +++ b/src/modules/commerce/Commerce.cpp @@ -12,7 +12,7 @@ namespace faker::commerce { std::string_view department() { - return Helper::arrayElement(departments); + return helper::arrayElement(departments); } std::string sku(unsigned int length) @@ -22,17 +22,17 @@ std::string sku(unsigned int length) std::string_view productAdjective() { - return Helper::arrayElement(productAdjectives); + return helper::arrayElement(productAdjectives); } std::string_view productMaterial() { - return Helper::arrayElement(productMaterials); + return helper::arrayElement(productMaterials); } std::string_view productName() { - return Helper::arrayElement(productNames); + return helper::arrayElement(productNames); } std::string productFullName() @@ -153,42 +153,42 @@ std::string ISBN10() std::string_view paymentType() { - return Helper::arrayElement(paymentTypes); + return helper::arrayElement(paymentTypes); } std::string_view paymentProvider() { - return Helper::arrayElement(paymentProviders); + return helper::arrayElement(paymentProviders); } std::string_view productDescription() { - return Helper::arrayElement(productDescriptions); + return helper::arrayElement(productDescriptions); } std::string_view productCategory() { - return Helper::arrayElement(productCategoryNames); + return helper::arrayElement(productCategoryNames); } std::string_view productReview() { - return Helper::arrayElement(productReviews); + return helper::arrayElement(productReviews); } std::string_view discountType() { - return Helper::arrayElement(discountTypes); + return helper::arrayElement(discountTypes); } std::string_view orderStatus() { - return Helper::arrayElement(orderStatuses); + return helper::arrayElement(orderStatuses); } std::string_view shippingCarrier() { - return Helper::arrayElement(shippingCarriers); + return helper::arrayElement(shippingCarriers); } } diff --git a/src/modules/company/Company.cpp b/src/modules/company/Company.cpp index 27e58e07e..96d8715e5 100644 --- a/src/modules/company/Company.cpp +++ b/src/modules/company/Company.cpp @@ -18,7 +18,7 @@ std::string name() switch (number::integer(3)) { case 0: - companyName = FormatHelper::format("{} {}", person::lastName(), Helper::arrayElement(companySuffixes)); + companyName = FormatHelper::format("{} {}", person::lastName(), helper::arrayElement(companySuffixes)); break; case 1: companyName = FormatHelper::format("{} {} {}", person::firstName(), person::lastName(), person::jobArea()); @@ -29,7 +29,7 @@ std::string name() break; case 3: companyName = FormatHelper::format("{} {} {} {}", person::firstName(), person::lastName(), person::jobArea(), - Helper::arrayElement(companySuffixes)); + helper::arrayElement(companySuffixes)); break; } @@ -38,12 +38,12 @@ std::string name() std::string_view type() { - return Helper::arrayElement(companyTypes); + return helper::arrayElement(companyTypes); } std::string_view industry() { - return Helper::arrayElement(companyIndustries); + return helper::arrayElement(companyIndustries); } std::string buzzPhrase() @@ -53,17 +53,17 @@ std::string buzzPhrase() std::string_view buzzAdjective() { - return Helper::arrayElement(buzzAdjectives); + return helper::arrayElement(buzzAdjectives); } std::string_view buzzNoun() { - return Helper::arrayElement(buzzNouns); + return helper::arrayElement(buzzNouns); } std::string_view buzzVerb() { - return Helper::arrayElement(buzzVerbs); + return helper::arrayElement(buzzVerbs); } std::string catchPhrase() @@ -73,16 +73,16 @@ std::string catchPhrase() std::string_view catchPhraseAdjective() { - return Helper::arrayElement(catchPhraseAdjectives); + return helper::arrayElement(catchPhraseAdjectives); } std::string_view catchPhraseDescriptor() { - return Helper::arrayElement(catchPhraseDescriptors); + return helper::arrayElement(catchPhraseDescriptors); } std::string_view catchPhraseNoun() { - return Helper::arrayElement(catchPhraseNouns); + return helper::arrayElement(catchPhraseNouns); } } diff --git a/src/modules/computer/Computer.cpp b/src/modules/computer/Computer.cpp index d837ea227..592e1acee 100644 --- a/src/modules/computer/Computer.cpp +++ b/src/modules/computer/Computer.cpp @@ -9,46 +9,46 @@ namespace faker::computer { std::string_view type() { - return Helper::arrayElement(computerTypes); + return helper::arrayElement(computerTypes); } std::string_view manufacture() { - return Helper::arrayElement(computerManufacturers); + return helper::arrayElement(computerManufacturers); } std::string_view model() { - return Helper::arrayElement(computerModels); + return helper::arrayElement(computerModels); } std::string_view cpuManufacture() { - return Helper::arrayElement(cpuManufacturers); + return helper::arrayElement(cpuManufacturers); } std::string_view cpuType() { - return Helper::arrayElement(cpuTypes); + return helper::arrayElement(cpuTypes); } std::string_view cpuModel() { - return Helper::arrayElement(cpuModels); + return helper::arrayElement(cpuModels); } std::string_view gpuManufacture() { - return Helper::arrayElement(gpuManufacturers); + return helper::arrayElement(gpuManufacturers); } std::string_view gpuType() { - return Helper::arrayElement(gpuTypes); + return helper::arrayElement(gpuTypes); } std::string_view gpuModel() { - return Helper::arrayElement(gpuModels); + return helper::arrayElement(gpuModels); } } diff --git a/src/modules/database/Database.cpp b/src/modules/database/Database.cpp index 9bfa5ba14..440a04f4b 100644 --- a/src/modules/database/Database.cpp +++ b/src/modules/database/Database.cpp @@ -12,22 +12,22 @@ namespace faker::database { std::string_view columnName() { - return Helper::arrayElement(columnNames); + return helper::arrayElement(columnNames); } std::string_view columnType() { - return Helper::arrayElement(columnTypes); + return helper::arrayElement(columnTypes); } std::string_view collation() { - return Helper::arrayElement(collations); + return helper::arrayElement(collations); } std::string_view engine() { - return Helper::arrayElement(engines); + return helper::arrayElement(engines); } std::string mongoDbObjectId() diff --git a/src/modules/date/Date.cpp b/src/modules/date/Date.cpp index 135626a76..6fe23a422 100644 --- a/src/modules/date/Date.cpp +++ b/src/modules/date/Date.cpp @@ -132,22 +132,22 @@ std::string birthdateByYear(int minYear, int maxYear, DateFormat dateFormat) std::string_view weekdayName() { - return Helper::arrayElement(weekdayNames); + return helper::arrayElement(weekdayNames); } std::string_view weekdayAbbreviatedName() { - return Helper::arrayElement(weekdayAbbreviatedNames); + return helper::arrayElement(weekdayAbbreviatedNames); } std::string_view monthName() { - return Helper::arrayElement(monthNames); + return helper::arrayElement(monthNames); } std::string_view monthAbbreviatedName() { - return Helper::arrayElement(monthAbbreviatedNames); + return helper::arrayElement(monthAbbreviatedNames); } unsigned int year() @@ -195,7 +195,7 @@ unsigned dayOfWeek() std::string_view timezoneRandom() { - return Helper::arrayElement(timezonesAbbreviatedNames); + return helper::arrayElement(timezonesAbbreviatedNames); } } diff --git a/src/modules/finance/Finance.cpp b/src/modules/finance/Finance.cpp index 58351d8a0..16f4eb705 100644 --- a/src/modules/finance/Finance.cpp +++ b/src/modules/finance/Finance.cpp @@ -14,33 +14,32 @@ #include "faker-cxx/types/Precision.h" #include "FinanceData.h" - namespace faker::finance { Currency currency() { - return Helper::arrayElement(currencies); + return helper::arrayElement(currencies); } std::string_view currencyName() { - return Helper::arrayElement(currencies).name; + return helper::arrayElement(currencies).name; } std::string_view currencyCode() { - return Helper::arrayElement(currencies).code; + return helper::arrayElement(currencies).code; } std::string_view currencySymbol() { - return Helper::arrayElement(currencies).symbol; + return helper::arrayElement(currencies).symbol; } std::string_view accountType() { - return Helper::arrayElement(accountTypes); + return helper::arrayElement(accountTypes); } std::string amount(double min, double max, Precision precision, const std::string& symbol) @@ -56,7 +55,7 @@ std::string amount(double min, double max, Precision precision, const std::strin std::string iban(std::optional country) { - const auto ibanCountry = country ? *country : Helper::arrayElement(ibanCountries); + const auto ibanCountry = country ? *country : helper::arrayElement(ibanCountries); const auto& ibanFormat = ibanFormats.at(ibanCountry); @@ -91,9 +90,9 @@ std::string iban(std::optional country) std::string_view bic(std::optional country) { - const auto bicCountry = country ? *country : Helper::arrayElement(bicCountries); + const auto bicCountry = country ? *country : helper::arrayElement(bicCountries); - return Helper::arrayElement(bicCountriesCodes.at(bicCountry)); + return helper::arrayElement(bicCountriesCodes.at(bicCountry)); } std::string accountNumber(unsigned int length) @@ -113,21 +112,21 @@ std::string routingNumber() std::string creditCardNumber(std::optional creditCardType) { - const auto creditCardTargetType = creditCardType ? *creditCardType : Helper::arrayElement(creditCardTypes); + const auto creditCardTargetType = creditCardType ? *creditCardType : helper::arrayElement(creditCardTypes); switch (creditCardTargetType) { case CreditCardType::AmericanExpress: - return Helper::replaceCreditCardSymbols( - static_cast(Helper::arrayElement(americanExpressCreditCardFormats))); + return helper::replaceCreditCardSymbols( + static_cast(helper::arrayElement(americanExpressCreditCardFormats))); case CreditCardType::Discover: - return Helper::replaceCreditCardSymbols( - static_cast(Helper::arrayElement(discoverCreditCardFormats))); + return helper::replaceCreditCardSymbols( + static_cast(helper::arrayElement(discoverCreditCardFormats))); case CreditCardType::MasterCard: - return Helper::replaceCreditCardSymbols( - static_cast(Helper::arrayElement(masterCardCreditCardFormats))); + return helper::replaceCreditCardSymbols( + static_cast(helper::arrayElement(masterCardCreditCardFormats))); case CreditCardType::Visa: - return Helper::replaceCreditCardSymbols(static_cast(Helper::arrayElement(visaCreditCardFormats))); + return helper::replaceCreditCardSymbols(static_cast(helper::arrayElement(visaCreditCardFormats))); } return ""; @@ -142,7 +141,7 @@ std::string bitcoinAddress() { const unsigned addressLength = number::integer(26u, 33u); - auto address = Helper::arrayElement(std::vector{"1", "3"}); + auto address = helper::arrayElement(std::vector{"1", "3"}); address += string::alphanumeric(addressLength, string::StringCasing::Mixed, "0OIl"); @@ -153,7 +152,7 @@ std::string litecoinAddress() { const unsigned addressLength = number::integer(26u, 33u); - auto address = Helper::arrayElement(std::vector{"L", "M", "3"}); + auto address = helper::arrayElement(std::vector{"L", "M", "3"}); address += string::alphanumeric(addressLength, string::StringCasing::Mixed, "0OIl"); @@ -174,7 +173,7 @@ std::string creditCardExpirationDate() std::string_view creditCardType() { - return Helper::arrayElement(creditCardNames); + return helper::arrayElement(creditCardNames); } } diff --git a/src/modules/food/Food.cpp b/src/modules/food/Food.cpp index 9625f9fcd..305ca4ce4 100644 --- a/src/modules/food/Food.cpp +++ b/src/modules/food/Food.cpp @@ -9,71 +9,71 @@ namespace faker::food { std::string_view alcoholicBeverage() { - return Helper::arrayElement(alcoholicBeverages); + return helper::arrayElement(alcoholicBeverages); } std::string_view dishName() { - return Helper::arrayElement(dishNames); + return helper::arrayElement(dishNames); } std::string_view foodCategory() { - return Helper::arrayElement(foodCategories); + return helper::arrayElement(foodCategories); } std::string_view fruit() { - return Helper::arrayElement(fruits); + return helper::arrayElement(fruits); } std::string_view grain() { - return Helper::arrayElement(grains); + return helper::arrayElement(grains); } std::string_view meat() { - return Helper::arrayElement(meats); + return helper::arrayElement(meats); } std::string_view milkProduct() { - return Helper::arrayElement(milkProducts); + return helper::arrayElement(milkProducts); } std::string_view nonalcoholicBeverage() { - return Helper::arrayElement(nonalcoholicBeverages); + return helper::arrayElement(nonalcoholicBeverages); } std::string_view nut() { - return Helper::arrayElement(nuts); + return helper::arrayElement(nuts); } std::string_view oil() { - return Helper::arrayElement(oils); + return helper::arrayElement(oils); } std::string_view seafood() { - return Helper::arrayElement(seafoods); + return helper::arrayElement(seafoods); } std::string_view seed() { - return Helper::arrayElement(seeds); + return helper::arrayElement(seeds); } std::string_view sugarProduct() { - return Helper::arrayElement(sugarProducts); + return helper::arrayElement(sugarProducts); } std::string_view vegetable() { - return Helper::arrayElement(vegetables); + return helper::arrayElement(vegetables); } } diff --git a/src/modules/hacker/Hacker.cpp b/src/modules/hacker/Hacker.cpp index d7fd09698..f7d0d4c38 100644 --- a/src/modules/hacker/Hacker.cpp +++ b/src/modules/hacker/Hacker.cpp @@ -11,32 +11,32 @@ namespace faker::hacker { std::string_view abbreviation() { - return Helper::arrayElement(abbreviations); + return helper::arrayElement(abbreviations); } std::string_view adjective() { - return Helper::arrayElement(adjectives); + return helper::arrayElement(adjectives); } std::string_view noun() { - return Helper::arrayElement(nouns); + return helper::arrayElement(nouns); } std::string_view verb() { - return Helper::arrayElement(verbs); + return helper::arrayElement(verbs); } std::string_view ingverb() { - return Helper::arrayElement(ingverbs); + return helper::arrayElement(ingverbs); } std::string phrase() { - const auto splitRandomPhrase = StringHelper::split(static_cast(Helper::arrayElement(phrases))); + const auto splitRandomPhrase = StringHelper::split(static_cast(helper::arrayElement(phrases))); std::string phrase; diff --git a/src/modules/helper/Helper.cpp b/src/modules/helper/Helper.cpp index d90030f2c..176283047 100644 --- a/src/modules/helper/Helper.cpp +++ b/src/modules/helper/Helper.cpp @@ -1,7 +1,6 @@ #include "faker-cxx/Helper.h" #include -#include #include #include #include @@ -10,20 +9,18 @@ #include "../../common/StringHelper.h" #include "faker-cxx/Number.h" -namespace faker +namespace faker::helper { -std::random_device Helper::randomDevice; - -std::mt19937 Helper::pseudoRandomGenerator(Helper::randomDevice()); - -std::string Helper::shuffleString(std::string data) +std::string shuffleString(std::string data) { + static std::mt19937 pseudoRandomGenerator(std::random_device{}()); + std::shuffle(data.begin(), data.end(), pseudoRandomGenerator); return data; } -std::string Helper::replaceSymbolWithNumber(const std::string& str, const char& symbol) +std::string replaceSymbolWithNumber(const std::string& str, const char& symbol) { std::string result; @@ -46,7 +43,7 @@ std::string Helper::replaceSymbolWithNumber(const std::string& str, const char& return result; } -std::string Helper::replaceCreditCardSymbols(const std::string& inputString, char symbol) +std::string replaceCreditCardSymbols(const std::string& inputString, char symbol) { // Replace regex-like expressions in the given string with matching values. std::string modifiedString = regexpStyleStringParse(inputString); @@ -67,7 +64,7 @@ std::string Helper::replaceCreditCardSymbols(const std::string& inputString, cha return modifiedString; } -std::string Helper::regexpStyleStringParse(const std::string& input) +std::string regexpStyleStringParse(const std::string& input) { std::string data = input; // Deal with range repeat `{min,max}` diff --git a/src/modules/image/Image.cpp b/src/modules/image/Image.cpp index 0bda7f9e4..64d78bb5e 100644 --- a/src/modules/image/Image.cpp +++ b/src/modules/image/Image.cpp @@ -18,12 +18,10 @@ const std::array imageTypes = {"ai", "bmp", "eps", "gif", "pdf", "png", "psd", "raw", "svg", "tiff", "webp"}; std::unordered_map imageCategoryToLoremFlickrStringMapping = { - {ImageCategory::Animals, "animals"}, {ImageCategory::Business, "business"}, - {ImageCategory::Cats, "cats"}, {ImageCategory::City, "city"}, - {ImageCategory::Food, "food"}, {ImageCategory::Nightlife, "nightlife"}, - {ImageCategory::Fashion, "fashion"}, {ImageCategory::People, "people"}, - {ImageCategory::Nature, "nature"}, {ImageCategory::Sports, "sports"}, - {ImageCategory::Technics, "technics"}, {ImageCategory::Transport, "transport"}, + {ImageCategory::Animals, "animals"}, {ImageCategory::Business, "business"}, {ImageCategory::Cats, "cats"}, + {ImageCategory::City, "city"}, {ImageCategory::Food, "food"}, {ImageCategory::Nightlife, "nightlife"}, + {ImageCategory::Fashion, "fashion"}, {ImageCategory::People, "people"}, {ImageCategory::Nature, "nature"}, + {ImageCategory::Sports, "sports"}, {ImageCategory::Technics, "technics"}, {ImageCategory::Transport, "transport"}, }; } @@ -49,6 +47,6 @@ std::string dimensions() std::string_view type() { - return Helper::arrayElement(imageTypes); + return helper::arrayElement(imageTypes); } } diff --git a/src/modules/internet/Internet.cpp b/src/modules/internet/Internet.cpp index 5f9259d83..b1802afa7 100644 --- a/src/modules/internet/Internet.cpp +++ b/src/modules/internet/Internet.cpp @@ -52,16 +52,11 @@ constexpr unsigned int ipv4ClassBSecondSectorUpperBound = 31u; constexpr unsigned int ipv4SectorUpperBound = 255u; const std::map> emojiTypeToEmojisMapping = { - {EmojiType::Smiley, Helper::toVector(smileyEmojis)}, - {EmojiType::Body, Helper::toVector(bodyEmojis)}, - {EmojiType::Person, Helper::toVector(personEmojis)}, - {EmojiType::Nature, Helper::toVector(natureEmojis)}, - {EmojiType::Food, Helper::toVector(foodEmojis)}, - {EmojiType::Travel, Helper::toVector(travelEmojis)}, - {EmojiType::Activity, Helper::toVector(activityEmojis)}, - {EmojiType::Object, Helper::toVector(objectEmojis)}, - {EmojiType::Symbol, Helper::toVector(symbolEmojis)}, - {EmojiType::Flag, Helper::toVector(flagEmojis)}, + {EmojiType::Smiley, helper::toVector(smileyEmojis)}, {EmojiType::Body, helper::toVector(bodyEmojis)}, + {EmojiType::Person, helper::toVector(personEmojis)}, {EmojiType::Nature, helper::toVector(natureEmojis)}, + {EmojiType::Food, helper::toVector(foodEmojis)}, {EmojiType::Travel, helper::toVector(travelEmojis)}, + {EmojiType::Activity, helper::toVector(activityEmojis)}, {EmojiType::Object, helper::toVector(objectEmojis)}, + {EmojiType::Symbol, helper::toVector(symbolEmojis)}, {EmojiType::Flag, helper::toVector(flagEmojis)}, }; } @@ -85,8 +80,7 @@ std::vector getAllEmojis() return emojis; } -std::string username(std::optional firstNameInit, std::optional lastNameInit, - Country country) +std::string username(std::optional firstNameInit, std::optional lastNameInit, Country country) { const auto firstName = firstNameInit ? *firstNameInit : person::firstName(country); const auto lastName = lastNameInit ? *lastNameInit : person::lastName(country); @@ -100,11 +94,11 @@ std::string username(std::optional firstNameInit, std::optional{".", "_", ""}), lastName); + helper::arrayElement(std::vector{".", "_", ""}), lastName); break; case 2: username = - FormatHelper::format("{}{}{}{}", firstName, Helper::arrayElement(std::vector{".", "_", ""}), + FormatHelper::format("{}{}{}{}", firstName, helper::arrayElement(std::vector{".", "_", ""}), lastName, number::integer(99)); break; } @@ -113,16 +107,16 @@ std::string username(std::optional firstNameInit, std::optional firstName, std::optional lastName, - std::optional emailHost) + std::optional emailHost) { return FormatHelper::format("{}@{}", username(std::move(firstName), std::move(lastName)), - emailHost ? *emailHost : Helper::arrayElement(emailHosts)); + emailHost ? *emailHost : helper::arrayElement(emailHosts)); } std::string exampleEmail(std::optional firstName, std::optional lastName) { return FormatHelper::format("{}@{}", username(std::move(firstName), std::move(lastName)), - Helper::arrayElement(emailExampleHosts)); + helper::arrayElement(emailExampleHosts)); } std::string password(int length, const PasswordOptions& options) @@ -153,7 +147,7 @@ std::string password(int length, const PasswordOptions& options) for (int i = 0; i < length; ++i) { - password += Helper::arrayElement(characters); + password += helper::arrayElement(characters); } return password; @@ -165,11 +159,11 @@ std::string_view emoji(std::optional type) { const auto& emojisMapped = emojiTypeToEmojisMapping.at(*type); - return Helper::arrayElement(emojisMapped); + return helper::arrayElement(emojisMapped); } const auto emojis = getAllEmojis(); - return Helper::arrayElement(emojis); + return helper::arrayElement(emojis); } bool checkIfEmojiIsValid(const std::string& emojiToCheck) @@ -180,12 +174,12 @@ bool checkIfEmojiIsValid(const std::string& emojiToCheck) std::string_view protocol() { - return Helper::arrayElement(webProtocols); + return helper::arrayElement(webProtocols); } std::string_view httpMethod() { - return Helper::arrayElement(httpMethodNames); + return helper::arrayElement(httpMethodNames); } unsigned httpStatusCode(std::optional responseType) @@ -194,7 +188,7 @@ unsigned httpStatusCode(std::optional responseType) { const auto& statusCodes = httpResponseTypeToCodesMapping.at(*responseType); - return Helper::arrayElement(statusCodes); + return helper::arrayElement(statusCodes); } std::vector statusCodes; @@ -208,22 +202,22 @@ unsigned httpStatusCode(std::optional responseType) statusCodes.insert(statusCodes.end(), httpStatusClientErrorCodes.begin(), httpStatusClientErrorCodes.end()); statusCodes.insert(statusCodes.end(), httpStatusServerErrorCodes.begin(), httpStatusServerErrorCodes.end()); - return Helper::arrayElement(statusCodes); + return helper::arrayElement(statusCodes); } std::string_view httpRequestHeader() { - return Helper::arrayElement(httpRequestHeaders); + return helper::arrayElement(httpRequestHeaders); } std::string_view httpResponseHeader() { - return Helper::arrayElement(httpResponseHeaders); + return helper::arrayElement(httpResponseHeaders); } std::string_view httpMediaType() { - return Helper::arrayElement(httpMediaTypes); + return helper::arrayElement(httpMediaTypes); } std::string ipv4(const IPv4Class& ipv4class) @@ -257,8 +251,7 @@ std::string ipv4(const IPv4Class& ipv4class) return FormatHelper::format("{}.{}.{}.{}", sectors[0], sectors[1], sectors[2], sectors[3]); } -std::string ipv4(const std::array& baseIpv4Address, - const std::array& generationMask) +std::string ipv4(const std::array& baseIpv4Address, const std::array& generationMask) { std::array sectors{}; @@ -333,7 +326,7 @@ std::string domainWord() std::string_view domainSuffix() { - return Helper::arrayElement(domainSuffixes); + return helper::arrayElement(domainSuffixes); } std::string anonymousUsername(unsigned maxLength) diff --git a/src/modules/location/Location.cpp b/src/modules/location/Location.cpp index 8d76626e7..0ec943b54 100644 --- a/src/modules/location/Location.cpp +++ b/src/modules/location/Location.cpp @@ -97,12 +97,12 @@ Country getCountry(const AddressCountry& addressCountry) std::string_view country() { - return Helper::arrayElement(allCountries); + return helper::arrayElement(allCountries); } std::string_view countryCode() { - return Helper::arrayElement(countryCodes); + return helper::arrayElement(countryCodes); } std::string_view county(AddressCountry country) @@ -114,31 +114,31 @@ std::string_view county(AddressCountry country) return ""; } - return Helper::arrayElement(countryAddresses.counties); + return helper::arrayElement(countryAddresses.counties); } std::string_view state(AddressCountry country) { const auto& countryAddresses = getAddresses(country); - return Helper::arrayElement(countryAddresses.states); + return helper::arrayElement(countryAddresses.states); } std::string city(AddressCountry country) { const auto& countryAddresses = getAddresses(country); - const auto cityFormat = static_cast(Helper::arrayElement(countryAddresses.cityFormats)); + const auto cityFormat = static_cast(helper::arrayElement(countryAddresses.cityFormats)); const auto dataGeneratorsMapping = std::unordered_map>{ {"firstName", [&country]() { return static_cast(person::firstName(getCountry(country))); }}, {"lastName", [&country]() { return static_cast(person::lastName(getCountry(country))); }}, {"cityName", - [&countryAddresses]() { return static_cast(Helper::arrayElement(countryAddresses.cities)); }}, + [&countryAddresses]() { return static_cast(helper::arrayElement(countryAddresses.cities)); }}, {"cityPrefix", [&countryAddresses]() - { return static_cast(Helper::arrayElement(countryAddresses.cityPrefixes)); }}, + { return static_cast(helper::arrayElement(countryAddresses.cityPrefixes)); }}, {"citySuffix", [&countryAddresses]() - { return static_cast(Helper::arrayElement(countryAddresses.citySuffixes)); }}}; + { return static_cast(helper::arrayElement(countryAddresses.citySuffixes)); }}}; return FormatHelper::fillTokenValues(cityFormat, dataGeneratorsMapping); } @@ -147,7 +147,7 @@ std::string zipCode(AddressCountry country) { const auto& countryAddresses = getAddresses(country); - return Helper::replaceSymbolWithNumber(static_cast(countryAddresses.zipCodeFormat)); + return helper::replaceSymbolWithNumber(static_cast(countryAddresses.zipCodeFormat)); } std::string streetAddress(AddressCountry country) @@ -159,7 +159,7 @@ std::string streetAddress(AddressCountry country) {"street", [&country]() { return street(country); }}, {"secondaryAddress", [&country]() { return secondaryAddress(country); }}}; - const auto addressFormat = static_cast(Helper::arrayElement(countryAddresses.addressFormats)); + const auto addressFormat = static_cast(helper::arrayElement(countryAddresses.addressFormats)); return FormatHelper::fillTokenValues(addressFormat, dataGeneratorsMapping); } @@ -168,17 +168,17 @@ std::string street(AddressCountry country) { const auto& countryAddresses = getAddresses(country); - const auto streetFormat = static_cast(Helper::arrayElement(countryAddresses.streetFormats)); + const auto streetFormat = static_cast(helper::arrayElement(countryAddresses.streetFormats)); const auto dataGeneratorsMapping = std::unordered_map>{ {"firstName", [&country]() { return static_cast(person::firstName(getCountry(country))); }}, {"lastName", [&country]() { return static_cast(person::lastName(getCountry(country))); }}, {"streetName", [&countryAddresses]() - { return static_cast(Helper::arrayElement(countryAddresses.streetNames)); }}, + { return static_cast(helper::arrayElement(countryAddresses.streetNames)); }}, {"streetPrefix", [&countryAddresses]() - { return static_cast(Helper::arrayElement(countryAddresses.streetPrefixes)); }}, + { return static_cast(helper::arrayElement(countryAddresses.streetPrefixes)); }}, {"streetSuffix", [&countryAddresses]() - { return static_cast(Helper::arrayElement(countryAddresses.streetSuffixes)); }}}; + { return static_cast(helper::arrayElement(countryAddresses.streetSuffixes)); }}}; return FormatHelper::fillTokenValues(streetFormat, dataGeneratorsMapping); } @@ -188,9 +188,9 @@ std::string buildingNumber(AddressCountry country) const auto& countryAddresses = getAddresses(country); const auto buildingNumberFormat = - static_cast(Helper::arrayElement(countryAddresses.buildingNumberFormats)); + static_cast(helper::arrayElement(countryAddresses.buildingNumberFormats)); - return Helper::replaceSymbolWithNumber(buildingNumberFormat); + return helper::replaceSymbolWithNumber(buildingNumberFormat); } std::string secondaryAddress(AddressCountry country) @@ -203,9 +203,9 @@ std::string secondaryAddress(AddressCountry country) } const auto secondaryAddressFormat = - static_cast(Helper::arrayElement(countryAddresses.secondaryAddressFormats)); + static_cast(helper::arrayElement(countryAddresses.secondaryAddressFormats)); - return Helper::replaceSymbolWithNumber(secondaryAddressFormat); + return helper::replaceSymbolWithNumber(secondaryAddressFormat); } std::string latitude(Precision precision) @@ -224,12 +224,12 @@ std::string longitude(Precision precision) std::string_view direction() { - return Helper::arrayElement(directions); + return helper::arrayElement(directions); } std::string_view timeZone() { - return Helper::arrayElement(timeZones); + return helper::arrayElement(timeZones); } } diff --git a/src/modules/lorem/Lorem.cpp b/src/modules/lorem/Lorem.cpp index 6fdc9295c..2ddf02a24 100644 --- a/src/modules/lorem/Lorem.cpp +++ b/src/modules/lorem/Lorem.cpp @@ -15,7 +15,7 @@ namespace faker::lorem { std::string_view word() { - return Helper::arrayElement(loremWords); + return helper::arrayElement(loremWords); } std::string words(unsigned numberOfWords) diff --git a/src/modules/medicine/Medicine.cpp b/src/modules/medicine/Medicine.cpp index 0a2906739..d98130f33 100644 --- a/src/modules/medicine/Medicine.cpp +++ b/src/modules/medicine/Medicine.cpp @@ -9,17 +9,17 @@ namespace faker::medicine { std::string_view condition() { - return Helper::arrayElement(medicalConditions); + return helper::arrayElement(medicalConditions); } std::string_view medicalTest() { - return Helper::arrayElement(medicalTests); + return helper::arrayElement(medicalTests); } std::string_view specialty() { - return Helper::arrayElement(specialties); + return helper::arrayElement(specialties); } } diff --git a/src/modules/movie/Movie.cpp b/src/modules/movie/Movie.cpp index fda28c532..9ebacf0cb 100644 --- a/src/modules/movie/Movie.cpp +++ b/src/modules/movie/Movie.cpp @@ -9,32 +9,32 @@ namespace faker::movie { std::string_view genre() { - return Helper::arrayElement(movieGenres); + return helper::arrayElement(movieGenres); } std::string_view movieTitle() { - return Helper::arrayElement(movies); + return helper::arrayElement(movies); } std::string_view tvShow() { - return Helper::arrayElement(tvShows); + return helper::arrayElement(tvShows); } std::string_view director() { - return Helper::arrayElement(directors); + return helper::arrayElement(directors); } std::string_view actor() { - return Helper::arrayElement(actors); + return helper::arrayElement(actors); } std::string_view actress() { - return Helper::arrayElement(actresses); + return helper::arrayElement(actresses); } } diff --git a/src/modules/music/Music.cpp b/src/modules/music/Music.cpp index d68e11075..5f932226b 100644 --- a/src/modules/music/Music.cpp +++ b/src/modules/music/Music.cpp @@ -9,16 +9,16 @@ namespace faker::music { std::string_view artist() { - return Helper::arrayElement(artists); + return helper::arrayElement(artists); } std::string_view genre() { - return Helper::arrayElement(musicGenres); + return helper::arrayElement(musicGenres); } std::string_view songName() { - return Helper::arrayElement(songNames); + return helper::arrayElement(songNames); } } diff --git a/src/modules/number/Number.cpp b/src/modules/number/Number.cpp index 33e630041..891132779 100644 --- a/src/modules/number/Number.cpp +++ b/src/modules/number/Number.cpp @@ -1,10 +1 @@ #include "faker-cxx/Number.h" - -#include - -namespace faker::number -{ -std::random_device randomDevice; - -std::mt19937 pseudoRandomGenerator(randomDevice()); -} diff --git a/src/modules/person/Person.cpp b/src/modules/person/Person.cpp index 23980b416..042287399 100644 --- a/src/modules/person/Person.cpp +++ b/src/modules/person/Person.cpp @@ -187,7 +187,7 @@ std::string_view firstName(std::optional countryOpt, std::optional firstNames.insert(firstNames.end(), femalesFirstNames.begin(), femalesFirstNames.end()); } - return Helper::arrayElement(firstNames); + return helper::arrayElement(firstNames); } std::string_view lastName(std::optional countryOpt, std::optional sex) @@ -219,7 +219,7 @@ std::string_view lastName(std::optional countryOpt, std::optional lastNames.insert(lastNames.end(), femalesLastNames.begin(), femalesLastNames.end()); } - return Helper::arrayElement(lastNames); + return helper::arrayElement(lastNames); } std::string fullName(std::optional countryOpt, std::optional sex) @@ -228,14 +228,14 @@ std::string fullName(std::optional countryOpt, std::optional sex) const auto& peopleNames = getPeopleNamesByCountry(country); - std::vector> weightedElements; + std::vector> weightedElements; for (const auto& nameFormat : peopleNames.nameFormats) { weightedElements.push_back({nameFormat.weight, nameFormat.format}); } - const auto nameFormat = static_cast(Helper::weightedArrayElement(weightedElements)); + const auto nameFormat = static_cast(helper::weightedArrayElement(weightedElements)); const auto dataGeneratorsMapping = std::unordered_map>{ {"firstName", [&country, &sex]() { return std::string{firstName(country, sex)}; }}, @@ -280,7 +280,7 @@ std::string_view prefix(std::optional countryOpt, std::optional se return {}; } - return Helper::arrayElement(prefixes); + return helper::arrayElement(prefixes); } std::string_view suffix(std::optional countryOpt, std::optional sex) @@ -317,16 +317,16 @@ std::string_view suffix(std::optional countryOpt, std::optional se return {}; } - return Helper::arrayElement(suffixes); + return helper::arrayElement(suffixes); } std::string bio() { - const auto randomBioFormat = static_cast(Helper::arrayElement(bioFormats)); + const auto randomBioFormat = static_cast(helper::arrayElement(bioFormats)); const std::unordered_map> dataGeneratorsMapping{ - {"bio_part", []() { return Helper::arrayElement(bioParts); }}, - {"bio_supporter", []() { return Helper::arrayElement(bioSupporters); }}, + {"bio_part", []() { return helper::arrayElement(bioParts); }}, + {"bio_supporter", []() { return helper::arrayElement(bioSupporters); }}, {"noun", []() { return word::noun(); }}, {"emoji", []() { return internet::emoji(); }}}; @@ -337,7 +337,7 @@ std::string_view sex(std::optional languageOpt) { const std::vector sexes{"Male", "Female"}; - const auto chosenSex = Helper::arrayElement(sexes); + const auto chosenSex = helper::arrayElement(sexes); const auto sexEnum = chosenSex == "Male" ? Sex::Male : Sex::Female; @@ -355,7 +355,7 @@ std::string_view sex(std::optional languageOpt) std::string_view gender() { - return Helper::arrayElement(genders); + return helper::arrayElement(genders); } std::string jobTitle() @@ -365,41 +365,41 @@ std::string jobTitle() std::string_view jobDescriptor() { - return Helper::arrayElement(jobDescriptors); + return helper::arrayElement(jobDescriptors); } std::string_view jobArea() { - return Helper::arrayElement(jobAreas); + return helper::arrayElement(jobAreas); } std::string_view jobType() { - return Helper::arrayElement(jobTypes); + return helper::arrayElement(jobTypes); } std::string_view hobby() { - return Helper::arrayElement(hobbies); + return helper::arrayElement(hobbies); } std::string_view language() { - return Helper::arrayElement(languages); + return helper::arrayElement(languages); } std::string_view nationality() { - return Helper::arrayElement(nationalities); + return helper::arrayElement(nationalities); } std::string ssn(std::optional country) { - const auto ssnCountry = country ? *country : Helper::arrayElement(supportedSsnCountries); + const auto ssnCountry = country ? *country : helper::arrayElement(supportedSsnCountries); const auto& ssnFormat = std::string{ssnFormats.at(ssnCountry)}; - auto ssnWithoutRegexes = Helper::regexpStyleStringParse(ssnFormat); + auto ssnWithoutRegexes = helper::regexpStyleStringParse(ssnFormat); std::string ssn; @@ -428,12 +428,12 @@ std::string ssn(std::optional country) std::string_view westernZodiac() { - return Helper::arrayElement(westernZodiacs); + return helper::arrayElement(westernZodiacs); } std::string_view chineseZodiac() { - return Helper::arrayElement(chineseZodiacs); + return helper::arrayElement(chineseZodiacs); } std::string passport(std::optional countryOpt) diff --git a/src/modules/phone/Phone.cpp b/src/modules/phone/Phone.cpp index d3e3aa117..80a7d5943 100644 --- a/src/modules/phone/Phone.cpp +++ b/src/modules/phone/Phone.cpp @@ -10,8 +10,7 @@ namespace faker::phone { -std::unordered_map phoneNumberFormatMap = - createPhoneNumberFormatMap(); +std::unordered_map phoneNumberFormatMap = createPhoneNumberFormatMap(); std::string number(std::optional format) { @@ -19,14 +18,14 @@ std::string number(std::optional format) if (!format.has_value() || format->empty()) { - selectedFormat = Helper::arrayElement(phone::phoneNumbers); + selectedFormat = helper::arrayElement(phone::phoneNumbers); } else { selectedFormat = format.value(); } - return Helper::replaceSymbolWithNumber(selectedFormat); + return helper::replaceSymbolWithNumber(selectedFormat); } std::string number(PhoneNumberCountryFormat format) @@ -38,27 +37,27 @@ std::string number(PhoneNumberCountryFormat format) return phoneNumberFormatMap.at(PhoneNumberCountryFormat::Default); } - return Helper::replaceSymbolWithNumber(countryFormat); + return helper::replaceSymbolWithNumber(countryFormat); } std::string imei() { - return Helper::replaceCreditCardSymbols("##-######-######-L", '#'); + return helper::replaceCreditCardSymbols("##-######-######-L", '#'); } std::string_view platform() { - return Helper::arrayElement(phone::PhonePlatforms); + return helper::arrayElement(phone::PhonePlatforms); } std::string_view modelName() { - return Helper::arrayElement(phone::PhoneModelNames); + return helper::arrayElement(phone::PhoneModelNames); } std::string_view manufacturer() { - return Helper::arrayElement(phone::PhoneManufacturers); + return helper::arrayElement(phone::PhoneManufacturers); } std::unordered_map createPhoneNumberFormatMap() @@ -79,6 +78,6 @@ std::unordered_map createPhoneNumberForma std::string_view areaCode() { - return Helper::arrayElement(phone::areaCodes); + return helper::arrayElement(phone::areaCodes); } } diff --git a/src/modules/plant/Plant.cpp b/src/modules/plant/Plant.cpp index d87b8ee32..304452f7e 100644 --- a/src/modules/plant/Plant.cpp +++ b/src/modules/plant/Plant.cpp @@ -9,41 +9,41 @@ namespace faker::plant { std::string_view tree() { - return Helper::arrayElement(trees); + return helper::arrayElement(trees); } std::string_view flower() { - return Helper::arrayElement(flowers); + return helper::arrayElement(flowers); } std::string_view shrub() { - return Helper::arrayElement(shrubs); + return helper::arrayElement(shrubs); } std::string_view grass() { - return Helper::arrayElement(grasses); + return helper::arrayElement(grasses); } std::string_view fern() { - return Helper::arrayElement(ferns); + return helper::arrayElement(ferns); } std::string_view succulent() { - return Helper::arrayElement(succulents); + return helper::arrayElement(succulents); } std::string_view vine() { - return Helper::arrayElement(vines); + return helper::arrayElement(vines); } std::string_view plantType() { - return Helper::arrayElement(plantTypes); + return helper::arrayElement(plantTypes); } } diff --git a/src/modules/science/Science.cpp b/src/modules/science/Science.cpp index 950e4849b..a533e0a18 100644 --- a/src/modules/science/Science.cpp +++ b/src/modules/science/Science.cpp @@ -7,7 +7,7 @@ namespace faker { Science::ChemicalElement Science::chemicalElement() { - return Helper::arrayElement(chemicalElements); + return helper::arrayElement(chemicalElements); } Science::Unit Science::unit() @@ -19,32 +19,32 @@ Science::Unit Science::unit() units.insert(units.end(), currentUnits.begin(), currentUnits.end()); units.insert(units.end(), temperatureUnits.begin(), temperatureUnits.end()); - return Helper::arrayElement(units); + return helper::arrayElement(units); } Science::Unit Science::distanceUnit() { - return Helper::arrayElement(distanceUnits); + return helper::arrayElement(distanceUnits); } Science::Unit Science::timeUnit() { - return Helper::arrayElement(timeUnits); + return helper::arrayElement(timeUnits); } Science::Unit Science::massUnit() { - return Helper::arrayElement(massUnits); + return helper::arrayElement(massUnits); } Science::Unit Science::tempUnit() { - return Helper::arrayElement(temperatureUnits); + return helper::arrayElement(temperatureUnits); } Science::Unit Science::currentUnit() { - return Helper::arrayElement(currentUnits); + return helper::arrayElement(currentUnits); } } diff --git a/src/modules/sport/Sport.cpp b/src/modules/sport/Sport.cpp index ea0ccb0af..3f713b7e0 100644 --- a/src/modules/sport/Sport.cpp +++ b/src/modules/sport/Sport.cpp @@ -9,26 +9,26 @@ namespace faker::sport { std::string_view sportName() { - return Helper::arrayElement(sportNames); + return helper::arrayElement(sportNames); } std::string_view soccerTeam() { - return Helper::arrayElement(soccerTeams); + return helper::arrayElement(soccerTeams); } std::string_view maleAthlete() { - return Helper::arrayElement(maleAthletes); + return helper::arrayElement(maleAthletes); } std::string_view femaleAthlete() { - return Helper::arrayElement(femaleAthletes); + return helper::arrayElement(femaleAthletes); } std::string_view sportEvent() { - return Helper::arrayElement(sportEvents); + return helper::arrayElement(sportEvents); } } diff --git a/src/modules/string/String.cpp b/src/modules/string/String.cpp index f6c0c83c2..59318f73e 100644 --- a/src/modules/string/String.cpp +++ b/src/modules/string/String.cpp @@ -49,8 +49,7 @@ const std::map> hexCasingToCharSetMapping{ {HexCasing::Upper, hexUpperCharSet}, }; -std::string generateStringWithGuarantee(GuaranteeMap& guarantee, std::set& targetCharacters, - unsigned int length) +std::string generateStringWithGuarantee(GuaranteeMap& guarantee, std::set& targetCharacters, unsigned int length) { std::string output{}; output += generateAtLeastString(guarantee); @@ -65,7 +64,7 @@ std::string generateStringWithGuarantee(GuaranteeMap& guarantee, std::set& while (true) { // pick random char from targetCharacters - generatedChar = Helper::setElement(targetCharacters); + generatedChar = helper::setElement(targetCharacters); auto it = guarantee.find(generatedChar); // if no constraint on generated char, break out of loop @@ -87,7 +86,7 @@ std::string generateStringWithGuarantee(GuaranteeMap& guarantee, std::set& output += generatedChar; } // shuffle the generated string as the atleast string generated earlier was not generated randomly - output = Helper::shuffleString(output); + output = helper::shuffleString(output); return output; } } @@ -153,7 +152,7 @@ std::string fromCharacters(const std::string& characters, unsigned int length) for (unsigned i = 0; i < length; i++) { - result += Helper::arrayElement(characters); + result += helper::arrayElement(characters); } return result; @@ -192,7 +191,7 @@ std::string alpha(unsigned length, StringCasing casing, const std::string& exclu for (unsigned i = 0; i < length; i++) { - alpha += Helper::arrayElement(targetCharacters); + alpha += helper::arrayElement(targetCharacters); } return alpha; @@ -227,7 +226,7 @@ std::string alphanumeric(unsigned int length, StringCasing casing, const std::st for (unsigned i = 0; i < length; i++) { - alphanumeric += Helper::arrayElement(targetCharacters); + alphanumeric += helper::arrayElement(targetCharacters); } return alphanumeric; @@ -254,11 +253,11 @@ std::string numeric(unsigned int length, bool allowLeadingZeros) { if (i == 0 && allowLeadingZeros) { - alphanumeric += Helper::arrayElement(numericCharacters); + alphanumeric += helper::arrayElement(numericCharacters); } else { - alphanumeric += Helper::arrayElement(numericCharactersWithoutZero); + alphanumeric += helper::arrayElement(numericCharactersWithoutZero); } } @@ -308,7 +307,7 @@ std::string hexadecimal(unsigned int length, HexCasing casing, HexPrefix prefix) for (unsigned i = 0; i < length; i++) { - hexadecimal += Helper::arrayElement(hexadecimalCharacters); + hexadecimal += helper::arrayElement(hexadecimalCharacters); } return hexadecimal; diff --git a/src/modules/system/System.cpp b/src/modules/system/System.cpp index b9c8d15d1..38d2ac36d 100644 --- a/src/modules/system/System.cpp +++ b/src/modules/system/System.cpp @@ -100,7 +100,7 @@ std::string fileExtension(const std::optional& mimeType) } } - return Helper::arrayElement(extensions); + return helper::arrayElement(extensions); } else { @@ -113,7 +113,7 @@ std::string fileExtension(const std::optional& mimeType) std::vector extensions(extensionSet.begin(), extensionSet.end()); - return Helper::arrayElement(extensions); + return helper::arrayElement(extensions); } } @@ -137,7 +137,7 @@ std::string commonFileName(const std::optional& ext) std::string_view commonFileExtension() { - auto mimeType = Helper::arrayElement(commonMimeTypes); + auto mimeType = helper::arrayElement(commonMimeTypes); return extension(mimeType); } @@ -153,17 +153,17 @@ std::string_view mimeType() mimeTypeKeys.push_back(entry); } - return Helper::arrayElement(mimeTypeKeys); + return helper::arrayElement(mimeTypeKeys); } std::string_view fileType() { - return Helper::arrayElement(commonFileTypes); + return helper::arrayElement(commonFileTypes); } std::string_view directoryPath() { - return Helper::arrayElement(directoryPaths); + return helper::arrayElement(directoryPaths); } std::string filePath() @@ -182,8 +182,8 @@ std::string semver() std::string networkInterface(const std::optional& options) { - const auto defaultInterfaceType = Helper::arrayElement(commonInterfaceTypes); - const std::string defaultInterfaceSchema = std::string(Helper::objectKey(commonInterfaceSchemas)); + const auto defaultInterfaceType = helper::arrayElement(commonInterfaceTypes); + const std::string defaultInterfaceSchema = std::string(helper::objectKey(commonInterfaceSchemas)); std::string interfaceType = std::string(defaultInterfaceType); std::string interfaceSchema = defaultInterfaceSchema; @@ -211,8 +211,8 @@ std::string networkInterface(const std::optional& optio } else if (interfaceSchema == "slot") { - suffix = Helper::maybe([&]() { return "f" + digit(); }); - suffix += Helper::maybe([&]() { return "d" + digit(); }); + suffix = helper::maybe([&]() { return "f" + digit(); }); + suffix += helper::maybe([&]() { return "d" + digit(); }); } else if (interfaceSchema == "mac") { @@ -220,10 +220,10 @@ std::string networkInterface(const std::optional& optio } else if (interfaceSchema == "pci") { - prefix = Helper::maybe([&]() { return "P" + digit(); }); + prefix = helper::maybe([&]() { return "P" + digit(); }); suffix = digit() + "s" + digit(); - suffix += Helper::maybe([&]() { return "f" + digit(); }); - suffix += Helper::maybe([&]() { return "d" + digit(); }); + suffix += helper::maybe([&]() { return "f" + digit(); }); + suffix += helper::maybe([&]() { return "d" + digit(); }); } return prefix + interfaceType + std::string(commonInterfaceSchemas.at(interfaceSchema)) + suffix; @@ -253,12 +253,12 @@ std::string cron(const CronOptions& options) years = {std::to_string(number::integer(1970, 2099)), "*"}; } - const auto minute = Helper::arrayElement(minutes); - const auto hour = Helper::arrayElement(hours); - const auto day = Helper::arrayElement(days); - const auto month = Helper::arrayElement(months); - const auto dayOfWeek = Helper::arrayElement(daysOfWeek); - const auto year = Helper::arrayElement(years); + const auto minute = helper::arrayElement(minutes); + const auto hour = helper::arrayElement(hours); + const auto day = helper::arrayElement(days); + const auto month = helper::arrayElement(months); + const auto dayOfWeek = helper::arrayElement(daysOfWeek); + const auto year = helper::arrayElement(years); std::string standardExpression = minute + " " + hour + " " + day + " " + month + " " + dayOfWeek; @@ -271,6 +271,6 @@ std::string cron(const CronOptions& options) "@reboot", "@weekly", "@yearly"}; return (!includeNonStandard || datatype::boolean(0)) ? standardExpression : - Helper::arrayElement(nonStandardExpressions); + helper::arrayElement(nonStandardExpressions); } } diff --git a/src/modules/vehicle/Vehicle.cpp b/src/modules/vehicle/Vehicle.cpp index 0eb5ffecd..a856c3808 100644 --- a/src/modules/vehicle/Vehicle.cpp +++ b/src/modules/vehicle/Vehicle.cpp @@ -14,32 +14,32 @@ namespace faker::vehicle std::string_view bicycle() { - return Helper::arrayElement(bicycle_types); + return helper::arrayElement(bicycle_types); } std::string_view color() { - return Helper::arrayElement(vehicle_colors); + return helper::arrayElement(vehicle_colors); } std::string_view fuel() { - return Helper::arrayElement(fuel_types); + return helper::arrayElement(fuel_types); } std::string_view manufacturer() { - return Helper::arrayElement(manufacturers); + return helper::arrayElement(manufacturers); } std::string_view model() { - return Helper::arrayElement(models); + return helper::arrayElement(models); } std::string_view type() { - return Helper::arrayElement(vehicle_types); + return helper::arrayElement(vehicle_types); } std::string vehicleName() diff --git a/src/modules/videoGame/VideoGame.cpp b/src/modules/videoGame/VideoGame.cpp index 8424674f0..420ff6327 100644 --- a/src/modules/videoGame/VideoGame.cpp +++ b/src/modules/videoGame/VideoGame.cpp @@ -9,21 +9,21 @@ namespace faker::videogame { std::string_view gameTitle() { - return Helper::arrayElement(videoGameNames); + return helper::arrayElement(videoGameNames); } std::string_view genre() { - return Helper::arrayElement(videoGameGenres); + return helper::arrayElement(videoGameGenres); } std::string_view platform() { - return Helper::arrayElement(platforms); + return helper::arrayElement(platforms); } std::string_view studioName() { - return Helper::arrayElement(studioNames); + return helper::arrayElement(studioNames); } } diff --git a/src/modules/weather/Weather.cpp b/src/modules/weather/Weather.cpp index 1ded67c30..6048d545d 100644 --- a/src/modules/weather/Weather.cpp +++ b/src/modules/weather/Weather.cpp @@ -9,6 +9,6 @@ namespace faker::weather { std::string_view weatherDescription() { - return Helper::arrayElement(weatherDescriptions); + return helper::arrayElement(weatherDescriptions); } } diff --git a/src/modules/word/Word.cpp b/src/modules/word/Word.cpp index f0282aee8..b59690a97 100644 --- a/src/modules/word/Word.cpp +++ b/src/modules/word/Word.cpp @@ -16,7 +16,7 @@ auto sortedSizeArrayElement(std::optional length, It start, It end { if (!length) { - return Helper::arrayElement(start, end); + return helper::arrayElement(start, end); } size_t length_64 = *length; @@ -25,21 +25,26 @@ auto sortedSizeArrayElement(std::optional length, It start, It end if (lower_it == end) { - return Helper::arrayElement(start, end); + return helper::arrayElement(start, end); } - else + + if (lower_it->size() != length) { - if (lower_it->size() != length) - return Helper::arrayElement(start, end); + return helper::arrayElement(start, end); + } + + auto upper_it = lower_it; - auto upper_it = lower_it; - for (; upper_it != end; upper_it++) + for (; upper_it != end; upper_it++) + { + if (upper_it->size() != lower_it->size()) { - if (upper_it->size() != lower_it->size()) - break; + + break; } - return Helper::arrayElement(lower_it, upper_it); } + + return helper::arrayElement(lower_it, upper_it); } std::string_view sample(std::optional length) diff --git a/tests/modules/color/ColorTest.cpp b/tests/modules/color/ColorTest.cpp index a7dfcf3cd..ded954999 100644 --- a/tests/modules/color/ColorTest.cpp +++ b/tests/modules/color/ColorTest.cpp @@ -76,8 +76,9 @@ TEST_F(ColorTest, shouldGenerateHexColorWithoutAlpha) ASSERT_EQ(hexadecimal.size(), 7); ASSERT_EQ(prefix, "#"); - ASSERT_TRUE(std::ranges::any_of(hexNumber, [hexNumber](char hexNumberCharacter) - { return string::hexLowerCharacters.find(hexNumberCharacter) != std::string::npos; })); + ASSERT_TRUE( + std::ranges::any_of(hexNumber, [hexNumber](char hexNumberCharacter) + { return string::hexLowerCharacters.find(hexNumberCharacter) != std::string::npos; })); } TEST_F(ColorTest, shouldGenerateHexColorWithAlpha) @@ -89,8 +90,9 @@ TEST_F(ColorTest, shouldGenerateHexColorWithAlpha) ASSERT_EQ(hexadecimal.size(), 10); ASSERT_EQ(prefix, "0x"); - ASSERT_TRUE(std::ranges::any_of(hexNumber, [hexNumber](char hexNumberCharacter) - { return string::hexUpperCharacters.find(hexNumberCharacter) != std::string::npos; })); + ASSERT_TRUE( + std::ranges::any_of(hexNumber, [hexNumber](char hexNumberCharacter) + { return string::hexUpperCharacters.find(hexNumberCharacter) != std::string::npos; })); } TEST_F(ColorTest, shouldGenerateHslWithoutAlpha) diff --git a/tests/modules/company/CompanyTest.cpp b/tests/modules/company/CompanyTest.cpp index 1860898b4..29c54282e 100644 --- a/tests/modules/company/CompanyTest.cpp +++ b/tests/modules/company/CompanyTest.cpp @@ -25,8 +25,10 @@ TEST_F(CompanyTest, shouldGenerateCompanyName) const auto companyNameElements = StringHelper::split(companyName, " "); - std::vector expectedFirstNames(person::englishMaleFirstNames.begin(), person::englishMaleFirstNames.end()); - expectedFirstNames.insert(expectedFirstNames.end(), person::englishFemaleFirstNames.begin(), person::englishFemaleFirstNames.end()); + std::vector expectedFirstNames(person::englishMaleFirstNames.begin(), + person::englishMaleFirstNames.end()); + expectedFirstNames.insert(expectedFirstNames.end(), person::englishFemaleFirstNames.begin(), + person::englishFemaleFirstNames.end()); if (companyNameElements.size() == 2) { diff --git a/tests/modules/finance/FinanceTest.cpp b/tests/modules/finance/FinanceTest.cpp index 7a769ffca..c48f684da 100644 --- a/tests/modules/finance/FinanceTest.cpp +++ b/tests/modules/finance/FinanceTest.cpp @@ -230,12 +230,14 @@ TEST_F(FinanceTest, shouldGenerateIban) { const auto generatedIban = iban(); - ASSERT_TRUE(generatedIban.starts_with("AT") || generatedIban.starts_with("BE") || generatedIban.starts_with("BG") || generatedIban.starts_with("HR") || - generatedIban.starts_with("CY") || generatedIban.starts_with("CZ") || generatedIban.starts_with("DK") || generatedIban.starts_with("EE") || - generatedIban.starts_with("FI") || generatedIban.starts_with("FR") || generatedIban.starts_with("DE") || generatedIban.starts_with("GR") || - generatedIban.starts_with("HU") || generatedIban.starts_with("IE") || generatedIban.starts_with("IT") || generatedIban.starts_with("LV") || - generatedIban.starts_with("LT") || generatedIban.starts_with("LU") || generatedIban.starts_with("MT") || generatedIban.starts_with("NL") || - generatedIban.starts_with("PL") || generatedIban.starts_with("PT") || generatedIban.starts_with("RO") || generatedIban.starts_with("SK") || + ASSERT_TRUE(generatedIban.starts_with("AT") || generatedIban.starts_with("BE") || generatedIban.starts_with("BG") || + generatedIban.starts_with("HR") || generatedIban.starts_with("CY") || generatedIban.starts_with("CZ") || + generatedIban.starts_with("DK") || generatedIban.starts_with("EE") || generatedIban.starts_with("FI") || + generatedIban.starts_with("FR") || generatedIban.starts_with("DE") || generatedIban.starts_with("GR") || + generatedIban.starts_with("HU") || generatedIban.starts_with("IE") || generatedIban.starts_with("IT") || + generatedIban.starts_with("LV") || generatedIban.starts_with("LT") || generatedIban.starts_with("LU") || + generatedIban.starts_with("MT") || generatedIban.starts_with("NL") || generatedIban.starts_with("PL") || + generatedIban.starts_with("PT") || generatedIban.starts_with("RO") || generatedIban.starts_with("SK") || generatedIban.starts_with("SI") || generatedIban.starts_with("ES") || generatedIban.starts_with("SE")); } @@ -391,8 +393,9 @@ TEST_F(FinanceTest, shouldGenerateEthereumAddress) ASSERT_EQ(generatedEthereumAddress.size(), 42); ASSERT_EQ(prefix, "0x"); - ASSERT_TRUE(std::ranges::any_of(hexNumber, [hexNumber](char hexNumberCharacter) - { return string::hexLowerCharacters.find(hexNumberCharacter) != std::string::npos; })); + ASSERT_TRUE( + std::ranges::any_of(hexNumber, [hexNumber](char hexNumberCharacter) + { return string::hexLowerCharacters.find(hexNumberCharacter) != std::string::npos; })); } TEST_F(FinanceTest, shouldGenerateExpirationDate) @@ -428,10 +431,8 @@ TEST_P(FinanceBicTest, CheckBicGenerator) } INSTANTIATE_TEST_SUITE_P(TestBicGenerator, FinanceBicTest, - Values(BicCountry::Poland, BicCountry::UnitedStates, - BicCountry::UnitedKingdom, BicCountry::Germany, - BicCountry::Romania, BicCountry::France, BicCountry::Italy, - BicCountry::Spain, BicCountry::Netherlands, - BicCountry::India), + Values(BicCountry::Poland, BicCountry::UnitedStates, BicCountry::UnitedKingdom, + BicCountry::Germany, BicCountry::Romania, BicCountry::France, BicCountry::Italy, + BicCountry::Spain, BicCountry::Netherlands, BicCountry::India), [](const TestParamInfo& paramInfo) { return generatedBicTestName.at(paramInfo.param); }); diff --git a/tests/modules/git/GitTest.cpp b/tests/modules/git/GitTest.cpp index 10770a7f0..a96814093 100644 --- a/tests/modules/git/GitTest.cpp +++ b/tests/modules/git/GitTest.cpp @@ -59,7 +59,7 @@ TEST_F(GitTest, branchIssueNumTest) while (!numberAtFront) { branchElements = StringHelper::split(branch(testValue), "-"); - + try { number = std::stoi(branchElements[0]); diff --git a/tests/modules/helper/HelperTest.cpp b/tests/modules/helper/HelperTest.cpp index e37f2a387..a4609d181 100644 --- a/tests/modules/helper/HelperTest.cpp +++ b/tests/modules/helper/HelperTest.cpp @@ -12,8 +12,9 @@ #include "gtest/gtest.h" -using namespace faker; using namespace ::testing; +using namespace faker; +using namespace faker::helper; class HelperTest : public Test { @@ -21,9 +22,9 @@ class HelperTest : public Test TEST_F(HelperTest, ArrayElement) { - std::vector data{"hello", "world"}; + std::vector data{"hello", "world", "this", "is", "faker-cxx", "library"}; - const auto result = Helper::arrayElement(data); + const auto result = arrayElement(data); ASSERT_TRUE(std::ranges::any_of(data, [&result](const std::string& element) { return result == element; })); } @@ -32,14 +33,14 @@ TEST_F(HelperTest, ArrayElementEmptyData) { std::vector data{}; - ASSERT_THROW(Helper::arrayElement(data), std::invalid_argument); + ASSERT_THROW(arrayElement(data), std::invalid_argument); } TEST_F(HelperTest, ArrayElementSpan) { std::vector data{"hello", "world"}; - const auto result = Helper::arrayElement(std::span(data)); + const auto result = arrayElement(std::span(data)); ASSERT_TRUE(std::ranges::any_of(data, [&result](const std::string& element) { return result == element; })); } @@ -48,38 +49,38 @@ TEST_F(HelperTest, ArrayElementSpanEmptyData) { std::vector data{}; - ASSERT_THROW(Helper::arrayElement(std::span(data)), std::invalid_argument); + ASSERT_THROW(arrayElement(std::span(data)), std::invalid_argument); } TEST_F(HelperTest, WeightedArrayElement) { - std::vector> data{{1, "hello"}, {9, "world"}}; + std::vector> data{{1, "hello"}, {9, "world"}}; - const auto result = Helper::weightedArrayElement(data); + const auto result = weightedArrayElement(data); - ASSERT_TRUE(std::ranges::any_of(data, [&result](const Helper::WeightedElement& element) + ASSERT_TRUE(std::ranges::any_of(data, [&result](const WeightedElement& element) { return result == element.value; })); } TEST_F(HelperTest, WeightedArrayZeroSum) { - std::vector> data{{0, "hello"}, {0, "world"}}; + std::vector> data{{0, "hello"}, {0, "world"}}; - ASSERT_THROW(Helper::weightedArrayElement(data), std::invalid_argument); + ASSERT_THROW(weightedArrayElement(data), std::invalid_argument); } TEST_F(HelperTest, WeightedArrayEmptyData) { - std::vector> data{}; + std::vector> data{}; - ASSERT_THROW(Helper::weightedArrayElement(data), std::invalid_argument); + ASSERT_THROW(weightedArrayElement(data), std::invalid_argument); } TEST_F(HelperTest, ShuffleString) { std::string input = "Hello World!"; - const auto result = Helper::shuffleString(input); + const auto result = shuffleString(input); ASSERT_TRUE( std::ranges::all_of(input, [&result](char character) { return result.find(character) != std::string::npos; })); @@ -95,7 +96,7 @@ TEST_F(HelperTest, SetElement) for (int i = 0; i < 30; ++i) { - randomChars.push_back(Helper::setElement(chars)); + randomChars.push_back(setElement(chars)); } for (auto character : randomChars) @@ -108,14 +109,14 @@ TEST_F(HelperTest, SetElementEmptyData) { std::set chars{}; - ASSERT_THROW(Helper::setElement(chars), std::invalid_argument); + ASSERT_THROW(setElement(chars), std::invalid_argument); } TEST_F(HelperTest, ReplaceSymbolWithNumber) { std::string input = "123#456!"; - const auto result = Helper::replaceSymbolWithNumber(input); + const auto result = replaceSymbolWithNumber(input); ASSERT_TRUE(std::ranges::all_of(result, ::isdigit)); } @@ -124,14 +125,14 @@ TEST_F(HelperTest, RegexpStyleStringParse) { std::string input = "#{5}[2-4]test[1-3]"; - const auto result = Helper::regexpStyleStringParse(input); + const auto result = regexpStyleStringParse(input); ASSERT_EQ(result.size(), 11); } TEST_F(HelperTest, ReplaceCreditCardSymbols) { - const auto result_default = Helper::replaceCreditCardSymbols(); + const auto result_default = replaceCreditCardSymbols(); ASSERT_EQ(result_default.size(), 24); ASSERT_EQ(result_default[4], '-'); ASSERT_EQ(result_default[9], '-'); @@ -139,7 +140,7 @@ TEST_F(HelperTest, ReplaceCreditCardSymbols) ASSERT_EQ(result_default[19], '-'); const auto format_custom = "1234-[4-9]-##!!-L"; - const auto result_custom = Helper::replaceCreditCardSymbols(format_custom); + const auto result_custom = replaceCreditCardSymbols(format_custom); std::regex custom_format_regex("1234-[4-9]-\\d{2}[2-9]{2}-\\d"); ASSERT_TRUE(std::regex_match(result_custom, custom_format_regex)); @@ -155,44 +156,44 @@ TEST_F(HelperTest, ObjectKeyTest) std::unordered_map testMap = {{1, "one"}, {2, "two"}, {3, "three"}}; ASSERT_NO_THROW({ - int key = Helper::objectKey(testMap); + int key = objectKey(testMap); EXPECT_TRUE(testMap.find(key) != testMap.end()); }); std::unordered_map emptyMap; - ASSERT_THROW({ Helper::objectKey(emptyMap); }, std::runtime_error); + ASSERT_THROW({ objectKey(emptyMap); }, std::runtime_error); } TEST_F(HelperTest, MaybeString) { double highProbability = 1; - auto result = Helper::maybe([]() { return "Hello World!"; }, highProbability); + auto result = maybe([]() { return "Hello World!"; }, highProbability); EXPECT_EQ(result, "Hello World!"); double lowProbability = 0; - result = Helper::maybe([]() { return "Hello World!"; }, lowProbability); + result = maybe([]() { return "Hello World!"; }, lowProbability); EXPECT_EQ(result, ""); } TEST_F(HelperTest, MaybeInt) { double highProbability = 1; - auto result = Helper::maybe([]() { return 42; }, highProbability); + auto result = maybe([]() { return 42; }, highProbability); EXPECT_EQ(result, 42); double lowProbability = 0; - result = Helper::maybe([]() { return 42; }, lowProbability); + result = maybe([]() { return 42; }, lowProbability); EXPECT_EQ(result, 0); } TEST_F(HelperTest, MaybeDouble) { double highProbability = 1; - auto result = Helper::maybe([]() { return 3.14; }, highProbability); + auto result = maybe([]() { return 3.14; }, highProbability); EXPECT_EQ(result, 3.14); double lowProbability = 0; - result = Helper::maybe([]() { return 3.14; }, lowProbability); + result = maybe([]() { return 3.14; }, lowProbability); EXPECT_EQ(result, 0.0); } diff --git a/tests/modules/internet/InternetTest.cpp b/tests/modules/internet/InternetTest.cpp index b8deb1ed4..f137369a2 100644 --- a/tests/modules/internet/InternetTest.cpp +++ b/tests/modules/internet/InternetTest.cpp @@ -100,7 +100,8 @@ class InternetTest : public Test TEST_F(InternetTest, shouldGenerateUsername) { - std::vector firstNames(person::englishMaleFirstNames.begin(), person::englishMaleFirstNames.end()); + std::vector firstNames(person::englishMaleFirstNames.begin(), + person::englishMaleFirstNames.end()); firstNames.insert(firstNames.end(), person::englishFemaleFirstNames.begin(), person::englishFemaleFirstNames.end()); const auto generatedUsername = username(); @@ -124,7 +125,8 @@ TEST_F(InternetTest, shouldGenerateUsernameWithFirstNameProvided) TEST_F(InternetTest, shouldGenerateUsernameWithLastNameProvided) { - std::vector firstNames(person::englishMaleFirstNames.begin(), person::englishMaleFirstNames.end()); + std::vector firstNames(person::englishMaleFirstNames.begin(), + person::englishMaleFirstNames.end()); firstNames.insert(firstNames.end(), person::englishFemaleFirstNames.begin(), person::englishFemaleFirstNames.end()); const auto lastName = "Cieslar"; @@ -164,7 +166,8 @@ TEST_F(InternetTest, shouldGenerateInternationalUsernames) TEST_F(InternetTest, shouldGenerateEmail) { - std::vector firstNames(person::englishMaleFirstNames.begin(), person::englishMaleFirstNames.end()); + std::vector firstNames(person::englishMaleFirstNames.begin(), + person::englishMaleFirstNames.end()); firstNames.insert(firstNames.end(), person::englishFemaleFirstNames.begin(), person::englishFemaleFirstNames.end()); const auto generatedEmail = email(); @@ -206,7 +209,8 @@ TEST_F(InternetTest, shouldGenerateEmailWithFirstName) TEST_F(InternetTest, shouldGenerateEmailWithLastName) { - std::vector firstNames(person::englishMaleFirstNames.begin(), person::englishMaleFirstNames.end()); + std::vector firstNames(person::englishMaleFirstNames.begin(), + person::englishMaleFirstNames.end()); firstNames.insert(firstNames.end(), person::englishFemaleFirstNames.begin(), person::englishFemaleFirstNames.end()); const auto lastName = "Howard"; @@ -250,7 +254,8 @@ TEST_F(InternetTest, shouldGenerateEmailWithFullName) TEST_F(InternetTest, shouldGenerateEmailWithSpecifiedEmailHost) { - std::vector firstNames(person::englishMaleFirstNames.begin(), person::englishMaleFirstNames.end()); + std::vector firstNames(person::englishMaleFirstNames.begin(), + person::englishMaleFirstNames.end()); firstNames.insert(firstNames.end(), person::englishFemaleFirstNames.begin(), person::englishFemaleFirstNames.end()); const auto emailHost = "example.com"; @@ -273,7 +278,8 @@ TEST_F(InternetTest, shouldGenerateEmailWithSpecifiedEmailHost) TEST_F(InternetTest, shouldGenerateExampleEmail) { - std::vector firstNames(person::englishMaleFirstNames.begin(), person::englishMaleFirstNames.end()); + std::vector firstNames(person::englishMaleFirstNames.begin(), + person::englishMaleFirstNames.end()); firstNames.insert(firstNames.end(), person::englishFemaleFirstNames.begin(), person::englishFemaleFirstNames.end()); const auto email = exampleEmail(); @@ -315,7 +321,8 @@ TEST_F(InternetTest, shouldGenerateExampleEmailWithFirstName) TEST_F(InternetTest, shouldGenerateExampleEmailWithLastName) { - std::vector firstNames(person::englishMaleFirstNames.begin(), person::englishMaleFirstNames.end()); + std::vector firstNames(person::englishMaleFirstNames.begin(), + person::englishMaleFirstNames.end()); firstNames.insert(firstNames.end(), person::englishFemaleFirstNames.begin(), person::englishFemaleFirstNames.end()); const auto lastName = "Wilkinson"; @@ -628,13 +635,13 @@ TEST_F(InternetTest, shouldGenerateIpv6) ASSERT_TRUE(std::ranges::all_of(generatedIpv6Parts, [](const std::string& generatedIpv6Part) { return generatedIpv6Part.size() == 4; })); - ASSERT_TRUE(std::ranges::all_of(generatedIpv6Parts, - [](const std::string_view& generatedIpv6Part) - { - return std::ranges::all_of( - generatedIpv6Part, [](char hexCharacter) - { return string::hexLowerCharacters.find(hexCharacter) != std::string::npos; }); - })); + ASSERT_TRUE(std::ranges::all_of( + generatedIpv6Parts, + [](const std::string_view& generatedIpv6Part) + { + return std::ranges::all_of(generatedIpv6Part, [](char hexCharacter) + { return string::hexLowerCharacters.find(hexCharacter) != std::string::npos; }); + })); } TEST_F(InternetTest, MacDefaultSeparator) diff --git a/tests/modules/location/LocationTest.cpp b/tests/modules/location/LocationTest.cpp index a033bb3b9..3fdc140a0 100644 --- a/tests/modules/location/LocationTest.cpp +++ b/tests/modules/location/LocationTest.cpp @@ -164,8 +164,10 @@ TEST_P(LocationTest, shouldGenerateCity) const auto& generatedCityPrefix = generatedCityElements[0]; - std::vector firstNames(person::brazilianMaleFirstNames.begin(), person::brazilianMaleFirstNames.end()); - firstNames.insert(firstNames.end(), person::brazilianFemaleFirstNames.begin(), person::brazilianFemaleFirstNames.end()); + std::vector firstNames(person::brazilianMaleFirstNames.begin(), + person::brazilianMaleFirstNames.end()); + firstNames.insert(firstNames.end(), person::brazilianFemaleFirstNames.begin(), + person::brazilianFemaleFirstNames.end()); std::vector lastNames(person::brazilianLastNames.begin(), person::brazilianLastNames.end()); @@ -285,13 +287,15 @@ TEST_F(LocationTest, shouldGenerateUsaStreet) const auto& generatedFirstOrLastName = generatedStreetElements[0]; const auto& generatedStreetSuffix = generatedStreetElements[1]; - std::vector firstNames(person::englishMaleFirstNames.begin(), person::englishMaleFirstNames.end()); + std::vector firstNames(person::englishMaleFirstNames.begin(), + person::englishMaleFirstNames.end()); firstNames.insert(firstNames.end(), person::englishFemaleFirstNames.begin(), person::englishFemaleFirstNames.end()); ASSERT_EQ(generatedStreetElements.size(), 2); ASSERT_TRUE(std::ranges::any_of(firstNames, [&generatedFirstOrLastName](const std::string_view& firstName) { return firstName == generatedFirstOrLastName; }) || - std::ranges::any_of(person::englishLastNames, [&generatedFirstOrLastName](const std::string_view& lastName) + std::ranges::any_of(person::englishLastNames, + [&generatedFirstOrLastName](const std::string_view& lastName) { return lastName == generatedFirstOrLastName; })); ASSERT_TRUE(std::ranges::any_of(usaStreetSuffixes, [&generatedStreetSuffix](const std::string_view& streetSuffix) { return streetSuffix == generatedStreetSuffix; })); @@ -307,7 +311,8 @@ TEST_F(LocationTest, shouldGenerateUsaStreetAddress) const auto& generatedFirstOrLastName = generatedStreetAddressElements[1]; const auto& generatedStreetSuffix = generatedStreetAddressElements[2]; - std::vector firstNames(person::englishMaleFirstNames.begin(), person::englishMaleFirstNames.end()); + std::vector firstNames(person::englishMaleFirstNames.begin(), + person::englishMaleFirstNames.end()); firstNames.insert(firstNames.end(), person::englishFemaleFirstNames.begin(), person::englishFemaleFirstNames.end()); ASSERT_EQ(generatedStreetAddressElements.size(), 3); @@ -315,7 +320,8 @@ TEST_F(LocationTest, shouldGenerateUsaStreetAddress) ASSERT_TRUE(checkIfAllCharactersAreNumeric(generatedBuildingNumber)); ASSERT_TRUE(std::ranges::any_of(firstNames, [&generatedFirstOrLastName](const std::string_view& firstName) { return firstName == generatedFirstOrLastName; }) || - std::ranges::any_of(person::englishLastNames, [&generatedFirstOrLastName](const std::string_view& lastName) + std::ranges::any_of(person::englishLastNames, + [&generatedFirstOrLastName](const std::string_view& lastName) { return lastName == generatedFirstOrLastName; })); ASSERT_TRUE(std::ranges::any_of(usaStreetSuffixes, [&generatedStreetSuffix](const std::string_view& streetSuffix) { return streetSuffix == generatedStreetSuffix; })); @@ -357,7 +363,8 @@ TEST_F(LocationTest, shouldGenerateRussiaStreet) const auto& generatedStreetSuffix = StringHelper::join({generatedStreetElements.begin() + 1, generatedStreetElements.end()}); - std::vector firstNames(person::russianMaleFirstNames.begin(), person::russianMaleFirstNames.end()); + std::vector firstNames(person::russianMaleFirstNames.begin(), + person::russianMaleFirstNames.end()); firstNames.insert(firstNames.end(), person::russianFemaleFirstNames.begin(), person::russianFemaleFirstNames.end()); std::vector lastNames(person::russianMaleLastNames.begin(), person::russianMaleLastNames.end()); @@ -377,7 +384,8 @@ TEST_F(LocationTest, shouldGenerateRussiaStreetAddress) { const auto generatedStreetAddress = streetAddress(AddressCountry::Russia); - std::vector firstNames(person::russianMaleFirstNames.begin(), person::russianMaleFirstNames.end()); + std::vector firstNames(person::russianMaleFirstNames.begin(), + person::russianMaleFirstNames.end()); firstNames.insert(firstNames.end(), person::russianFemaleFirstNames.begin(), person::russianFemaleFirstNames.end()); std::vector lastNames(person::russianMaleLastNames.begin(), person::russianMaleLastNames.end()); @@ -536,11 +544,15 @@ TEST_F(LocationTest, shouldGenerateUkraineStreet) [&generatedStreetPrefix](const std::string_view& streetPrefix) { return streetPrefix == generatedStreetPrefix; })); - std::vector firstNames(person::ukrainianMaleFirstNames.begin(), person::ukrainianMaleFirstNames.end()); - firstNames.insert(firstNames.end(), person::ukrainianFemaleFirstNames.begin(), person::ukrainianFemaleFirstNames.end()); + std::vector firstNames(person::ukrainianMaleFirstNames.begin(), + person::ukrainianMaleFirstNames.end()); + firstNames.insert(firstNames.end(), person::ukrainianFemaleFirstNames.begin(), + person::ukrainianFemaleFirstNames.end()); - std::vector lastNames(person::ukrainianMalesLastNames.begin(), person::ukrainianMalesLastNames.end()); - firstNames.insert(firstNames.end(), person::ukrainianFemaleLastNames.begin(), person::ukrainianFemaleLastNames.end()); + std::vector lastNames(person::ukrainianMalesLastNames.begin(), + person::ukrainianMalesLastNames.end()); + firstNames.insert(firstNames.end(), person::ukrainianFemaleLastNames.begin(), + person::ukrainianFemaleLastNames.end()); ASSERT_TRUE(std::ranges::any_of(firstNames, [&generatedStreetSuffix](const std::string_view& firstName) { return generatedStreetSuffix.find(firstName) != std::string::npos; }) || @@ -557,11 +569,15 @@ TEST_F(LocationTest, shouldGenerateUkraineStreetAddress) ASSERT_TRUE(std::ranges::any_of(ukraineStreetPrefixes, [&generatedStreetAddress](const std::string_view& prefix) { return generatedStreetAddress.find(prefix) != std::string::npos; })); - std::vector firstNames(person::ukrainianMaleFirstNames.begin(), person::ukrainianMaleFirstNames.end()); - firstNames.insert(firstNames.end(), person::ukrainianFemaleFirstNames.begin(), person::ukrainianFemaleFirstNames.end()); + std::vector firstNames(person::ukrainianMaleFirstNames.begin(), + person::ukrainianMaleFirstNames.end()); + firstNames.insert(firstNames.end(), person::ukrainianFemaleFirstNames.begin(), + person::ukrainianFemaleFirstNames.end()); - std::vector lastNames(person::ukrainianMalesLastNames.begin(), person::ukrainianMalesLastNames.end()); - firstNames.insert(firstNames.end(), person::ukrainianFemaleLastNames.begin(), person::ukrainianFemaleLastNames.end()); + std::vector lastNames(person::ukrainianMalesLastNames.begin(), + person::ukrainianMalesLastNames.end()); + firstNames.insert(firstNames.end(), person::ukrainianFemaleLastNames.begin(), + person::ukrainianFemaleLastNames.end()); ASSERT_TRUE(std::ranges::any_of(firstNames, [&generatedStreetAddress](const std::string_view& firstName) { return generatedStreetAddress.find(firstName) != std::string::npos; }) || @@ -584,7 +600,8 @@ TEST_F(LocationTest, shouldGenerateItalyStreet) ASSERT_TRUE(std::ranges::any_of(italyStreetPrefixes, [&generatedStreetPrefix](const std::string_view& streetPrefix) { return streetPrefix == generatedStreetPrefix; })); - std::vector firstNames(person::italianMaleFirstNames.begin(), person::italianMaleFirstNames.end()); + std::vector firstNames(person::italianMaleFirstNames.begin(), + person::italianMaleFirstNames.end()); firstNames.insert(firstNames.end(), person::italianFemaleFirstNames.begin(), person::italianFemaleFirstNames.end()); ASSERT_TRUE(std::ranges::any_of(firstNames, [&generatedStreetSuffix](const std::string_view& firstName) @@ -600,12 +617,14 @@ TEST_F(LocationTest, shouldGenerateItalyStreetAddress) ASSERT_TRUE(std::ranges::any_of(italyStreetPrefixes, [&generatedStreetAddress](const std::string_view& prefix) { return generatedStreetAddress.find(prefix) != std::string::npos; })); - std::vector firstNames(person::italianMaleFirstNames.begin(), person::italianMaleFirstNames.end()); + std::vector firstNames(person::italianMaleFirstNames.begin(), + person::italianMaleFirstNames.end()); firstNames.insert(firstNames.end(), person::italianFemaleFirstNames.begin(), person::italianFemaleFirstNames.end()); ASSERT_TRUE(std::ranges::any_of(firstNames, [&generatedStreetAddress](const std::string_view& firstName) { return generatedStreetAddress.find(firstName) != std::string::npos; }) || - std::ranges::any_of(person::italianLastNames, [&generatedStreetAddress](const std::string_view& lastName) + std::ranges::any_of(person::italianLastNames, + [&generatedStreetAddress](const std::string_view& lastName) { return generatedStreetAddress.find(lastName) != std::string::npos; })); } @@ -645,8 +664,10 @@ TEST_F(LocationTest, shouldGenerateAustraliaStreet) { const auto generatedStreet = street(AddressCountry::Australia); - std::vector firstNames(person::australianMaleFirstNames.begin(), person::australianMaleFirstNames.end()); - firstNames.insert(firstNames.end(), person::australianFemaleFirstNames.begin(), person::australianFemaleFirstNames.end()); + std::vector firstNames(person::australianMaleFirstNames.begin(), + person::australianMaleFirstNames.end()); + firstNames.insert(firstNames.end(), person::australianFemaleFirstNames.begin(), + person::australianFemaleFirstNames.end()); ASSERT_TRUE((std::ranges::any_of(firstNames, [&generatedStreet](const std::string_view& firstName) { return generatedStreet.find(firstName) != std::string::npos; }) || @@ -666,19 +687,21 @@ TEST_F(LocationTest, shouldGenerateAustraliaStreetAddress) const auto& generatedStreetSuffix = StringHelper::join({generatedStreetAddressElements.begin() + 1, generatedStreetAddressElements.end()}); - std::vector firstNames(person::australianMaleFirstNames.begin(), person::australianMaleFirstNames.end()); - firstNames.insert(firstNames.end(), person::australianFemaleFirstNames.begin(), person::australianFemaleFirstNames.end()); + std::vector firstNames(person::australianMaleFirstNames.begin(), + person::australianMaleFirstNames.end()); + firstNames.insert(firstNames.end(), person::australianFemaleFirstNames.begin(), + person::australianFemaleFirstNames.end()); ASSERT_TRUE(!generatedBuildingNumber.empty() && generatedBuildingNumber.size() <= 4); ASSERT_TRUE(checkIfAllCharactersAreNumeric(generatedBuildingNumber)); - ASSERT_TRUE((std::ranges::any_of(firstNames, [&generatedStreetSuffix](const std::string_view& firstName) - { return generatedStreetSuffix.find(firstName) != std::string::npos; }) || - std::ranges::any_of(person::australianLastNames, [&generatedStreetSuffix](const std::string_view& lastName) - { return generatedStreetSuffix.find(lastName) != std::string::npos; })) && - std::ranges::any_of(australiaStreetSuffixes, - [&generatedStreetSuffix](const std::string_view& streetSuffix) - { return generatedStreetSuffix.find(streetSuffix) != std::string::npos; })); + ASSERT_TRUE( + (std::ranges::any_of(firstNames, [&generatedStreetSuffix](const std::string_view& firstName) + { return generatedStreetSuffix.find(firstName) != std::string::npos; }) || + std::ranges::any_of(person::australianLastNames, [&generatedStreetSuffix](const std::string_view& lastName) + { return generatedStreetSuffix.find(lastName) != std::string::npos; })) && + std::ranges::any_of(australiaStreetSuffixes, [&generatedStreetSuffix](const std::string_view& streetSuffix) + { return generatedStreetSuffix.find(streetSuffix) != std::string::npos; })); } TEST_F(LocationTest, shouldGenerateIndiaStreetAddress) @@ -718,7 +741,8 @@ TEST_F(LocationTest, shouldGenerateSpainStreet) { const auto generatedStreet = street(AddressCountry::Spain); - std::vector firstNames(person::spanishMaleFirstNames.begin(), person::spanishMaleFirstNames.end()); + std::vector firstNames(person::spanishMaleFirstNames.begin(), + person::spanishMaleFirstNames.end()); firstNames.insert(firstNames.end(), person::spanishFemaleFirstNames.begin(), person::spanishFemaleFirstNames.end()); ASSERT_TRUE((std::ranges::any_of(firstNames, [&generatedStreet](const std::string_view& firstName) @@ -736,12 +760,14 @@ TEST_F(LocationTest, shouldGenerateSpainStreetAddress) ASSERT_TRUE(std::ranges::any_of(spainStreetSuffixes, [&generatedStreetAddress](const std::string_view& suffix) { return generatedStreetAddress.find(suffix) != std::string::npos; })); - std::vector firstNames(person::spanishMaleFirstNames.begin(), person::spanishMaleFirstNames.end()); + std::vector firstNames(person::spanishMaleFirstNames.begin(), + person::spanishMaleFirstNames.end()); firstNames.insert(firstNames.end(), person::spanishFemaleFirstNames.begin(), person::spanishFemaleFirstNames.end()); ASSERT_TRUE(std::ranges::any_of(firstNames, [&generatedStreetAddress](const std::string_view& firstName) { return generatedStreetAddress.find(firstName) != std::string::npos; }) || - std::ranges::any_of(person::spanishLastNames, [&generatedStreetAddress](const std::string_view& lastName) + std::ranges::any_of(person::spanishLastNames, + [&generatedStreetAddress](const std::string_view& lastName) { return generatedStreetAddress.find(lastName) != std::string::npos; })); } @@ -754,7 +780,8 @@ TEST_F(LocationTest, shouldGenerateFinlandStreet) const auto& generatedStreetPrefix = generatedStreetElements[0]; const auto& generatedStreetSuffix = generatedStreetElements[1]; - std::vector firstNames(person::finnishMaleFirstNames.begin(), person::finnishMaleFirstNames.end()); + std::vector firstNames(person::finnishMaleFirstNames.begin(), + person::finnishMaleFirstNames.end()); firstNames.insert(firstNames.end(), person::finnishFemaleFirstNames.begin(), person::finnishFemaleFirstNames.end()); ASSERT_GE(generatedStreetElements.size(), 2); @@ -776,12 +803,14 @@ TEST_F(LocationTest, shouldGenerateFinlandStreetAddress) ASSERT_TRUE(std::ranges::any_of(finlandStreetSuffixes, [&generatedStreetAddress](const std::string_view& suffix) { return generatedStreetAddress.find(suffix) != std::string::npos; })); - std::vector firstNames(person::finnishMaleFirstNames.begin(), person::finnishMaleFirstNames.end()); + std::vector firstNames(person::finnishMaleFirstNames.begin(), + person::finnishMaleFirstNames.end()); firstNames.insert(firstNames.end(), person::finnishFemaleFirstNames.begin(), person::finnishFemaleFirstNames.end()); ASSERT_TRUE(std::ranges::any_of(firstNames, [&generatedStreetAddress](const std::string_view& firstName) { return generatedStreetAddress.find(firstName) != std::string::npos; }) || - std::ranges::any_of(person::finnishLastNames, [&generatedStreetAddress](const std::string_view& lastName) + std::ranges::any_of(person::finnishLastNames, + [&generatedStreetAddress](const std::string_view& lastName) { return generatedStreetAddress.find(lastName) != std::string::npos; })); } diff --git a/tests/modules/lorem/LoremTest.cpp b/tests/modules/lorem/LoremTest.cpp index bc858c478..ba06b15c6 100644 --- a/tests/modules/lorem/LoremTest.cpp +++ b/tests/modules/lorem/LoremTest.cpp @@ -32,7 +32,6 @@ TEST_F(LoremTest, shouldGenerateWords) const auto generatedWords = words(numberOfWords); const auto separatedWords = faker::StringHelper::split(generatedWords, " "); - ASSERT_EQ(separatedWords.size(), numberOfWords); ASSERT_TRUE(std::ranges::all_of( diff --git a/tests/modules/system/SystemTest.cpp b/tests/modules/system/SystemTest.cpp index f0350227a..485585c81 100644 --- a/tests/modules/system/SystemTest.cpp +++ b/tests/modules/system/SystemTest.cpp @@ -191,8 +191,6 @@ TEST_F(SystemTest, FileTypeTest) const auto fileTypeResult = fileType(); - std::cout << fileTypeResult << std::endl; - bool isValidFileType = std::ranges::find(expectedTypes, fileTypeResult) != expectedTypes.end(); EXPECT_TRUE(isValidFileType);