diff --git a/include/faker-cxx/Color.h b/include/faker-cxx/Color.h index d44e8e48..6b6db8b7 100644 --- a/include/faker-cxx/Color.h +++ b/include/faker-cxx/Color.h @@ -73,6 +73,16 @@ class Color * Color::lch(true) // "lcha(0, 0, 100, 0.50)" * @endcode */ - static std::string lch(bool includeAlpha = false); + static std::string lch(bool includeAlpha = false); + + /** + * @brief Return a CMYK color + * + * @returns CMYK color formatted with cmyk(X,X,X,X) + * @code + * Color::cmyk() // "cmyk(0.72, 0.88, 0.00, 0.06)" + * @endcode + */ + static std::string cmyk(); }; } diff --git a/src/modules/color/Color.cpp b/src/modules/color/Color.cpp index e06ec376..02519d22 100644 --- a/src/modules/color/Color.cpp +++ b/src/modules/color/Color.cpp @@ -89,4 +89,14 @@ std::string Color::lch(bool includeAlpha) return fmt::format("lcha({}, {}, {}, {})", luminance, chroma, hue, formattedAlpha); } +std::string Color::cmyk() +{ + const std::floating_point auto cyan = Number::decimal(1.); + const std::floating_point auto magenta = Number::decimal(1.); + const std::floating_point auto yellow = Number::decimal(1.); + const std::floating_point auto key = Number::decimal(1.); + + return fmt::format("cmyk({:.2f}, {:.2f}, {:.2f}, {:.2f})", cyan, magenta, yellow, key); +} + } diff --git a/src/modules/color/ColorTest.cpp b/src/modules/color/ColorTest.cpp index 304ff0cb..0125ed7f 100644 --- a/src/modules/color/ColorTest.cpp +++ b/src/modules/color/ColorTest.cpp @@ -168,3 +168,26 @@ TEST_F(ColorTest, shouldGenerateLchWithAlpha) ASSERT_TRUE(hue >= 0 && hue <= 360); ASSERT_TRUE(alpha >= 0 && alpha <= 1); } + +TEST_F(ColorTest, shouldGenerateCmykColor) +{ + const auto generatedCmykColor = faker::Color::cmyk(); + const auto cmykValues = + faker::StringHelper::split(generatedCmykColor.substr(5, generatedCmykColor.size() - 1), " "); + + auto offset = cmykValues[0].size(); + const auto cyan = std::stod(cmykValues[0].data(), &offset); + offset = cmykValues[1].size(); + const auto magenta = std::stod(cmykValues[1].data(), &offset); + offset = cmykValues[2].size(); + const auto yellow = std::stod(cmykValues[2].data(), &offset); + offset = cmykValues[3].size(); + const auto key = std::stod(cmykValues[3].data(), &offset); + + ASSERT_TRUE(generatedCmykColor.starts_with("cmyk(")); + ASSERT_TRUE(generatedCmykColor.ends_with(")")); + ASSERT_TRUE(0. <= cyan && cyan <= 1.); + ASSERT_TRUE(0. <= magenta && magenta <= 1.); + ASSERT_TRUE(0. <= yellow && yellow <= 1.); + ASSERT_TRUE(0. <= key && key <= 1.); +}