From df538ad4f3b9ca3e98822299d6f233e219bc2fd4 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 26 Jan 2023 20:26:59 +0100 Subject: test libglitter_desaturate_{double,float} MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libglitter_desaturate_double.c | 72 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) (limited to 'libglitter_desaturate_double.c') diff --git a/libglitter_desaturate_double.c b/libglitter_desaturate_double.c index ba588f4..0797ddc 100644 --- a/libglitter_desaturate_double.c +++ b/libglitter_desaturate_double.c @@ -55,7 +55,77 @@ libglitter_desaturate_double(double **rasters, size_t nrasters, size_t rowsize, int main(void) { - return 0; /* TODO add test */ + double rasters1[4 * 10 * 3][4], *rasters1list[4], primary_ys[4], saturation; + double rasters2[4 * 10 * 3][4], *rasters2list[4], saturations[4]; + size_t i, j; + + void *randptr = malloc(1); + srand((unsigned int)(uintptr_t)randptr); + free(randptr); + +#define RANDOMISE(SAT)\ + do {\ + saturation = (SAT);\ + saturations[0] = saturation;\ + saturations[1] = saturation;\ + saturations[2] = saturation;\ + saturations[3] = saturation;\ + for (i = 0; i < 4; i++) {\ + rasters1list[i] = rasters1[i];\ + rasters2list[i] = rasters2[i];\ + primary_ys[i] = rand() / (double)RAND_MAX;\ + for (j = 0; j < 4 * 10 * 3; j++)\ + rasters1[j][i] = rand() / (double)RAND_MAX;\ + }\ + memcpy(rasters2, rasters1, sizeof(rasters1));\ + } while (0) + + RANDOMISE(rand() / (double)RAND_MAX); + libglitter_desaturate_double(rasters1list, 4, 10, 3, 7, 4, saturation, primary_ys); + libglitter_per_channel_desaturate_double(rasters2list, 4, 10, 3, 7, 4, saturations, primary_ys); + ASSERT(!memcmp(rasters1, rasters2, sizeof(rasters1))); + + RANDOMISE(rand() / (double)RAND_MAX); + libglitter_desaturate_double(rasters1list, 3, 10, 3, 7, 4, saturation, primary_ys); + libglitter_per_channel_desaturate_double(rasters2list, 3, 10, 3, 7, 4, saturations, primary_ys); + ASSERT(!memcmp(rasters1, rasters2, sizeof(rasters1))); + + RANDOMISE(rand() / (double)RAND_MAX); + libglitter_desaturate_double(rasters1list, 3, 10, 3, 7, 4, saturation, NULL); + libglitter_per_channel_desaturate_double(rasters2list, 3, 10, 3, 7, 4, saturations, NULL); + ASSERT(!memcmp(rasters1, rasters2, sizeof(rasters1))); + + RANDOMISE(0); + libglitter_desaturate_double(rasters1list, 4, 10, 3, 7, 4, saturation, primary_ys); + libglitter_per_channel_desaturate_double(rasters2list, 4, 10, 3, 7, 4, saturations, primary_ys); + ASSERT(!memcmp(rasters1, rasters2, sizeof(rasters1))); + + RANDOMISE(0); + libglitter_desaturate_double(rasters1list, 3, 10, 3, 7, 4, saturation, primary_ys); + libglitter_per_channel_desaturate_double(rasters2list, 3, 10, 3, 7, 4, saturations, primary_ys); + ASSERT(!memcmp(rasters1, rasters2, sizeof(rasters1))); + + RANDOMISE(0); + libglitter_desaturate_double(rasters1list, 3, 10, 3, 7, 4, saturation, NULL); + libglitter_per_channel_desaturate_double(rasters2list, 3, 10, 3, 7, 4, saturations, NULL); + ASSERT(!memcmp(rasters1, rasters2, sizeof(rasters1))); + + RANDOMISE(1); + libglitter_desaturate_double(rasters1list, 4, 10, 3, 7, 4, saturation, primary_ys); + libglitter_per_channel_desaturate_double(rasters2list, 4, 10, 3, 7, 4, saturations, primary_ys); + ASSERT(!memcmp(rasters1, rasters2, sizeof(rasters1))); + + RANDOMISE(1); + libglitter_desaturate_double(rasters1list, 3, 10, 3, 7, 4, saturation, primary_ys); + libglitter_per_channel_desaturate_double(rasters2list, 3, 10, 3, 7, 4, saturations, primary_ys); + ASSERT(!memcmp(rasters1, rasters2, sizeof(rasters1))); + + RANDOMISE(1); + libglitter_desaturate_double(rasters1list, 3, 10, 3, 7, 4, saturation, NULL); + libglitter_per_channel_desaturate_double(rasters2list, 3, 10, 3, 7, 4, saturations, NULL); + ASSERT(!memcmp(rasters1, rasters2, sizeof(rasters1))); + + return 0; } -- cgit v1.2.3-70-g09d2