From 0fccb0fc86d4b3054e50aed2ba900d99cb69d48d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Thu, 12 Jun 2014 01:34:40 +0200 Subject: [PATCH] testboxes: Fix find_closest_point_to_line() test Eeeks, testing floating points for equality ... --- src/core/testboxes.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/core/testboxes.c b/src/core/testboxes.c index aa676ef41..24a6756e8 100644 --- a/src/core/testboxes.c +++ b/src/core/testboxes.c @@ -25,6 +25,7 @@ #include #include /* Just for the definition of the various gravities */ #include /* To initialize random seed */ +#include #define NUM_RANDOM_RUNS 10000 @@ -1332,6 +1333,7 @@ test_gravity_resize () printf ("%s passed.\n", G_STRFUNC); } +#define EPSILON 0.000000001 static void test_find_closest_point_to_line () { @@ -1346,7 +1348,7 @@ test_find_closest_point_to_line () x2, y2, px, py, &rx, &ry); - g_assert (rx == answer_x && ry == answer_y); + g_assert (fabs (rx - answer_x) < EPSILON && fabs (ry - answer_y) < EPSILON); /* Special test for x1 == x2, so that slop of line is infinite */ x1 = 3.0; y1 = 49.0; @@ -1357,7 +1359,7 @@ test_find_closest_point_to_line () x2, y2, px, py, &rx, &ry); - g_assert (rx == answer_x && ry == answer_y); + g_assert (fabs (rx - answer_x) < EPSILON && fabs (ry - answer_y) < EPSILON); /* Special test for y1 == y2, so perp line has slope of infinity */ x1 = 3.14; y1 = 7.0; @@ -1368,7 +1370,7 @@ test_find_closest_point_to_line () x2, y2, px, py, &rx, &ry); - g_assert (rx == answer_x && ry == answer_y); + g_assert (fabs (rx - answer_x) < EPSILON && fabs (ry - answer_y) < EPSILON); /* Test when we the point we want to be closest to is actually on the line */ x1 = 3.0; y1 = 49.0; @@ -1379,7 +1381,7 @@ test_find_closest_point_to_line () x2, y2, px, py, &rx, &ry); - g_assert (rx == answer_x && ry == answer_y); + g_assert (fabs (rx - answer_x) < EPSILON && fabs (ry - answer_y) < EPSILON); printf ("%s passed.\n", G_STRFUNC); }