diff options
author | Florian Müllner <fmuellner@gnome.org> | 2014-06-12 01:34:40 +0200 |
---|---|---|
committer | Florian Müllner <fmuellner@gnome.org> | 2014-06-12 01:39:54 +0200 |
commit | 0fccb0fc86d4b3054e50aed2ba900d99cb69d48d (patch) | |
tree | 3370f2ea53731a9168608b9909548346783b29f2 | |
parent | 8100cefd4c34a366af404f9ec022917f7b2fbc45 (diff) | |
download | mutter-0fccb0fc86d4b3054e50aed2ba900d99cb69d48d.tar.gz |
testboxes: Fix find_closest_point_to_line() test
Eeeks, testing floating points for equality ...
-rw-r--r-- | src/core/testboxes.c | 10 |
1 files 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 <stdio.h> #include <X11/Xutil.h> /* Just for the definition of the various gravities */ #include <time.h> /* To initialize random seed */ +#include <math.h> #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); } |