add tests for CPC_compare_colors()

This commit is contained in:
Thomas BERNARD 2019-11-13 23:41:35 +01:00 committed by Thomas Bernard
parent e3f089667a
commit 28543ecd97
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C
2 changed files with 48 additions and 1 deletions

View File

@ -2,4 +2,5 @@
* TEST(function_to_test) */
TEST(MOTO_MAP_pack)
TEST(CPC_compare_colors)

View File

@ -26,11 +26,11 @@
///@file tests.c
/// Unit tests.
///
/// TODO : make a test binary and include the tests to the constant-integration
#include <stdio.h>
#include <string.h>
#include "../struct.h"
#include "../oldies.h"
#include "../gfx2log.h"
/**
@ -83,3 +83,49 @@ int Test_MOTO_MAP_pack(void)
}
return 1; // test OK
}
int Test_CPC_compare_colors(void)
{
unsigned int r, g, b;
T_Components c1, c2;
for (r = 0; r < 16; r++)
{
for (g = 0; g < 16; g++)
{
for (b = 0; b < 16; b++)
{
c1.R = r * 0x11;
c1.G = g * 0x11;
c1.B = b * 0x11;
if (!CPC_compare_colors(&c1, &c1))
return 0; // same colors should be recognized as identical !!!
c2.R = ((r + 6) & 15) * 0x11;
c2.G = c1.G;
c2.B = c1.B;
if (CPC_compare_colors(&c1, &c2))
{
GFX2_Log(GFX2_ERROR, "#%02x%02x%02x <> #%02x%02x%02x\n",
c1.R, c1.G, c1.B, c2.R, c2.G, c2.B);
return 0; // Should be differents !
}
c2.R = c1.R;
c2.G = ((g + 6) & 15) * 0x11;
if (CPC_compare_colors(&c1, &c2))
{
GFX2_Log(GFX2_ERROR, "#%02x%02x%02x <> #%02x%02x%02x\n",
c1.R, c1.G, c1.B, c2.R, c2.G, c2.B);
return 0; // Should be differents !
}
c2.G = c1.G;
c2.B = ((b + 6) & 15) * 0x11;
if (CPC_compare_colors(&c1, &c2))
{
GFX2_Log(GFX2_ERROR, "#%02x%02x%02x <> #%02x%02x%02x\n",
c1.R, c1.G, c1.B, c2.R, c2.G, c2.B);
return 0; // Should be differents !
}
}
}
}
return 1; // test OK
}