Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ranges #94

Merged
merged 2 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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"
}
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions Dockerfile.gcc13
Original file line number Diff line number Diff line change
@@ -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" ]
3 changes: 1 addition & 2 deletions src/common/StringHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
13 changes: 5 additions & 8 deletions src/modules/book/BookTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 16 additions & 16 deletions src/modules/color/ColorTest.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "faker-cxx/Color.h"

#include <algorithm>
#include <charconv>

#include "gtest/gtest.h"

Expand All @@ -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)
Expand All @@ -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(")"));
Expand All @@ -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(")"));
Expand All @@ -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)
Expand All @@ -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; }));
}
67 changes: 31 additions & 36 deletions src/modules/commerce/CommerceTest.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "faker-cxx/Commerce.h"

#include <algorithm>
#include <charconv>

#include "gtest/gtest.h"

Expand All @@ -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, ".");

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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; }));
}
Loading