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

tests/unittests: test black corner case for color_rgb2hsv() #9940

Merged
merged 1 commit into from
Sep 27, 2019
Merged
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
19 changes: 19 additions & 0 deletions tests/unittests/tests-color/tests-color.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include "tests-color.h"

#define HSV_EPSILON (1E-10f)

static void test_str2rgb_upper_case__success(void)
{
const char *color_str = "F09A1D";
Expand Down Expand Up @@ -73,6 +75,22 @@ static void test_rgb2hex__success(void)
TEST_ASSERT_EQUAL_INT(0x000AB13C, hex);
}

static void test_rgb2hsv__black(void)
{
color_hsv_t hsv;
color_rgb_t rgb = { .r = 0x00, .g = 0x00, .b = 0x00 };

color_rgb2hsv(&rgb, &hsv);

/* XXX floats should never be compared for equality, so we check if we
* are within HSV_EPSILON of tolerance */
TEST_ASSERT(-HSV_EPSILON <= hsv.s);
TEST_ASSERT(-HSV_EPSILON <= hsv.v);
TEST_ASSERT( HSV_EPSILON >= hsv.s);
TEST_ASSERT( HSV_EPSILON >= hsv.v);
/* Hue for black is undefined so we don't check it */
}

static void test_rgb_invert__success(void)
{
const color_rgb_t col = {.r = 100, .g = 128, .b = 0};
Expand Down Expand Up @@ -109,6 +127,7 @@ Test *tests_color_tests(void)
new_TestFixture(test_hex2rgb__success),
new_TestFixture(test_rgb2hex__success),
new_TestFixture(test_rgb2str__success),
new_TestFixture(test_rgb2hsv__black),
new_TestFixture(test_rgb_invert__success),
new_TestFixture(test_rgb_complementary__success),
};
Expand Down