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

feat: added space function and a simple test for it #975

Merged
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
11 changes: 11 additions & 0 deletions include/faker-cxx/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,15 @@ FAKER_CXX_EXPORT std::string hwb();
* @endcode
*/
FAKER_CXX_EXPORT std::string yuv();

/**
* @brief Returns a random color space.
*
* @returns A color space string (e.g., "sRGB", "CMYK").
*
* @code
* faker::color::space() // "sRGB"
* @endcode
*/
FAKER_CXX_EXPORT std::string space();
}
10 changes: 10 additions & 0 deletions src/modules/color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,23 @@ std::span<const std::string_view> getColors(Locale locale)
}
}

const std::array<std::string_view, 20> colorSpaces = {
"sRGB", "Adobe RGB", "ProPhoto RGB", "DCI-P3", "Rec. 709", "Rec. 2020", "CMYK",
"XYZ", "Lab", "ACES", "CIE 1931 XYZ", "CIE 1976 L*a*b*", "CIE 1976 L*u*v*", "CIEUVW",
"Y'UV", "Y'IQ", "Y'DbDr", "YCC", "YPbPr", "YPbPr601"};

std::string_view name(Locale locale)
{
const auto& colors = getColors(locale);

return helper::randomElement(colors);
}

std::string space()
{
return std::string(helper::randomElement(colorSpaces));
}

std::string rgb(bool includeAlpha)
{
const std::integral auto red = number::integer(255);
Expand Down
14 changes: 14 additions & 0 deletions tests/modules/color_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,17 @@ TEST_F(ColorTest, shouldGenerateYuv)
ASSERT_TRUE(chrominanceBlueColor >= 0 && chrominanceBlueColor <= 255);
ASSERT_TRUE(chrominanceRedColor >= 0 && chrominanceRedColor <= 255);
}

TEST_F(ColorTest, shouldGenerateColorSpace)
{
const auto generatedColorSpace = space();

const std::array<std::string_view, 20> expectedColorSpaces = {
"sRGB", "Adobe RGB", "ProPhoto RGB", "DCI-P3", "Rec. 709", "Rec. 2020", "CMYK",
"XYZ", "Lab", "ACES", "CIE 1931 XYZ", "CIE 1976 L*a*b*", "CIE 1976 L*u*v*", "CIEUVW",
"Y'UV", "Y'IQ", "Y'DbDr", "YCC", "YPbPr", "YPbPr601"};

ASSERT_TRUE(std::any_of(expectedColorSpaces.begin(), expectedColorSpaces.end(),
[generatedColorSpace](const std::string_view& colorSpace)
{ return colorSpace == generatedColorSpace; }));
}
Loading