diff --git a/CMakeLists.txt b/CMakeLists.txt index fe3289c17..22ae2752e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,7 @@ set(FAKER_SOURCES src/modules/color/Color.cpp src/modules/color/ColorData.cpp src/modules/commerce/Commerce.cpp + src/modules/commerce/CommerceData.cpp src/modules/company/Company.cpp src/modules/computer/Computer.cpp src/modules/crypto/Crypto.cpp diff --git a/include/faker-cxx/Commerce.h b/include/faker-cxx/Commerce.h index 511c6f03c..2457bce37 100644 --- a/include/faker-cxx/Commerce.h +++ b/include/faker-cxx/Commerce.h @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace faker { @@ -16,7 +16,7 @@ class Commerce * Commerce::department() // "Books" * @endcode */ - static std::string department(); + static std::string_view department(); /** * @brief Generates a random price between the given bounds (inclusive). @@ -51,7 +51,7 @@ class Commerce * Commerce::productAdjective() // "Handcrafted" * @endcode */ - static std::string productAdjective(); + static std::string_view productAdjective(); /** * @brief Returns a random product material. @@ -62,7 +62,7 @@ class Commerce * Commerce::productMaterial() // "Wooden" * @endcode */ - static std::string productMaterial(); + static std::string_view productMaterial(); /** * @brief Returns a random product short name. @@ -73,7 +73,7 @@ class Commerce * Commerce::productName() // "Computer" * @endcode */ - static std::string productName(); + static std::string_view productName(); /** * @brief Returns a random product full name. @@ -150,7 +150,7 @@ class Commerce * Commerce::paymentType() // "Credit Card" * @endcode */ - static std::string paymentType(); + static std::string_view paymentType(); /** * @brief Returns a random payment provider. @@ -161,7 +161,7 @@ class Commerce * Commerce::paymentProvider() // "Paypal" * @endcode */ - static std::string paymentProvider(); + static std::string_view paymentProvider(); /** * @brief Returns a random product description. @@ -172,7 +172,7 @@ class Commerce * Commerce::productDescription() // "Elevate your lifestyle with premium quality product." * @endcode */ - static std::string productDescription(); + static std::string_view productDescription(); /** * @brief Returns a random product category. @@ -183,7 +183,7 @@ class Commerce * Commerce::productCategory() // "Electronics" * @endcode */ - static std::string productCategory(); + static std::string_view productCategory(); /** * @brief Returns a random product review. @@ -194,7 +194,7 @@ class Commerce * Commerce::productReview() // "Unfortunately, it broke shortly after I started using it." * @endcode */ - static std::string productReview(); + static std::string_view productReview(); /** * @brief Returns a random product rating (0-5). @@ -216,7 +216,7 @@ class Commerce * Commerce::discountType() // "percentage" * @endcode */ - static std::string discountType(); + static std::string_view discountType(); /** * @brief Returns random discount code within the specified range of 6 to 12 characters. @@ -271,7 +271,7 @@ class Commerce * Commerce::orderStatus() // "shipped" * @endcode */ - static std::string orderStatus(); + static std::string_view orderStatus(); /** * @brief Returns a random shipping carrier. @@ -282,6 +282,6 @@ class Commerce * Commerce::shippingMethod() // "FedEx" * @endcode */ - static std::string shippingCarrier(); + static std::string_view shippingCarrier(); }; } diff --git a/src/modules/color/ColorData.h b/src/modules/color/ColorData.h index 26da00e6b..2e1394bf7 100644 --- a/src/modules/color/ColorData.h +++ b/src/modules/color/ColorData.h @@ -1,3 +1,5 @@ +#pragma once + #include #include diff --git a/src/modules/commerce/Commerce.cpp b/src/modules/commerce/Commerce.cpp index 3eec45279..d73169079 100644 --- a/src/modules/commerce/Commerce.cpp +++ b/src/modules/commerce/Commerce.cpp @@ -1,16 +1,16 @@ #include "faker-cxx/Commerce.h" #include "../../common/FormatHelper.h" -#include "data/Commerce.h" +#include "CommerceData.h" #include "faker-cxx/Finance.h" #include "faker-cxx/Helper.h" #include "faker-cxx/String.h" namespace faker { -std::string Commerce::department() +std::string_view Commerce::department() { - return Helper::arrayElement(departments); + return Helper::arrayElement(departments); } std::string Commerce::price(double min, double max) @@ -23,19 +23,19 @@ std::string Commerce::sku(unsigned int length) return String::numeric(length, false); } -std::string Commerce::productAdjective() +std::string_view Commerce::productAdjective() { - return Helper::arrayElement(productAdjectives); + return Helper::arrayElement(productAdjectives); } -std::string Commerce::productMaterial() +std::string_view Commerce::productMaterial() { - return Helper::arrayElement(productMaterials); + return Helper::arrayElement(productMaterials); } -std::string Commerce::productName() +std::string_view Commerce::productName() { - return Helper::arrayElement(productNames); + return Helper::arrayElement(productNames); } std::string Commerce::productFullName() @@ -45,9 +45,10 @@ std::string Commerce::productFullName() std::string Commerce::EAN13() { - std::string ean13 = String::numeric(12, false); + const auto ean13 = String::numeric(12, false); int sum = 0; + for (size_t i = 0; i < 12; i++) { if (i % 2 == 0) @@ -72,9 +73,10 @@ std::string Commerce::EAN13() std::string Commerce::EAN8() { - std::string ean8 = String::numeric(7, false); + const auto ean8 = String::numeric(7, false); int sum = 0; + for (size_t i = 0; i < 7; i++) { if (i % 2 == 0) @@ -99,9 +101,10 @@ std::string Commerce::EAN8() std::string Commerce::ISBN13() { - std::string isbn13 = String::numeric(12, true); + const auto isbn13 = String::numeric(12, true); int sum = 0; + for (size_t i = 0; i < 12; i++) { if (i % 2 == 0) @@ -126,9 +129,10 @@ std::string Commerce::ISBN13() std::string Commerce::ISBN10() { - std::string isbn10 = String::numeric(9, true); + const auto isbn10 = String::numeric(9, true); int sum = 0, weight = 10; + for (size_t i = 0; i < 9; i++) { sum += (isbn10[i] - '0') * weight; @@ -155,29 +159,29 @@ std::string Commerce::productId() return String::alphanumeric(10, StringCasing::Upper, ""); } -std::string Commerce::paymentType() +std::string_view Commerce::paymentType() { - return Helper::arrayElement(paymentTypes); + return Helper::arrayElement(paymentTypes); } -std::string Commerce::paymentProvider() +std::string_view Commerce::paymentProvider() { - return Helper::arrayElement(paymentProviders); + return Helper::arrayElement(paymentProviders); } -std::string Commerce::productDescription() +std::string_view Commerce::productDescription() { - return Helper::arrayElement(productDescriptions); + return Helper::arrayElement(productDescriptions); } -std::string Commerce::productCategory() +std::string_view Commerce::productCategory() { - return Helper::arrayElement(productCategoryNames); + return Helper::arrayElement(productCategoryNames); } -std::string Commerce::productReview() +std::string_view Commerce::productReview() { - return Helper::arrayElement(productReviews); + return Helper::arrayElement(productReviews); } double Commerce::productRating() @@ -186,28 +190,30 @@ double Commerce::productRating() return std::ceil(ratingValue * 100) / 100; } -std::string Commerce::discountType() +std::string_view Commerce::discountType() { - return Helper::arrayElement(discountTypes); + return Helper::arrayElement(discountTypes); } std::string Commerce::discountCode() { - const std::integral auto codeLength = Number::integer(kMinDiscountCodeLength, kMaxDiscountCodeLength); + const std::integral auto codeLength = Number::integer(minDiscountCodeLength, maxDiscountCodeLength); + return String::alphanumeric(codeLength, StringCasing::Upper); } double Commerce::discountAmount() { - const std::floating_point auto amountValue = - Number::decimal(kMinDiscountAmountValue, kMaxDiscountAmountValue); + const std::floating_point auto amountValue = Number::decimal(minDiscountAmount, maxDiscountAmount); + return std::ceil(amountValue * 100) / 100; } double Commerce::discountPercentage() { const std::floating_point auto percentageValue = - Number::decimal(kMinDiscountPercentageValue, kMaxDiscountPercentageValue); + Number::decimal(minDiscountPercentage, maxDiscountPercentage); + return std::ceil(percentageValue * 100) / 100; } @@ -216,14 +222,14 @@ std::string Commerce::orderNumber() return String::numeric(7, true); } -std::string Commerce::orderStatus() +std::string_view Commerce::orderStatus() { - return Helper::arrayElement(orderStatuses); + return Helper::arrayElement(orderStatuses); } -std::string Commerce::shippingCarrier() +std::string_view Commerce::shippingCarrier() { - return Helper::arrayElement(shippingCarriers); + return Helper::arrayElement(shippingCarriers); } } diff --git a/src/modules/commerce/CommerceData.cpp b/src/modules/commerce/CommerceData.cpp new file mode 100644 index 000000000..c3cb7f9de --- /dev/null +++ b/src/modules/commerce/CommerceData.cpp @@ -0,0 +1,110 @@ +#include "CommerceData.h" + +namespace faker +{ +const std::array departments = { + "Books", "Movies", "Music", "Games", "Electronics", "Computers", "Home", "Garden", + "Tools", "Grocery", "Health", "Beauty", "Toys", "Kids", "Baby", "Clothing", + "Shoes", "Jewelery", "Sports", "Outdoors", "Automotive", "Industrial"}; + +const std::array productAdjectives = { + "Small", "Ergonomic", "Electronic", "Rustic", "Intelligent", "Gorgeous", "Incredible", "Elegant", + "Fantastic", "Practical", "Modern", "Recycled", "Sleek", "Bespoke", "Awesome", "Generic", + "Handcrafted", "Handmade", "Oriental", "Licensed", "Luxurious", "Refined", "Unbranded", "Tasty"}; + +const std::array productMaterials = {"Steel", "Bronze", "Wooden", "Concrete", + "Plastic", "Cotton", "Granite", "Rubber", + "Metal", "Soft", "Fresh", "Frozen"}; + +const std::array productNames = {"Chair", "Car", "Computer", "Keyboard", "Mouse", "Bike", + "Ball", "Gloves", "Pants", "Shirt", "Table", "Shoes", + "Hat", "Towels", "Soap", "Tuna", "Chicken", "Fish", + "Cheese", "Bacon", "Pizza", "Salad", "Sausages", "Chips"}; + +const std::array paymentTypes = {"Credit Card", "Debit Card", "Cash", "Bank Transfer", "Check"}; + +const std::array paymentProviders = { + "Stripe", "Paypal", "Square", "Helcim", "Merchant One", "Flagship Merchant Services", "Stax"}; + +const std::array productDescriptions = { + "Experience convenience and efficiency with innovative solution.", + "Elevate your lifestyle with premium quality product.", + "Unlock endless possibilities with versatile tool, offering flexibility and adaptability,", + "Enhance your performance with cutting-edge technology.", + "Discover the perfect balance of style and functionality with sleek design.", + "Embrace comfort and luxury with indulgent product.", + "Achieve peace of mind with reliable solution, providing stability and assurance in every use.", + "Ignite your creativity with versatile accessory.", + "Experience the difference with high-performance product, engineered for superior quality.", + "Simplify your life with user-friendly solution, designed with intuitive features .", + "Upgrade your everyday routine with essential product, adding convenience and efficiency to " + "your tasks.", + "Stay connected and productive with innovative technology, keeping you in control and on top " + "of your game.", + "Make a statement with stylish addition, adding a touch of elegance and sophistication to any " + "setting.", + "Experience reliability like never before with dependable product, ensuring consistent " + "performance day in and day out.", + "Unleash your potential with versatile tool, empowering you to tackle any challenge and " + "achieve your goals.", + "Experience comfort redefined with ergonomic design, prioritizing your well-being and comfort " + "in every use.", + "Optimize your efficiency with streamlined solution, eliminating unnecessary steps and " + "maximizing productivity.", + "Experience durability and longevity with rugged construction, built to withstand the test of " + "time and rigorous use."}; + +const std::array productCategoryNames = {"Art and Craft", + "Baby Products", + "Beauty Products", + "Board Games and Puzzles", + "Books and Stationery", + "Clothing, Shoes, and Jewelry", + "Electronics", + "Fitness Equipment", + "Furniture and Furnishings", + "Health and Wellness", + "Home Decor", + "Kitchen Appliances", + "Musical Instruments", + "Office Supplies", + "Outdoor Gear", + "Pet Supplies", + "Photography Equipment", + "Sporting Goods", + "Tech Gadgets", + "Toys"}; + +const std::array productReviews = { + "This product exceeded my expectations.", + "I'm thrilled with the quality of this purchase.", + "This product is worth every penny.", + "I'm impressed with how well it performs.", + "I've been using it for a while now, and it hasn't disappointed.", + "It's okay, but nothing special.", + "I'm on the fence about this product.", + "There are pros and cons to this purchase.", + "It's neither good nor bad, just average.", + "I have mixed feelings about this product.", + "It's decent, but there's room for improvement.", + "It meets my basic needs, but there are better options out there.", + "I would consider it if you're on a budget.", + "Not bad, but not great either.", + "It's acceptable, but I expected more for the price.", + "I was disappointed with the overall quality of this product.", + "Unfortunately, it broke shortly after I started using it.", + "I found it to be overpriced for what it offers.", + "It feels cheaply made and lacks durability.", + "It's difficult to operate and not user-friendly."}; + +const std::array discountTypes = {"percentage", "value"}; + +const std::array shippingCarriers = { + "UPS", "FedEx", "USPS", "DHL", "Canada Post", "Royal Mail", "Australia Post", "Correos", "Deutsche Post", +}; + +const std::array orderStatuses = { + "In Transit", "Out for Delivery", "Delivered", "Failed Attempt", "Exception", "Pending", "Expired", +}; + +} diff --git a/src/modules/commerce/CommerceData.h b/src/modules/commerce/CommerceData.h new file mode 100644 index 000000000..16804d0fb --- /dev/null +++ b/src/modules/commerce/CommerceData.h @@ -0,0 +1,27 @@ +#pragma once + +#include +#include + +namespace faker +{ +constexpr unsigned minDiscountCodeLength = 6; +constexpr unsigned maxDiscountCodeLength = 12; +constexpr double minDiscountAmount = 10.; +constexpr double maxDiscountAmount = 1000.; +constexpr double minDiscountPercentage = 1.; +constexpr double maxDiscountPercentage = 90.; + +extern const std::array departments; +extern const std::array productAdjectives; +extern const std::array productMaterials; +extern const std::array productNames; +extern const std::array paymentTypes; +extern const std::array paymentProviders; +extern const std::array productDescriptions; +extern const std::array productCategoryNames; +extern const std::array productReviews; +extern const std::array discountTypes; +extern const std::array shippingCarriers; +extern const std::array orderStatuses; +} diff --git a/src/modules/commerce/data/Commerce.h b/src/modules/commerce/data/Commerce.h deleted file mode 100644 index dadf12010..000000000 --- a/src/modules/commerce/data/Commerce.h +++ /dev/null @@ -1,112 +0,0 @@ -#pragma once - -#include -#include - -namespace faker -{ -const unsigned int kMinDiscountCodeLength = 6, kMaxDiscountCodeLength = 12; - -const double kMinDiscountAmountValue = 10., kMaxDiscountAmountValue = 1000.; - -const double kMinDiscountPercentageValue = 1., kMaxDiscountPercentageValue = 90.; - -const std::vector departments = { - "Books", "Movies", "Music", "Games", "Electronics", "Computers", "Home", "Garden", - "Tools", "Grocery", "Health", "Beauty", "Toys", "Kids", "Baby", "Clothing", - "Shoes", "Jewelery", "Sports", "Outdoors", "Automotive", "Industrial"}; - -const std::vector productAdjectives = { - "Small", "Ergonomic", "Electronic", "Rustic", "Intelligent", "Gorgeous", "Incredible", "Elegant", - "Fantastic", "Practical", "Modern", "Recycled", "Sleek", "Bespoke", "Awesome", "Generic", - "Handcrafted", "Handmade", "Oriental", "Licensed", "Luxurious", "Refined", "Unbranded", "Tasty"}; - -const std::vector productMaterials = {"Steel", "Bronze", "Wooden", "Concrete", "Plastic", "Cotton", - "Granite", "Rubber", "Metal", "Soft", "Fresh", "Frozen"}; - -const std::vector productNames = {"Chair", "Car", "Computer", "Keyboard", "Mouse", "Bike", - "Ball", "Gloves", "Pants", "Shirt", "Table", "Shoes", - "Hat", "Towels", "Soap", "Tuna", "Chicken", "Fish", - "Cheese", "Bacon", "Pizza", "Salad", "Sausages", "Chips"}; - -const std::vector paymentTypes = {"Credit Card", "Debit Card", "Cash", "Bank Transfer", "Check"}; - -const std::vector paymentProviders = { - "Stripe", "Paypal", "Square", "Helcim", "Merchant One", "Flagship Merchant Services", "Stax"}; - -const std::vector productDescriptions = { - "Experience convenience and efficiency with innovative solution.", - "Elevate your lifestyle with premium quality product.", - "Unlock endless possibilities with versatile tool, offering flexibility and adaptability,", - "Enhance your performance with cutting-edge technology.", - "Discover the perfect balance of style and functionality with sleek design.", - "Embrace comfort and luxury with indulgent product.", - "Achieve peace of mind with reliable solution, providing stability and assurance in every use.", - "Ignite your creativity with versatile accessory.", - "Experience the difference with high-performance product, engineered for superior quality.", - "Simplify your life with user-friendly solution, designed with intuitive features .", - "Upgrade your everyday routine with essential product, adding convenience and efficiency to your tasks.", - "Stay connected and productive with innovative technology, keeping you in control and on top of your game.", - "Make a statement with stylish addition, adding a touch of elegance and sophistication to any setting.", - "Experience reliability like never before with dependable product, ensuring consistent performance day in and day ", - "out.", - "Unleash your potential with versatile tool, empowering you to tackle any challenge and achieve your goals.", - "Experience comfort redefined with ergonomic design, prioritizing your well-being and comfort in every use.", - "Optimize your efficiency with streamlined solution, eliminating unnecessary steps and maximizing productivity.", - "Experience durability and longevity with rugged construction, built to withstand the test of time and rigorous ", - "use.", -}; - -const std::vector productCategoryNames = {"Art and Craft", - "Baby Products", - "Beauty Products", - "Board Games and Puzzles", - "Books and Stationery", - "Clothing, Shoes, and Jewelry", - "Electronics", - "Fitness Equipment", - "Furniture and Furnishings", - "Health and Wellness", - "Home Decor", - "Kitchen Appliances", - "Musical Instruments", - "Office Supplies", - "Outdoor Gear", - "Pet Supplies", - "Photography Equipment", - "Sporting Goods", - "Tech Gadgets", - "Toys"}; - -const std::vector productReviews = {"This product exceeded my expectations.", - "I'm thrilled with the quality of this purchase.", - "This product is worth every penny.", - "I'm impressed with how well it performs.", - "I've been using it for a while now, and it hasn't disappointed.", - "It's okay, but nothing special.", - "I'm on the fence about this product.", - "There are pros and cons to this purchase.", - "It's neither good nor bad, just average.", - "I have mixed feelings about this product.", - "It's decent, but there's room for improvement.", - "It meets my basic needs, but there are better options out there.", - "I would consider it if you're on a budget.", - "Not bad, but not great either.", - "It's acceptable, but I expected more for the price.", - "I was disappointed with the overall quality of this product.", - "Unfortunately, it broke shortly after I started using it.", - "I found it to be overpriced for what it offers.", - "It feels cheaply made and lacks durability.", - "It's difficult to operate and not user-friendly."}; - -const std::vector discountTypes = {"percentage", "value"}; - -const std::vector shippingCarriers = { - "UPS", "FedEx", "USPS", "DHL", "Canada Post", "Royal Mail", "Australia Post", "Correos", "Deutsche Post", -}; - -const std::vector orderStatuses = { - "In Transit", "Out for Delivery", "Delivered", "Failed Attempt", "Exception", "Pending", "Expired", -}; - -} diff --git a/tests/modules/commerce/CommerceTest.cpp b/tests/modules/commerce/CommerceTest.cpp index 50044b4d7..b70176e00 100644 --- a/tests/modules/commerce/CommerceTest.cpp +++ b/tests/modules/commerce/CommerceTest.cpp @@ -4,9 +4,9 @@ #include "gtest/gtest.h" +#include "commerce/CommerceData.h" #include "common/StringHelper.h" #include "string/data/Characters.h" -#include "commerce/data/Commerce.h" using namespace ::testing; using namespace faker; @@ -20,7 +20,7 @@ TEST_F(CommerceTest, shouldGenerateCommerceDepartment) { const auto generatedDepartment = Commerce::department(); - ASSERT_TRUE(std::ranges::any_of(departments, [generatedDepartment](const std::string& department) + ASSERT_TRUE(std::ranges::any_of(departments, [generatedDepartment](const std::string_view& department) { return department == generatedDepartment; })); } @@ -79,11 +79,11 @@ TEST_F(CommerceTest, shouldGenerateProductFullName) const auto& generatedProductMaterial = productFullNameElements[1]; const auto& generatedProductName = productFullNameElements[2]; - ASSERT_TRUE(std::ranges::any_of(productAdjectives, [generatedProductAdjective](const std::string& adjective) + ASSERT_TRUE(std::ranges::any_of(productAdjectives, [generatedProductAdjective](const std::string_view& adjective) { return adjective == generatedProductAdjective; })); - ASSERT_TRUE(std::ranges::any_of(productMaterials, [generatedProductMaterial](const std::string& material) + ASSERT_TRUE(std::ranges::any_of(productMaterials, [generatedProductMaterial](const std::string_view& material) { return material == generatedProductMaterial; })); - ASSERT_TRUE(std::ranges::any_of(productNames, [generatedProductName](const std::string& productName) + ASSERT_TRUE(std::ranges::any_of(productNames, [generatedProductName](const std::string_view& productName) { return productName == generatedProductName; })); } @@ -91,7 +91,7 @@ TEST_F(CommerceTest, shouldGenerateProductAdjective) { const auto generatedProductAdjective = Commerce::productAdjective(); - ASSERT_TRUE(std::ranges::any_of(productAdjectives, [generatedProductAdjective](const std::string& adjective) + ASSERT_TRUE(std::ranges::any_of(productAdjectives, [generatedProductAdjective](const std::string_view& adjective) { return adjective == generatedProductAdjective; })); } @@ -99,7 +99,7 @@ TEST_F(CommerceTest, shouldGenerateProductMaterial) { const auto generatedProductMaterial = Commerce::productMaterial(); - ASSERT_TRUE(std::ranges::any_of(productMaterials, [generatedProductMaterial](const std::string& material) + ASSERT_TRUE(std::ranges::any_of(productMaterials, [generatedProductMaterial](const std::string_view& material) { return material == generatedProductMaterial; })); } @@ -107,7 +107,7 @@ TEST_F(CommerceTest, shouldGenerateProductName) { const auto generatedProductName = Commerce::productName(); - ASSERT_TRUE(std::ranges::any_of(productNames, [generatedProductName](const std::string& productName) + ASSERT_TRUE(std::ranges::any_of(productNames, [generatedProductName](const std::string_view& productName) { return productName == generatedProductName; })); } @@ -213,7 +213,7 @@ TEST_F(CommerceTest, shouldGeneratePaymentType) { const auto generatedPaymentType = Commerce::paymentType(); - ASSERT_TRUE(std::ranges::any_of(paymentTypes, [generatedPaymentType](const std::string& paymentType) + ASSERT_TRUE(std::ranges::any_of(paymentTypes, [generatedPaymentType](const std::string_view& paymentType) { return paymentType == generatedPaymentType; })); } @@ -221,7 +221,8 @@ TEST_F(CommerceTest, shouldGeneratePaymentProvider) { const auto generatedPaymentProvider = Commerce::paymentProvider(); - ASSERT_TRUE(std::ranges::any_of(paymentProviders, [generatedPaymentProvider](const std::string& paymentProvider) + ASSERT_TRUE(std::ranges::any_of(paymentProviders, + [generatedPaymentProvider](const std::string_view& paymentProvider) { return paymentProvider == generatedPaymentProvider; })); } @@ -230,7 +231,7 @@ TEST_F(CommerceTest, shouldGenerateProductDescription) const auto generatedProductDescription = Commerce::productDescription(); ASSERT_TRUE(std::ranges::any_of(productDescriptions, - [generatedProductDescription](const std::string& productDescription) + [generatedProductDescription](const std::string_view& productDescription) { return productDescription == generatedProductDescription; })); } @@ -238,7 +239,8 @@ TEST_F(CommerceTest, shouldGenerateProductCategory) { const auto generatedProductCategory = Commerce::productCategory(); - ASSERT_TRUE(std::ranges::any_of(productCategoryNames, [generatedProductCategory](const std::string& productCategory) + ASSERT_TRUE(std::ranges::any_of(productCategoryNames, + [generatedProductCategory](const std::string_view& productCategory) { return productCategory == generatedProductCategory; })); } @@ -246,7 +248,7 @@ TEST_F(CommerceTest, shouldGenerateProductReview) { const auto generatedProductReview = Commerce::productReview(); - ASSERT_TRUE(std::ranges::any_of(productReviews, [generatedProductReview](const std::string& productReview) + ASSERT_TRUE(std::ranges::any_of(productReviews, [generatedProductReview](const std::string_view& productReview) { return productReview == generatedProductReview; })); } @@ -261,7 +263,7 @@ TEST_F(CommerceTest, shouldGenerateDiscountType) { const auto generatedDiscountType = Commerce::discountType(); - ASSERT_TRUE(std::ranges::any_of(discountTypes, [generatedDiscountType](const std::string& discountType) + ASSERT_TRUE(std::ranges::any_of(discountTypes, [generatedDiscountType](const std::string_view& discountType) { return discountType == generatedDiscountType; })); } @@ -270,8 +272,8 @@ TEST_F(CommerceTest, shouldGenerateDiscountCode) const auto generatedDiscountCode = Commerce::discountCode(); - ASSERT_TRUE(kMinDiscountCodeLength <= generatedDiscountCode.length() && - generatedDiscountCode.length() <= kMaxDiscountCodeLength); + ASSERT_TRUE(minDiscountCodeLength <= generatedDiscountCode.length() && + generatedDiscountCode.length() <= maxDiscountCodeLength); ASSERT_TRUE(std::ranges::all_of(generatedDiscountCode, [](char generatedDiscountCodeCharacter) @@ -287,16 +289,15 @@ TEST_F(CommerceTest, shouldGenerateDiscountAmount) { const auto generatedDiscountAmount = Commerce::discountAmount(); - ASSERT_TRUE(kMinDiscountAmountValue <= generatedDiscountAmount && - generatedDiscountAmount <= kMaxDiscountAmountValue); + ASSERT_TRUE(minDiscountAmount <= generatedDiscountAmount && generatedDiscountAmount <= maxDiscountAmount); } TEST_F(CommerceTest, shouldGenerateDiscountPercentage) { const auto generatedDiscountPercentage = Commerce::discountPercentage(); - ASSERT_TRUE(kMinDiscountPercentageValue <= generatedDiscountPercentage && - generatedDiscountPercentage <= kMaxDiscountPercentageValue); + ASSERT_TRUE(minDiscountPercentage <= generatedDiscountPercentage && + generatedDiscountPercentage <= maxDiscountPercentage); } TEST_F(CommerceTest, shouldGenerateOrderNumber) @@ -309,13 +310,16 @@ TEST_F(CommerceTest, shouldGenerateOrderNumber) TEST_F(CommerceTest, shouldGenerateOrderStatus) { const auto generatedOrderStatus = Commerce::orderStatus(); - ASSERT_TRUE(std::ranges::any_of(orderStatuses, [generatedOrderStatus](const std::string& orderStatus) + + ASSERT_TRUE(std::ranges::any_of(orderStatuses, [generatedOrderStatus](const std::string_view& orderStatus) { return orderStatus == generatedOrderStatus; })); } TEST_F(CommerceTest, shouldGenerateShippingCarrier) { const auto generatedShippingCarrier = Commerce::shippingCarrier(); - ASSERT_TRUE(std::ranges::any_of(shippingCarriers, [generatedShippingCarrier](const std::string& shippingCarrier) + + ASSERT_TRUE(std::ranges::any_of(shippingCarriers, + [generatedShippingCarrier](const std::string_view& shippingCarrier) { return shippingCarrier == generatedShippingCarrier; })); }