From e139df3e3d77a30649c78a86ef9a7ed797063ccb Mon Sep 17 00:00:00 2001 From: Guru Mehar Rachaputi Date: Tue, 25 Jun 2024 06:57:20 +0200 Subject: [PATCH 1/2] refactor: number module migrate - number module migration from class to functions within phone namespace - modified reference to functions from number module in all dependent modules Signed-off-by: Guru Mehar Rachaputi --- include/faker-cxx/Helper.h | 12 +++--- include/faker-cxx/Number.h | 23 ++++------ src/modules/airline/Airline.cpp | 6 +-- src/modules/color/Color.cpp | 56 ++++++++++++------------- src/modules/company/Company.cpp | 2 +- src/modules/datatype/Datatype.cpp | 6 +-- src/modules/date/Date.cpp | 16 +++---- src/modules/finance/Finance.cpp | 6 +-- src/modules/git/Git.cpp | 10 ++--- src/modules/helper/Helper.cpp | 8 ++-- src/modules/image/Image.cpp | 4 +- src/modules/internet/Internet.cpp | 20 ++++----- src/modules/location/Location.cpp | 4 +- src/modules/lorem/Lorem.cpp | 6 +-- src/modules/number/Number.cpp | 6 +-- src/modules/person/Person.cpp | 2 +- src/modules/string/String.cpp | 10 ++--- src/modules/system/System.cpp | 24 +++++------ src/modules/vehicle/Vehicle.cpp | 2 +- src/modules/word/Word.cpp | 2 +- tests/modules/git/GitTest.cpp | 2 +- tests/modules/internet/InternetTest.cpp | 2 +- tests/modules/number/NumberTest.cpp | 15 +++---- 23 files changed, 120 insertions(+), 124 deletions(-) diff --git a/include/faker-cxx/Helper.h b/include/faker-cxx/Helper.h index 9bf118d29..f108ed67f 100644 --- a/include/faker-cxx/Helper.h +++ b/include/faker-cxx/Helper.h @@ -39,7 +39,7 @@ class Helper throw std::invalid_argument{"Data is empty."}; } - const auto index = Number::integer(data.size() - 1); + const auto index = faker::number::integer(data.size() - 1); return data[index]; } @@ -52,7 +52,7 @@ class Helper throw std::invalid_argument{"Data is empty."}; } - const auto index = Number::integer(data.size() - 1); + const auto index = faker::number::integer(data.size() - 1); return data[index]; } @@ -67,7 +67,7 @@ class Helper throw std::invalid_argument{"Range [start,end) is empty."}; } - const std::integral auto index = Number::integer(size - 1); + const std::integral auto index = faker::number::integer(size - 1); return start[index]; } @@ -93,7 +93,7 @@ class Helper throw std::invalid_argument{"Data is empty."}; } - const auto index = Number::integer(data.size() - 1); + const auto index = faker::number::integer(data.size() - 1); return data[index]; } @@ -119,7 +119,7 @@ class Helper throw std::invalid_argument{"Data is empty."}; } - const auto index = Number::integer(data.size() - 1); + const auto index = faker::number::integer(data.size() - 1); return *(data.begin() + index); } @@ -191,7 +191,7 @@ class Helper throw std::invalid_argument{"Sum of weights is zero."}; } - const std::integral auto targetWeightValue = Number::integer(1, sumOfWeights); + const std::integral auto targetWeightValue = faker::number::integer(1, sumOfWeights); unsigned currentSum = 0; diff --git a/include/faker-cxx/Number.h b/include/faker-cxx/Number.h index ac60f1020..edfa8de0e 100644 --- a/include/faker-cxx/Number.h +++ b/include/faker-cxx/Number.h @@ -4,11 +4,11 @@ #include #include -namespace faker +namespace faker::number { -class Number -{ -public: + namespace{ + std::mt19937 pseudoRandomGenerator; + } /** * @brief Generates a random integer number in the given range, bounds included. * @@ -22,7 +22,7 @@ class Number * @return T a random integer number */ template - static I integer(I min, I max) + I integer(I min, I max) { if (min > max) { @@ -47,9 +47,9 @@ class Number * @return T a random integer number */ template - static I integer(I max) + I integer(I max) { - return Number::integer(static_cast(0), max); + return integer(static_cast(0), max); } /** @@ -65,7 +65,7 @@ class Number * @return F a random decimal number. */ template - static F decimal(F min, F max) + F decimal(F min, F max) { if (min > max) { @@ -90,13 +90,8 @@ class Number * @return F, a random decimal number. */ template - static F decimal(F max) + F decimal(F max) { return decimal(static_cast(0.), max); } - -private: - static std::random_device randomDevice; - static std::mt19937 pseudoRandomGenerator; -}; } diff --git a/src/modules/airline/Airline.cpp b/src/modules/airline/Airline.cpp index 5c285ba00..16c1d9894 100644 --- a/src/modules/airline/Airline.cpp +++ b/src/modules/airline/Airline.cpp @@ -32,7 +32,7 @@ Airport airport() std::string seat(AircraftType aircraftType) { - return std::to_string(Number::integer(1, aircraftTypeMaxRows.at(aircraftType))) + + return std::to_string(faker::number::integer(1, aircraftTypeMaxRows.at(aircraftType))) + Helper::arrayElement(aircraftTypeSeatLetters.at(aircraftType)); } @@ -60,9 +60,9 @@ std::string flightNumberByRange(bool addLeadingZeros, Range length) { if (addLeadingZeros) { - return String::numeric(Number::integer(length.min, length.max), true); + return String::numeric(faker::number::integer(length.min, length.max), true); } - return String::numeric(Number::integer(length.min, length.max), false); + return String::numeric(faker::number::integer(length.min, length.max), false); } } diff --git a/src/modules/color/Color.cpp b/src/modules/color/Color.cpp index edf2cf1cf..f330baa0b 100644 --- a/src/modules/color/Color.cpp +++ b/src/modules/color/Color.cpp @@ -19,16 +19,16 @@ std::string_view name() std::string rgb(bool includeAlpha) { - const std::integral auto red = Number::integer(255); - const std::integral auto green = Number::integer(255); - const std::integral auto blue = Number::integer(255); + const std::integral auto red = faker::number::integer(255); + const std::integral auto green = faker::number::integer(255); + const std::integral auto blue = faker::number::integer(255); if (!includeAlpha) { return FormatHelper::format("rgb({}, {}, {})", red, green, blue); } - std::floating_point auto alpha = Number::decimal(1.0); + std::floating_point auto alpha = faker::number::decimal(1.0); return FormatHelper::format("rgba({}, {}, {}, {:.2f})", red, green, blue, alpha); } @@ -40,78 +40,78 @@ std::string hex(HexCasing casing, HexPrefix prefix, bool includeAlpha) std::string hsl(bool include_alpha) { - std::integral auto hue = Number::integer(360); - std::integral auto saturation = Number::integer(100); - std::integral auto lightness = Number::integer(100); + std::integral auto hue = faker::number::integer(360); + std::integral auto saturation = faker::number::integer(100); + std::integral auto lightness = faker::number::integer(100); if (!include_alpha) { return FormatHelper::format("hsl({}, {}, {})", hue, saturation, lightness); } - std::floating_point auto alpha = Number::decimal(1.0); + std::floating_point auto alpha = faker::number::decimal(1.0); return FormatHelper::format("hsla({}, {}, {}, {:.2f})", hue, saturation, lightness, alpha); } std::string lch(bool include_alpha) { - std::integral auto luminance = Number::integer(100); - std::integral auto chroma = Number::integer(100); - std::integral auto hue = Number::integer(360); + std::integral auto luminance = faker::number::integer(100); + std::integral auto chroma = faker::number::integer(100); + std::integral auto hue = faker::number::integer(360); if (!include_alpha) { return FormatHelper::format("lch({}, {}, {})", luminance, chroma, hue); } - std::floating_point auto alpha = Number::decimal(1.0); + std::floating_point auto alpha = faker::number::decimal(1.0); return FormatHelper::format("lcha({}, {}, {}, {:.2f})", luminance, chroma, hue, alpha); } std::string cmyk() { - std::floating_point auto cyan = Number::decimal(1.); - std::floating_point auto magenta = Number::decimal(1.); - std::floating_point auto yellow = Number::decimal(1.); - std::floating_point auto key = Number::decimal(1.); + std::floating_point auto cyan = faker::number::decimal(1.); + std::floating_point auto magenta = faker::number::decimal(1.); + std::floating_point auto yellow = faker::number::decimal(1.); + std::floating_point auto key = faker::number::decimal(1.); return FormatHelper::format("cmyk({:.2f}, {:.2f}, {:.2f}, {:.2f})", cyan, magenta, yellow, key); } std::string lab() { - std::floating_point auto lightness = Number::decimal(100.0); - std::floating_point auto red_green = Number::decimal(-128.0, 128.0); - std::floating_point auto blue_yellow = Number::decimal(-128.0, 128.0); + std::floating_point auto lightness = faker::number::decimal(100.0); + std::floating_point auto red_green = faker::number::decimal(-128.0, 128.0); + std::floating_point auto blue_yellow = faker::number::decimal(-128.0, 128.0); return FormatHelper::format("lab({:.2f}, {:.2f}, {:.2f})", lightness, red_green, blue_yellow); } std::string hsb() { - std::integral auto hue = Number::integer(360); - std::integral auto saturation = Number::integer(100); - std::integral auto brightness = Number::integer(100); + std::integral auto hue = faker::number::integer(360); + std::integral auto saturation = faker::number::integer(100); + std::integral auto brightness = faker::number::integer(100); return FormatHelper::format("hsb({}, {}, {})", hue, saturation, brightness); } std::string hsv() { - std::integral auto hue = Number::integer(360); - std::integral auto saturation = Number::integer(100); - std::integral auto value = Number::integer(100); + std::integral auto hue = faker::number::integer(360); + std::integral auto saturation = faker::number::integer(100); + std::integral auto value = faker::number::integer(100); return FormatHelper::format("hsv({}, {}, {})", hue, saturation, value); } std::string yuv() { - std::integral auto luminance = Number::integer(255); - std::integral auto chrominance_blue = Number::integer(255); - std::integral auto chrominance_red = Number::integer(255); + std::integral auto luminance = faker::number::integer(255); + std::integral auto chrominance_blue = faker::number::integer(255); + std::integral auto chrominance_red = faker::number::integer(255); return FormatHelper::format("yuv({}, {}, {})", luminance, chrominance_blue, chrominance_red); } diff --git a/src/modules/company/Company.cpp b/src/modules/company/Company.cpp index 5f0a6d582..82e322ef4 100644 --- a/src/modules/company/Company.cpp +++ b/src/modules/company/Company.cpp @@ -15,7 +15,7 @@ std::string name() { std::string companyName; - switch (Number::integer(3)) + switch (faker::number::integer(3)) { case 0: companyName = FormatHelper::format("{} {}", Person::lastName(), Helper::arrayElement(companySuffixes)); diff --git a/src/modules/datatype/Datatype.cpp b/src/modules/datatype/Datatype.cpp index 260896d11..290c43510 100644 --- a/src/modules/datatype/Datatype.cpp +++ b/src/modules/datatype/Datatype.cpp @@ -8,7 +8,7 @@ namespace faker::datatype { bool boolean() { - return Number::decimal(0.f, 1.f) > 0.5f; + return faker::number::decimal(0.f, 1.f) > 0.5f; } bool boolean(double probability) @@ -27,9 +27,9 @@ bool boolean(double probability) return true; } - return Number::decimal(0., 1.) < prob; + return faker::number::decimal(0., 1.) < prob; } - return Number::decimal(0., 1.) < 0.5; + return faker::number::decimal(0., 1.) < 0.5; } } diff --git a/src/modules/date/Date.cpp b/src/modules/date/Date.cpp index b39898098..9e3e75548 100644 --- a/src/modules/date/Date.cpp +++ b/src/modules/date/Date.cpp @@ -47,7 +47,7 @@ std::string betweenDate(const auto& from, const auto& to, DateFormat dateFormat) const auto size = std::chrono::duration_cast(to - from).count(); - const auto randomDateWithinRange = from + std::chrono::seconds{Number::integer(size - 1)}; + const auto randomDateWithinRange = from + std::chrono::seconds{faker::number::integer(size - 1)}; return serializeTimePoint(randomDateWithinRange, dateFormat); } @@ -155,27 +155,27 @@ unsigned int year() unsigned minYear = 1950; unsigned maxYear = 2050; - return Number::integer(minYear, maxYear); + return faker::number::integer(minYear, maxYear); } unsigned int month() { - return Number::integer(1, 12); + return faker::number::integer(1, 12); } unsigned int hour() { - return Number::integer(0, 23); + return faker::number::integer(0, 23); } unsigned int minute() { - return Number::integer(0, 59); + return faker::number::integer(0, 59); } unsigned int second() { - return Number::integer(0, 59); + return faker::number::integer(0, 59); } std::string time() @@ -185,12 +185,12 @@ std::string time() unsigned int dayOfMonth() { - return Number::integer(1, 31); + return faker::number::integer(1, 31); } unsigned dayOfWeek() { - return Number::integer(1, 7); + return faker::number::integer(1, 7); } std::string_view timezoneRandom() diff --git a/src/modules/finance/Finance.cpp b/src/modules/finance/Finance.cpp index 5d656dc43..533294e7a 100644 --- a/src/modules/finance/Finance.cpp +++ b/src/modules/finance/Finance.cpp @@ -44,7 +44,7 @@ std::string_view Finance::accountType() std::string Finance::amount(double min, double max, Precision precision, const std::string& symbol) { - const std::floating_point auto generatedNumber = Number::decimal(min, max); + const std::floating_point auto generatedNumber = faker::number::decimal(min, max); std::string result{symbol}; @@ -139,7 +139,7 @@ std::string Finance::creditCardCvv() std::string Finance::bitcoinAddress() { - const unsigned addressLength = Number::integer(26u, 33u); + const unsigned addressLength = faker::number::integer(26u, 33u); auto address = Helper::arrayElement(std::vector{"1", "3"}); @@ -150,7 +150,7 @@ std::string Finance::bitcoinAddress() std::string Finance::litecoinAddress() { - const unsigned addressLength = Number::integer(26u, 33u); + const unsigned addressLength = faker::number::integer(26u, 33u); auto address = Helper::arrayElement(std::vector{"L", "M", "3"}); diff --git a/src/modules/git/Git.cpp b/src/modules/git/Git.cpp index 80f64b6b9..4f2191ccf 100644 --- a/src/modules/git/Git.cpp +++ b/src/modules/git/Git.cpp @@ -20,14 +20,14 @@ namespace faker::git std::string branch(unsigned maxIssueNum) { - switch (Number::integer(1, 3)) + switch (faker::number::integer(1, 3)) { case 1: return FormatHelper::format("{}-{}", word::verb(), word::noun()); case 2: return FormatHelper::format("{}-{}-{}", word::verb(), word::adjective(), word::noun()); default: - return FormatHelper::format("{}-{}-{}-{}", Number::integer(unsigned(1), maxIssueNum), word::verb(), + return FormatHelper::format("{}-{}-{}-{}", faker::number::integer(unsigned(1), maxIssueNum), word::verb(), word::adjective(), word::noun()); } } @@ -48,11 +48,11 @@ std::string commitDate(unsigned years) const auto time = StringHelper::split(restSplit[1], "Z")[0]; - int timeZone = Number::integer(0, 12); + int timeZone = faker::number::integer(0, 12); std::string timeZoneString; - if (Number::integer(0, 1)) + if (faker::number::integer(0, 1)) { timeZoneString += "-"; } @@ -112,7 +112,7 @@ std::string commitEntry(std::optional dateYears, std::optional(token.position())) + StringHelper::repeat(token[1], repetitions) + data.substr(static_cast(token.position() + token.length())); @@ -112,7 +112,7 @@ std::string Helper::regexpStyleStringParse(const std::string& input) } data = data.substr(0, static_cast(token.position())) + - std::to_string(Number::integer(min, max)) + + std::to_string(faker::number::integer(min, max)) + data.substr(static_cast(token.position() + token.length())); } diff --git a/src/modules/image/Image.cpp b/src/modules/image/Image.cpp index 2c5a9f193..9490ffefc 100644 --- a/src/modules/image/Image.cpp +++ b/src/modules/image/Image.cpp @@ -39,12 +39,12 @@ std::string Image::imageUrl(unsigned int width, unsigned int height, std::option std::string Image::githubAvatarUrl() { - return FormatHelper::format("https://avatars.githubusercontent.com/u/{}", Number::integer(100000000)); + return FormatHelper::format("https://avatars.githubusercontent.com/u/{}", faker::number::integer(100000000)); } std::string Image::dimensions() { - return FormatHelper::format("{}x{}", Number::integer(1, 32720), Number::integer(1, 17280)); + return FormatHelper::format("{}x{}", faker::number::integer(1, 32720), faker::number::integer(1, 17280)); } std::string_view Image::type() diff --git a/src/modules/internet/Internet.cpp b/src/modules/internet/Internet.cpp index f3cc2dc82..63eeb10d0 100644 --- a/src/modules/internet/Internet.cpp +++ b/src/modules/internet/Internet.cpp @@ -93,10 +93,10 @@ std::string Internet::username(std::optional firstNameInit, std::op std::string username; - switch (Number::integer(2)) + switch (faker::number::integer(2)) { case 0: - username = FormatHelper::format("{}{}{}", firstName, lastName, Number::integer(999)); + username = FormatHelper::format("{}{}{}", firstName, lastName, faker::number::integer(999)); break; case 1: username = FormatHelper::format("{}{}{}", firstName, @@ -105,7 +105,7 @@ std::string Internet::username(std::optional firstNameInit, std::op case 2: username = FormatHelper::format("{}{}{}{}", firstName, Helper::arrayElement(std::vector{".", "_", ""}), - lastName, Number::integer(99)); + lastName, faker::number::integer(99)); break; } @@ -230,20 +230,20 @@ std::string Internet::ipv4(const IPv4Class& ipv4class) { std::array sectors{}; - sectors[3] = Number::integer(ipv4SectorUpperBound); - sectors[2] = Number::integer(ipv4SectorUpperBound); + sectors[3] = faker::number::integer(ipv4SectorUpperBound); + sectors[2] = faker::number::integer(ipv4SectorUpperBound); switch (ipv4class) { case IPv4Class::A: { - sectors[1] = Number::integer(ipv4SectorUpperBound); + sectors[1] = faker::number::integer(ipv4SectorUpperBound); sectors[0] = ipv4ClassAFirstSector; break; } case IPv4Class::B: { - sectors[1] = Number::integer(ipv4ClassBSecondSectorLowerBound, ipv4ClassBSecondSectorUpperBound); + sectors[1] = faker::number::integer(ipv4ClassBSecondSectorLowerBound, ipv4ClassBSecondSectorUpperBound); sectors[0] = ipv4ClassBFirstSector; break; } @@ -264,7 +264,7 @@ std::string Internet::ipv4(const std::array& baseIpv4Address, for (std::size_t i = 0; i < ipv4AddressSectors; i++) { - sectors[i] = (~generationMask[i]) & Number::integer(ipv4SectorUpperBound); + sectors[i] = (~generationMask[i]) & faker::number::integer(ipv4SectorUpperBound); sectors[i] |= (baseIpv4Address[i] & generationMask[i]); } @@ -311,7 +311,7 @@ std::string Internet::mac(const std::string& sep) unsigned Internet::port() { - return Number::integer(65535u); + return faker::number::integer(65535u); } std::string Internet::url(const WebProtocol& webProtocol) @@ -346,7 +346,7 @@ std::string Internet::anonymousUsername(unsigned maxLength) else if (maxLength > defaultMax) maxLength = defaultMax; - const std::integral auto adjectiveLength = Number::integer(3, 1 + maxLength / 2); + const std::integral auto adjectiveLength = faker::number::integer(3, 1 + maxLength / 2); const auto nounLength = maxLength - adjectiveLength; diff --git a/src/modules/location/Location.cpp b/src/modules/location/Location.cpp index f783df915..0b968e207 100644 --- a/src/modules/location/Location.cpp +++ b/src/modules/location/Location.cpp @@ -210,14 +210,14 @@ std::string Location::secondaryAddress(AddressCountry country) std::string Location::latitude(Precision precision) { - const std::floating_point auto latitude = Number::decimal(-90.0, 90.0); + const std::floating_point auto latitude = faker::number::decimal(-90.0, 90.0); return FormatHelper::precisionFormat(precision, latitude); } std::string Location::longitude(Precision precision) { - const std::floating_point auto longitude = Number::decimal(-180.0, 180.0); + const std::floating_point auto longitude = faker::number::decimal(-180.0, 180.0); return FormatHelper::precisionFormat(precision, longitude); } diff --git a/src/modules/lorem/Lorem.cpp b/src/modules/lorem/Lorem.cpp index 20d6f35cb..98349e7e6 100644 --- a/src/modules/lorem/Lorem.cpp +++ b/src/modules/lorem/Lorem.cpp @@ -33,7 +33,7 @@ std::string Lorem::words(unsigned numberOfWords) std::string Lorem::sentence(unsigned minNumberOfWords, unsigned maxNumberOfWords) { - const std::integral auto numberOfWords = Number::integer(minNumberOfWords, maxNumberOfWords); + const std::integral auto numberOfWords = faker::number::integer(minNumberOfWords, maxNumberOfWords); const auto sentenceWords = words(numberOfWords); @@ -42,7 +42,7 @@ std::string Lorem::sentence(unsigned minNumberOfWords, unsigned maxNumberOfWords std::string Lorem::sentences(unsigned minNumberOfSentences, unsigned maxNumberOfSentences) { - const std::integral auto numberOfSentences = Number::integer(minNumberOfSentences, maxNumberOfSentences); + const std::integral auto numberOfSentences = faker::number::integer(minNumberOfSentences, maxNumberOfSentences); std::vector sentences; sentences.reserve(numberOfSentences); @@ -75,7 +75,7 @@ std::string Lorem::paragraph(unsigned int minNumberOfSentences, unsigned int max std::string Lorem::paragraphs(unsigned int minNumberOfParagraphs, unsigned int maxNumberOfParagraphs) { - const std::integral auto numberOfParagraphs = Number::integer(minNumberOfParagraphs, maxNumberOfParagraphs); + const std::integral auto numberOfParagraphs = faker::number::integer(minNumberOfParagraphs, maxNumberOfParagraphs); std::vector paragraphs; paragraphs.reserve(numberOfParagraphs); diff --git a/src/modules/number/Number.cpp b/src/modules/number/Number.cpp index 470d47bb1..33e630041 100644 --- a/src/modules/number/Number.cpp +++ b/src/modules/number/Number.cpp @@ -2,9 +2,9 @@ #include -namespace faker +namespace faker::number { -std::random_device Number::randomDevice; +std::random_device randomDevice; -std::mt19937 Number::pseudoRandomGenerator(Number::randomDevice()); +std::mt19937 pseudoRandomGenerator(randomDevice()); } diff --git a/src/modules/person/Person.cpp b/src/modules/person/Person.cpp index 6ec3963a7..96d14d6d8 100644 --- a/src/modules/person/Person.cpp +++ b/src/modules/person/Person.cpp @@ -415,7 +415,7 @@ std::string Person::ssn(std::optional country) } else if (ssnFormatCharacter == '#') { - ssn += std::to_string(Number::integer(0, 9)); + ssn += std::to_string(faker::number::integer(0, 9)); } else { diff --git a/src/modules/string/String.cpp b/src/modules/string/String.cpp index 2e8733aa6..7e6ec56c1 100644 --- a/src/modules/string/String.cpp +++ b/src/modules/string/String.cpp @@ -130,7 +130,7 @@ std::string String::sample(unsigned int length) for (unsigned i = 0; i < length; i++) { - sample += static_cast(Number::integer(33, 125)); + sample += static_cast(faker::number::integer(33, 125)); } return sample; @@ -287,7 +287,7 @@ std::string String::numeric(GuaranteeMap&& guarantee, const unsigned length, boo // if leading zero not allowed, pick first digit a non-zero else { - auto firstChar = std::to_string(Number::integer(1, 9)); + auto firstChar = std::to_string(faker::number::integer(1, 9)); auto it = guarantee.find(firstChar[0]); if (it != guarantee.end()) { @@ -329,7 +329,7 @@ std::string String::hexadecimal(std::optional min, std::optional max) defaultMax = max.value(); } - return FormatHelper::format("{:x}", Number::integer(defaultMin, defaultMax)); + return FormatHelper::format("{:x}", faker::number::integer(defaultMin, defaultMax)); } std::string String::hexadecimal(GuaranteeMap&& guarantee, unsigned int length, HexCasing casing, HexPrefix prefix) @@ -349,7 +349,7 @@ std::string String::binary(unsigned int length) std::string binaryNumber; for (unsigned int i = 0; i < length; ++i) { - binaryNumber += static_cast(Number::integer(1)); + binaryNumber += static_cast(faker::number::integer(1)); } return "0b" + binaryNumber; } @@ -372,7 +372,7 @@ std::string String::octal(unsigned int length) std::string octalNumber; for (unsigned int i = 0; i < length; ++i) { - octalNumber += static_cast(Number::integer(7)); + octalNumber += static_cast(faker::number::integer(7)); } return "0o" + octalNumber; } diff --git a/src/modules/system/System.cpp b/src/modules/system/System.cpp index f2f6083c8..32cf386d4 100644 --- a/src/modules/system/System.cpp +++ b/src/modules/system/System.cpp @@ -66,7 +66,7 @@ std::string fileName(const FileOptions& options) else { const std::integral auto numExtensions = - Number::integer(options.extensionRange.min, options.extensionRange.max); + faker::number::integer(options.extensionRange.min, options.extensionRange.max); for (int i = 0; i < numExtensions; ++i) { @@ -173,9 +173,9 @@ std::string filePath() std::string semver() { - const int major = Number::integer(9); - const int minor = Number::integer(9); - const int patch = Number::integer(9); + const int major = faker::number::integer(9); + const int minor = faker::number::integer(9); + const int patch = faker::number::integer(9); return FormatHelper::format("{}.{}.{}", major, minor, patch); } @@ -233,24 +233,24 @@ std::string cron(const CronOptions& options) { bool includeYear = options.includeYear; bool includeNonStandard = options.includeNonStandard; - std::vector minutes = {std::to_string(Number::integer(59)), "*"}; - std::vector hours = {std::to_string(Number::integer(23)), "*"}; - std::vector days = {std::to_string(Number::integer(1, 31)), "*", "?"}; - std::vector months = {std::to_string(Number::integer(1, 12)), "*"}; + std::vector minutes = {std::to_string(faker::number::integer(59)), "*"}; + std::vector hours = {std::to_string(faker::number::integer(23)), "*"}; + std::vector days = {std::to_string(faker::number::integer(1, 31)), "*", "?"}; + std::vector months = {std::to_string(faker::number::integer(1, 12)), "*"}; std::vector daysOfWeek = { - std::to_string(Number::integer(6)), + std::to_string(faker::number::integer(6)), std::string( - cronDayOfWeek[static_cast(Number::integer(0, static_cast(cronDayOfWeek.size() - 1)))]), + cronDayOfWeek[static_cast(faker::number::integer(0, static_cast(cronDayOfWeek.size() - 1)))]), "*", "?"}; std::vector years; if (includeYear) { - years.push_back(std::to_string(Number::integer(1970, 2099))); + years.push_back(std::to_string(faker::number::integer(1970, 2099))); } else { - years = {std::to_string(Number::integer(1970, 2099)), "*"}; + years = {std::to_string(faker::number::integer(1970, 2099)), "*"}; } const auto minute = Helper::arrayElement(minutes); diff --git a/src/modules/vehicle/Vehicle.cpp b/src/modules/vehicle/Vehicle.cpp index b2a12837e..3080a93ad 100644 --- a/src/modules/vehicle/Vehicle.cpp +++ b/src/modules/vehicle/Vehicle.cpp @@ -54,7 +54,7 @@ std::string vin() return FormatHelper::format("{}{}{}{}", String::alphanumeric(10, StringCasing::Upper, exclude_characters), String::alpha(1, StringCasing::Upper, exclude_characters), String::alphanumeric(1, StringCasing::Upper, exclude_characters), - Number::integer(10000, 99999)); + faker::number::integer(10000, 99999)); } std::string vrm() diff --git a/src/modules/word/Word.cpp b/src/modules/word/Word.cpp index b3b624ba8..3e6c16171 100644 --- a/src/modules/word/Word.cpp +++ b/src/modules/word/Word.cpp @@ -63,7 +63,7 @@ std::string words(unsigned numberOfWords) for (unsigned i = 0; i < numberOfWords; i++) { - tmp[i] = Number::integer(last_index); + tmp[i] = faker::number::integer(last_index); auto vw = _allWords[tmp[i]]; reserve_size += vw.size(); } diff --git a/tests/modules/git/GitTest.cpp b/tests/modules/git/GitTest.cpp index 327af241e..b91e9cc72 100644 --- a/tests/modules/git/GitTest.cpp +++ b/tests/modules/git/GitTest.cpp @@ -48,7 +48,7 @@ TEST_F(GitTest, shouldGenerateBranch) TEST_F(GitTest, branchIssueNumTest) { - auto testValue = unsigned(Number::integer(2, 100)); + auto testValue = unsigned(faker::number::integer(2, 100)); std::vector branchElements = StringHelper::split(branch(testValue), "-"); diff --git a/tests/modules/internet/InternetTest.cpp b/tests/modules/internet/InternetTest.cpp index 54197f732..78fcffa9b 100644 --- a/tests/modules/internet/InternetTest.cpp +++ b/tests/modules/internet/InternetTest.cpp @@ -734,7 +734,7 @@ TEST_F(InternetTest, shouldGenerateAnonymousUsername) { for (int i = 0; i < 100; i++) { - const std::integral auto maxLength = Number::integer(6, 20); + const std::integral auto maxLength = faker::number::integer(6, 20); const auto generatedUsername = Internet::anonymousUsername(maxLength); ASSERT_EQ(generatedUsername.length(), maxLength); diff --git a/tests/modules/number/NumberTest.cpp b/tests/modules/number/NumberTest.cpp index 2606a423d..a4bdeda5a 100644 --- a/tests/modules/number/NumberTest.cpp +++ b/tests/modules/number/NumberTest.cpp @@ -6,6 +6,7 @@ using namespace ::testing; using namespace faker; +using namespace faker::number; class NumberTest : public Test { @@ -14,19 +15,19 @@ class NumberTest : public Test TEST_F(NumberTest, integer_givenInvalidRangeArguments_shouldThrowInvalidArgument) { - ASSERT_THROW(Number::integer(10, 2), std::invalid_argument); + ASSERT_THROW(integer(10, 2), std::invalid_argument); } TEST_F(NumberTest, givenRangeWithSameNumbers_shouldGenerateThisNumber) { - const int actualRandomNumber = Number::integer(2, 2); + const int actualRandomNumber = integer(2, 2); ASSERT_EQ(actualRandomNumber, 2); } TEST_F(NumberTest, givenValidRange_shouldGenerateNumberWithinGivenRange) { - const int actualRandomNumber = Number::integer(2, 10); + const int actualRandomNumber = integer(2, 10); ASSERT_TRUE(actualRandomNumber >= 2); ASSERT_TRUE(actualRandomNumber <= 10); @@ -34,7 +35,7 @@ TEST_F(NumberTest, givenValidRange_shouldGenerateNumberWithinGivenRange) TEST_F(NumberTest, givenSingleArgument_shouldCorrectlyResolveToTwoArgsOverload) { - const int randomNumber = Number::integer(10); + const int randomNumber = integer(10); ASSERT_TRUE(randomNumber >= 0); ASSERT_TRUE(randomNumber <= 10); @@ -42,12 +43,12 @@ TEST_F(NumberTest, givenSingleArgument_shouldCorrectlyResolveToTwoArgsOverload) TEST_F(NumberTest, decimal_givenInvalidRangeArguments_shouldThrowInvalidArgument) { - ASSERT_THROW(Number::decimal(10.f, 2.f), std::invalid_argument); + ASSERT_THROW(decimal(10.f, 2.f), std::invalid_argument); } TEST_F(NumberTest, givenValidRangeArguments_shouldGenerateDecimalNumberThatIsInGivenRange) { - const std::floating_point auto actualRandomNumber = Number::decimal(2.f, 10.f); + const std::floating_point auto actualRandomNumber = decimal(2.f, 10.f); ASSERT_TRUE(actualRandomNumber >= 2.f); ASSERT_TRUE(actualRandomNumber <= 10.f); @@ -55,7 +56,7 @@ TEST_F(NumberTest, givenValidRangeArguments_shouldGenerateDecimalNumberThatIsInG TEST_F(NumberTest, givenRangeWithSameNumberSection_shouldGenerateThisNumberForDecimal) { - const std::floating_point auto actualRandomNumber = Number::decimal(2.f, 2.f); + const std::floating_point auto actualRandomNumber = decimal(2.f, 2.f); ASSERT_EQ(actualRandomNumber, 2.f); } From e4d1f35067d65fc76e6eeee975cc63a615e4a203 Mon Sep 17 00:00:00 2001 From: Guru Mehar Rachaputi Date: Tue, 25 Jun 2024 13:22:38 +0200 Subject: [PATCH 2/2] changed namespace from faker::number to number Signed-off-by: Guru Mehar Rachaputi --- include/faker-cxx/Helper.h | 12 +++--- src/modules/airline/Airline.cpp | 6 +-- src/modules/color/Color.cpp | 56 ++++++++++++------------- src/modules/company/Company.cpp | 2 +- src/modules/datatype/Datatype.cpp | 6 +-- src/modules/date/Date.cpp | 16 +++---- src/modules/finance/Finance.cpp | 6 +-- src/modules/git/Git.cpp | 10 ++--- src/modules/helper/Helper.cpp | 8 ++-- src/modules/image/Image.cpp | 4 +- src/modules/internet/Internet.cpp | 20 ++++----- src/modules/location/Location.cpp | 4 +- src/modules/lorem/Lorem.cpp | 6 +-- src/modules/person/Person.cpp | 2 +- src/modules/string/String.cpp | 10 ++--- src/modules/system/System.cpp | 24 +++++------ src/modules/vehicle/Vehicle.cpp | 2 +- src/modules/word/Word.cpp | 2 +- tests/modules/git/GitTest.cpp | 2 +- tests/modules/internet/InternetTest.cpp | 2 +- 20 files changed, 100 insertions(+), 100 deletions(-) diff --git a/include/faker-cxx/Helper.h b/include/faker-cxx/Helper.h index f108ed67f..54e7beb91 100644 --- a/include/faker-cxx/Helper.h +++ b/include/faker-cxx/Helper.h @@ -39,7 +39,7 @@ class Helper throw std::invalid_argument{"Data is empty."}; } - const auto index = faker::number::integer(data.size() - 1); + const auto index = number::integer(data.size() - 1); return data[index]; } @@ -52,7 +52,7 @@ class Helper throw std::invalid_argument{"Data is empty."}; } - const auto index = faker::number::integer(data.size() - 1); + const auto index = number::integer(data.size() - 1); return data[index]; } @@ -67,7 +67,7 @@ class Helper throw std::invalid_argument{"Range [start,end) is empty."}; } - const std::integral auto index = faker::number::integer(size - 1); + const std::integral auto index = number::integer(size - 1); return start[index]; } @@ -93,7 +93,7 @@ class Helper throw std::invalid_argument{"Data is empty."}; } - const auto index = faker::number::integer(data.size() - 1); + const auto index = number::integer(data.size() - 1); return data[index]; } @@ -119,7 +119,7 @@ class Helper throw std::invalid_argument{"Data is empty."}; } - const auto index = faker::number::integer(data.size() - 1); + const auto index = number::integer(data.size() - 1); return *(data.begin() + index); } @@ -191,7 +191,7 @@ class Helper throw std::invalid_argument{"Sum of weights is zero."}; } - const std::integral auto targetWeightValue = faker::number::integer(1, sumOfWeights); + const std::integral auto targetWeightValue = number::integer(1, sumOfWeights); unsigned currentSum = 0; diff --git a/src/modules/airline/Airline.cpp b/src/modules/airline/Airline.cpp index 16c1d9894..5fb9ade00 100644 --- a/src/modules/airline/Airline.cpp +++ b/src/modules/airline/Airline.cpp @@ -32,7 +32,7 @@ Airport airport() std::string seat(AircraftType aircraftType) { - return std::to_string(faker::number::integer(1, aircraftTypeMaxRows.at(aircraftType))) + + return std::to_string(number::integer(1, aircraftTypeMaxRows.at(aircraftType))) + Helper::arrayElement(aircraftTypeSeatLetters.at(aircraftType)); } @@ -60,9 +60,9 @@ std::string flightNumberByRange(bool addLeadingZeros, Range length) { if (addLeadingZeros) { - return String::numeric(faker::number::integer(length.min, length.max), true); + return String::numeric(number::integer(length.min, length.max), true); } - return String::numeric(faker::number::integer(length.min, length.max), false); + return String::numeric(number::integer(length.min, length.max), false); } } diff --git a/src/modules/color/Color.cpp b/src/modules/color/Color.cpp index f330baa0b..166d5e844 100644 --- a/src/modules/color/Color.cpp +++ b/src/modules/color/Color.cpp @@ -19,16 +19,16 @@ std::string_view name() std::string rgb(bool includeAlpha) { - const std::integral auto red = faker::number::integer(255); - const std::integral auto green = faker::number::integer(255); - const std::integral auto blue = faker::number::integer(255); + const std::integral auto red = number::integer(255); + const std::integral auto green = number::integer(255); + const std::integral auto blue = number::integer(255); if (!includeAlpha) { return FormatHelper::format("rgb({}, {}, {})", red, green, blue); } - std::floating_point auto alpha = faker::number::decimal(1.0); + std::floating_point auto alpha = number::decimal(1.0); return FormatHelper::format("rgba({}, {}, {}, {:.2f})", red, green, blue, alpha); } @@ -40,78 +40,78 @@ std::string hex(HexCasing casing, HexPrefix prefix, bool includeAlpha) std::string hsl(bool include_alpha) { - std::integral auto hue = faker::number::integer(360); - std::integral auto saturation = faker::number::integer(100); - std::integral auto lightness = faker::number::integer(100); + std::integral auto hue = number::integer(360); + std::integral auto saturation = number::integer(100); + std::integral auto lightness = number::integer(100); if (!include_alpha) { return FormatHelper::format("hsl({}, {}, {})", hue, saturation, lightness); } - std::floating_point auto alpha = faker::number::decimal(1.0); + std::floating_point auto alpha = number::decimal(1.0); return FormatHelper::format("hsla({}, {}, {}, {:.2f})", hue, saturation, lightness, alpha); } std::string lch(bool include_alpha) { - std::integral auto luminance = faker::number::integer(100); - std::integral auto chroma = faker::number::integer(100); - std::integral auto hue = faker::number::integer(360); + std::integral auto luminance = number::integer(100); + std::integral auto chroma = number::integer(100); + std::integral auto hue = number::integer(360); if (!include_alpha) { return FormatHelper::format("lch({}, {}, {})", luminance, chroma, hue); } - std::floating_point auto alpha = faker::number::decimal(1.0); + std::floating_point auto alpha = number::decimal(1.0); return FormatHelper::format("lcha({}, {}, {}, {:.2f})", luminance, chroma, hue, alpha); } std::string cmyk() { - std::floating_point auto cyan = faker::number::decimal(1.); - std::floating_point auto magenta = faker::number::decimal(1.); - std::floating_point auto yellow = faker::number::decimal(1.); - std::floating_point auto key = faker::number::decimal(1.); + std::floating_point auto cyan = number::decimal(1.); + std::floating_point auto magenta = number::decimal(1.); + std::floating_point auto yellow = number::decimal(1.); + std::floating_point auto key = number::decimal(1.); return FormatHelper::format("cmyk({:.2f}, {:.2f}, {:.2f}, {:.2f})", cyan, magenta, yellow, key); } std::string lab() { - std::floating_point auto lightness = faker::number::decimal(100.0); - std::floating_point auto red_green = faker::number::decimal(-128.0, 128.0); - std::floating_point auto blue_yellow = faker::number::decimal(-128.0, 128.0); + std::floating_point auto lightness = number::decimal(100.0); + std::floating_point auto red_green = number::decimal(-128.0, 128.0); + std::floating_point auto blue_yellow = number::decimal(-128.0, 128.0); return FormatHelper::format("lab({:.2f}, {:.2f}, {:.2f})", lightness, red_green, blue_yellow); } std::string hsb() { - std::integral auto hue = faker::number::integer(360); - std::integral auto saturation = faker::number::integer(100); - std::integral auto brightness = faker::number::integer(100); + std::integral auto hue = number::integer(360); + std::integral auto saturation = number::integer(100); + std::integral auto brightness = number::integer(100); return FormatHelper::format("hsb({}, {}, {})", hue, saturation, brightness); } std::string hsv() { - std::integral auto hue = faker::number::integer(360); - std::integral auto saturation = faker::number::integer(100); - std::integral auto value = faker::number::integer(100); + std::integral auto hue = number::integer(360); + std::integral auto saturation = number::integer(100); + std::integral auto value = number::integer(100); return FormatHelper::format("hsv({}, {}, {})", hue, saturation, value); } std::string yuv() { - std::integral auto luminance = faker::number::integer(255); - std::integral auto chrominance_blue = faker::number::integer(255); - std::integral auto chrominance_red = faker::number::integer(255); + std::integral auto luminance = number::integer(255); + std::integral auto chrominance_blue = number::integer(255); + std::integral auto chrominance_red = number::integer(255); return FormatHelper::format("yuv({}, {}, {})", luminance, chrominance_blue, chrominance_red); } diff --git a/src/modules/company/Company.cpp b/src/modules/company/Company.cpp index 82e322ef4..e8a84d6bc 100644 --- a/src/modules/company/Company.cpp +++ b/src/modules/company/Company.cpp @@ -15,7 +15,7 @@ std::string name() { std::string companyName; - switch (faker::number::integer(3)) + switch (number::integer(3)) { case 0: companyName = FormatHelper::format("{} {}", Person::lastName(), Helper::arrayElement(companySuffixes)); diff --git a/src/modules/datatype/Datatype.cpp b/src/modules/datatype/Datatype.cpp index 290c43510..98b198976 100644 --- a/src/modules/datatype/Datatype.cpp +++ b/src/modules/datatype/Datatype.cpp @@ -8,7 +8,7 @@ namespace faker::datatype { bool boolean() { - return faker::number::decimal(0.f, 1.f) > 0.5f; + return number::decimal(0.f, 1.f) > 0.5f; } bool boolean(double probability) @@ -27,9 +27,9 @@ bool boolean(double probability) return true; } - return faker::number::decimal(0., 1.) < prob; + return number::decimal(0., 1.) < prob; } - return faker::number::decimal(0., 1.) < 0.5; + return number::decimal(0., 1.) < 0.5; } } diff --git a/src/modules/date/Date.cpp b/src/modules/date/Date.cpp index 9e3e75548..135626a76 100644 --- a/src/modules/date/Date.cpp +++ b/src/modules/date/Date.cpp @@ -47,7 +47,7 @@ std::string betweenDate(const auto& from, const auto& to, DateFormat dateFormat) const auto size = std::chrono::duration_cast(to - from).count(); - const auto randomDateWithinRange = from + std::chrono::seconds{faker::number::integer(size - 1)}; + const auto randomDateWithinRange = from + std::chrono::seconds{number::integer(size - 1)}; return serializeTimePoint(randomDateWithinRange, dateFormat); } @@ -155,27 +155,27 @@ unsigned int year() unsigned minYear = 1950; unsigned maxYear = 2050; - return faker::number::integer(minYear, maxYear); + return number::integer(minYear, maxYear); } unsigned int month() { - return faker::number::integer(1, 12); + return number::integer(1, 12); } unsigned int hour() { - return faker::number::integer(0, 23); + return number::integer(0, 23); } unsigned int minute() { - return faker::number::integer(0, 59); + return number::integer(0, 59); } unsigned int second() { - return faker::number::integer(0, 59); + return number::integer(0, 59); } std::string time() @@ -185,12 +185,12 @@ std::string time() unsigned int dayOfMonth() { - return faker::number::integer(1, 31); + return number::integer(1, 31); } unsigned dayOfWeek() { - return faker::number::integer(1, 7); + return number::integer(1, 7); } std::string_view timezoneRandom() diff --git a/src/modules/finance/Finance.cpp b/src/modules/finance/Finance.cpp index 533294e7a..01feef513 100644 --- a/src/modules/finance/Finance.cpp +++ b/src/modules/finance/Finance.cpp @@ -44,7 +44,7 @@ std::string_view Finance::accountType() std::string Finance::amount(double min, double max, Precision precision, const std::string& symbol) { - const std::floating_point auto generatedNumber = faker::number::decimal(min, max); + const std::floating_point auto generatedNumber = number::decimal(min, max); std::string result{symbol}; @@ -139,7 +139,7 @@ std::string Finance::creditCardCvv() std::string Finance::bitcoinAddress() { - const unsigned addressLength = faker::number::integer(26u, 33u); + const unsigned addressLength = number::integer(26u, 33u); auto address = Helper::arrayElement(std::vector{"1", "3"}); @@ -150,7 +150,7 @@ std::string Finance::bitcoinAddress() std::string Finance::litecoinAddress() { - const unsigned addressLength = faker::number::integer(26u, 33u); + const unsigned addressLength = number::integer(26u, 33u); auto address = Helper::arrayElement(std::vector{"L", "M", "3"}); diff --git a/src/modules/git/Git.cpp b/src/modules/git/Git.cpp index 4f2191ccf..9676a2069 100644 --- a/src/modules/git/Git.cpp +++ b/src/modules/git/Git.cpp @@ -20,14 +20,14 @@ namespace faker::git std::string branch(unsigned maxIssueNum) { - switch (faker::number::integer(1, 3)) + switch (number::integer(1, 3)) { case 1: return FormatHelper::format("{}-{}", word::verb(), word::noun()); case 2: return FormatHelper::format("{}-{}-{}", word::verb(), word::adjective(), word::noun()); default: - return FormatHelper::format("{}-{}-{}-{}", faker::number::integer(unsigned(1), maxIssueNum), word::verb(), + return FormatHelper::format("{}-{}-{}-{}", number::integer(unsigned(1), maxIssueNum), word::verb(), word::adjective(), word::noun()); } } @@ -48,11 +48,11 @@ std::string commitDate(unsigned years) const auto time = StringHelper::split(restSplit[1], "Z")[0]; - int timeZone = faker::number::integer(0, 12); + int timeZone = number::integer(0, 12); std::string timeZoneString; - if (faker::number::integer(0, 1)) + if (number::integer(0, 1)) { timeZoneString += "-"; } @@ -112,7 +112,7 @@ std::string commitEntry(std::optional dateYears, std::optional(token.position())) + StringHelper::repeat(token[1], repetitions) + data.substr(static_cast(token.position() + token.length())); @@ -112,7 +112,7 @@ std::string Helper::regexpStyleStringParse(const std::string& input) } data = data.substr(0, static_cast(token.position())) + - std::to_string(faker::number::integer(min, max)) + + std::to_string(number::integer(min, max)) + data.substr(static_cast(token.position() + token.length())); } diff --git a/src/modules/image/Image.cpp b/src/modules/image/Image.cpp index 9490ffefc..00d9e4ca1 100644 --- a/src/modules/image/Image.cpp +++ b/src/modules/image/Image.cpp @@ -39,12 +39,12 @@ std::string Image::imageUrl(unsigned int width, unsigned int height, std::option std::string Image::githubAvatarUrl() { - return FormatHelper::format("https://avatars.githubusercontent.com/u/{}", faker::number::integer(100000000)); + return FormatHelper::format("https://avatars.githubusercontent.com/u/{}", number::integer(100000000)); } std::string Image::dimensions() { - return FormatHelper::format("{}x{}", faker::number::integer(1, 32720), faker::number::integer(1, 17280)); + return FormatHelper::format("{}x{}", number::integer(1, 32720), number::integer(1, 17280)); } std::string_view Image::type() diff --git a/src/modules/internet/Internet.cpp b/src/modules/internet/Internet.cpp index 63eeb10d0..117916cec 100644 --- a/src/modules/internet/Internet.cpp +++ b/src/modules/internet/Internet.cpp @@ -93,10 +93,10 @@ std::string Internet::username(std::optional firstNameInit, std::op std::string username; - switch (faker::number::integer(2)) + switch (number::integer(2)) { case 0: - username = FormatHelper::format("{}{}{}", firstName, lastName, faker::number::integer(999)); + username = FormatHelper::format("{}{}{}", firstName, lastName, number::integer(999)); break; case 1: username = FormatHelper::format("{}{}{}", firstName, @@ -105,7 +105,7 @@ std::string Internet::username(std::optional firstNameInit, std::op case 2: username = FormatHelper::format("{}{}{}{}", firstName, Helper::arrayElement(std::vector{".", "_", ""}), - lastName, faker::number::integer(99)); + lastName, number::integer(99)); break; } @@ -230,20 +230,20 @@ std::string Internet::ipv4(const IPv4Class& ipv4class) { std::array sectors{}; - sectors[3] = faker::number::integer(ipv4SectorUpperBound); - sectors[2] = faker::number::integer(ipv4SectorUpperBound); + sectors[3] = number::integer(ipv4SectorUpperBound); + sectors[2] = number::integer(ipv4SectorUpperBound); switch (ipv4class) { case IPv4Class::A: { - sectors[1] = faker::number::integer(ipv4SectorUpperBound); + sectors[1] = number::integer(ipv4SectorUpperBound); sectors[0] = ipv4ClassAFirstSector; break; } case IPv4Class::B: { - sectors[1] = faker::number::integer(ipv4ClassBSecondSectorLowerBound, ipv4ClassBSecondSectorUpperBound); + sectors[1] = number::integer(ipv4ClassBSecondSectorLowerBound, ipv4ClassBSecondSectorUpperBound); sectors[0] = ipv4ClassBFirstSector; break; } @@ -264,7 +264,7 @@ std::string Internet::ipv4(const std::array& baseIpv4Address, for (std::size_t i = 0; i < ipv4AddressSectors; i++) { - sectors[i] = (~generationMask[i]) & faker::number::integer(ipv4SectorUpperBound); + sectors[i] = (~generationMask[i]) & number::integer(ipv4SectorUpperBound); sectors[i] |= (baseIpv4Address[i] & generationMask[i]); } @@ -311,7 +311,7 @@ std::string Internet::mac(const std::string& sep) unsigned Internet::port() { - return faker::number::integer(65535u); + return number::integer(65535u); } std::string Internet::url(const WebProtocol& webProtocol) @@ -346,7 +346,7 @@ std::string Internet::anonymousUsername(unsigned maxLength) else if (maxLength > defaultMax) maxLength = defaultMax; - const std::integral auto adjectiveLength = faker::number::integer(3, 1 + maxLength / 2); + const std::integral auto adjectiveLength = number::integer(3, 1 + maxLength / 2); const auto nounLength = maxLength - adjectiveLength; diff --git a/src/modules/location/Location.cpp b/src/modules/location/Location.cpp index 0b968e207..a3adf6caf 100644 --- a/src/modules/location/Location.cpp +++ b/src/modules/location/Location.cpp @@ -210,14 +210,14 @@ std::string Location::secondaryAddress(AddressCountry country) std::string Location::latitude(Precision precision) { - const std::floating_point auto latitude = faker::number::decimal(-90.0, 90.0); + const std::floating_point auto latitude = number::decimal(-90.0, 90.0); return FormatHelper::precisionFormat(precision, latitude); } std::string Location::longitude(Precision precision) { - const std::floating_point auto longitude = faker::number::decimal(-180.0, 180.0); + const std::floating_point auto longitude = number::decimal(-180.0, 180.0); return FormatHelper::precisionFormat(precision, longitude); } diff --git a/src/modules/lorem/Lorem.cpp b/src/modules/lorem/Lorem.cpp index 98349e7e6..5e210e640 100644 --- a/src/modules/lorem/Lorem.cpp +++ b/src/modules/lorem/Lorem.cpp @@ -33,7 +33,7 @@ std::string Lorem::words(unsigned numberOfWords) std::string Lorem::sentence(unsigned minNumberOfWords, unsigned maxNumberOfWords) { - const std::integral auto numberOfWords = faker::number::integer(minNumberOfWords, maxNumberOfWords); + const std::integral auto numberOfWords = number::integer(minNumberOfWords, maxNumberOfWords); const auto sentenceWords = words(numberOfWords); @@ -42,7 +42,7 @@ std::string Lorem::sentence(unsigned minNumberOfWords, unsigned maxNumberOfWords std::string Lorem::sentences(unsigned minNumberOfSentences, unsigned maxNumberOfSentences) { - const std::integral auto numberOfSentences = faker::number::integer(minNumberOfSentences, maxNumberOfSentences); + const std::integral auto numberOfSentences = number::integer(minNumberOfSentences, maxNumberOfSentences); std::vector sentences; sentences.reserve(numberOfSentences); @@ -75,7 +75,7 @@ std::string Lorem::paragraph(unsigned int minNumberOfSentences, unsigned int max std::string Lorem::paragraphs(unsigned int minNumberOfParagraphs, unsigned int maxNumberOfParagraphs) { - const std::integral auto numberOfParagraphs = faker::number::integer(minNumberOfParagraphs, maxNumberOfParagraphs); + const std::integral auto numberOfParagraphs = number::integer(minNumberOfParagraphs, maxNumberOfParagraphs); std::vector paragraphs; paragraphs.reserve(numberOfParagraphs); diff --git a/src/modules/person/Person.cpp b/src/modules/person/Person.cpp index 96d14d6d8..488dcba22 100644 --- a/src/modules/person/Person.cpp +++ b/src/modules/person/Person.cpp @@ -415,7 +415,7 @@ std::string Person::ssn(std::optional country) } else if (ssnFormatCharacter == '#') { - ssn += std::to_string(faker::number::integer(0, 9)); + ssn += std::to_string(number::integer(0, 9)); } else { diff --git a/src/modules/string/String.cpp b/src/modules/string/String.cpp index 7e6ec56c1..be3607095 100644 --- a/src/modules/string/String.cpp +++ b/src/modules/string/String.cpp @@ -130,7 +130,7 @@ std::string String::sample(unsigned int length) for (unsigned i = 0; i < length; i++) { - sample += static_cast(faker::number::integer(33, 125)); + sample += static_cast(number::integer(33, 125)); } return sample; @@ -287,7 +287,7 @@ std::string String::numeric(GuaranteeMap&& guarantee, const unsigned length, boo // if leading zero not allowed, pick first digit a non-zero else { - auto firstChar = std::to_string(faker::number::integer(1, 9)); + auto firstChar = std::to_string(number::integer(1, 9)); auto it = guarantee.find(firstChar[0]); if (it != guarantee.end()) { @@ -329,7 +329,7 @@ std::string String::hexadecimal(std::optional min, std::optional max) defaultMax = max.value(); } - return FormatHelper::format("{:x}", faker::number::integer(defaultMin, defaultMax)); + return FormatHelper::format("{:x}", number::integer(defaultMin, defaultMax)); } std::string String::hexadecimal(GuaranteeMap&& guarantee, unsigned int length, HexCasing casing, HexPrefix prefix) @@ -349,7 +349,7 @@ std::string String::binary(unsigned int length) std::string binaryNumber; for (unsigned int i = 0; i < length; ++i) { - binaryNumber += static_cast(faker::number::integer(1)); + binaryNumber += static_cast(number::integer(1)); } return "0b" + binaryNumber; } @@ -372,7 +372,7 @@ std::string String::octal(unsigned int length) std::string octalNumber; for (unsigned int i = 0; i < length; ++i) { - octalNumber += static_cast(faker::number::integer(7)); + octalNumber += static_cast(number::integer(7)); } return "0o" + octalNumber; } diff --git a/src/modules/system/System.cpp b/src/modules/system/System.cpp index 32cf386d4..b5c5aab36 100644 --- a/src/modules/system/System.cpp +++ b/src/modules/system/System.cpp @@ -66,7 +66,7 @@ std::string fileName(const FileOptions& options) else { const std::integral auto numExtensions = - faker::number::integer(options.extensionRange.min, options.extensionRange.max); + number::integer(options.extensionRange.min, options.extensionRange.max); for (int i = 0; i < numExtensions; ++i) { @@ -173,9 +173,9 @@ std::string filePath() std::string semver() { - const int major = faker::number::integer(9); - const int minor = faker::number::integer(9); - const int patch = faker::number::integer(9); + const int major = number::integer(9); + const int minor = number::integer(9); + const int patch = number::integer(9); return FormatHelper::format("{}.{}.{}", major, minor, patch); } @@ -233,24 +233,24 @@ std::string cron(const CronOptions& options) { bool includeYear = options.includeYear; bool includeNonStandard = options.includeNonStandard; - std::vector minutes = {std::to_string(faker::number::integer(59)), "*"}; - std::vector hours = {std::to_string(faker::number::integer(23)), "*"}; - std::vector days = {std::to_string(faker::number::integer(1, 31)), "*", "?"}; - std::vector months = {std::to_string(faker::number::integer(1, 12)), "*"}; + std::vector minutes = {std::to_string(number::integer(59)), "*"}; + std::vector hours = {std::to_string(number::integer(23)), "*"}; + std::vector days = {std::to_string(number::integer(1, 31)), "*", "?"}; + std::vector months = {std::to_string(number::integer(1, 12)), "*"}; std::vector daysOfWeek = { - std::to_string(faker::number::integer(6)), + std::to_string(number::integer(6)), std::string( - cronDayOfWeek[static_cast(faker::number::integer(0, static_cast(cronDayOfWeek.size() - 1)))]), + cronDayOfWeek[static_cast(number::integer(0, static_cast(cronDayOfWeek.size() - 1)))]), "*", "?"}; std::vector years; if (includeYear) { - years.push_back(std::to_string(faker::number::integer(1970, 2099))); + years.push_back(std::to_string(number::integer(1970, 2099))); } else { - years = {std::to_string(faker::number::integer(1970, 2099)), "*"}; + years = {std::to_string(number::integer(1970, 2099)), "*"}; } const auto minute = Helper::arrayElement(minutes); diff --git a/src/modules/vehicle/Vehicle.cpp b/src/modules/vehicle/Vehicle.cpp index 3080a93ad..0fdf833d6 100644 --- a/src/modules/vehicle/Vehicle.cpp +++ b/src/modules/vehicle/Vehicle.cpp @@ -54,7 +54,7 @@ std::string vin() return FormatHelper::format("{}{}{}{}", String::alphanumeric(10, StringCasing::Upper, exclude_characters), String::alpha(1, StringCasing::Upper, exclude_characters), String::alphanumeric(1, StringCasing::Upper, exclude_characters), - faker::number::integer(10000, 99999)); + number::integer(10000, 99999)); } std::string vrm() diff --git a/src/modules/word/Word.cpp b/src/modules/word/Word.cpp index 3e6c16171..f0282aee8 100644 --- a/src/modules/word/Word.cpp +++ b/src/modules/word/Word.cpp @@ -63,7 +63,7 @@ std::string words(unsigned numberOfWords) for (unsigned i = 0; i < numberOfWords; i++) { - tmp[i] = faker::number::integer(last_index); + tmp[i] = number::integer(last_index); auto vw = _allWords[tmp[i]]; reserve_size += vw.size(); } diff --git a/tests/modules/git/GitTest.cpp b/tests/modules/git/GitTest.cpp index b91e9cc72..10770a7f0 100644 --- a/tests/modules/git/GitTest.cpp +++ b/tests/modules/git/GitTest.cpp @@ -48,7 +48,7 @@ TEST_F(GitTest, shouldGenerateBranch) TEST_F(GitTest, branchIssueNumTest) { - auto testValue = unsigned(faker::number::integer(2, 100)); + auto testValue = unsigned(number::integer(2, 100)); std::vector branchElements = StringHelper::split(branch(testValue), "-"); diff --git a/tests/modules/internet/InternetTest.cpp b/tests/modules/internet/InternetTest.cpp index 78fcffa9b..10c0841ce 100644 --- a/tests/modules/internet/InternetTest.cpp +++ b/tests/modules/internet/InternetTest.cpp @@ -734,7 +734,7 @@ TEST_F(InternetTest, shouldGenerateAnonymousUsername) { for (int i = 0; i < 100; i++) { - const std::integral auto maxLength = faker::number::integer(6, 20); + const std::integral auto maxLength = number::integer(6, 20); const auto generatedUsername = Internet::anonymousUsername(maxLength); ASSERT_EQ(generatedUsername.length(), maxLength);