diff --git a/include/faker-cxx/Commerce.h b/include/faker-cxx/Commerce.h index 741beed4..3e5762ad 100644 --- a/include/faker-cxx/Commerce.h +++ b/include/faker-cxx/Commerce.h @@ -2,208 +2,204 @@ #include -namespace faker +namespace faker::commerce { -class Commerce -{ -public: - /** - * @brief Returns a random commerce department. - * - * @returns Commerce department name. - * - * @code - * Commerce::department() // "Books" - * @endcode - */ - static std::string_view department(); - - /** - * @brief Generates a random sku by default only with digits. - * - * @param length The length of the sku. - * - * @code - * Commerce::sku() // "3027" - * Commerce::sku(8) // "10512056" - * @endcode - */ - static std::string sku(unsigned length = 4); - - /** - * @brief Returns a random product adjective. - * - * @returns Product adjective. - * - * @code - * Commerce::productAdjective() // "Handcrafted" - * @endcode - */ - static std::string_view productAdjective(); - - /** - * @brief Returns a random product material. - * - * @returns Product material. - * - * @code - * Commerce::productMaterial() // "Wooden" - * @endcode - */ - static std::string_view productMaterial(); - - /** - * @brief Returns a random product short name. - * - * @returns Product short name. - * - * @code - * Commerce::productName() // "Computer" - * @endcode - */ - static std::string_view productName(); - - /** - * @brief Returns a random product full name. - * - * @returns Product full name. - * - * @code - * Commerce::productFullName() // "Incredible Soft Gloves" - * @endcode - */ - static std::string productFullName(); - - /** - * @brief Returns a random valid ean13 code. - * - * @returns Ean13 code. - * - * @code - * Commerce::EAN13() // "1234567890128" - * @endcode - */ - static std::string EAN13(); - - /** - * @brief Returns a random valid ean8 code. - * - * @returns Ean8 code. - * - * @code - * Commerce::EAN8() // "90311017" - * @endcode - */ - static std::string EAN8(); - - /** - * @brief Returns a random valid isbn13 code. - * - * @returns Isbn13 code. - * - * @code - * Commerce::ISBN13() // "9781234567897" - * @endcode - */ - static std::string ISBN13(); - - /** - * @brief Returns a random valid ISBN10 code. - * - * @returns Isbn10 code. - * - * @code - * Commerce::ISBN10() // "0200716018" - * @endcode - */ - static std::string ISBN10(); - - /** - * @brief Returns a random payment type. - * - * @returns paymentType. - * - * @code - * Commerce::paymentType() // "Credit Card" - * @endcode - */ - static std::string_view paymentType(); - - /** - * @brief Returns a random payment provider. - * - * @returns paymentProvider. - * - * @code - * Commerce::paymentProvider() // "Paypal" - * @endcode - */ - static std::string_view paymentProvider(); - - /** - * @brief Returns a random product description. - * - * @returns productDescription. - * - * @code - * Commerce::productDescription() // "Elevate your lifestyle with premium quality product." - * @endcode - */ - static std::string_view productDescription(); - - /** - * @brief Returns a random product category. - * - * @returns productCategory. - * - * @code - * Commerce::productCategory() // "Electronics" - * @endcode - */ - static std::string_view productCategory(); - - /** - * @brief Returns a random product review. - * - * @returns productReview. - * - * @code - * Commerce::productReview() // "Unfortunately, it broke shortly after I started using it." - * @endcode - */ - static std::string_view productReview(); - - /** - * @brief Returns a random discount type. - * - * @returns discountType. - * - * @code - * Commerce::discountType() // "percentage" - * @endcode - */ - static std::string_view discountType(); - - /** - * @brief Returns a random order status. - * - * @returns orderStatus. - * - * @code - * Commerce::orderStatus() // "shipped" - * @endcode - */ - static std::string_view orderStatus(); - - /** - * @brief Returns a random shipping carrier. - * - * @returns shipping carrier - * - * @code - * Commerce::shippingMethod() // "FedEx" - * @endcode - */ - static std::string_view shippingCarrier(); -}; +/** + * @brief Returns a random commerce department. + * + * @returns Commerce department name. + * + * @code + * commerce::department() // "Books" + * @endcode + */ +std::string_view department(); + +/** + * @brief Generates a random sku by default only with digits. + * + * @param length The length of the sku. + * + * @code + * commerce::sku() // "3027" + * commerce::sku(8) // "10512056" + * @endcode + */ +std::string sku(unsigned length = 4); + +/** + * @brief Returns a random product adjective. + * + * @returns Product adjective. + * + * @code + * commerce::productAdjective() // "Handcrafted" + * @endcode + */ +std::string_view productAdjective(); + +/** + * @brief Returns a random product material. + * + * @returns Product material. + * + * @code + * commerce::productMaterial() // "Wooden" + * @endcode + */ +std::string_view productMaterial(); + +/** + * @brief Returns a random product short name. + * + * @returns Product short name. + * + * @code + * commerce::productName() // "Computer" + * @endcode + */ +std::string_view productName(); + +/** + * @brief Returns a random product full name. + * + * @returns Product full name. + * + * @code + * commerce::productFullName() // "Incredible Soft Gloves" + * @endcode + */ +std::string productFullName(); + +/** + * @brief Returns a random valid ean13 code. + * + * @returns Ean13 code. + * + * @code + * commerce::EAN13() // "1234567890128" + * @endcode + */ +std::string EAN13(); + +/** + * @brief Returns a random valid ean8 code. + * + * @returns Ean8 code. + * + * @code + * commerce::EAN8() // "90311017" + * @endcode + */ +std::string EAN8(); + +/** + * @brief Returns a random valid isbn13 code. + * + * @returns Isbn13 code. + * + * @code + * commerce::ISBN13() // "9781234567897" + * @endcode + */ +std::string ISBN13(); + +/** + * @brief Returns a random valid ISBN10 code. + * + * @returns Isbn10 code. + * + * @code + * commerce::ISBN10() // "0200716018" + * @endcode + */ +std::string ISBN10(); + +/** + * @brief Returns a random payment type. + * + * @returns paymentType. + * + * @code + * commerce::paymentType() // "Credit Card" + * @endcode + */ +std::string_view paymentType(); + +/** + * @brief Returns a random payment provider. + * + * @returns paymentProvider. + * + * @code + * commerce::paymentProvider() // "Paypal" + * @endcode + */ +std::string_view paymentProvider(); + +/** + * @brief Returns a random product description. + * + * @returns productDescription. + * + * @code + * commerce::productDescription() // "Elevate your lifestyle with premium quality product." + * @endcode + */ +std::string_view productDescription(); + +/** + * @brief Returns a random product category. + * + * @returns productCategory. + * + * @code + * commerce::productCategory() // "Electronics" + * @endcode + */ +std::string_view productCategory(); + +/** + * @brief Returns a random product review. + * + * @returns productReview. + * + * @code + * commerce::productReview() // "Unfortunately, it broke shortly after I started using it." + * @endcode + */ +std::string_view productReview(); + +/** + * @brief Returns a random discount type. + * + * @returns discountType. + * + * @code + * commerce::discountType() // "percentage" + * @endcode + */ +std::string_view discountType(); + +/** + * @brief Returns a random order status. + * + * @returns orderStatus. + * + * @code + * commerce::orderStatus() // "shipped" + * @endcode + */ +std::string_view orderStatus(); + +/** + * @brief Returns a random shipping carrier. + * + * @returns shipping carrier + * + * @code + * commerce::shippingMethod() // "FedEx" + * @endcode + */ +std::string_view shippingCarrier(); } diff --git a/src/modules/commerce/Commerce.cpp b/src/modules/commerce/Commerce.cpp index cea2e7f8..31ec3cc3 100644 --- a/src/modules/commerce/Commerce.cpp +++ b/src/modules/commerce/Commerce.cpp @@ -8,39 +8,39 @@ #include "faker-cxx/Helper.h" #include "faker-cxx/String.h" -namespace faker +namespace faker::commerce { -std::string_view Commerce::department() +std::string_view department() { return Helper::arrayElement(departments); } -std::string Commerce::sku(unsigned int length) +std::string sku(unsigned int length) { return String::numeric(length, false); } -std::string_view Commerce::productAdjective() +std::string_view productAdjective() { return Helper::arrayElement(productAdjectives); } -std::string_view Commerce::productMaterial() +std::string_view productMaterial() { return Helper::arrayElement(productMaterials); } -std::string_view Commerce::productName() +std::string_view productName() { return Helper::arrayElement(productNames); } -std::string Commerce::productFullName() +std::string productFullName() { return FormatHelper::format("{} {} {}", productAdjective(), productMaterial(), productName()); } -std::string Commerce::EAN13() +std::string EAN13() { const auto ean13 = String::numeric(12, false); @@ -68,7 +68,7 @@ std::string Commerce::EAN13() return ean13 + std::to_string(checkDigit); } -std::string Commerce::EAN8() +std::string EAN8() { const auto ean8 = String::numeric(7, false); @@ -96,7 +96,7 @@ std::string Commerce::EAN8() return ean8 + std::to_string(checkDigit); } -std::string Commerce::ISBN13() +std::string ISBN13() { const auto isbn13 = String::numeric(12, true); @@ -124,7 +124,7 @@ std::string Commerce::ISBN13() return isbn13 + std::to_string(checkDigit); } -std::string Commerce::ISBN10() +std::string ISBN10() { const auto isbn10 = String::numeric(9, true); @@ -151,42 +151,42 @@ std::string Commerce::ISBN10() return isbn10 + std::to_string(checkDigit); } -std::string_view Commerce::paymentType() +std::string_view paymentType() { return Helper::arrayElement(paymentTypes); } -std::string_view Commerce::paymentProvider() +std::string_view paymentProvider() { return Helper::arrayElement(paymentProviders); } -std::string_view Commerce::productDescription() +std::string_view productDescription() { return Helper::arrayElement(productDescriptions); } -std::string_view Commerce::productCategory() +std::string_view productCategory() { return Helper::arrayElement(productCategoryNames); } -std::string_view Commerce::productReview() +std::string_view productReview() { return Helper::arrayElement(productReviews); } -std::string_view Commerce::discountType() +std::string_view discountType() { return Helper::arrayElement(discountTypes); } -std::string_view Commerce::orderStatus() +std::string_view orderStatus() { return Helper::arrayElement(orderStatuses); } -std::string_view Commerce::shippingCarrier() +std::string_view shippingCarrier() { return Helper::arrayElement(shippingCarriers); } diff --git a/src/modules/commerce/CommerceData.cpp b/src/modules/commerce/CommerceData.cpp index bcf7eb2e..00bf9e49 100644 --- a/src/modules/commerce/CommerceData.cpp +++ b/src/modules/commerce/CommerceData.cpp @@ -3,31 +3,38 @@ #include #include -namespace faker +namespace faker::commerce { 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"}; + "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"}; + "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 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 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 paymentTypes = { + "Credit Card", "Debit Card", "Cash", "Bank Transfer", "Check", +}; const std::array paymentProviders = { - "Stripe", "Paypal", "Square", "Helcim", "Merchant One", "Flagship Merchant Services", "Stax"}; + "Stripe", "Paypal", "Square", "Helcim", "Merchant One", "Flagship Merchant Services", "Stax", +}; const std::array productDescriptions = { "Experience convenience and efficiency with innovative solution.", @@ -55,28 +62,31 @@ const std::array productDescriptions = { "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."}; + "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 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.", @@ -98,9 +108,13 @@ const std::array productReviews = { "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."}; + "It's difficult to operate and not user-friendly.", +}; -const std::array discountTypes = {"percentage", "value"}; +const std::array discountTypes = { + "percentage", + "value", +}; const std::array shippingCarriers = { "UPS", "FedEx", "USPS", "DHL", "Canada Post", "Royal Mail", "Australia Post", "Correos", "Deutsche Post", diff --git a/src/modules/commerce/CommerceData.h b/src/modules/commerce/CommerceData.h index 16804d0f..b343d4c4 100644 --- a/src/modules/commerce/CommerceData.h +++ b/src/modules/commerce/CommerceData.h @@ -3,15 +3,8 @@ #include #include -namespace faker +namespace faker::commerce { -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; diff --git a/tests/modules/commerce/CommerceTest.cpp b/tests/modules/commerce/CommerceTest.cpp index 5ea9743f..52cd699e 100644 --- a/tests/modules/commerce/CommerceTest.cpp +++ b/tests/modules/commerce/CommerceTest.cpp @@ -11,6 +11,7 @@ using namespace ::testing; using namespace faker; +using namespace faker::commerce; class CommerceTest : public Test { @@ -19,7 +20,7 @@ class CommerceTest : public Test TEST_F(CommerceTest, shouldGenerateCommerceDepartment) { - const auto generatedDepartment = Commerce::department(); + const auto generatedDepartment = department(); ASSERT_TRUE(std::ranges::any_of(departments, [generatedDepartment](const std::string_view& department) { return department == generatedDepartment; })); @@ -27,10 +28,10 @@ TEST_F(CommerceTest, shouldGenerateCommerceDepartment) TEST_F(CommerceTest, shouldGenerateSku) { - const auto sku = Commerce::sku(); + const auto generatedSku = sku(); - ASSERT_EQ(sku.size(), 4); - ASSERT_TRUE(std::ranges::all_of(sku, + ASSERT_EQ(generatedSku.size(), 4); + ASSERT_TRUE(std::ranges::all_of(generatedSku, [](char skuCharacter) { return std::ranges::any_of(numericCharacters, @@ -43,10 +44,10 @@ TEST_F(CommerceTest, shouldGenerateSkuWithSpecifiedLength) { const auto skuLength = 8; - const auto sku = Commerce::sku(skuLength); + const auto generatedSku = sku(skuLength); - ASSERT_EQ(sku.size(), skuLength); - ASSERT_TRUE(std::ranges::all_of(sku, + ASSERT_EQ(generatedSku.size(), skuLength); + ASSERT_TRUE(std::ranges::all_of(generatedSku, [](char skuCharacter) { return std::ranges::any_of(numericCharacters, @@ -57,9 +58,9 @@ TEST_F(CommerceTest, shouldGenerateSkuWithSpecifiedLength) TEST_F(CommerceTest, shouldGenerateProductFullName) { - const auto productFullName = Commerce::productFullName(); + const auto generatedProductFullName = productFullName(); - const auto productFullNameElements = StringHelper::split(productFullName, " "); + const auto productFullNameElements = StringHelper::split(generatedProductFullName, " "); const auto& generatedProductAdjective = productFullNameElements[0]; const auto& generatedProductMaterial = productFullNameElements[1]; @@ -75,7 +76,7 @@ TEST_F(CommerceTest, shouldGenerateProductFullName) TEST_F(CommerceTest, shouldGenerateProductAdjective) { - const auto generatedProductAdjective = Commerce::productAdjective(); + const auto generatedProductAdjective = productAdjective(); ASSERT_TRUE(std::ranges::any_of(productAdjectives, [generatedProductAdjective](const std::string_view& adjective) { return adjective == generatedProductAdjective; })); @@ -83,7 +84,7 @@ TEST_F(CommerceTest, shouldGenerateProductAdjective) TEST_F(CommerceTest, shouldGenerateProductMaterial) { - const auto generatedProductMaterial = Commerce::productMaterial(); + const auto generatedProductMaterial = productMaterial(); ASSERT_TRUE(std::ranges::any_of(productMaterials, [generatedProductMaterial](const std::string_view& material) { return material == generatedProductMaterial; })); @@ -91,7 +92,7 @@ TEST_F(CommerceTest, shouldGenerateProductMaterial) TEST_F(CommerceTest, shouldGenerateProductName) { - const auto generatedProductName = Commerce::productName(); + const auto generatedProductName = productName(); ASSERT_TRUE(std::ranges::any_of(productNames, [generatedProductName](const std::string_view& productName) { return productName == generatedProductName; })); @@ -99,7 +100,7 @@ TEST_F(CommerceTest, shouldGenerateProductName) TEST_F(CommerceTest, shouldGenerateEan13) { - const auto generatedEan13 = Commerce::EAN13(); + const auto generatedEan13 = EAN13(); int sum = 0; for (size_t i = 0; i < 13; i++) @@ -120,7 +121,7 @@ TEST_F(CommerceTest, shouldGenerateEan13) TEST_F(CommerceTest, shouldGenerateEan8) { - const auto generatedEan8 = Commerce::EAN8(); + const auto generatedEan8 = EAN8(); int sum = 0; for (size_t i = 0; i < 8; i++) @@ -141,7 +142,7 @@ TEST_F(CommerceTest, shouldGenerateEan8) TEST_F(CommerceTest, shouldGenerateIsbn13) { - const auto generatedIsbn13 = Commerce::ISBN13(); + const auto generatedIsbn13 = ISBN13(); int sum = 0; for (size_t i = 0; i < 13; i++) @@ -162,7 +163,7 @@ TEST_F(CommerceTest, shouldGenerateIsbn13) TEST_F(CommerceTest, shouldGenerateIsbn10) { - const auto generatedIsbn10 = Commerce::ISBN10(); + const auto generatedIsbn10 = ISBN10(); int sum = 0, weight = 10; if (generatedIsbn10[9] == 'X') @@ -189,7 +190,7 @@ TEST_F(CommerceTest, shouldGenerateIsbn10) TEST_F(CommerceTest, shouldGeneratePaymentType) { - const auto generatedPaymentType = Commerce::paymentType(); + const auto generatedPaymentType = paymentType(); ASSERT_TRUE(std::ranges::any_of(paymentTypes, [generatedPaymentType](const std::string_view& paymentType) { return paymentType == generatedPaymentType; })); @@ -197,7 +198,7 @@ TEST_F(CommerceTest, shouldGeneratePaymentType) TEST_F(CommerceTest, shouldGeneratePaymentProvider) { - const auto generatedPaymentProvider = Commerce::paymentProvider(); + const auto generatedPaymentProvider = paymentProvider(); ASSERT_TRUE(std::ranges::any_of(paymentProviders, [generatedPaymentProvider](const std::string_view& paymentProvider) @@ -206,7 +207,7 @@ TEST_F(CommerceTest, shouldGeneratePaymentProvider) TEST_F(CommerceTest, shouldGenerateProductDescription) { - const auto generatedProductDescription = Commerce::productDescription(); + const auto generatedProductDescription = productDescription(); ASSERT_TRUE(std::ranges::any_of(productDescriptions, [generatedProductDescription](const std::string_view& productDescription) @@ -215,7 +216,7 @@ TEST_F(CommerceTest, shouldGenerateProductDescription) TEST_F(CommerceTest, shouldGenerateProductCategory) { - const auto generatedProductCategory = Commerce::productCategory(); + const auto generatedProductCategory = productCategory(); ASSERT_TRUE(std::ranges::any_of(productCategoryNames, [generatedProductCategory](const std::string_view& productCategory) @@ -224,7 +225,7 @@ TEST_F(CommerceTest, shouldGenerateProductCategory) TEST_F(CommerceTest, shouldGenerateProductReview) { - const auto generatedProductReview = Commerce::productReview(); + const auto generatedProductReview = productReview(); ASSERT_TRUE(std::ranges::any_of(productReviews, [generatedProductReview](const std::string_view& productReview) { return productReview == generatedProductReview; })); @@ -232,7 +233,7 @@ TEST_F(CommerceTest, shouldGenerateProductReview) TEST_F(CommerceTest, shouldGenerateDiscountType) { - const auto generatedDiscountType = Commerce::discountType(); + const auto generatedDiscountType = discountType(); ASSERT_TRUE(std::ranges::any_of(discountTypes, [generatedDiscountType](const std::string_view& discountType) { return discountType == generatedDiscountType; })); @@ -240,7 +241,7 @@ TEST_F(CommerceTest, shouldGenerateDiscountType) TEST_F(CommerceTest, shouldGenerateOrderStatus) { - const auto generatedOrderStatus = Commerce::orderStatus(); + const auto generatedOrderStatus = orderStatus(); ASSERT_TRUE(std::ranges::any_of(orderStatuses, [generatedOrderStatus](const std::string_view& orderStatus) { return orderStatus == generatedOrderStatus; })); @@ -248,7 +249,7 @@ TEST_F(CommerceTest, shouldGenerateOrderStatus) TEST_F(CommerceTest, shouldGenerateShippingCarrier) { - const auto generatedShippingCarrier = Commerce::shippingCarrier(); + const auto generatedShippingCarrier = shippingCarrier(); ASSERT_TRUE(std::ranges::any_of(shippingCarriers, [generatedShippingCarrier](const std::string_view& shippingCarrier)