diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..09505236f --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,31 @@ +{ + "name": "Existing Dockerfile", + "build": { + "context": "..", + "dockerfile": "../Dockerfile.gcc13" + }, + "customizations": { + "vscode": { + "extensions": [ + "twxs.cmake", + "ms-vscode.cmake-tools", + "ms-vscode.cpptools", + "ms-vscode.cpptools-extension-pack", + "jbenden.c-cpp-flylint", + "matepek.vscode-catch2-test-adapter", + "piotrkosek.vscode-gtest-test-adapter-with-code-lens", + "derivitec-ltd.cmake-test-adapter", + "fredericbonnet.cmake-test-adapter", + "streetsidesoftware.code-spell-checker" + ] + } + }, + "features": { + "ghcr.io/devcontainers/features/git:1": {} + } + // "features": {}, + // "forwardPorts": [], + // "postCreateCommand": "cat /etc/os-release", + // "customizations": {}, + // "remoteUser": "devcontainer" +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index ce821e9d7..ac2c42e8d 100644 --- a/.gitignore +++ b/.gitignore @@ -49,8 +49,8 @@ src/modules/location/.DS_Store html/ latex/ - CMakeSettings.json - .vs/ - out/ - build-linux-gxx - build-linux-clang +CMakeSettings.json +.vs/ +out/ +build-linux-gxx +build-linux-clang diff --git a/Dockerfile.gcc13 b/Dockerfile.gcc13 new file mode 100644 index 000000000..1c3ff82d8 --- /dev/null +++ b/Dockerfile.gcc13 @@ -0,0 +1,8 @@ +FROM gcc:13.2 + +RUN apt update -y && \ + apt install -y cmake ninja-build && \ + ln -s /usr/local/bin/g++ /usr/bin/g++-13 && \ + rm -rf /var/lib/apt/lists/* + +ENTRYPOINT [ "bash" ] \ No newline at end of file diff --git a/src/common/StringHelper.cpp b/src/common/StringHelper.cpp index 6c6aab37f..3b4c87f30 100644 --- a/src/common/StringHelper.cpp +++ b/src/common/StringHelper.cpp @@ -59,8 +59,7 @@ std::string StringHelper::toLower(const std::string& data) { std::string lowerData{data}; - std::transform(lowerData.begin(), lowerData.end(), lowerData.begin(), - [](unsigned char c) { return std::tolower(c); }); + std::ranges::transform(lowerData, lowerData.begin(), [](unsigned char c) { return std::tolower(c); }); return lowerData; } diff --git a/src/modules/book/BookTest.cpp b/src/modules/book/BookTest.cpp index da4347b09..bd19bdf48 100644 --- a/src/modules/book/BookTest.cpp +++ b/src/modules/book/BookTest.cpp @@ -22,32 +22,29 @@ TEST_F(BookTest, shouldGenerateTitle) { const auto bookTitle = Book::title(); - ASSERT_TRUE(std::any_of(titles.begin(), titles.end(), - [bookTitle](const std::string& title) { return title == bookTitle; })); + ASSERT_TRUE(std::ranges::any_of(titles, [bookTitle](const std::string& title) { return title == bookTitle; })); } TEST_F(BookTest, shouldGenerateGenre) { const auto bookGenre = Book::genre(); - ASSERT_TRUE(std::any_of(genres.begin(), genres.end(), - [bookGenre](const std::string& genre) { return genre == bookGenre; })); + ASSERT_TRUE(std::ranges::any_of(genres, [bookGenre](const std::string& genre) { return genre == bookGenre; })); } TEST_F(BookTest, shouldGenerateAuthor) { const auto bookAuthor = Book::author(); - ASSERT_TRUE(std::any_of(authors.begin(), authors.end(), - [bookAuthor](const std::string& author) { return author == bookAuthor; })); + ASSERT_TRUE(std::ranges::any_of(authors, [bookAuthor](const std::string& author) { return author == bookAuthor; })); } TEST_F(BookTest, shouldGeneratePublisher) { const auto bookPublisher = Book::publisher(); - ASSERT_TRUE(std::any_of(publishers.begin(), publishers.end(), - [bookPublisher](const std::string& publisher) { return publisher == bookPublisher; })); + ASSERT_TRUE(std::ranges::any_of(publishers, [bookPublisher](const std::string& publisher) + { return publisher == bookPublisher; })); } TEST_F(BookTest, shouldGenerateIsbn) diff --git a/src/modules/color/ColorTest.cpp b/src/modules/color/ColorTest.cpp index 62ae5a74d..8682c969c 100644 --- a/src/modules/color/ColorTest.cpp +++ b/src/modules/color/ColorTest.cpp @@ -1,6 +1,7 @@ #include "faker-cxx/Color.h" #include +#include #include "gtest/gtest.h" @@ -20,9 +21,8 @@ TEST_F(ColorTest, shouldGenerateColorName) { const auto generatedColorName = Color::name(); - ASSERT_TRUE(std::any_of(colors.begin(), colors.end(), - [generatedColorName](const std::string& colorName) - { return colorName == generatedColorName; })); + ASSERT_TRUE(std::ranges::any_of(colors, [generatedColorName](const std::string& colorName) + { return colorName == generatedColorName; })); } TEST_F(ColorTest, shouldGenerateRgbColorWithoutAlpha) @@ -31,9 +31,10 @@ TEST_F(ColorTest, shouldGenerateRgbColorWithoutAlpha) const auto rgbNumbers = StringHelper::split(generatedRgbColor.substr(4, generatedRgbColor.size() - 1), " "); - const auto& red = std::stoi(rgbNumbers[0]); - const auto& green = std::stoi(rgbNumbers[1]); - const auto& blue = std::stoi(rgbNumbers[2]); + int red, green, blue; + std::from_chars(rgbNumbers[0].data(), rgbNumbers[0].data() + rgbNumbers[0].size(), red); + std::from_chars(rgbNumbers[1].data(), rgbNumbers[1].data() + rgbNumbers[1].size(), green); + std::from_chars(rgbNumbers[2].data(), rgbNumbers[2].data() + rgbNumbers[2].size(), blue); ASSERT_TRUE(generatedRgbColor.starts_with("rgb(")); ASSERT_TRUE(generatedRgbColor.ends_with(")")); @@ -48,10 +49,11 @@ TEST_F(ColorTest, shouldGenerateRgbColorWithAlpha) const auto rgbaNumbers = StringHelper::split(generatedRgbaColor.substr(5, generatedRgbaColor.size() - 1), " "); - const auto& red = std::stoi(rgbaNumbers[0]); - const auto& green = std::stoi(rgbaNumbers[1]); - const auto& blue = std::stoi(rgbaNumbers[2]); - const auto& alpha = std::stod(rgbaNumbers[3]); + int red, green, blue, alpha; + std::from_chars(rgbaNumbers[0].data(), rgbaNumbers[0].data() + rgbaNumbers[0].size(), red); + std::from_chars(rgbaNumbers[1].data(), rgbaNumbers[1].data() + rgbaNumbers[1].size(), green); + std::from_chars(rgbaNumbers[2].data(), rgbaNumbers[2].data() + rgbaNumbers[2].size(), blue); + std::from_chars(rgbaNumbers[3].data(), rgbaNumbers[3].data() + rgbaNumbers[3].size(), alpha); ASSERT_TRUE(generatedRgbaColor.starts_with("rgba(")); ASSERT_TRUE(generatedRgbaColor.ends_with(")")); @@ -70,9 +72,8 @@ TEST_F(ColorTest, shouldGenerateHexColorWithoutAlpha) ASSERT_EQ(hexadecimal.size(), 7); ASSERT_EQ(prefix, "#"); - ASSERT_TRUE(std::any_of(hexNumber.begin(), hexNumber.end(), - [hexNumber](char hexNumberCharacter) - { return hexLowerCharacters.find(hexNumberCharacter) != std::string::npos; })); + ASSERT_TRUE(std::ranges::any_of(hexNumber, [hexNumber](char hexNumberCharacter) + { return hexLowerCharacters.find(hexNumberCharacter) != std::string::npos; })); } TEST_F(ColorTest, shouldGenerateHexColorWithAlpha) @@ -84,7 +85,6 @@ TEST_F(ColorTest, shouldGenerateHexColorWithAlpha) ASSERT_EQ(hexadecimal.size(), 10); ASSERT_EQ(prefix, "0x"); - ASSERT_TRUE(std::any_of(hexNumber.begin(), hexNumber.end(), - [hexNumber](char hexNumberCharacter) - { return hexUpperCharacters.find(hexNumberCharacter) != std::string::npos; })); + ASSERT_TRUE(std::ranges::any_of(hexNumber, [hexNumber](char hexNumberCharacter) + { return hexUpperCharacters.find(hexNumberCharacter) != std::string::npos; })); } diff --git a/src/modules/commerce/CommerceTest.cpp b/src/modules/commerce/CommerceTest.cpp index 32efc1bc0..456e30946 100644 --- a/src/modules/commerce/CommerceTest.cpp +++ b/src/modules/commerce/CommerceTest.cpp @@ -1,6 +1,7 @@ #include "faker-cxx/Commerce.h" #include +#include #include "gtest/gtest.h" @@ -20,16 +21,16 @@ TEST_F(CommerceTest, shouldGenerateCommerceDepartment) { const auto generatedDepartment = Commerce::department(); - ASSERT_TRUE(std::any_of(departments.begin(), departments.end(), - [generatedDepartment](const std::string& department) - { return department == generatedDepartment; })); + ASSERT_TRUE(std::ranges::any_of(departments, [generatedDepartment](const std::string& department) + { return department == generatedDepartment; })); } TEST_F(CommerceTest, shouldGeneratePrice) { const auto generatedPrice = Commerce::price(100, 10000); - const auto priceAsFloat = std::stof(generatedPrice); + auto priceAsFloat{0.0f}; + std::from_chars(generatedPrice.data(), generatedPrice.data() + generatedPrice.size(), priceAsFloat); const auto generatedPriceElements = StringHelper::split(generatedPrice, "."); @@ -44,13 +45,13 @@ TEST_F(CommerceTest, shouldGenerateSku) const auto sku = Commerce::sku(); ASSERT_EQ(sku.size(), 4); - ASSERT_TRUE(std::all_of(sku.begin(), sku.end(), - [](char skuCharacter) - { - return std::any_of(numericCharacters.begin(), numericCharacters.end(), - [skuCharacter](char numericCharacter) - { return skuCharacter == numericCharacter; }); - })); + ASSERT_TRUE(std::ranges::all_of(sku, + [](char skuCharacter) + { + return std::ranges::any_of(numericCharacters, + [skuCharacter](char numericCharacter) + { return skuCharacter == numericCharacter; }); + })); } TEST_F(CommerceTest, shouldGenerateSkuWithSpecifiedLength) @@ -60,13 +61,13 @@ TEST_F(CommerceTest, shouldGenerateSkuWithSpecifiedLength) const auto sku = Commerce::sku(skuLength); ASSERT_EQ(sku.size(), skuLength); - ASSERT_TRUE(std::all_of(sku.begin(), sku.end(), - [](char skuCharacter) - { - return std::any_of(numericCharacters.begin(), numericCharacters.end(), - [skuCharacter](char numericCharacter) - { return skuCharacter == numericCharacter; }); - })); + ASSERT_TRUE(std::ranges::all_of(sku, + [](char skuCharacter) + { + return std::ranges::any_of(numericCharacters, + [skuCharacter](char numericCharacter) + { return skuCharacter == numericCharacter; }); + })); } TEST_F(CommerceTest, shouldGenerateProductFullName) @@ -79,40 +80,34 @@ TEST_F(CommerceTest, shouldGenerateProductFullName) const auto& generatedProductMaterial = productFullNameElements[1]; const auto& generatedProductName = productFullNameElements[2]; - ASSERT_TRUE(std::any_of(productAdjectives.begin(), productAdjectives.end(), - [generatedProductAdjective](const std::string& adjective) - { return adjective == generatedProductAdjective; })); - ASSERT_TRUE(std::any_of(productMaterials.begin(), productMaterials.end(), - [generatedProductMaterial](const std::string& material) - { return material == generatedProductMaterial; })); - ASSERT_TRUE(std::any_of(productNames.begin(), productNames.end(), - [generatedProductName](const std::string& productName) - { return productName == generatedProductName; })); + ASSERT_TRUE(std::ranges::any_of(productAdjectives, [generatedProductAdjective](const std::string& adjective) + { return adjective == generatedProductAdjective; })); + ASSERT_TRUE(std::ranges::any_of(productMaterials, [generatedProductMaterial](const std::string& material) + { return material == generatedProductMaterial; })); + ASSERT_TRUE(std::ranges::any_of(productNames, [generatedProductName](const std::string& productName) + { return productName == generatedProductName; })); } TEST_F(CommerceTest, shouldGenerateProductAdjective) { const auto generatedProductAdjective = Commerce::productAdjective(); - ASSERT_TRUE(std::any_of(productAdjectives.begin(), productAdjectives.end(), - [generatedProductAdjective](const std::string& adjective) - { return adjective == generatedProductAdjective; })); + ASSERT_TRUE(std::ranges::any_of(productAdjectives, [generatedProductAdjective](const std::string& adjective) + { return adjective == generatedProductAdjective; })); } TEST_F(CommerceTest, shouldGenerateProductMaterial) { const auto generatedProductMaterial = Commerce::productMaterial(); - ASSERT_TRUE(std::any_of(productMaterials.begin(), productMaterials.end(), - [generatedProductMaterial](const std::string& material) - { return material == generatedProductMaterial; })); + ASSERT_TRUE(std::ranges::any_of(productMaterials, [generatedProductMaterial](const std::string& material) + { return material == generatedProductMaterial; })); } TEST_F(CommerceTest, shouldGenerateProductName) { const auto generatedProductName = Commerce::productName(); - ASSERT_TRUE(std::any_of(productNames.begin(), productNames.end(), - [generatedProductName](const std::string& productName) - { return productName == generatedProductName; })); + ASSERT_TRUE(std::ranges::any_of(productNames, [generatedProductName](const std::string& productName) + { return productName == generatedProductName; })); } diff --git a/src/modules/company/CompanyTest.cpp b/src/modules/company/CompanyTest.cpp index 8f73a6c73..f51e3b571 100644 --- a/src/modules/company/CompanyTest.cpp +++ b/src/modules/company/CompanyTest.cpp @@ -43,12 +43,10 @@ TEST_F(CompanyTest, shouldGenerateCompanyName) const auto& generatedLastName = companyNameElements[0]; const auto& generatedCompanySuffix = companyNameElements[1]; - ASSERT_TRUE(std::any_of(englishLastNames.begin(), englishLastNames.end(), - [generatedLastName](const std::string& lastName) - { return lastName == generatedLastName; })); - ASSERT_TRUE(std::any_of(companySuffixes.begin(), companySuffixes.end(), - [generatedCompanySuffix](const std::string& companySuffix) - { return companySuffix == generatedCompanySuffix; })); + ASSERT_TRUE(std::ranges::any_of(englishLastNames, [generatedLastName](const std::string& lastName) + { return lastName == generatedLastName; })); + ASSERT_TRUE(std::ranges::any_of(companySuffixes, [generatedCompanySuffix](const std::string& companySuffix) + { return companySuffix == generatedCompanySuffix; })); } else if (companyNameElements.size() == 3) { @@ -56,15 +54,12 @@ TEST_F(CompanyTest, shouldGenerateCompanyName) const auto& generatedLastName = companyNameElements[1]; const auto& generatedJobArea = companyNameElements[2]; - ASSERT_TRUE(std::any_of(expectedFirstNames.begin(), expectedFirstNames.end(), - [generatedFirstName](const std::string& firstName) - { return firstName == generatedFirstName; })); - ASSERT_TRUE(std::any_of(englishLastNames.begin(), englishLastNames.end(), - [generatedLastName](const std::string& lastName) - { return lastName == generatedLastName; })); - ASSERT_TRUE(std::any_of(jobAreas.begin(), jobAreas.end(), - [generatedJobArea](const std::string& jobArea) - { return jobArea == generatedJobArea; })); + ASSERT_TRUE(std::ranges::any_of(expectedFirstNames, [generatedFirstName](const std::string& firstName) + { return firstName == generatedFirstName; })); + ASSERT_TRUE(std::ranges::any_of(englishLastNames, [generatedLastName](const std::string& lastName) + { return lastName == generatedLastName; })); + ASSERT_TRUE(std::ranges::any_of(jobAreas, [generatedJobArea](const std::string& jobArea) + { return jobArea == generatedJobArea; })); } else if (companyNameElements.size() == 4) { @@ -73,18 +68,15 @@ TEST_F(CompanyTest, shouldGenerateCompanyName) const auto& generatedJobArea = companyNameElements[2]; const auto& lastElement = companyNameElements[3]; - ASSERT_TRUE(std::any_of(expectedFirstNames.begin(), expectedFirstNames.end(), - [generatedFirstName](const std::string& firstName) - { return firstName == generatedFirstName; })); - ASSERT_TRUE(std::any_of(englishLastNames.begin(), englishLastNames.end(), - [generatedLastName](const std::string& lastName) - { return lastName == generatedLastName; })); - ASSERT_TRUE(std::any_of(jobAreas.begin(), jobAreas.end(), - [generatedJobArea](const std::string& jobArea) - { return jobArea == generatedJobArea; })); - ASSERT_TRUE(lastElement == "Services" || std::any_of(companySuffixes.begin(), companySuffixes.end(), - [lastElement](const std::string& companySuffix) - { return companySuffix == lastElement; })); + ASSERT_TRUE(std::ranges::any_of(expectedFirstNames, [generatedFirstName](const std::string& firstName) + { return firstName == generatedFirstName; })); + ASSERT_TRUE(std::ranges::any_of(englishLastNames, [generatedLastName](const std::string& lastName) + { return lastName == generatedLastName; })); + ASSERT_TRUE(std::ranges::any_of(jobAreas, [generatedJobArea](const std::string& jobArea) + { return jobArea == generatedJobArea; })); + ASSERT_TRUE(lastElement == "Services" || + std::ranges::any_of(companySuffixes, [lastElement](const std::string& companySuffix) + { return companySuffix == lastElement; })); } } @@ -92,100 +84,88 @@ TEST_F(CompanyTest, shouldGenerateCompanyType) { const auto generatedCompanyType = Company::type(); - ASSERT_TRUE(std::any_of(companyTypes.begin(), companyTypes.end(), - [generatedCompanyType](const std::string& companyType) - { return companyType == generatedCompanyType; })); + ASSERT_TRUE(std::ranges::any_of(companyTypes, [generatedCompanyType](const std::string& companyType) + { return companyType == generatedCompanyType; })); } TEST_F(CompanyTest, shouldGenerateCompanyIndustry) { const auto generatedCompanyIndustry = Company::industry(); - ASSERT_TRUE(std::any_of(companyIndustries.begin(), companyIndustries.end(), - [generatedCompanyIndustry](const std::string& companyIndustry) - { return companyIndustry == generatedCompanyIndustry; })); + ASSERT_TRUE(std::ranges::any_of(companyIndustries, [generatedCompanyIndustry](const std::string& companyIndustry) + { return companyIndustry == generatedCompanyIndustry; })); } TEST_F(CompanyTest, shouldGenerateBuzzPhrase) { const auto buzzPhrase = Company::buzzPhrase(); - ASSERT_TRUE(std::any_of(buzzVerbs.begin(), buzzVerbs.end(), - [buzzPhrase](const std::string& buzzVerb) - { return buzzPhrase.find(buzzVerb) != std::string::npos; })); - ASSERT_TRUE(std::any_of(buzzAdjectives.begin(), buzzAdjectives.end(), - [buzzPhrase](const std::string& buzzAdjective) - { return buzzPhrase.find(buzzAdjective) != std::string::npos; })); - ASSERT_TRUE(std::any_of(buzzNouns.begin(), buzzNouns.end(), - [buzzPhrase](const std::string& buzzNoun) - { return buzzPhrase.find(buzzNoun) != std::string::npos; })); + ASSERT_TRUE(std::ranges::any_of(buzzVerbs, [buzzPhrase](const std::string& buzzVerb) + { return buzzPhrase.find(buzzVerb) != std::string::npos; })); + ASSERT_TRUE(std::ranges::any_of(buzzAdjectives, [buzzPhrase](const std::string& buzzAdjective) + { return buzzPhrase.find(buzzAdjective) != std::string::npos; })); + ASSERT_TRUE(std::ranges::any_of(buzzNouns, [buzzPhrase](const std::string& buzzNoun) + { return buzzPhrase.find(buzzNoun) != std::string::npos; })); } TEST_F(CompanyTest, shouldGenerateBuzzVerb) { const auto generatedBuzzVerb = Company::buzzVerb(); - ASSERT_TRUE(std::any_of(buzzVerbs.begin(), buzzVerbs.end(), - [generatedBuzzVerb](const std::string& buzzVerb) - { return buzzVerb == generatedBuzzVerb; })); + ASSERT_TRUE(std::ranges::any_of(buzzVerbs, [generatedBuzzVerb](const std::string& buzzVerb) + { return buzzVerb == generatedBuzzVerb; })); } TEST_F(CompanyTest, shouldGenerateBuzzAdjective) { const auto generatedBuzzAdjective = Company::buzzAdjective(); - ASSERT_TRUE(std::any_of(buzzAdjectives.begin(), buzzAdjectives.end(), - [generatedBuzzAdjective](const std::string& buzzAdjective) - { return buzzAdjective == generatedBuzzAdjective; })); + ASSERT_TRUE(std::ranges::any_of(buzzAdjectives, [generatedBuzzAdjective](const std::string& buzzAdjective) + { return buzzAdjective == generatedBuzzAdjective; })); } TEST_F(CompanyTest, shouldGenerateBuzzNoun) { const auto generatedBuzzNoun = Company::buzzNoun(); - ASSERT_TRUE(std::any_of(buzzNouns.begin(), buzzNouns.end(), - [generatedBuzzNoun](const std::string& buzzNoun) - { return buzzNoun == generatedBuzzNoun; })); + ASSERT_TRUE(std::ranges::any_of(buzzNouns, [generatedBuzzNoun](const std::string& buzzNoun) + { return buzzNoun == generatedBuzzNoun; })); } TEST_F(CompanyTest, shouldGenerateCatchPhrase) { const auto catchPhrase = Company::catchPhrase(); - ASSERT_TRUE(std::any_of(catchPhraseAdjectives.begin(), catchPhraseAdjectives.end(), - [catchPhrase](const std::string& catchPhraseAdjective) - { return catchPhrase.find(catchPhraseAdjective) != std::string::npos; })); - ASSERT_TRUE(std::any_of(catchPhraseDescriptors.begin(), catchPhraseDescriptors.end(), - [catchPhrase](const std::string& catchPhraseDescriptor) - { return catchPhrase.find(catchPhraseDescriptor) != std::string::npos; })); - ASSERT_TRUE(std::any_of(catchPhraseNouns.begin(), catchPhraseNouns.end(), - [catchPhrase](const std::string& catchPhraseNoun) - { return catchPhrase.find(catchPhraseNoun) != std::string::npos; })); + ASSERT_TRUE(std::ranges::any_of(catchPhraseAdjectives, [catchPhrase](const std::string& catchPhraseAdjective) + { return catchPhrase.find(catchPhraseAdjective) != std::string::npos; })); + ASSERT_TRUE(std::ranges::any_of(catchPhraseDescriptors, [catchPhrase](const std::string& catchPhraseDescriptor) + { return catchPhrase.find(catchPhraseDescriptor) != std::string::npos; })); + ASSERT_TRUE(std::ranges::any_of(catchPhraseNouns, [catchPhrase](const std::string& catchPhraseNoun) + { return catchPhrase.find(catchPhraseNoun) != std::string::npos; })); } TEST_F(CompanyTest, shouldGenerateCatchPhraseAdjective) { const auto generatedCatchPhraseAdjective = Company::catchPhraseAdjective(); - ASSERT_TRUE(std::any_of(catchPhraseAdjectives.begin(), catchPhraseAdjectives.end(), - [generatedCatchPhraseAdjective](const std::string& catchPhraseAdjective) - { return catchPhraseAdjective == generatedCatchPhraseAdjective; })); + ASSERT_TRUE(std::ranges::any_of(catchPhraseAdjectives, + [generatedCatchPhraseAdjective](const std::string& catchPhraseAdjective) + { return catchPhraseAdjective == generatedCatchPhraseAdjective; })); } TEST_F(CompanyTest, shouldGenerateCatchPhraseDescriptor) { const auto generatedCatchPhraseDescriptor = Company::catchPhraseDescriptor(); - ASSERT_TRUE(std::any_of(catchPhraseDescriptors.begin(), catchPhraseDescriptors.end(), - [generatedCatchPhraseDescriptor](const std::string& catchPhraseDescriptor) - { return catchPhraseDescriptor == generatedCatchPhraseDescriptor; })); + ASSERT_TRUE(std::ranges::any_of(catchPhraseDescriptors, + [generatedCatchPhraseDescriptor](const std::string& catchPhraseDescriptor) + { return catchPhraseDescriptor == generatedCatchPhraseDescriptor; })); } TEST_F(CompanyTest, shouldGenerateCatchPhraseNoun) { const auto generatedCatchPhraseNoun = Company::catchPhraseNoun(); - ASSERT_TRUE(std::any_of(catchPhraseNouns.begin(), catchPhraseNouns.end(), - [generatedCatchPhraseNoun](const std::string& catchPhraseNoun) - { return catchPhraseNoun == generatedCatchPhraseNoun; })); + ASSERT_TRUE(std::ranges::any_of(catchPhraseNouns, [generatedCatchPhraseNoun](const std::string& catchPhraseNoun) + { return catchPhraseNoun == generatedCatchPhraseNoun; })); } diff --git a/src/modules/database/DatabaseTest.cpp b/src/modules/database/DatabaseTest.cpp index 85104d44d..adf4f66b5 100644 --- a/src/modules/database/DatabaseTest.cpp +++ b/src/modules/database/DatabaseTest.cpp @@ -22,35 +22,32 @@ TEST_F(DatabaseTest, shouldGenerateColumnName) { const auto generatedColumnName = Database::columnName(); - ASSERT_TRUE(std::any_of(columnNames.begin(), columnNames.end(), - [generatedColumnName](const std::string& columnName) - { return generatedColumnName == columnName; })); + ASSERT_TRUE(std::ranges::any_of(columnNames, [generatedColumnName](const std::string& columnName) + { return generatedColumnName == columnName; })); } TEST_F(DatabaseTest, shouldGenerateColumnType) { const auto generatedColumnType = Database::columnType(); - ASSERT_TRUE(std::any_of(columnTypes.begin(), columnTypes.end(), - [generatedColumnType](const std::string& columnType) - { return generatedColumnType == columnType; })); + ASSERT_TRUE(std::ranges::any_of(columnTypes, [generatedColumnType](const std::string& columnType) + { return generatedColumnType == columnType; })); } TEST_F(DatabaseTest, shouldGenerateEngine) { const auto generatedEngine = Database::engine(); - ASSERT_TRUE(std::any_of(engines.begin(), engines.end(), - [generatedEngine](const std::string& engine) { return generatedEngine == engine; })); + ASSERT_TRUE(std::ranges::any_of(engines, [generatedEngine](const std::string& engine) + { return generatedEngine == engine; })); } TEST_F(DatabaseTest, shouldGenerateCollation) { const auto generatedCollation = Database::collation(); - ASSERT_TRUE(std::any_of(collations.begin(), collations.end(), - [generatedCollation](const std::string& collation) - { return generatedCollation == collation; })); + ASSERT_TRUE(std::ranges::any_of(collations, [generatedCollation](const std::string& collation) + { return generatedCollation == collation; })); } TEST_F(DatabaseTest, shouldGenerateMongoDbObjectId) @@ -58,7 +55,6 @@ TEST_F(DatabaseTest, shouldGenerateMongoDbObjectId) const auto mongoDbObjectId = Database::mongoDbObjectId(); ASSERT_EQ(mongoDbObjectId.size(), 24); - ASSERT_TRUE(std::any_of(mongoDbObjectId.begin(), mongoDbObjectId.end(), - [](char hexNumberCharacter) - { return hexLowerCharacters.find(hexNumberCharacter) != std::string::npos; })); + ASSERT_TRUE(std::ranges::any_of(mongoDbObjectId, [](char hexNumberCharacter) + { return hexLowerCharacters.find(hexNumberCharacter) != std::string::npos; })); } diff --git a/src/modules/datatype/DatatypeTest.cpp b/src/modules/datatype/DatatypeTest.cpp index dd1d5023f..dbec3007f 100644 --- a/src/modules/datatype/DatatypeTest.cpp +++ b/src/modules/datatype/DatatypeTest.cpp @@ -18,8 +18,7 @@ TEST_F(DatatypeTest, shouldGenerateBoolean) const auto boolean = Datatype::boolean(); - ASSERT_TRUE(std::any_of(booleanValues.begin(), booleanValues.end(), - [boolean](bool booleanValue) { return boolean == booleanValue; })); + ASSERT_TRUE(std::ranges::any_of(booleanValues, [boolean](bool booleanValue) { return boolean == booleanValue; })); } TEST_F(DatatypeTest, BooleanWithProbTest) diff --git a/src/modules/date/DateTest.cpp b/src/modules/date/DateTest.cpp index 56e23a619..e547aae19 100644 --- a/src/modules/date/DateTest.cpp +++ b/src/modules/date/DateTest.cpp @@ -1,6 +1,7 @@ #include "faker-cxx/Date.h" #include +#include #include #include "gtest/gtest.h" @@ -36,15 +37,18 @@ class DateTest : public Test const auto& date = isoStringDateTime[0]; const auto dateElements = StringHelper::split(date, "-"); - const auto& year = std::stoi(dateElements[0]); - const auto& month = std::stoi(dateElements[1]); - const auto& day = std::stoi(dateElements[2]); + int year, month, day; + std::from_chars(dateElements[0].data(), dateElements[0].data() + dateElements[0].size(), year); + std::from_chars(dateElements[1].data(), dateElements[1].data() + dateElements[1].size(), month); + std::from_chars(dateElements[2].data(), dateElements[2].data() + dateElements[2].size(), day); const auto& time = isoStringDateTime[1]; const auto timeElements = StringHelper::split(time, ":"); - const auto& hour = std::stoi(timeElements[0]); - const auto& minutes = std::stoi(timeElements[1]); - const auto& seconds = std::stoi(timeElements[2]); + + int hour, minutes, seconds; + std::from_chars(timeElements[0].data(), timeElements[0].data() + timeElements[0].size(), hour); + std::from_chars(timeElements[1].data(), timeElements[1].data() + timeElements[1].size(), minutes); + std::from_chars(timeElements[2].data(), timeElements[2].data() + timeElements[2].size(), seconds); tm dateTime{}; @@ -151,34 +155,32 @@ TEST_F(DateTest, shouldGenerateWeekdayName) { const auto generatedWeekdayName = Date::weekdayName(); - ASSERT_TRUE(std::any_of(weekdayNames.begin(), weekdayNames.end(), - [generatedWeekdayName](const std::string& weekdayName) - { return weekdayName == generatedWeekdayName; })); + ASSERT_TRUE(std::ranges::any_of(weekdayNames, [generatedWeekdayName](const std::string& weekdayName) + { return weekdayName == generatedWeekdayName; })); } TEST_F(DateTest, shouldGenerateWeekdayAbbreviatedName) { const auto generatedWeekdayAbbreviatedName = Date::weekdayAbbreviatedName(); - ASSERT_TRUE(std::any_of(weekdayAbbreviatedNames.begin(), weekdayAbbreviatedNames.end(), - [generatedWeekdayAbbreviatedName](const std::string& weekdayAbbreviatedName) - { return weekdayAbbreviatedName == generatedWeekdayAbbreviatedName; })); + ASSERT_TRUE(std::ranges::any_of(weekdayAbbreviatedNames, + [generatedWeekdayAbbreviatedName](const std::string& weekdayAbbreviatedName) + { return weekdayAbbreviatedName == generatedWeekdayAbbreviatedName; })); } TEST_F(DateTest, shouldGenerateMonthName) { const auto generatedMonthName = Date::monthName(); - ASSERT_TRUE(std::any_of(monthNames.begin(), monthNames.end(), - [generatedMonthName](const std::string& monthName) - { return monthName == generatedMonthName; })); + ASSERT_TRUE(std::ranges::any_of(monthNames, [generatedMonthName](const std::string& monthName) + { return monthName == generatedMonthName; })); } TEST_F(DateTest, shouldGenerateMonthAbbreviatedName) { const auto generatedMonthAbbreviatedName = Date::monthAbbreviatedName(); - ASSERT_TRUE(std::any_of(monthAbbreviatedNames.begin(), monthAbbreviatedNames.end(), - [generatedMonthAbbreviatedName](const std::string& monthAbbreviatedName) - { return monthAbbreviatedName == generatedMonthAbbreviatedName; })); + ASSERT_TRUE(std::ranges::any_of(monthAbbreviatedNames, + [generatedMonthAbbreviatedName](const std::string& monthAbbreviatedName) + { return monthAbbreviatedName == generatedMonthAbbreviatedName; })); } diff --git a/src/modules/finance/FinanceTest.cpp b/src/modules/finance/FinanceTest.cpp index d92dd9d4d..198543721 100644 --- a/src/modules/finance/FinanceTest.cpp +++ b/src/modules/finance/FinanceTest.cpp @@ -1,6 +1,7 @@ #include "faker-cxx/Finance.h" #include +#include #include #include @@ -86,24 +87,24 @@ class FinanceTest : public TestWithParam public: static bool checkIfAllCharactersAreNumeric(const std::string& data) { - return std::all_of(data.begin(), data.end(), - [](char dataCharacter) - { - return std::any_of(numericCharacters.begin(), numericCharacters.end(), - [dataCharacter](char numericCharacter) - { return numericCharacter == dataCharacter; }); - }); + return std::ranges::all_of(data, + [](char dataCharacter) + { + return std::ranges::any_of(numericCharacters, + [dataCharacter](char numericCharacter) + { return numericCharacter == dataCharacter; }); + }); } static bool checkIfAllCharactersAreCreditCardCharacters(const std::string& data) { - return std::all_of(data.begin(), data.end(), - [](char dataCharacter) - { - return std::any_of(creditCardCharacters.begin(), creditCardCharacters.end(), - [dataCharacter](char creditCardCharacter) - { return creditCardCharacter == dataCharacter; }); - }); + return std::ranges::all_of(data, + [](char dataCharacter) + { + return std::ranges::any_of(creditCardCharacters, + [dataCharacter](char creditCardCharacter) + { return creditCardCharacter == dataCharacter; }); + }); } }; @@ -111,51 +112,47 @@ TEST_F(FinanceTest, shouldGenerateCurrency) { const auto generatedCurrency = Finance::currency(); - ASSERT_TRUE(std::any_of(currencies.begin(), currencies.end(), - [generatedCurrency](const Currency& currency) { return currency == generatedCurrency; })); + ASSERT_TRUE(std::ranges::any_of(currencies, [generatedCurrency](const Currency& currency) + { return currency == generatedCurrency; })); } TEST_F(FinanceTest, shouldGenerateCurrencyName) { const auto generatedCurrencyName = Finance::currencyName(); - ASSERT_TRUE(std::any_of(currencies.begin(), currencies.end(), - [generatedCurrencyName](const Currency& currency) - { return currency.name == generatedCurrencyName; })); + ASSERT_TRUE(std::ranges::any_of(currencies, [generatedCurrencyName](const Currency& currency) + { return currency.name == generatedCurrencyName; })); } TEST_F(FinanceTest, shouldGenerateCurrencyCode) { const auto generatedCurrencyCode = Finance::currencyCode(); - ASSERT_TRUE(std::any_of(currencies.begin(), currencies.end(), - [generatedCurrencyCode](const Currency& currency) - { return currency.code == generatedCurrencyCode; })); + ASSERT_TRUE(std::ranges::any_of(currencies, [generatedCurrencyCode](const Currency& currency) + { return currency.code == generatedCurrencyCode; })); } TEST_F(FinanceTest, shouldGenerateCurrencySymbol) { const auto generatedCurrencySymbol = Finance::currencySymbol(); - ASSERT_TRUE(std::any_of(currencies.begin(), currencies.end(), - [generatedCurrencySymbol](const Currency& currency) - { return currency.symbol == generatedCurrencySymbol; })); + ASSERT_TRUE(std::ranges::any_of(currencies, [generatedCurrencySymbol](const Currency& currency) + { return currency.symbol == generatedCurrencySymbol; })); } TEST_F(FinanceTest, shouldGenerateAccountType) { const auto generatedAccountType = Finance::accountType(); - ASSERT_TRUE(std::any_of(accountTypes.begin(), accountTypes.end(), - [generatedAccountType](const std::string& accountType) - { return accountType == generatedAccountType; })); + ASSERT_TRUE(std::ranges::any_of(accountTypes, [generatedAccountType](const std::string& accountType) + { return accountType == generatedAccountType; })); } TEST_F(FinanceTest, shouldGenerateAmount) { + auto amountAsFloat{0.0f}; const auto generatedAmount = Finance::amount(); - - const auto amountAsFloat = std::stof(generatedAmount); + std::from_chars(generatedAmount.data(), generatedAmount.data() + generatedAmount.size(), amountAsFloat); const auto generatedAmountParts = StringHelper::split(generatedAmount, "."); @@ -226,9 +223,8 @@ TEST_F(FinanceTest, shouldGenerateBic) const auto polandBankIdentifiersCodes = bankIdentifiersCodesMapping.at(BicCountry::Poland); - ASSERT_TRUE(std::any_of(polandBankIdentifiersCodes.begin(), polandBankIdentifiersCodes.end(), - [bic](const std::string& polandBankIdentifierCode) - { return bic == polandBankIdentifierCode; })); + ASSERT_TRUE(std::ranges::any_of(polandBankIdentifiersCodes, [bic](const std::string& polandBankIdentifierCode) + { return bic == polandBankIdentifierCode; })); } TEST_F(FinanceTest, shouldGeneratePolandBic) @@ -237,9 +233,8 @@ TEST_F(FinanceTest, shouldGeneratePolandBic) const auto polandBankIdentifiersCodes = bankIdentifiersCodesMapping.at(BicCountry::Poland); - ASSERT_TRUE(std::any_of(polandBankIdentifiersCodes.begin(), polandBankIdentifiersCodes.end(), - [bic](const std::string& polandBankIdentifierCode) - { return bic == polandBankIdentifierCode; })); + ASSERT_TRUE(std::ranges::any_of(polandBankIdentifiersCodes, [bic](const std::string& polandBankIdentifierCode) + { return bic == polandBankIdentifierCode; })); } TEST_F(FinanceTest, shouldGenerateAccountNumber) @@ -354,14 +349,14 @@ TEST_F(FinanceTest, shouldGenerateBitcoinAddress) const std::string supportedBitcoinAddressCharacters = "ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz123456789"; ASSERT_TRUE(bitcoinAddress.starts_with("1") || bitcoinAddress.starts_with("3")); - ASSERT_TRUE(std::all_of(bitcoinAddress.begin(), bitcoinAddress.end(), - [&supportedBitcoinAddressCharacters](char dataCharacter) - { - return std::any_of(supportedBitcoinAddressCharacters.begin(), - supportedBitcoinAddressCharacters.end(), - [dataCharacter](char supportedBitcoinAddressCharacter) - { return supportedBitcoinAddressCharacter == dataCharacter; }); - })); + ASSERT_TRUE(std::ranges::all_of(bitcoinAddress, + [&supportedBitcoinAddressCharacters](char dataCharacter) + { + return std::ranges::any_of( + supportedBitcoinAddressCharacters, + [dataCharacter](char supportedBitcoinAddressCharacter) + { return supportedBitcoinAddressCharacter == dataCharacter; }); + })); } TEST_F(FinanceTest, shouldGenerateLitecoinAddress) @@ -375,14 +370,14 @@ TEST_F(FinanceTest, shouldGenerateLitecoinAddress) ASSERT_TRUE(litecoinAddress.starts_with("L") || litecoinAddress.starts_with("M") || litecoinAddress.starts_with("3")); - ASSERT_TRUE(std::all_of(litecoinAddress.begin(), litecoinAddress.end(), - [&supportedLitecoinAddressCharacters](char dataCharacter) - { - return std::any_of(supportedLitecoinAddressCharacters.begin(), - supportedLitecoinAddressCharacters.end(), - [dataCharacter](char supportedLitecoinAddressCharacter) - { return supportedLitecoinAddressCharacter == dataCharacter; }); - })); + ASSERT_TRUE(std::ranges::all_of(litecoinAddress, + [&supportedLitecoinAddressCharacters](char dataCharacter) + { + return std::ranges::any_of( + supportedLitecoinAddressCharacters, + [dataCharacter](char supportedLitecoinAddressCharacter) + { return supportedLitecoinAddressCharacter == dataCharacter; }); + })); } TEST_F(FinanceTest, shouldGenerateEthereumAddress) @@ -394,7 +389,6 @@ TEST_F(FinanceTest, shouldGenerateEthereumAddress) ASSERT_EQ(ethereumAddress.size(), 42); ASSERT_EQ(prefix, "0x"); - ASSERT_TRUE(std::any_of(hexNumber.begin(), hexNumber.end(), - [hexNumber](char hexNumberCharacter) - { return hexLowerCharacters.find(hexNumberCharacter) != std::string::npos; })); + ASSERT_TRUE(std::ranges::any_of(hexNumber, [hexNumber](char hexNumberCharacter) + { return hexLowerCharacters.find(hexNumberCharacter) != std::string::npos; })); } diff --git a/src/modules/helper/HelperTest.cpp b/src/modules/helper/HelperTest.cpp index dfff6064d..b58053a1c 100644 --- a/src/modules/helper/HelperTest.cpp +++ b/src/modules/helper/HelperTest.cpp @@ -24,7 +24,7 @@ TEST_F(HelperTest, ReplaceSymbolWithNumber) std::string result = Helper::replaceSymbolWithNumber(input); // The result should contain digits instead of '#' and '!' - ASSERT_TRUE(std::all_of(result.begin(), result.end(), ::isdigit)); + ASSERT_TRUE(std::ranges::all_of(result, ::isdigit)); } TEST_F(HelperTest, RegexpStyleStringParse) diff --git a/src/modules/internet/Internet.cpp b/src/modules/internet/Internet.cpp index 6df21099d..27b91e677 100644 --- a/src/modules/internet/Internet.cpp +++ b/src/modules/internet/Internet.cpp @@ -229,7 +229,7 @@ std::string Internet::mac(const std::string& sep) std::string currentSep = sep; std::vector acceptableSeparators = {":", "-", ""}; - if (std::find(acceptableSeparators.begin(), acceptableSeparators.end(), currentSep) == acceptableSeparators.end()) + if (std::ranges::find(acceptableSeparators, currentSep) == acceptableSeparators.end()) { currentSep = ":"; } diff --git a/src/modules/internet/InternetTest.cpp b/src/modules/internet/InternetTest.cpp index 3561f2f33..deb387ac8 100644 --- a/src/modules/internet/InternetTest.cpp +++ b/src/modules/internet/InternetTest.cpp @@ -1,6 +1,7 @@ #include "faker-cxx/Internet.h" #include +#include #include #include "gtest/gtest.h" @@ -45,15 +46,15 @@ IPv4Address deconstructIpv4String(const std::string& ipv4) constexpr char separator = '.'; - std::for_each(result.begin(), result.end(), - [&ss](unsigned int& c) - { - std::string token; + std::ranges::for_each(result, + [&ss](unsigned int& c) + { + std::string token; - std::getline(ss, token, separator); + std::getline(ss, token, separator); - c = static_cast(std::stoi(token)); - }); + std::from_chars(token.data(), token.data() + token.size(), c); + }); return result; } @@ -87,9 +88,8 @@ class InternetTest : public Test const auto generatedNoun = domainWord.substr(foundAdjective->size() + 1); - ASSERT_TRUE(std::any_of(nouns.begin(), nouns.end(), - [generatedNoun](const std::string& noun) - { return generatedNoun == StringHelper::toLower(noun); })); + ASSERT_TRUE(std::ranges::any_of(nouns, [generatedNoun](const std::string& noun) + { return generatedNoun == StringHelper::toLower(noun); })); } std::vector sortedAdjectivesDescendingBySize{adjectives}; @@ -103,12 +103,10 @@ TEST_F(InternetTest, shouldGenerateUsername) const auto username = Internet::username(); - ASSERT_TRUE(std::any_of(firstNames.begin(), firstNames.end(), - [username](const std::string& firstName) - { return username.find(firstName) != std::string::npos; })); - ASSERT_TRUE(std::any_of(englishLastNames.begin(), englishLastNames.end(), - [username](const std::string& lastName) - { return username.find(lastName) != std::string::npos; })); + ASSERT_TRUE(std::ranges::any_of(firstNames, [username](const std::string& firstName) + { return username.find(firstName) != std::string::npos; })); + ASSERT_TRUE(std::ranges::any_of(englishLastNames, [username](const std::string& lastName) + { return username.find(lastName) != std::string::npos; })); } TEST_F(InternetTest, shouldGenerateUsernameWithFirstNameProvided) @@ -118,9 +116,8 @@ TEST_F(InternetTest, shouldGenerateUsernameWithFirstNameProvided) const auto username = Internet::username(firstName); ASSERT_TRUE(username.find(firstName) != std::string::npos); - ASSERT_TRUE(std::any_of(englishLastNames.begin(), englishLastNames.end(), - [username](const std::string& lastName) - { return username.find(lastName) != std::string::npos; })); + ASSERT_TRUE(std::ranges::any_of(englishLastNames, [username](const std::string& lastName) + { return username.find(lastName) != std::string::npos; })); } TEST_F(InternetTest, shouldGenerateUsernameWithLastNameProvided) @@ -133,9 +130,8 @@ TEST_F(InternetTest, shouldGenerateUsernameWithLastNameProvided) const auto username = Internet::username(std::nullopt, lastName); - ASSERT_TRUE(std::any_of(firstNames.begin(), firstNames.end(), - [username](const std::string& firstName) - { return username.find(firstName) != std::string::npos; })); + ASSERT_TRUE(std::ranges::any_of(firstNames, [username](const std::string& firstName) + { return username.find(firstName) != std::string::npos; })); ASSERT_TRUE(username.find(lastName) != std::string::npos); } @@ -166,15 +162,12 @@ TEST_F(InternetTest, shouldGenerateEmail) const auto& generatedUsername = emailParts[0]; const auto& generatedEmailHost = emailParts[1]; - ASSERT_TRUE(std::any_of(emailHosts.begin(), emailHosts.end(), - [generatedEmailHost](const std::string& emailHost) - { return generatedEmailHost == emailHost; })); - ASSERT_TRUE(std::any_of(firstNames.begin(), firstNames.end(), - [generatedUsername](const std::string& firstName) - { return generatedUsername.find(firstName) != std::string::npos; })); - ASSERT_TRUE(std::any_of(englishLastNames.begin(), englishLastNames.end(), - [generatedUsername](const std::string& lastName) - { return generatedUsername.find(lastName) != std::string::npos; })); + ASSERT_TRUE(std::ranges::any_of(emailHosts, [generatedEmailHost](const std::string& emailHost) + { return generatedEmailHost == emailHost; })); + ASSERT_TRUE(std::ranges::any_of(firstNames, [generatedUsername](const std::string& firstName) + { return generatedUsername.find(firstName) != std::string::npos; })); + ASSERT_TRUE(std::ranges::any_of(englishLastNames, [generatedUsername](const std::string& lastName) + { return generatedUsername.find(lastName) != std::string::npos; })); } TEST_F(InternetTest, shouldGenerateEmailWithFirstName) @@ -190,13 +183,11 @@ TEST_F(InternetTest, shouldGenerateEmailWithFirstName) const auto& generatedUsername = emailParts[0]; const auto& generatedEmailHost = emailParts[1]; - ASSERT_TRUE(std::any_of(emailHosts.begin(), emailHosts.end(), - [generatedEmailHost](const std::string& emailHost) - { return generatedEmailHost == emailHost; })); + ASSERT_TRUE(std::ranges::any_of(emailHosts, [generatedEmailHost](const std::string& emailHost) + { return generatedEmailHost == emailHost; })); ASSERT_TRUE(generatedUsername.find(firstName) != std::string::npos); - ASSERT_TRUE(std::any_of(englishLastNames.begin(), englishLastNames.end(), - [generatedUsername](const std::string& lastName) - { return generatedUsername.find(lastName) != std::string::npos; })); + ASSERT_TRUE(std::ranges::any_of(englishLastNames, [generatedUsername](const std::string& lastName) + { return generatedUsername.find(lastName) != std::string::npos; })); } TEST_F(InternetTest, shouldGenerateEmailWithLastName) @@ -216,12 +207,10 @@ TEST_F(InternetTest, shouldGenerateEmailWithLastName) const auto& generatedUsername = emailParts[0]; const auto& generatedEmailHost = emailParts[1]; - ASSERT_TRUE(std::any_of(emailHosts.begin(), emailHosts.end(), - [generatedEmailHost](const std::string& emailHost) - { return generatedEmailHost == emailHost; })); - ASSERT_TRUE(std::any_of(firstNames.begin(), firstNames.end(), - [generatedUsername](const std::string& firstName) - { return generatedUsername.find(firstName) != std::string::npos; })); + ASSERT_TRUE(std::ranges::any_of(emailHosts, [generatedEmailHost](const std::string& emailHost) + { return generatedEmailHost == emailHost; })); + ASSERT_TRUE(std::ranges::any_of(firstNames, [generatedUsername](const std::string& firstName) + { return generatedUsername.find(firstName) != std::string::npos; })); ASSERT_TRUE(generatedUsername.find(lastName) != std::string::npos); } @@ -244,9 +233,8 @@ TEST_F(InternetTest, shouldGenerateEmailWithFullName) const auto& generatedUsername = emailParts[0]; const auto& generatedEmailHost = emailParts[1]; - ASSERT_TRUE(std::any_of(emailHosts.begin(), emailHosts.end(), - [generatedEmailHost](const std::string& emailHost) - { return generatedEmailHost == emailHost; })); + ASSERT_TRUE(std::ranges::any_of(emailHosts, [generatedEmailHost](const std::string& emailHost) + { return generatedEmailHost == emailHost; })); ASSERT_TRUE(generatedUsername.find(firstName) != std::string::npos); ASSERT_TRUE(generatedUsername.find(lastName) != std::string::npos); } @@ -269,12 +257,10 @@ TEST_F(InternetTest, shouldGenerateEmailWithSpecifiedEmailHost) const auto& generatedEmailHost = emailParts[1]; ASSERT_EQ(generatedEmailHost, emailHost); - ASSERT_TRUE(std::any_of(firstNames.begin(), firstNames.end(), - [generatedUsername](const std::string& firstName) - { return generatedUsername.find(firstName) != std::string::npos; })); - ASSERT_TRUE(std::any_of(englishLastNames.begin(), englishLastNames.end(), - [generatedUsername](const std::string& lastName) - { return generatedUsername.find(lastName) != std::string::npos; })); + ASSERT_TRUE(std::ranges::any_of(firstNames, [generatedUsername](const std::string& firstName) + { return generatedUsername.find(firstName) != std::string::npos; })); + ASSERT_TRUE(std::ranges::any_of(englishLastNames, [generatedUsername](const std::string& lastName) + { return generatedUsername.find(lastName) != std::string::npos; })); } TEST_F(InternetTest, shouldGenerateExampleEmail) @@ -292,15 +278,12 @@ TEST_F(InternetTest, shouldGenerateExampleEmail) const auto& generatedUsername = emailParts[0]; const auto& generatedEmailHost = emailParts[1]; - ASSERT_TRUE(std::any_of(emailExampleHosts.begin(), emailExampleHosts.end(), - [generatedEmailHost](const std::string& emailHost) - { return generatedEmailHost == emailHost; })); - ASSERT_TRUE(std::any_of(firstNames.begin(), firstNames.end(), - [generatedUsername](const std::string& firstName) - { return generatedUsername.find(firstName) != std::string::npos; })); - ASSERT_TRUE(std::any_of(englishLastNames.begin(), englishLastNames.end(), - [generatedUsername](const std::string& lastName) - { return generatedUsername.find(lastName) != std::string::npos; })); + ASSERT_TRUE(std::ranges::any_of(emailExampleHosts, [generatedEmailHost](const std::string& emailHost) + { return generatedEmailHost == emailHost; })); + ASSERT_TRUE(std::ranges::any_of(firstNames, [generatedUsername](const std::string& firstName) + { return generatedUsername.find(firstName) != std::string::npos; })); + ASSERT_TRUE(std::ranges::any_of(englishLastNames, [generatedUsername](const std::string& lastName) + { return generatedUsername.find(lastName) != std::string::npos; })); } TEST_F(InternetTest, shouldGenerateExampleEmailWithFirstName) @@ -316,13 +299,11 @@ TEST_F(InternetTest, shouldGenerateExampleEmailWithFirstName) const auto& generatedUsername = emailParts[0]; const auto& generatedEmailHost = emailParts[1]; - ASSERT_TRUE(std::any_of(emailExampleHosts.begin(), emailExampleHosts.end(), - [generatedEmailHost](const std::string& emailHost) - { return generatedEmailHost == emailHost; })); + ASSERT_TRUE(std::ranges::any_of(emailExampleHosts, [generatedEmailHost](const std::string& emailHost) + { return generatedEmailHost == emailHost; })); ASSERT_TRUE(generatedUsername.find(firstName) != std::string::npos); - ASSERT_TRUE(std::any_of(englishLastNames.begin(), englishLastNames.end(), - [generatedUsername](const std::string& lastName) - { return generatedUsername.find(lastName) != std::string::npos; })); + ASSERT_TRUE(std::ranges::any_of(englishLastNames, [generatedUsername](const std::string& lastName) + { return generatedUsername.find(lastName) != std::string::npos; })); } TEST_F(InternetTest, shouldGenerateExampleEmailWithLastName) @@ -342,12 +323,10 @@ TEST_F(InternetTest, shouldGenerateExampleEmailWithLastName) const auto& generatedUsername = emailParts[0]; const auto& generatedEmailHost = emailParts[1]; - ASSERT_TRUE(std::any_of(emailExampleHosts.begin(), emailExampleHosts.end(), - [generatedEmailHost](const std::string& emailHost) - { return generatedEmailHost == emailHost; })); - ASSERT_TRUE(std::any_of(firstNames.begin(), firstNames.end(), - [generatedUsername](const std::string& firstName) - { return generatedUsername.find(firstName) != std::string::npos; })); + ASSERT_TRUE(std::ranges::any_of(emailExampleHosts, [generatedEmailHost](const std::string& emailHost) + { return generatedEmailHost == emailHost; })); + ASSERT_TRUE(std::ranges::any_of(firstNames, [generatedUsername](const std::string& firstName) + { return generatedUsername.find(firstName) != std::string::npos; })); ASSERT_TRUE(generatedUsername.find(lastName) != std::string::npos); } @@ -370,9 +349,8 @@ TEST_F(InternetTest, shouldGenerateExampleEmailWithFullName) const auto& generatedUsername = emailParts[0]; const auto& generatedEmailHost = emailParts[1]; - ASSERT_TRUE(std::any_of(emailExampleHosts.begin(), emailExampleHosts.end(), - [generatedEmailHost](const std::string& emailHost) - { return generatedEmailHost == emailHost; })); + ASSERT_TRUE(std::ranges::any_of(emailExampleHosts, [generatedEmailHost](const std::string& emailHost) + { return generatedEmailHost == emailHost; })); ASSERT_TRUE(generatedUsername.find(firstName) != std::string::npos); ASSERT_TRUE(generatedUsername.find(lastName) != std::string::npos); } @@ -384,9 +362,8 @@ TEST_F(InternetTest, shouldGeneratePassword) const auto password = Internet::password(); ASSERT_EQ(password.size(), 15); - ASSERT_TRUE(std::all_of(password.begin(), password.end(), - [passwordCharacters](char passwordCharacter) - { return passwordCharacters.find(passwordCharacter) != std::string::npos; })); + ASSERT_TRUE(std::ranges::all_of(password, [passwordCharacters](char passwordCharacter) + { return passwordCharacters.find(passwordCharacter) != std::string::npos; })); } TEST_F(InternetTest, shouldGeneratePasswordWithSpecifiedLength) @@ -398,9 +375,8 @@ TEST_F(InternetTest, shouldGeneratePasswordWithSpecifiedLength) const auto password = Internet::password(passwordLength); ASSERT_EQ(password.size(), passwordLength); - ASSERT_TRUE(std::all_of(password.begin(), password.end(), - [passwordCharacters](char passwordCharacter) - { return passwordCharacters.find(passwordCharacter) != std::string::npos; })); + ASSERT_TRUE(std::ranges::all_of(password, [passwordCharacters](char passwordCharacter) + { return passwordCharacters.find(passwordCharacter) != std::string::npos; })); } TEST_F(InternetTest, shouldGenerateImageUrl) @@ -442,105 +418,104 @@ TEST_F(InternetTest, shouldGenerateEmoji) emojis.insert(emojis.end(), symbolEmojis.begin(), symbolEmojis.end()); emojis.insert(emojis.end(), flagEmojis.begin(), flagEmojis.end()); - ASSERT_TRUE(std::any_of(emojis.begin(), emojis.end(), - [generatedEmoji](const std::string& emoji) { return generatedEmoji == emoji; })); + ASSERT_TRUE( + std::ranges::any_of(emojis, [generatedEmoji](const std::string& emoji) { return generatedEmoji == emoji; })); } TEST_F(InternetTest, shouldGenerateSmileyEmoji) { const auto generatedEmoji = Internet::emoji(EmojiType::Smiley); - ASSERT_TRUE(std::any_of(smileyEmojis.begin(), smileyEmojis.end(), - [generatedEmoji](const std::string& emoji) { return generatedEmoji == emoji; })); + ASSERT_TRUE(std::ranges::any_of(smileyEmojis, + [generatedEmoji](const std::string& emoji) { return generatedEmoji == emoji; })); } TEST_F(InternetTest, shouldGenerateBodyEmoji) { const auto generatedEmoji = Internet::emoji(EmojiType::Body); - ASSERT_TRUE(std::any_of(bodyEmojis.begin(), bodyEmojis.end(), - [generatedEmoji](const std::string& emoji) { return generatedEmoji == emoji; })); + ASSERT_TRUE(std::ranges::any_of(bodyEmojis, + [generatedEmoji](const std::string& emoji) { return generatedEmoji == emoji; })); } TEST_F(InternetTest, shouldGeneratePersonEmoji) { const auto generatedEmoji = Internet::emoji(EmojiType::Person); - ASSERT_TRUE(std::any_of(personEmojis.begin(), personEmojis.end(), - [generatedEmoji](const std::string& emoji) { return generatedEmoji == emoji; })); + ASSERT_TRUE(std::ranges::any_of(personEmojis, + [generatedEmoji](const std::string& emoji) { return generatedEmoji == emoji; })); } TEST_F(InternetTest, shouldGenerateNatureEmoji) { const auto generatedEmoji = Internet::emoji(EmojiType::Nature); - ASSERT_TRUE(std::any_of(natureEmojis.begin(), natureEmojis.end(), - [generatedEmoji](const std::string& emoji) { return generatedEmoji == emoji; })); + ASSERT_TRUE(std::ranges::any_of(natureEmojis, + [generatedEmoji](const std::string& emoji) { return generatedEmoji == emoji; })); } TEST_F(InternetTest, shouldGenerateFoodEmoji) { const auto generatedEmoji = Internet::emoji(EmojiType::Food); - ASSERT_TRUE(std::any_of(foodEmojis.begin(), foodEmojis.end(), - [generatedEmoji](const std::string& emoji) { return generatedEmoji == emoji; })); + ASSERT_TRUE(std::ranges::any_of(foodEmojis, + [generatedEmoji](const std::string& emoji) { return generatedEmoji == emoji; })); } TEST_F(InternetTest, shouldGenerateTravelEmoji) { const auto generatedEmoji = Internet::emoji(EmojiType::Travel); - ASSERT_TRUE(std::any_of(travelEmojis.begin(), travelEmojis.end(), - [generatedEmoji](const std::string& emoji) { return generatedEmoji == emoji; })); + ASSERT_TRUE(std::ranges::any_of(travelEmojis, + [generatedEmoji](const std::string& emoji) { return generatedEmoji == emoji; })); } TEST_F(InternetTest, shouldGenerateActivityEmoji) { const auto generatedEmoji = Internet::emoji(EmojiType::Activity); - ASSERT_TRUE(std::any_of(activityEmojis.begin(), activityEmojis.end(), - [generatedEmoji](const std::string& emoji) { return generatedEmoji == emoji; })); + ASSERT_TRUE(std::ranges::any_of(activityEmojis, + [generatedEmoji](const std::string& emoji) { return generatedEmoji == emoji; })); } TEST_F(InternetTest, shouldGenerateObjectEmoji) { const auto generatedEmoji = Internet::emoji(EmojiType::Object); - ASSERT_TRUE(std::any_of(objectEmojis.begin(), objectEmojis.end(), - [generatedEmoji](const std::string& emoji) { return generatedEmoji == emoji; })); + ASSERT_TRUE(std::ranges::any_of(objectEmojis, + [generatedEmoji](const std::string& emoji) { return generatedEmoji == emoji; })); } TEST_F(InternetTest, shouldGenerateSymbolEmoji) { const auto generatedEmoji = Internet::emoji(EmojiType::Symbol); - ASSERT_TRUE(std::any_of(symbolEmojis.begin(), symbolEmojis.end(), - [generatedEmoji](const std::string& emoji) { return generatedEmoji == emoji; })); + ASSERT_TRUE(std::ranges::any_of(symbolEmojis, + [generatedEmoji](const std::string& emoji) { return generatedEmoji == emoji; })); } TEST_F(InternetTest, shouldGenerateFlagEmoji) { const auto generatedEmoji = Internet::emoji(EmojiType::Flag); - ASSERT_TRUE(std::any_of(flagEmojis.begin(), flagEmojis.end(), - [generatedEmoji](const std::string& emoji) { return generatedEmoji == emoji; })); + ASSERT_TRUE(std::ranges::any_of(flagEmojis, + [generatedEmoji](const std::string& emoji) { return generatedEmoji == emoji; })); } TEST_F(InternetTest, shouldGenerateProtocol) { const auto webProtocol = Internet::protocol(); - ASSERT_TRUE(std::any_of(webProtocols.begin(), webProtocols.end(), - [webProtocol](const std::string& protocol) { return webProtocol == protocol; })); + ASSERT_TRUE(std::ranges::any_of(webProtocols, + [webProtocol](const std::string& protocol) { return webProtocol == protocol; })); } TEST_F(InternetTest, shouldGenerateHttpMethod) { const auto generatedHttpMethod = Internet::httpMethod(); - ASSERT_TRUE(std::any_of(httpMethodNames.begin(), httpMethodNames.end(), - [generatedHttpMethod](const std::string& httpMethod) - { return generatedHttpMethod == httpMethod; })); + ASSERT_TRUE(std::ranges::any_of(httpMethodNames, [generatedHttpMethod](const std::string& httpMethod) + { return generatedHttpMethod == httpMethod; })); } TEST_F(InternetTest, shouldGenerateHttpStatusCode) @@ -554,54 +529,48 @@ TEST_F(InternetTest, shouldGenerateHttpStatusCode) statusCodes.insert(statusCodes.end(), httpStatusClientErrorCodes.begin(), httpStatusClientErrorCodes.end()); statusCodes.insert(statusCodes.end(), httpStatusServerErrorCodes.begin(), httpStatusServerErrorCodes.end()); - ASSERT_TRUE(std::any_of(statusCodes.begin(), statusCodes.end(), - [generatedHttpStatusCode](unsigned statusCode) - { return generatedHttpStatusCode == statusCode; })); + ASSERT_TRUE(std::ranges::any_of(statusCodes, [generatedHttpStatusCode](unsigned statusCode) + { return generatedHttpStatusCode == statusCode; })); } TEST_F(InternetTest, shouldGenerateHttpInformationalSuccessCode) { const auto generatedHttpStatusCode = Internet::httpStatusCode(HttpResponseType::Informational); - ASSERT_TRUE(std::any_of(httpStatusInformationalCodes.begin(), httpStatusInformationalCodes.end(), - [generatedHttpStatusCode](unsigned statusCode) - { return generatedHttpStatusCode == statusCode; })); + ASSERT_TRUE(std::ranges::any_of(httpStatusInformationalCodes, [generatedHttpStatusCode](unsigned statusCode) + { return generatedHttpStatusCode == statusCode; })); } TEST_F(InternetTest, shouldGenerateHttpStatusSuccessCode) { const auto generatedHttpStatusCode = Internet::httpStatusCode(HttpResponseType::Success); - ASSERT_TRUE(std::any_of(httpStatusSuccessCodes.begin(), httpStatusSuccessCodes.end(), - [generatedHttpStatusCode](unsigned statusCode) - { return generatedHttpStatusCode == statusCode; })); + ASSERT_TRUE(std::ranges::any_of(httpStatusSuccessCodes, [generatedHttpStatusCode](unsigned statusCode) + { return generatedHttpStatusCode == statusCode; })); } TEST_F(InternetTest, shouldGenerateHttpStatusRedirectionCode) { const auto generatedHttpStatusCode = Internet::httpStatusCode(HttpResponseType::Redirection); - ASSERT_TRUE(std::any_of(httpStatusRedirectionCodes.begin(), httpStatusRedirectionCodes.end(), - [generatedHttpStatusCode](unsigned statusCode) - { return generatedHttpStatusCode == statusCode; })); + ASSERT_TRUE(std::ranges::any_of(httpStatusRedirectionCodes, [generatedHttpStatusCode](unsigned statusCode) + { return generatedHttpStatusCode == statusCode; })); } TEST_F(InternetTest, shouldGenerateHttpStatusClientErrorCode) { const auto generatedHttpStatusCode = Internet::httpStatusCode(HttpResponseType::ClientError); - ASSERT_TRUE(std::any_of(httpStatusClientErrorCodes.begin(), httpStatusClientErrorCodes.end(), - [generatedHttpStatusCode](unsigned statusCode) - { return generatedHttpStatusCode == statusCode; })); + ASSERT_TRUE(std::ranges::any_of(httpStatusClientErrorCodes, [generatedHttpStatusCode](unsigned statusCode) + { return generatedHttpStatusCode == statusCode; })); } TEST_F(InternetTest, shouldGenerateHttpStatusServerErrorCode) { const auto generatedHttpStatusCode = Internet::httpStatusCode(HttpResponseType::ServerError); - ASSERT_TRUE(std::any_of(httpStatusServerErrorCodes.begin(), httpStatusServerErrorCodes.end(), - [generatedHttpStatusCode](unsigned statusCode) - { return generatedHttpStatusCode == statusCode; })); + ASSERT_TRUE(std::ranges::any_of(httpStatusServerErrorCodes, [generatedHttpStatusCode](unsigned statusCode) + { return generatedHttpStatusCode == statusCode; })); } TEST_F(InternetTest, shouldGenerateIpv4WithPrivateClassAAddress) @@ -652,16 +621,15 @@ TEST_F(InternetTest, shouldGenerateIpv6) ASSERT_EQ(generatedIpv6Parts.size(), 8); - ASSERT_TRUE(std::all_of(generatedIpv6Parts.begin(), generatedIpv6Parts.end(), - [](const std::string& generatedIpv6Part) { return generatedIpv6Part.size() == 4; })); - ASSERT_TRUE(std::all_of(generatedIpv6Parts.begin(), generatedIpv6Parts.end(), - [](const std::string& generatedIpv6Part) - { - return std::all_of( - generatedIpv6Part.begin(), generatedIpv6Part.end(), - [](char hexCharacter) - { return hexLowerCharacters.find(hexCharacter) != std::string::npos; }); - })); + 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& generatedIpv6Part) + { + return std::ranges::all_of( + generatedIpv6Part, [](char hexCharacter) + { return hexLowerCharacters.find(hexCharacter) != std::string::npos; }); + })); } TEST_F(InternetTest, MacDefaultSeparator) @@ -685,9 +653,8 @@ TEST_F(InternetTest, shouldGenerateDomainSuffix) { const auto generatedDomainSuffix = Internet::domainSuffix(); - ASSERT_TRUE(std::any_of(domainSuffixes.begin(), domainSuffixes.end(), - [generatedDomainSuffix](const std::string& domainSuffix) - { return generatedDomainSuffix == domainSuffix; })); + ASSERT_TRUE(std::ranges::any_of(domainSuffixes, [generatedDomainSuffix](const std::string& domainSuffix) + { return generatedDomainSuffix == domainSuffix; })); } TEST_F(InternetTest, shouldGenerateDomainWord) @@ -707,9 +674,8 @@ TEST_F(InternetTest, shouldGenerateDomainName) const auto& generatedDomainSuffix = generatedDomainNameParts[1]; assertDomainWord(generatedDomainWord); - ASSERT_TRUE(std::any_of(domainSuffixes.begin(), domainSuffixes.end(), - [generatedDomainSuffix](const std::string& domainSuffix) - { return generatedDomainSuffix == domainSuffix; })); + ASSERT_TRUE(std::ranges::any_of(domainSuffixes, [generatedDomainSuffix](const std::string& domainSuffix) + { return generatedDomainSuffix == domainSuffix; })); } TEST_F(InternetTest, shouldGenerateHttpsUrl) @@ -727,9 +693,8 @@ TEST_F(InternetTest, shouldGenerateHttpsUrl) const auto& generatedDomainSuffix = generatedDomainNameParts[1]; assertDomainWord(generatedDomainWord); - ASSERT_TRUE(std::any_of(domainSuffixes.begin(), domainSuffixes.end(), - [generatedDomainSuffix](const std::string& domainSuffix) - { return generatedDomainSuffix == domainSuffix; })); + ASSERT_TRUE(std::ranges::any_of(domainSuffixes, [generatedDomainSuffix](const std::string& domainSuffix) + { return generatedDomainSuffix == domainSuffix; })); ASSERT_EQ(generatedProtocol, "https"); } @@ -748,9 +713,8 @@ TEST_F(InternetTest, shouldGenerateHttpUrl) const auto& generatedDomainSuffix = generatedDomainNameParts[1]; assertDomainWord(generatedDomainWord); - ASSERT_TRUE(std::any_of(domainSuffixes.begin(), domainSuffixes.end(), - [generatedDomainSuffix](const std::string& domainSuffix) - { return generatedDomainSuffix == domainSuffix; })); + ASSERT_TRUE(std::ranges::any_of(domainSuffixes, [generatedDomainSuffix](const std::string& domainSuffix) + { return generatedDomainSuffix == domainSuffix; })); ASSERT_EQ(generatedProtocol, "http"); } diff --git a/src/modules/location/LocationTest.cpp b/src/modules/location/LocationTest.cpp index 571482a12..eb5dac0fb 100644 --- a/src/modules/location/LocationTest.cpp +++ b/src/modules/location/LocationTest.cpp @@ -1,6 +1,7 @@ #include "faker-cxx/Location.h" #include +#include #include "gtest/gtest.h" @@ -26,13 +27,13 @@ class LocationTest : public Test public: static bool checkIfAllCharactersAreNumeric(const std::string& data) { - return std::all_of(data.begin(), data.end(), - [](char dataCharacter) - { - return std::any_of(numericCharacters.begin(), numericCharacters.end(), - [dataCharacter](char numericCharacter) - { return numericCharacter == dataCharacter; }); - }); + return std::ranges::all_of(data, + [](char dataCharacter) + { + return std::ranges::any_of(numericCharacters, + [dataCharacter](char numericCharacter) + { return numericCharacter == dataCharacter; }); + }); } }; @@ -40,33 +41,32 @@ TEST_F(LocationTest, shouldGenerateCountry) { const auto generatedCountry = Location::country(); - ASSERT_TRUE(std::any_of(countries.begin(), countries.end(), - [generatedCountry](const std::string& country) { return country == generatedCountry; })); + ASSERT_TRUE(std::ranges::any_of(countries, [generatedCountry](const std::string& country) + { return country == generatedCountry; })); } TEST_F(LocationTest, shouldGenerateCountryCode) { const auto generatedCountryCode = Location::countryCode(); - ASSERT_TRUE(std::any_of(countryCodes.begin(), countryCodes.end(), - [generatedCountryCode](const std::string& countryCode) - { return countryCode == generatedCountryCode; })); + ASSERT_TRUE(std::ranges::any_of(countryCodes, [generatedCountryCode](const std::string& countryCode) + { return countryCode == generatedCountryCode; })); } TEST_F(LocationTest, shouldGenerateState) { const auto generatedState = Location::state(); - ASSERT_TRUE(std::any_of(states.begin(), states.end(), - [generatedState](const std::string& state) { return state == generatedState; })); + ASSERT_TRUE( + std::ranges::any_of(states, [generatedState](const std::string& state) { return state == generatedState; })); } TEST_F(LocationTest, shouldGenerateUsaCity) { const auto generatedCity = Location::city(); - ASSERT_TRUE(std::any_of(usaCities.begin(), usaCities.end(), - [generatedCity](const std::string& city) { return city == generatedCity; })); + ASSERT_TRUE( + std::ranges::any_of(usaCities, [generatedCity](const std::string& city) { return city == generatedCity; })); } TEST_F(LocationTest, shouldGenerateUsaZipCode) @@ -112,15 +112,12 @@ TEST_F(LocationTest, shouldGenerateUsaStreet) firstNames.insert(firstNames.end(), englishFirstNamesFemales.begin(), englishFirstNamesFemales.end()); ASSERT_EQ(generatedStreetElements.size(), 2); - ASSERT_TRUE(std::any_of(firstNames.begin(), firstNames.end(), - [generatedFirstOrLastName](const std::string& firstName) - { return firstName == generatedFirstOrLastName; }) || - std::any_of(englishLastNames.begin(), englishLastNames.end(), - [generatedFirstOrLastName](const std::string& lastName) - { return lastName == generatedFirstOrLastName; })); - ASSERT_TRUE(std::any_of(usaStreetSuffixes.begin(), usaStreetSuffixes.end(), - [generatedStreetSuffix](const std::string& streetSuffix) - { return streetSuffix == generatedStreetSuffix; })); + ASSERT_TRUE(std::ranges::any_of(firstNames, [generatedFirstOrLastName](const std::string& firstName) + { return firstName == generatedFirstOrLastName; }) || + std::ranges::any_of(englishLastNames, [generatedFirstOrLastName](const std::string& lastName) + { return lastName == generatedFirstOrLastName; })); + ASSERT_TRUE(std::ranges::any_of(usaStreetSuffixes, [generatedStreetSuffix](const std::string& streetSuffix) + { return streetSuffix == generatedStreetSuffix; })); } TEST_F(LocationTest, shouldGenerateUsaStreetAddress) @@ -139,23 +136,20 @@ TEST_F(LocationTest, shouldGenerateUsaStreetAddress) ASSERT_EQ(generatedStreetAddressElements.size(), 3); ASSERT_TRUE(generatedBuildingNumber.size() >= 3 && generatedBuildingNumber.size() <= 5); ASSERT_TRUE(checkIfAllCharactersAreNumeric(generatedBuildingNumber)); - ASSERT_TRUE(std::any_of(firstNames.begin(), firstNames.end(), - [generatedFirstOrLastName](const std::string& firstName) - { return firstName == generatedFirstOrLastName; }) || - std::any_of(englishLastNames.begin(), englishLastNames.end(), - [generatedFirstOrLastName](const std::string& lastName) - { return lastName == generatedFirstOrLastName; })); - ASSERT_TRUE(std::any_of(usaStreetSuffixes.begin(), usaStreetSuffixes.end(), - [generatedStreetSuffix](const std::string& streetSuffix) - { return streetSuffix == generatedStreetSuffix; })); + ASSERT_TRUE(std::ranges::any_of(firstNames, [generatedFirstOrLastName](const std::string& firstName) + { return firstName == generatedFirstOrLastName; }) || + std::ranges::any_of(englishLastNames, [generatedFirstOrLastName](const std::string& lastName) + { return lastName == generatedFirstOrLastName; })); + ASSERT_TRUE(std::ranges::any_of(usaStreetSuffixes, [generatedStreetSuffix](const std::string& streetSuffix) + { return streetSuffix == generatedStreetSuffix; })); } TEST_F(LocationTest, shouldGenerateRussiaCity) { const auto generatedCity = Location::city(Country::Russia); - ASSERT_TRUE(std::any_of(russiaCities.begin(), russiaCities.end(), - [generatedCity](const std::string& city) { return city == generatedCity; })); + ASSERT_TRUE( + std::ranges::any_of(russiaCities, [generatedCity](const std::string& city) { return city == generatedCity; })); } TEST_F(LocationTest, shouldGenerateRussiaZipCode) @@ -178,7 +172,8 @@ TEST_F(LocationTest, shouldGenerateLatitude) { const auto latitude = Location::latitude(); - const auto latitudeAsFloat = std::stof(latitude); + auto latitudeAsFloat{0.0f}; + std::from_chars(latitude.data(), latitude.data() + latitude.size(), latitudeAsFloat); const auto generatedLatitudeParts = StringHelper::split(latitude, "."); @@ -192,7 +187,8 @@ TEST_F(LocationTest, shouldGenerateLatitudeWithSpecifiedPrecision) { const auto latitude = Location::latitude(Precision::ThreeDp); - const auto latitudeAsFloat = std::stof(latitude); + auto latitudeAsFloat{0.0f}; + std::from_chars(latitude.data(), latitude.data() + latitude.size(), latitudeAsFloat); const auto generatedLatitudeParts = StringHelper::split(latitude, "."); @@ -206,7 +202,8 @@ TEST_F(LocationTest, shouldGenerateLongitude) { const auto longitude = Location::longitude(); - const auto longitudeAsFloat = std::stof(longitude); + auto longitudeAsFloat{0.0f}; + std::from_chars(longitude.data(), longitude.data() + longitude.size(), longitudeAsFloat); const auto generatedLongitudeParts = StringHelper::split(longitude, "."); @@ -220,7 +217,8 @@ TEST_F(LocationTest, shouldGenerateLongitudeWithSpecifiedPrecision) { const auto longitude = Location::longitude(Precision::SixDp); - const auto longitudeAsFloat = std::stof(longitude); + auto longitudeAsFloat{0.0f}; + std::from_chars(longitude.data(), longitude.data() + longitude.size(), longitudeAsFloat); const auto generatedLongitudeParts = StringHelper::split(longitude, "."); @@ -234,16 +232,14 @@ TEST_F(LocationTest, shouldGenerateDirection) { const auto generatedDirection = Location::direction(); - ASSERT_TRUE(std::any_of(directions.begin(), directions.end(), - [generatedDirection](const std::string& direction) - { return direction == generatedDirection; })); + ASSERT_TRUE(std::ranges::any_of(directions, [generatedDirection](const std::string& direction) + { return direction == generatedDirection; })); } TEST_F(LocationTest, shouldGenerateTimeZone) { const auto generatedTimeZone = Location::timeZone(); - ASSERT_TRUE(std::any_of(timeZones.begin(), timeZones.end(), - [generatedTimeZone](const std::string& timeZone) - { return timeZone == generatedTimeZone; })); + ASSERT_TRUE(std::ranges::any_of(timeZones, [generatedTimeZone](const std::string& timeZone) + { return timeZone == generatedTimeZone; })); } diff --git a/src/modules/lorem/LoremTest.cpp b/src/modules/lorem/LoremTest.cpp index 4f2f5a806..bac2f2340 100644 --- a/src/modules/lorem/LoremTest.cpp +++ b/src/modules/lorem/LoremTest.cpp @@ -19,8 +19,8 @@ TEST_F(LoremTest, shouldGenerateWord) { const auto generatedWord = Lorem::word(); - ASSERT_TRUE(std::any_of(loremWords.begin(), loremWords.end(), - [generatedWord](const std::string& word) { return word == generatedWord; })); + ASSERT_TRUE( + std::ranges::any_of(loremWords, [generatedWord](const std::string& word) { return word == generatedWord; })); } TEST_F(LoremTest, shouldGenerateWords) @@ -32,16 +32,14 @@ TEST_F(LoremTest, shouldGenerateWords) const auto separatedWords = StringHelper::split(generatedWords, " "); ASSERT_EQ(separatedWords.size(), numberOfWords); - ASSERT_TRUE(std::all_of(separatedWords.begin(), separatedWords.end(), - [](const std::string& separatedWord) - { - return std::any_of(loremWords.begin(), loremWords.end(), - [separatedWord](const std::string& word) { - return word == - static_cast(std::tolower(separatedWord[0])) + - separatedWord.substr(1); - }); - })); + ASSERT_TRUE(std::ranges::all_of( + separatedWords, + [](const std::string& separatedWord) + { + return std::ranges::any_of( + loremWords, [separatedWord](const std::string& word) + { return word == static_cast(std::tolower(separatedWord[0])) + separatedWord.substr(1); }); + })); } TEST_F(LoremTest, shouldGenerateSentence) @@ -55,15 +53,14 @@ TEST_F(LoremTest, shouldGenerateSentence) ASSERT_TRUE(std::isupper(sentence[0])); ASSERT_TRUE(sentence.ends_with(".")); ASSERT_TRUE(sentenceWords.size() >= 3 && sentenceWords.size() <= 10); - ASSERT_TRUE(std::all_of(sentenceWords.begin(), sentenceWords.end(), - [](const std::string& sentenceWord) - { - return std::any_of(loremWords.begin(), loremWords.end(), - [sentenceWord](const std::string& word) { - return word == static_cast(std::tolower(sentenceWord[0])) + - sentenceWord.substr(1); - }); - })); + ASSERT_TRUE(std::ranges::all_of( + sentenceWords, + [](const std::string& sentenceWord) + { + return std::ranges::any_of( + loremWords, [sentenceWord](const std::string& word) + { return word == static_cast(std::tolower(sentenceWord[0])) + sentenceWord.substr(1); }); + })); } TEST_F(LoremTest, shouldGenerateSentences) @@ -82,16 +79,14 @@ TEST_F(LoremTest, shouldGenerateSentences) ASSERT_TRUE(sentenceWords.size() >= 3 && sentenceWords.size() <= 10); - ASSERT_TRUE(std::all_of(sentenceWords.begin(), sentenceWords.end(), - [](const std::string& sentenceWord) - { - return std::any_of(loremWords.begin(), loremWords.end(), - [sentenceWord](const std::string& word) { - return word == - static_cast(std::tolower(sentenceWord[0])) + - sentenceWord.substr(1); - }); - })); + ASSERT_TRUE(std::ranges::all_of( + sentenceWords, + [](const std::string& sentenceWord) + { + return std::ranges::any_of( + loremWords, [sentenceWord](const std::string& word) + { return word == static_cast(std::tolower(sentenceWord[0])) + sentenceWord.substr(1); }); + })); } } @@ -102,16 +97,14 @@ TEST_F(LoremTest, shouldGenerateSlug) const auto separatedWords = StringHelper::split(generatedSlug, "-"); ASSERT_EQ(separatedWords.size(), 3); - ASSERT_TRUE(std::all_of(separatedWords.begin(), separatedWords.end(), - [](const std::string& separatedWord) - { - return std::any_of(loremWords.begin(), loremWords.end(), - [separatedWord](const std::string& word) { - return word == - static_cast(std::tolower(separatedWord[0])) + - separatedWord.substr(1); - }); - })); + ASSERT_TRUE(std::ranges::all_of( + separatedWords, + [](const std::string& separatedWord) + { + return std::ranges::any_of( + loremWords, [separatedWord](const std::string& word) + { return word == static_cast(std::tolower(separatedWord[0])) + separatedWord.substr(1); }); + })); } TEST_F(LoremTest, shouldGenerateParagraph) @@ -130,16 +123,14 @@ TEST_F(LoremTest, shouldGenerateParagraph) ASSERT_TRUE(sentenceWords.size() >= 3 && sentenceWords.size() <= 10); - ASSERT_TRUE(std::all_of(sentenceWords.begin(), sentenceWords.end(), - [](const std::string& sentenceWord) - { - return std::any_of(loremWords.begin(), loremWords.end(), - [sentenceWord](const std::string& word) { - return word == - static_cast(std::tolower(sentenceWord[0])) + - sentenceWord.substr(1); - }); - })); + ASSERT_TRUE(std::ranges::all_of( + sentenceWords, + [](const std::string& sentenceWord) + { + return std::ranges::any_of( + loremWords, [sentenceWord](const std::string& word) + { return word == static_cast(std::tolower(sentenceWord[0])) + sentenceWord.substr(1); }); + })); } } @@ -163,16 +154,14 @@ TEST_F(LoremTest, shouldGenerateParagraphs) ASSERT_TRUE(sentenceWords.size() >= 3 && sentenceWords.size() <= 10); - ASSERT_TRUE(std::all_of(sentenceWords.begin(), sentenceWords.end(), - [](const std::string& sentenceWord) - { - return std::any_of(loremWords.begin(), loremWords.end(), - [sentenceWord](const std::string& word) { - return word == - static_cast(std::tolower(sentenceWord[0])) + - sentenceWord.substr(1); - }); - })); + ASSERT_TRUE(std::ranges::all_of( + sentenceWords, + [](const std::string& sentenceWord) + { + return std::ranges::any_of( + loremWords, [sentenceWord](const std::string& word) + { return word == static_cast(std::tolower(sentenceWord[0])) + sentenceWord.substr(1); }); + })); } } } diff --git a/src/modules/movie/MovieTest.cpp b/src/modules/movie/MovieTest.cpp index 2f316bcdb..10156ce33 100644 --- a/src/modules/movie/MovieTest.cpp +++ b/src/modules/movie/MovieTest.cpp @@ -22,40 +22,38 @@ TEST_F(MovieTest, shouldGenerateGenre) { const auto generatedGenre = Movie::genre(); - ASSERT_TRUE(std::any_of(genres.begin(), genres.end(), - [generatedGenre](const std::string& genre) { return generatedGenre == genre; })); + ASSERT_TRUE( + std::ranges::any_of(genres, [generatedGenre](const std::string& genre) { return generatedGenre == genre; })); } TEST_F(MovieTest, shouldGenerateMovieTitle) { const auto generatedMovieTitle = Movie::movieTitle(); - ASSERT_TRUE(std::any_of(movieTitles.begin(), movieTitles.end(), - [generatedMovieTitle](const std::string& movieTitle) - { return generatedMovieTitle == movieTitle; })); + ASSERT_TRUE(std::ranges::any_of(movieTitles, [generatedMovieTitle](const std::string& movieTitle) + { return generatedMovieTitle == movieTitle; })); } TEST_F(MovieTest, shouldGenerateDirector) { const auto generatedDirector = Movie::director(); - ASSERT_TRUE(std::any_of(directors.begin(), directors.end(), - [generatedDirector](const std::string& director) - { return generatedDirector == director; })); + ASSERT_TRUE(std::ranges::any_of(directors, [generatedDirector](const std::string& director) + { return generatedDirector == director; })); } TEST_F(MovieTest, shouldGenerateActor) { const auto generatedActor = Movie::actor(); - ASSERT_TRUE(std::any_of(actors.begin(), actors.end(), - [generatedActor](const std::string& actor) { return generatedActor == actor; })); + ASSERT_TRUE( + std::ranges::any_of(actors, [generatedActor](const std::string& actor) { return generatedActor == actor; })); } TEST_F(MovieTest, shouldGenerateActress) { const auto generatedActress = Movie::actress(); - ASSERT_TRUE(std::any_of(actresses.begin(), actresses.end(), - [generatedActress](const std::string& actress) { return generatedActress == actress; })); + ASSERT_TRUE(std::ranges::any_of(actresses, [generatedActress](const std::string& actress) + { return generatedActress == actress; })); } diff --git a/src/modules/music/MusicTest.cpp b/src/modules/music/MusicTest.cpp index 960459182..39acb6c4d 100644 --- a/src/modules/music/MusicTest.cpp +++ b/src/modules/music/MusicTest.cpp @@ -20,23 +20,22 @@ TEST_F(MusicTest, shouldGenerateArtist) { const auto generatedArtist = Music::artist(); - ASSERT_TRUE(std::any_of(artists.begin(), artists.end(), - [generatedArtist](const std::string& artist) { return generatedArtist == artist; })); + ASSERT_TRUE(std::ranges::any_of(artists, [generatedArtist](const std::string& artist) + { return generatedArtist == artist; })); } TEST_F(MusicTest, shouldGenerateGenre) { const auto generatedGenre = Music::genre(); - ASSERT_TRUE(std::any_of(genres.begin(), genres.end(), - [generatedGenre](const std::string& genre) { return generatedGenre == genre; })); + ASSERT_TRUE( + std::ranges::any_of(genres, [generatedGenre](const std::string& genre) { return generatedGenre == genre; })); } TEST_F(MusicTest, shouldGenerateSongName) { const auto generatedSongName = Music::songName(); - ASSERT_TRUE(std::any_of(songNames.begin(), songNames.end(), - [generatedSongName](const std::string& songName) - { return generatedSongName == songName; })); + ASSERT_TRUE(std::ranges::any_of(songNames, [generatedSongName](const std::string& songName) + { return generatedSongName == songName; })); } diff --git a/src/modules/person/PersonTest.cpp b/src/modules/person/PersonTest.cpp index d5cff2a91..a54a5eab6 100644 --- a/src/modules/person/PersonTest.cpp +++ b/src/modules/person/PersonTest.cpp @@ -89,9 +89,8 @@ TEST_P(PersonTest, shouldGenerateFirstName) const auto generatedFirstName = Person::firstName(language); - ASSERT_TRUE(std::any_of(firstNames.begin(), firstNames.end(), - [generatedFirstName](const std::string& firstName) - { return firstName == generatedFirstName; })); + ASSERT_TRUE(std::ranges::any_of(firstNames, [generatedFirstName](const std::string& firstName) + { return firstName == generatedFirstName; })); } TEST_P(PersonTest, shouldGeneratemMaleFirstName) @@ -104,9 +103,8 @@ TEST_P(PersonTest, shouldGeneratemMaleFirstName) const auto generatedFirstName = Person::firstName(language, Sex::Male); - ASSERT_TRUE(std::any_of(firstNamesMales.begin(), firstNamesMales.end(), - [generatedFirstName](const std::string& firstName) - { return firstName == generatedFirstName; })); + ASSERT_TRUE(std::ranges::any_of(firstNamesMales, [generatedFirstName](const std::string& firstName) + { return firstName == generatedFirstName; })); } TEST_P(PersonTest, shouldGenerateFemaleFirstName) @@ -119,9 +117,8 @@ TEST_P(PersonTest, shouldGenerateFemaleFirstName) const auto generatedFirstName = Person::firstName(language, Sex::Female); - ASSERT_TRUE(std::any_of(firstNamesFemales.begin(), firstNamesFemales.end(), - [generatedFirstName](const std::string& firstName) - { return firstName == generatedFirstName; })); + ASSERT_TRUE(std::ranges::any_of(firstNamesFemales, [generatedFirstName](const std::string& firstName) + { return firstName == generatedFirstName; })); } TEST_P(PersonTest, shouldGenerateLastNameMale) @@ -132,9 +129,8 @@ TEST_P(PersonTest, shouldGenerateLastNameMale) const auto generatedLastName = Person::lastName(language, Sex::Male); - ASSERT_TRUE(std::any_of(lastNamesMale.begin(), lastNamesMale.end(), - [generatedLastName](const std::string& lastName) - { return lastName == generatedLastName; })); + ASSERT_TRUE(std::ranges::any_of(lastNamesMale, [generatedLastName](const std::string& lastName) + { return lastName == generatedLastName; })); } TEST_P(PersonTest, shouldGenerateLastNameFemale) @@ -145,9 +141,8 @@ TEST_P(PersonTest, shouldGenerateLastNameFemale) const auto generatedLastName = Person::lastName(language, Sex::Female); - ASSERT_TRUE(std::any_of(lastNamesFemale.begin(), lastNamesFemale.end(), - [generatedLastName](const std::string& lastName) - { return lastName == generatedLastName; })); + ASSERT_TRUE(std::ranges::any_of(lastNamesFemale, [generatedLastName](const std::string& lastName) + { return lastName == generatedLastName; })); } TEST_P(PersonTest, shouldGenerateFullName) @@ -176,12 +171,10 @@ TEST_P(PersonTest, shouldGenerateFullName) const auto& generatedFirstName = names[0]; - ASSERT_TRUE(std::any_of(firstNames.begin(), firstNames.end(), - [generatedFirstName](const std::string& firstName) - { return firstName == generatedFirstName; })); - ASSERT_TRUE(std::any_of(lastNames.begin(), lastNames.end(), - [generatedFullName](const std::string& lastName) - { return generatedFullName.find(lastName) != std::string::npos; })); + ASSERT_TRUE(std::ranges::any_of(firstNames, [generatedFirstName](const std::string& firstName) + { return firstName == generatedFirstName; })); + ASSERT_TRUE(std::ranges::any_of(lastNames, [generatedFullName](const std::string& lastName) + { return generatedFullName.find(lastName) != std::string::npos; })); } TEST_P(PersonTest, shouldGenerateMaleFullName) @@ -200,12 +193,10 @@ TEST_P(PersonTest, shouldGenerateMaleFullName) const auto& generatedFirstName = names[0]; - ASSERT_TRUE(std::any_of(firstNamesMales.begin(), firstNamesMales.end(), - [generatedFirstName](const std::string& firstName) - { return firstName == generatedFirstName; })); - ASSERT_TRUE(std::any_of(lastNames.begin(), lastNames.end(), - [generatedFullName](const std::string& lastName) - { return generatedFullName.find(lastName) != std::string::npos; })); + ASSERT_TRUE(std::ranges::any_of(firstNamesMales, [generatedFirstName](const std::string& firstName) + { return firstName == generatedFirstName; })); + ASSERT_TRUE(std::ranges::any_of(lastNames, [generatedFullName](const std::string& lastName) + { return generatedFullName.find(lastName) != std::string::npos; })); } TEST_P(PersonTest, shouldGenerateFemaleFullName) @@ -224,12 +215,10 @@ TEST_P(PersonTest, shouldGenerateFemaleFullName) const auto& generatedFirstName = names[0]; - ASSERT_TRUE(std::any_of(firstNamesFemales.begin(), firstNamesFemales.end(), - [generatedFirstName](const std::string& firstName) - { return firstName == generatedFirstName; })); - ASSERT_TRUE(std::any_of(lastNames.begin(), lastNames.end(), - [generatedFullName](const std::string& lastName) - { return generatedFullName.find(lastName) != std::string::npos; })); + ASSERT_TRUE(std::ranges::any_of(firstNamesFemales, [generatedFirstName](const std::string& firstName) + { return firstName == generatedFirstName; })); + ASSERT_TRUE(std::ranges::any_of(lastNames, [generatedFullName](const std::string& lastName) + { return generatedFullName.find(lastName) != std::string::npos; })); } INSTANTIATE_TEST_SUITE_P(TestPersonNamesByLanguages, PersonTest, ValuesIn(languages), @@ -241,41 +230,39 @@ TEST_F(PersonTest, shouldGenerateSex) const auto generatedSex = Person::sex(); - ASSERT_TRUE(std::any_of(sexes.begin(), sexes.end(), - [generatedSex](const std::string& sex) { return sex == generatedSex; })); + ASSERT_TRUE(std::ranges::any_of(sexes, [generatedSex](const std::string& sex) { return sex == generatedSex; })); } TEST_F(PersonTest, shouldGenerateGender) { const auto generatedGender = Person::gender(); - ASSERT_TRUE(std::any_of(genders.begin(), genders.end(), - [generatedGender](const std::string& gender) { return gender == generatedGender; })); + ASSERT_TRUE(std::ranges::any_of(genders, [generatedGender](const std::string& gender) + { return gender == generatedGender; })); } TEST_F(PersonTest, shouldGenerateJobDescriptor) { const auto generatedJobDescriptor = Person::jobDescriptor(); - ASSERT_TRUE(std::any_of(jobDescriptors.begin(), jobDescriptors.end(), - [generatedJobDescriptor](const std::string& jobDescriptor) - { return jobDescriptor == generatedJobDescriptor; })); + ASSERT_TRUE(std::ranges::any_of(jobDescriptors, [generatedJobDescriptor](const std::string& jobDescriptor) + { return jobDescriptor == generatedJobDescriptor; })); } TEST_F(PersonTest, shouldGenerateJobArea) { const auto generatedJobArea = Person::jobArea(); - ASSERT_TRUE(std::any_of(jobAreas.begin(), jobAreas.end(), - [generatedJobArea](const std::string& jobArea) { return jobArea == generatedJobArea; })); + ASSERT_TRUE(std::ranges::any_of(jobAreas, [generatedJobArea](const std::string& jobArea) + { return jobArea == generatedJobArea; })); } TEST_F(PersonTest, shouldGenerateJobType) { const auto generatedJobType = Person::jobType(); - ASSERT_TRUE(std::any_of(jobTypes.begin(), jobTypes.end(), - [generatedJobType](const std::string& jobType) { return jobType == generatedJobType; })); + ASSERT_TRUE(std::ranges::any_of(jobTypes, [generatedJobType](const std::string& jobType) + { return jobType == generatedJobType; })); } TEST_F(PersonTest, shouldGenerateJobTitle) @@ -288,21 +275,20 @@ TEST_F(PersonTest, shouldGenerateJobTitle) const auto& generatedJobArea = jobTitleElements[1]; const auto& generatedJobType = jobTitleElements[2]; - ASSERT_TRUE(std::any_of(jobDescriptors.begin(), jobDescriptors.end(), - [generatedJobDescriptor](const std::string& jobDescriptor) - { return jobDescriptor == generatedJobDescriptor; })); - ASSERT_TRUE(std::any_of(jobAreas.begin(), jobAreas.end(), - [generatedJobArea](const std::string& jobArea) { return jobArea == generatedJobArea; })); - ASSERT_TRUE(std::any_of(jobTypes.begin(), jobTypes.end(), - [generatedJobType](const std::string& jobType) { return jobType == generatedJobType; })); + ASSERT_TRUE(std::ranges::any_of(jobDescriptors, [generatedJobDescriptor](const std::string& jobDescriptor) + { return jobDescriptor == generatedJobDescriptor; })); + ASSERT_TRUE(std::ranges::any_of(jobAreas, [generatedJobArea](const std::string& jobArea) + { return jobArea == generatedJobArea; })); + ASSERT_TRUE(std::ranges::any_of(jobTypes, [generatedJobType](const std::string& jobType) + { return jobType == generatedJobType; })); } TEST_F(PersonTest, shouldGeneratePrefix) { const auto generatedPrefix = Person::prefix(); - ASSERT_TRUE(std::any_of(allPrefixes.begin(), allPrefixes.end(), - [generatedPrefix](const std::string& prefix) { return prefix == generatedPrefix; })); + ASSERT_TRUE(std::ranges::any_of(allPrefixes, [generatedPrefix](const std::string& prefix) + { return prefix == generatedPrefix; })); } TEST_F(PersonTest, shouldGenerateMalePrefix) @@ -316,6 +302,6 @@ TEST_F(PersonTest, shouldGenerateFemalePrefix) { const auto generatedPrefix = Person::prefix(Sex::Female); - ASSERT_TRUE(std::any_of(femalePrefixes.begin(), femalePrefixes.end(), - [generatedPrefix](const std::string& prefix) { return prefix == generatedPrefix; })); + ASSERT_TRUE(std::ranges::any_of(femalePrefixes, [generatedPrefix](const std::string& prefix) + { return prefix == generatedPrefix; })); } diff --git a/src/modules/phone/PhoneTest.cpp b/src/modules/phone/PhoneTest.cpp index 88a9e6273..0784e974e 100644 --- a/src/modules/phone/PhoneTest.cpp +++ b/src/modules/phone/PhoneTest.cpp @@ -14,9 +14,8 @@ class PhoneTest : public Test protected: static bool isStringNumericWithSpecialChars(const std::string& str) { - return std::all_of(str.begin(), str.end(), - [](char c) - { return std::isdigit(c) || c == '-' || c == '(' || c == ')' || c == '+' || c == ' '; }); + return std::ranges::all_of( + str, [](char c) { return std::isdigit(c) || c == '-' || c == '(' || c == ')' || c == '+' || c == ' '; }); } }; diff --git a/src/modules/string/StringTest.cpp b/src/modules/string/StringTest.cpp index de2a7e800..0128504d5 100644 --- a/src/modules/string/StringTest.cpp +++ b/src/modules/string/StringTest.cpp @@ -30,11 +30,9 @@ TEST_F(StringTest, shouldGenerateDefaultSampleString) const auto sample = String::sample(); ASSERT_EQ(sample.size(), 10); - ASSERT_TRUE(std::all_of(sample.begin(), sample.end(), - [](char sampleCharacter) { - return static_cast(sampleCharacter) >= 33 && - static_cast(sampleCharacter) <= 125; - })); + ASSERT_TRUE(std::ranges::all_of( + sample, [](char sampleCharacter) + { return static_cast(sampleCharacter) >= 33 && static_cast(sampleCharacter) <= 125; })); } TEST_F(StringTest, shouldGenerateSampleString) @@ -42,11 +40,9 @@ TEST_F(StringTest, shouldGenerateSampleString) const auto sample = String::sample(5); ASSERT_EQ(sample.size(), 5); - ASSERT_TRUE(std::all_of(sample.begin(), sample.end(), - [](char sampleCharacter) { - return static_cast(sampleCharacter) >= 33 && - static_cast(sampleCharacter) <= 125; - })); + ASSERT_TRUE(std::ranges::all_of( + sample, [](char sampleCharacter) + { return static_cast(sampleCharacter) >= 33 && static_cast(sampleCharacter) <= 125; })); } TEST_F(StringTest, shouldGenerateDefaultStringFromCharaters) @@ -56,9 +52,8 @@ TEST_F(StringTest, shouldGenerateDefaultStringFromCharaters) const auto fromCharacters = String::fromCharacters(characters); ASSERT_EQ(fromCharacters.size(), 1); - ASSERT_TRUE(std::all_of(fromCharacters.begin(), fromCharacters.end(), - [&characters](char sampleCharacter) - { return characters.find(sampleCharacter) != std::string::npos; })); + ASSERT_TRUE(std::ranges::all_of(fromCharacters, [&characters](char sampleCharacter) + { return characters.find(sampleCharacter) != std::string::npos; })); } TEST_F(StringTest, shouldGenerateStringFromCharaters) @@ -68,9 +63,8 @@ TEST_F(StringTest, shouldGenerateStringFromCharaters) const auto fromCharacters = String::fromCharacters(characters, 6); ASSERT_EQ(fromCharacters.size(), 6); - ASSERT_TRUE(std::all_of(fromCharacters.begin(), fromCharacters.end(), - [&characters](char sampleCharacter) - { return characters.find(sampleCharacter) != std::string::npos; })); + ASSERT_TRUE(std::ranges::all_of(fromCharacters, [&characters](char sampleCharacter) + { return characters.find(sampleCharacter) != std::string::npos; })); } TEST_F(StringTest, shouldGenerateDefaultApha) @@ -78,8 +72,8 @@ TEST_F(StringTest, shouldGenerateDefaultApha) const auto alpha = String::alpha(); ASSERT_EQ(alpha.size(), 1); - ASSERT_TRUE(std::any_of(mixedAlphaCharacters.begin(), mixedAlphaCharacters.end(), - [alpha](char mixedCharacter) { return alpha[0] == mixedCharacter; })); + ASSERT_TRUE( + std::ranges::any_of(mixedAlphaCharacters, [alpha](char mixedCharacter) { return alpha[0] == mixedCharacter; })); } TEST_F(StringTest, shouldGenerateMixedAlpha) @@ -89,13 +83,13 @@ TEST_F(StringTest, shouldGenerateMixedAlpha) const auto alpha = String::alpha(alphaLength); ASSERT_EQ(alpha.size(), alphaLength); - ASSERT_TRUE(std::all_of(alpha.begin(), alpha.end(), - [](char alphaCharacter) - { - return std::any_of(mixedAlphaCharacters.begin(), mixedAlphaCharacters.end(), - [alphaCharacter](char mixedCharacter) - { return mixedCharacter == alphaCharacter; }); - })); + ASSERT_TRUE(std::ranges::all_of(alpha, + [](char alphaCharacter) + { + return std::ranges::any_of(mixedAlphaCharacters, + [alphaCharacter](char mixedCharacter) + { return mixedCharacter == alphaCharacter; }); + })); } TEST_F(StringTest, shouldGenerateUpperAlpha) @@ -105,13 +99,13 @@ TEST_F(StringTest, shouldGenerateUpperAlpha) const auto alpha = String::alpha(alphaLength, StringCasing::Upper); ASSERT_EQ(alpha.size(), alphaLength); - ASSERT_TRUE(std::all_of(alpha.begin(), alpha.end(), - [](char alphaCharacter) - { - return std::any_of(upperCharacters.begin(), upperCharacters.end(), - [alphaCharacter](char upperCharacter) - { return upperCharacter == alphaCharacter; }); - })); + ASSERT_TRUE(std::ranges::all_of(alpha, + [](char alphaCharacter) + { + return std::ranges::any_of(upperCharacters, + [alphaCharacter](char upperCharacter) + { return upperCharacter == alphaCharacter; }); + })); } TEST_F(StringTest, shouldGenerateLowerAlpha) @@ -121,13 +115,13 @@ TEST_F(StringTest, shouldGenerateLowerAlpha) const auto alpha = String::alpha(alphaLength, StringCasing::Lower); ASSERT_EQ(alpha.size(), alphaLength); - ASSERT_TRUE(std::all_of(alpha.begin(), alpha.end(), - [](char alphaCharacter) - { - return std::any_of(lowerCharacters.begin(), lowerCharacters.end(), - [alphaCharacter](char lowerCharacter) - { return lowerCharacter == alphaCharacter; }); - })); + ASSERT_TRUE(std::ranges::all_of(alpha, + [](char alphaCharacter) + { + return std::ranges::any_of(lowerCharacters, + [alphaCharacter](char lowerCharacter) + { return lowerCharacter == alphaCharacter; }); + })); } TEST_F(StringTest, shouldGenerateDefaultAphanumeric) @@ -135,8 +129,8 @@ TEST_F(StringTest, shouldGenerateDefaultAphanumeric) const auto alphanumeric = String::alphanumeric(); ASSERT_EQ(alphanumeric.size(), 1); - ASSERT_TRUE(std::any_of(mixedAlphanumericCharacters.begin(), mixedAlphanumericCharacters.end(), - [alphanumeric](char mixedCharacter) { return alphanumeric[0] == mixedCharacter; })); + ASSERT_TRUE(std::ranges::any_of(mixedAlphanumericCharacters, + [alphanumeric](char mixedCharacter) { return alphanumeric[0] == mixedCharacter; })); } TEST_F(StringTest, shouldGenerateMixedAlphanumeric) @@ -146,14 +140,14 @@ TEST_F(StringTest, shouldGenerateMixedAlphanumeric) const auto alphanumeric = String::alphanumeric(alphanumericLength); ASSERT_EQ(alphanumeric.size(), alphanumericLength); - ASSERT_TRUE(std::all_of(alphanumeric.begin(), alphanumeric.end(), - [](char alphanumericCharacter) - { - return std::any_of(mixedAlphanumericCharacters.begin(), - mixedAlphanumericCharacters.end(), - [alphanumericCharacter](char mixedAlphanumericCharacter) - { return alphanumericCharacter == mixedAlphanumericCharacter; }); - })); + ASSERT_TRUE(std::ranges::all_of(alphanumeric, + [](char alphanumericCharacter) + { + return std::ranges::any_of( + mixedAlphanumericCharacters, + [alphanumericCharacter](char mixedAlphanumericCharacter) + { return alphanumericCharacter == mixedAlphanumericCharacter; }); + })); } TEST_F(StringTest, shouldGenerateUpperAlphanumeric) @@ -163,14 +157,14 @@ TEST_F(StringTest, shouldGenerateUpperAlphanumeric) const auto alphanumeric = String::alphanumeric(alphanumericLength, StringCasing::Upper); ASSERT_EQ(alphanumeric.size(), alphanumericLength); - ASSERT_TRUE(std::all_of(alphanumeric.begin(), alphanumeric.end(), - [](char alphanumericCharacter) - { - return std::any_of(upperAlphanumericCharacters.begin(), - upperAlphanumericCharacters.end(), - [alphanumericCharacter](char upperAlphanumericCharacter) - { return upperAlphanumericCharacter == alphanumericCharacter; }); - })); + ASSERT_TRUE(std::ranges::all_of(alphanumeric, + [](char alphanumericCharacter) + { + return std::ranges::any_of( + upperAlphanumericCharacters, + [alphanumericCharacter](char upperAlphanumericCharacter) + { return upperAlphanumericCharacter == alphanumericCharacter; }); + })); } TEST_F(StringTest, shouldGenerateLowerAlphanumeric) @@ -180,14 +174,14 @@ TEST_F(StringTest, shouldGenerateLowerAlphanumeric) const auto alphanumeric = String::alphanumeric(alphanumericLength, StringCasing::Lower); ASSERT_EQ(alphanumeric.size(), alphanumericLength); - ASSERT_TRUE(std::all_of(alphanumeric.begin(), alphanumeric.end(), - [](char alphanumericCharacter) - { - return std::any_of(lowerAlphanumericCharacters.begin(), - lowerAlphanumericCharacters.end(), - [alphanumericCharacter](char lowerAlphanumericCharacter) - { return lowerAlphanumericCharacter == alphanumericCharacter; }); - })); + ASSERT_TRUE(std::ranges::all_of(alphanumeric, + [](char alphanumericCharacter) + { + return std::ranges::any_of( + lowerAlphanumericCharacters, + [alphanumericCharacter](char lowerAlphanumericCharacter) + { return lowerAlphanumericCharacter == alphanumericCharacter; }); + })); } TEST_F(StringTest, shouldGenerateNumeric) @@ -195,8 +189,8 @@ TEST_F(StringTest, shouldGenerateNumeric) const auto numeric = String::numeric(); ASSERT_EQ(numeric.size(), 1); - ASSERT_TRUE(std::any_of(numeric.begin(), numeric.end(), - [numeric](char numericCharacter) { return numeric[0] == numericCharacter; })); + ASSERT_TRUE( + std::ranges::any_of(numeric, [numeric](char numericCharacter) { return numeric[0] == numericCharacter; })); } TEST_F(StringTest, shouldGenerateNumericWithoutLeadingZeros) @@ -209,16 +203,15 @@ TEST_F(StringTest, shouldGenerateNumericWithoutLeadingZeros) const auto numericWithPossibleZeroCharacters = numeric.substr(1); ASSERT_EQ(numeric.size(), numericLength); - ASSERT_TRUE(std::any_of(numericCharactersWithoutZero.begin(), numericCharactersWithoutZero.end(), - [nonZeroCharacter](char numericCharacter) - { return nonZeroCharacter == numericCharacter; })); - ASSERT_TRUE(std::all_of(numericWithPossibleZeroCharacters.begin(), numericWithPossibleZeroCharacters.end(), - [](char numericCharacterWithPossibleZero) - { - return std::any_of(numericCharacters.begin(), numericCharacters.end(), - [numericCharacterWithPossibleZero](char numericCharacter) - { return numericCharacterWithPossibleZero == numericCharacter; }); - })); + ASSERT_TRUE(std::ranges::any_of(numericCharactersWithoutZero, [nonZeroCharacter](char numericCharacter) + { return nonZeroCharacter == numericCharacter; })); + ASSERT_TRUE(std::ranges::all_of(numericWithPossibleZeroCharacters, + [](char numericCharacterWithPossibleZero) + { + return std::ranges::any_of( + numericCharacters, [numericCharacterWithPossibleZero](char numericCharacter) + { return numericCharacterWithPossibleZero == numericCharacter; }); + })); } TEST_F(StringTest, shouldGenerateHexadecimal) @@ -232,9 +225,8 @@ TEST_F(StringTest, shouldGenerateHexadecimal) ASSERT_EQ(hexadecimal.size(), hexadecimalLength + 2); ASSERT_EQ(prefix, "0x"); - ASSERT_TRUE(std::any_of(hexNumber.begin(), hexNumber.end(), - [hexNumber](char hexNumberCharacter) - { return hexLowerCharacters.find(hexNumberCharacter) != std::string::npos; })); + ASSERT_TRUE(std::ranges::any_of(hexNumber, [hexNumber](char hexNumberCharacter) + { return hexLowerCharacters.find(hexNumberCharacter) != std::string::npos; })); } TEST_F(StringTest, shouldGenerateHexadecimalWithHashPrefix) @@ -248,9 +240,8 @@ TEST_F(StringTest, shouldGenerateHexadecimalWithHashPrefix) ASSERT_EQ(hexadecimal.size(), hexadecimalLength + 1); ASSERT_EQ(prefix, "#"); - ASSERT_TRUE(std::any_of(hexNumber.begin(), hexNumber.end(), - [](char hexNumberCharacter) - { return hexUpperCharacters.find(hexNumberCharacter) != std::string::npos; })); + ASSERT_TRUE(std::ranges::any_of(hexNumber, [](char hexNumberCharacter) + { return hexUpperCharacters.find(hexNumberCharacter) != std::string::npos; })); } TEST_F(StringTest, shouldGenerateHexadecimalWithoutPrefix) @@ -260,9 +251,8 @@ TEST_F(StringTest, shouldGenerateHexadecimalWithoutPrefix) const auto hexadecimal = String::hexadecimal(hexadecimalLength, HexCasing::Upper, HexPrefix::None); ASSERT_EQ(hexadecimal.size(), hexadecimalLength); - ASSERT_TRUE(std::any_of(hexadecimal.begin(), hexadecimal.end(), - [](char hexNumberCharacter) - { return hexUpperCharacters.find(hexNumberCharacter) != std::string::npos; })); + ASSERT_TRUE(std::ranges::any_of(hexadecimal, [](char hexNumberCharacter) + { return hexUpperCharacters.find(hexNumberCharacter) != std::string::npos; })); } TEST_F(StringTest, shouldGenerateBinary) @@ -276,9 +266,8 @@ TEST_F(StringTest, shouldGenerateBinary) ASSERT_EQ(binary.size(), binaryLength + 2); ASSERT_EQ(prefix, "0b"); - ASSERT_TRUE(std::any_of(binary.begin(), binary.end(), - [](char binaryNumberCharacter) - { return std::string("01").find(binaryNumberCharacter) != std::string::npos; })); + ASSERT_TRUE(std::ranges::any_of(binary, [](char binaryNumberCharacter) + { return std::string("01").find(binaryNumberCharacter) != std::string::npos; })); } TEST_F(StringTest, shouldGenerateOctalWithPrefix) @@ -292,7 +281,7 @@ TEST_F(StringTest, shouldGenerateOctalWithPrefix) ASSERT_EQ(octal.size(), octalLength + 2); ASSERT_EQ(prefix, "0o"); - ASSERT_TRUE(std::any_of(octal.begin(), octal.end(), - [](char octalNumberCharacter) + ASSERT_TRUE( + std::ranges::any_of(octal, [](char octalNumberCharacter) { return std::string("01234567").find(octalNumberCharacter) != std::string::npos; })); } diff --git a/src/modules/system/System.cpp b/src/modules/system/System.cpp index e5a4424cc..dc786c9bb 100644 --- a/src/modules/system/System.cpp +++ b/src/modules/system/System.cpp @@ -55,8 +55,7 @@ std::string System::fileExt(const std::optional& mimeType) { if (mimeType.has_value() && !mimeType->empty()) { - auto it = std::find(mimeTypes.begin(), mimeTypes.end(), *mimeType); - if (it != mimeTypes.end()) + if (const auto it = std::ranges::find(mimeTypes, *mimeType); it != mimeTypes.end()) { const std::string& extension = *it; size_t pos = extension.find_last_of('/'); diff --git a/src/modules/system/SystemTest.cpp b/src/modules/system/SystemTest.cpp index a863a4def..d6edc4714 100644 --- a/src/modules/system/SystemTest.cpp +++ b/src/modules/system/SystemTest.cpp @@ -68,7 +68,7 @@ TEST_F(SystemTest, MimeTypeTest) { std::string mimeTypeResult = System::mimeType(); - bool isValidMimeType = std::find(mimeTypes.begin(), mimeTypes.end(), mimeTypeResult) != mimeTypes.end(); + bool isValidMimeType = std::ranges::find(mimeTypes, mimeTypeResult) != mimeTypes.end(); EXPECT_TRUE(isValidMimeType); } @@ -76,8 +76,7 @@ TEST_F(SystemTest, CommonFileTypeTest) { std::string commonFileTypeResult = System::commonFileType(); - bool isValidCommonFileType = - std::find(commonFileTypes.begin(), commonFileTypes.end(), commonFileTypeResult) != commonFileTypes.end(); + bool isValidCommonFileType = std::ranges::find(commonFileTypes, commonFileTypeResult) != commonFileTypes.end(); EXPECT_TRUE(isValidCommonFileType); } @@ -98,7 +97,7 @@ TEST_F(SystemTest, FileTypeTest) std::string fileTypeResult = System::fileType(); - bool isValidFileType = std::find(expectedTypes.begin(), expectedTypes.end(), fileTypeResult) != expectedTypes.end(); + bool isValidFileType = std::ranges::find(expectedTypes, fileTypeResult) != expectedTypes.end(); EXPECT_TRUE(isValidFileType); } @@ -153,8 +152,8 @@ TEST_F(SystemTest, IncludeYearOption) EXPECT_TRUE(isValidCronExpression(cronExpr)); int yearValue = -1; - std::smatch match; - if (std::regex_search(cronExpr, match, std::regex(R"(\b(19[7-9][0-9]|20[0-9]{2})\b)"))) + + if (std::smatch match; std::regex_search(cronExpr, match, std::regex(R"(\b(19[7-9][0-9]|20[0-9]{2})\b)"))) { yearValue = std::stoi(match.str()); } @@ -170,7 +169,6 @@ TEST_F(SystemTest, IncludeNonStandardOption) std::vector nonStandardExpressions = {"@annually", "@daily", "@hourly", "@monthly", "@reboot", "@weekly", "@yearly"}; - bool isNonStandard = std::find(nonStandardExpressions.begin(), nonStandardExpressions.end(), cronExpr) != - nonStandardExpressions.end(); + bool isNonStandard = std::ranges::find(nonStandardExpressions, cronExpr) != nonStandardExpressions.end(); EXPECT_TRUE(isNonStandard || isValidCronExpression(cronExpr)); } diff --git a/src/modules/word/WordTest.cpp b/src/modules/word/WordTest.cpp index d3cb746e5..e542c4c33 100644 --- a/src/modules/word/WordTest.cpp +++ b/src/modules/word/WordTest.cpp @@ -37,195 +37,186 @@ TEST_F(WordTest, shouldGenerateAdjective) { const auto generatedAdjective = Word::adjective(); - ASSERT_TRUE(std::any_of(adjectives.begin(), adjectives.end(), - [generatedAdjective](const std::string& word) { return word == generatedAdjective; })); + ASSERT_TRUE(std::ranges::any_of(adjectives, [generatedAdjective](const std::string& word) + { return word == generatedAdjective; })); } TEST_F(WordTest, shouldGenerateAdjectiveWithExistingLength) { const auto generatedAdjective = Word::adjective(5); - ASSERT_TRUE(std::any_of(adjectives.begin(), adjectives.end(), - [generatedAdjective](const std::string& word) { return word == generatedAdjective; })); + ASSERT_TRUE(std::ranges::any_of(adjectives, [generatedAdjective](const std::string& word) + { return word == generatedAdjective; })); } TEST_F(WordTest, shouldGenerateAdjectiveWithNonExistingLength) { const auto generatedAdjective = Word::adjective(100); - ASSERT_TRUE(std::any_of(adjectives.begin(), adjectives.end(), - [generatedAdjective](const std::string& word) { return word == generatedAdjective; })); + ASSERT_TRUE(std::ranges::any_of(adjectives, [generatedAdjective](const std::string& word) + { return word == generatedAdjective; })); } TEST_F(WordTest, shouldGenerateAdverb) { const auto generatedAdverb = Word::adverb(); - ASSERT_TRUE(std::any_of(adverbs.begin(), adverbs.end(), - [generatedAdverb](const std::string& word) { return word == generatedAdverb; })); + ASSERT_TRUE( + std::ranges::any_of(adverbs, [generatedAdverb](const std::string& word) { return word == generatedAdverb; })); } TEST_F(WordTest, shouldGenerateAdverbWithExistingLength) { const auto generatedAdverb = Word::adverb(5); - ASSERT_TRUE(std::any_of(adverbs.begin(), adverbs.end(), - [generatedAdverb](const std::string& word) { return word == generatedAdverb; })); + ASSERT_TRUE( + std::ranges::any_of(adverbs, [generatedAdverb](const std::string& word) { return word == generatedAdverb; })); } TEST_F(WordTest, shouldGenerateAdverbWithNonExistingLength) { const auto generatedAdverb = Word::adverb(100); - ASSERT_TRUE(std::any_of(adverbs.begin(), adverbs.end(), - [generatedAdverb](const std::string& word) { return word == generatedAdverb; })); + ASSERT_TRUE( + std::ranges::any_of(adverbs, [generatedAdverb](const std::string& word) { return word == generatedAdverb; })); } TEST_F(WordTest, shouldGenerateConjunction) { const auto generatedConjunction = Word::conjunction(); - ASSERT_TRUE(std::any_of(conjunctions.begin(), conjunctions.end(), - [generatedConjunction](const std::string& word) { return word == generatedConjunction; })); + ASSERT_TRUE(std::ranges::any_of(conjunctions, [generatedConjunction](const std::string& word) + { return word == generatedConjunction; })); } TEST_F(WordTest, shouldGenerateConjunctionWithExistingLength) { const auto generatedConjunction = Word::conjunction(5); - ASSERT_TRUE(std::any_of(conjunctions.begin(), conjunctions.end(), - [generatedConjunction](const std::string& word) { return word == generatedConjunction; })); + ASSERT_TRUE(std::ranges::any_of(conjunctions, [generatedConjunction](const std::string& word) + { return word == generatedConjunction; })); } TEST_F(WordTest, shouldGenerateConjunctionWithNonExistingLength) { const auto generatedConjunction = Word::conjunction(100); - ASSERT_TRUE(std::any_of(conjunctions.begin(), conjunctions.end(), - [generatedConjunction](const std::string& word) { return word == generatedConjunction; })); + ASSERT_TRUE(std::ranges::any_of(conjunctions, [generatedConjunction](const std::string& word) + { return word == generatedConjunction; })); } TEST_F(WordTest, shouldGenerateInterjection) { const auto generatedInterjection = Word::interjection(); - ASSERT_TRUE(std::any_of(interjections.begin(), interjections.end(), - [generatedInterjection](const std::string& word) - { return word == generatedInterjection; })); + ASSERT_TRUE(std::ranges::any_of(interjections, [generatedInterjection](const std::string& word) + { return word == generatedInterjection; })); } TEST_F(WordTest, shouldGenerateInterjectionWithExistingLength) { const auto generatedInterjection = Word::interjection(5); - ASSERT_TRUE(std::any_of(interjections.begin(), interjections.end(), - [generatedInterjection](const std::string& word) - { return word == generatedInterjection; })); + ASSERT_TRUE(std::ranges::any_of(interjections, [generatedInterjection](const std::string& word) + { return word == generatedInterjection; })); } TEST_F(WordTest, shouldGenerateInterjectionWithNonExistingLength) { const auto generatedInterjection = Word::interjection(100); - ASSERT_TRUE(std::any_of(interjections.begin(), interjections.end(), - [generatedInterjection](const std::string& word) - { return word == generatedInterjection; })); + ASSERT_TRUE(std::ranges::any_of(interjections, [generatedInterjection](const std::string& word) + { return word == generatedInterjection; })); } TEST_F(WordTest, shouldGenerateNoun) { const auto generatedNoun = Word::noun(); - ASSERT_TRUE(std::any_of(nouns.begin(), nouns.end(), - [generatedNoun](const std::string& word) { return word == generatedNoun; })); + ASSERT_TRUE(std::ranges::any_of(nouns, [generatedNoun](const std::string& word) { return word == generatedNoun; })); } TEST_F(WordTest, shouldGenerateNounWithExistingLength) { const auto generatedNoun = Word::noun(5); - ASSERT_TRUE(std::any_of(nouns.begin(), nouns.end(), - [generatedNoun](const std::string& word) { return word == generatedNoun; })); + ASSERT_TRUE(std::ranges::any_of(nouns, [generatedNoun](const std::string& word) { return word == generatedNoun; })); } TEST_F(WordTest, shouldGenerateNounWithNonExistingLength) { const auto generatedNoun = Word::noun(100); - ASSERT_TRUE(std::any_of(nouns.begin(), nouns.end(), - [generatedNoun](const std::string& word) { return word == generatedNoun; })); + ASSERT_TRUE(std::ranges::any_of(nouns, [generatedNoun](const std::string& word) { return word == generatedNoun; })); } TEST_F(WordTest, shouldGeneratePreposition) { const auto generatedPreposition = Word::preposition(); - ASSERT_TRUE(std::any_of(prepositions.begin(), prepositions.end(), - [generatedPreposition](const std::string& word) { return word == generatedPreposition; })); + ASSERT_TRUE(std::ranges::any_of(prepositions, [generatedPreposition](const std::string& word) + { return word == generatedPreposition; })); } TEST_F(WordTest, shouldGeneratePrepositionWithExistingLength) { const auto generatedPreposition = Word::preposition(5); - ASSERT_TRUE(std::any_of(prepositions.begin(), prepositions.end(), - [generatedPreposition](const std::string& word) { return word == generatedPreposition; })); + ASSERT_TRUE(std::ranges::any_of(prepositions, [generatedPreposition](const std::string& word) + { return word == generatedPreposition; })); } TEST_F(WordTest, shouldGeneratePrepositionWithNonExistingLength) { const auto generatedPreposition = Word::preposition(100); - ASSERT_TRUE(std::any_of(prepositions.begin(), prepositions.end(), - [generatedPreposition](const std::string& word) { return word == generatedPreposition; })); + ASSERT_TRUE(std::ranges::any_of(prepositions, [generatedPreposition](const std::string& word) + { return word == generatedPreposition; })); } TEST_F(WordTest, shouldGenerateVerb) { const auto generatedVerb = Word::verb(); - ASSERT_TRUE(std::any_of(verbs.begin(), verbs.end(), - [generatedVerb](const std::string& word) { return word == generatedVerb; })); + ASSERT_TRUE(std::ranges::any_of(verbs, [generatedVerb](const std::string& word) { return word == generatedVerb; })); } TEST_F(WordTest, shouldGenerateVerbWithExistingLength) { const auto generatedVerb = Word::verb(5); - ASSERT_TRUE(std::any_of(verbs.begin(), verbs.end(), - [generatedVerb](const std::string& word) { return word == generatedVerb; })); + ASSERT_TRUE(std::ranges::any_of(verbs, [generatedVerb](const std::string& word) { return word == generatedVerb; })); } TEST_F(WordTest, shouldGenerateVerbWithNonExistingLength) { const auto generatedVerb = Word::verb(100); - ASSERT_TRUE(std::any_of(verbs.begin(), verbs.end(), - [generatedVerb](const std::string& word) { return word == generatedVerb; })); + ASSERT_TRUE(std::ranges::any_of(verbs, [generatedVerb](const std::string& word) { return word == generatedVerb; })); } TEST_F(WordTest, shouldGenerateSample) { const auto generatedSample = Word::sample(); - ASSERT_TRUE(std::any_of(allWords.begin(), allWords.end(), - [generatedSample](const std::string& word) { return word == generatedSample; })); + ASSERT_TRUE( + std::ranges::any_of(allWords, [generatedSample](const std::string& word) { return word == generatedSample; })); } TEST_F(WordTest, shouldGenerateSampleWithExistingLength) { const auto generatedSample = Word::sample(5); - ASSERT_TRUE(std::any_of(allWords.begin(), allWords.end(), - [generatedSample](const std::string& word) { return word == generatedSample; })); + ASSERT_TRUE( + std::ranges::any_of(allWords, [generatedSample](const std::string& word) { return word == generatedSample; })); } TEST_F(WordTest, shouldGenerateSampleWithNonExistingLength) { const auto generatedSample = Word::sample(100); - ASSERT_TRUE(std::any_of(allWords.begin(), allWords.end(), - [generatedSample](const std::string& word) { return word == generatedSample; })); + ASSERT_TRUE( + std::ranges::any_of(allWords, [generatedSample](const std::string& word) { return word == generatedSample; })); } TEST_F(WordTest, shouldGenerateWords) @@ -234,7 +225,6 @@ TEST_F(WordTest, shouldGenerateWords) const auto separatedWords = StringHelper::split(generatedWords, " "); - ASSERT_TRUE(std::all_of(separatedWords.begin(), separatedWords.end(), - [this](const std::string& separatedWord) - { return std::find(allWords.begin(), allWords.end(), separatedWord) != allWords.end(); })); + ASSERT_TRUE(std::ranges::all_of(separatedWords, [this](const std::string& separatedWord) + { return std::ranges::find(allWords, separatedWord) != allWords.end(); })); }