[mutter] testboxes: Fix find_closest_point_to_line() test



commit 0fccb0fc86d4b3054e50aed2ba900d99cb69d48d
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Jun 12 01:34:40 2014 +0200

    testboxes: Fix find_closest_point_to_line() test
    
    Eeeks, testing floating points for equality ...

 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 aa676ef..24a6756 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);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]