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

Add tests for PR #505 with RGB to HSL fix #690

Closed
mloskot opened this issue Jun 24, 2022 · 0 comments · Fixed by #691
Closed

Add tests for PR #505 with RGB to HSL fix #690

mloskot opened this issue Jun 24, 2022 · 0 comments · Fixed by #691
Labels
good-first-issue Opportunity for new contributors to help improving GIL test New tests development or missing tests issues, no new functionality
Milestone

Comments

@mloskot
Copy link
Member

mloskot commented Jun 24, 2022

Contributor of #505 posted GTest-based tests in #505 (comment), copied below.
We need to port this to Boost.LightweightTest

#define rgb2hsl(r, g, b, h, s, l)                              \
  {                                                            \
    const float abs_error = 0.002;                             \
    using boost::gil::hsl32f_pixel_t;                          \
    using boost::gil::rgb8_pixel_t;                            \
    using boost::gil::hsl_color_space::hue_t;                  \
    using boost::gil::hsl_color_space::lightness_t;            \
    using boost::gil::hsl_color_space::saturation_t;           \
    rgb8_pixel_t rgb(r, g, b);                                 \
    hsl32f_pixel_t hsl;                                        \
                                                               \
    color_convert(rgb, hsl);                                   \
                                                               \
    ASSERT_NEAR(h, get_color(hsl, hue_t()), abs_error);        \
    ASSERT_NEAR(s, get_color(hsl, saturation_t()), abs_error); \
    ASSERT_NEAR(l, get_color(hsl, lightness_t()), abs_error);  \
  }

#define hsl2rgb(h, s, l, r, g, b)                         \
  {                                                       \
    const float abs_error = 1;                            \
    using boost::gil::blue_t;                             \
    using boost::gil::green_t;                            \
    using boost::gil::hsl32f_pixel_t;                     \
    using boost::gil::red_t;                              \
    using boost::gil::rgb8_pixel_t;                       \
    hsl32f_pixel_t hsl(h, s, l);                          \
    rgb8_pixel_t rgb;                                     \
                                                          \
    color_convert(hsl, rgb);                              \
                                                          \
    ASSERT_NEAR(r, get_color(rgb, red_t()), abs_error);   \
    ASSERT_NEAR(g, get_color(rgb, green_t()), abs_error); \
    ASSERT_NEAR(b, get_color(rgb, blue_t()), abs_error);  \
  }

TEST(ColorSpaceTest, RGBToHSL) {
  // black
  rgb2hsl(0, 0, 0, 0, 0, 0);

  // white
  rgb2hsl(255, 255, 255, 0, 0, 1);

  // red
  rgb2hsl(255, 0, 0, 0, 1, 0.5);

  // lime
  rgb2hsl(0, 255, 0, 2 / 6.f, 1, 0.5);

  // blue
  rgb2hsl(0, 0, 255, 4 / 6.f, 1, 0.5);

  // yellow
  rgb2hsl(255, 255, 0, 1 / 6.f, 1, 0.5);

  // cyan
  rgb2hsl(0, 255, 255, 3 / 6.f, 1, 0.5);

  // magenta
  rgb2hsl(255, 0, 255, 5 / 6.f, 1, 0.5);

  // silver
  rgb2hsl(191, 191, 191, 0, 0, 0.75);

  // gray
  rgb2hsl(128, 128, 128, 0, 0, 0.5);

  // maroon
  rgb2hsl(128, 0, 0, 0, 1, 0.25);

  // olive
  rgb2hsl(128, 128, 0, 1 / 6.f, 1, 0.25);

  // green
  rgb2hsl(0, 128, 0, 2 / 6.f, 1, 0.25);

  // purple
  rgb2hsl(128, 0, 128, 5 / 6.f, 1, 0.25);

  // teal
  rgb2hsl(0, 128, 128, 3 / 6.f, 1, 0.25);

  // navy
  rgb2hsl(0, 0, 128, 4 / 6.f, 1, 0.25);
}

TEST(ColorSpaceTest, HSLToRGB) {
  // black
  hsl2rgb(0, 0, 0, 0, 0, 0);

  // white
  hsl2rgb(0, 0, 1, 255, 255, 255);

  // red
  hsl2rgb(0, 1, 0.5, 255, 0, 0);

  // lime
  hsl2rgb(2 / 6.f, 1, 0.5, 0, 255, 0);

  // blue
  hsl2rgb(4 / 6.f, 1, 0.5, 0, 0, 255);

  // purple
  hsl2rgb(5 / 6.f, 1, 0.25, 128, 0, 128);

  // teal
  hsl2rgb(3 / 6.f, 1, 0.25, 0, 128, 128);

  // navy
  hsl2rgb(4 / 6.f, 1, 0.25, 0, 0, 128);
}
@mloskot mloskot added test New tests development or missing tests issues, no new functionality good-first-issue Opportunity for new contributors to help improving GIL labels Jun 24, 2022
mloskot pushed a commit that referenced this issue Jun 24, 2022
Tests will follow as part of #690
@mloskot mloskot added this to the Boost 1.80 milestone Jun 24, 2022
mloskot added a commit to mloskot/gil that referenced this issue Jun 25, 2022
Contributor of PR boostorg#505 posted GTest-based tests in.
This commit ports those tests to Boost.LightweightTest.

Closes boostorg#690
mloskot added a commit that referenced this issue Jun 25, 2022
Contributor of PR #505 posted GTest-based tests in.
This commit ports those tests to Boost.LightweightTest.

Closes #690
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good-first-issue Opportunity for new contributors to help improving GIL test New tests development or missing tests issues, no new functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant