[gegl] tests: Compare change-rect test buffers with small epsilon
- From: Martin Nordholts <martinn src gnome org>
- To: svn-commits-list gnome org
- Subject: [gegl] tests: Compare change-rect test buffers with small epsilon
- Date: Thu, 16 Jul 2009 11:45:43 +0000 (UTC)
commit 0414aa91024b259a35fee6714c3b04242d2d733d
Author: Danny Robson <danny blubinc net>
Date: Thu Jul 16 21:12:06 2009 +1000
tests: Compare change-rect test buffers with small epsilon
Comparing the expected and calculated buffers can fail if there is
some (small) accumulated error. Specifically, test 3 was failing on my
computer. Compare the buffers with some small epsilon to account for
this.
tests/test-change-processor-rect.c | 11 +++++++++--
1 files changed, 9 insertions(+), 2 deletions(-)
---
diff --git a/tests/test-change-processor-rect.c b/tests/test-change-processor-rect.c
index 50936f7..bb090cb 100644
--- a/tests/test-change-processor-rect.c
+++ b/tests/test-change-processor-rect.c
@@ -17,18 +17,23 @@
#include "config.h"
#include <string.h>
+#include <math.h>
#include "gegl.h"
#define SUCCESS 0
#define FAILURE -1
+#define FLOATS_EQUAL(x,y) (fabs((x) - (y)) < 0.00001f)
+
+
static gboolean
test_change_processor_rect_do_test (GeglProcessor *processor,
const GeglRectangle *rect,
GeglNode *sink)
{
- gboolean result = FALSE;
+ gint i = 0;
+ gboolean result = TRUE;
float expected_result_buffer[4] = { 1.0, 1.0, 1.0, 1.0 };
float result_buffer[4] = { 0, };
GeglBuffer *buffer = NULL;
@@ -48,7 +53,9 @@ test_change_processor_rect_do_test (GeglProcessor *processor,
result_buffer,
GEGL_AUTO_ROWSTRIDE);
- result = memcmp (result_buffer, expected_result_buffer, sizeof (expected_result_buffer)) == 0;
+ /* Compare with a small epsilon to account for accumulated error */
+ for(i = 0; i < G_N_ELEMENTS (expected_result_buffer); i++)
+ result = result && FLOATS_EQUAL (expected_result_buffer[i], result_buffer[i]);
gegl_node_set (sink,
"buffer", NULL,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]