diff options
| author | Victor Kareh <[email protected]> | 2019-09-23 14:55:54 -0400 | 
|---|---|---|
| committer | Robert Antoni Buj Gelonch <[email protected]> | 2019-09-24 16:10:41 +0200 | 
| commit | 744f9ff68b10b168bcceb20e550ac0b8239e7fea (patch) | |
| tree | c588f45ed135961cec1aa7af30a0706b7bdde868 | |
| parent | b73826b3c9e3c72893bbc07dc3d43e67928f9ea5 (diff) | |
| download | marco-744f9ff68b10b168bcceb20e550ac0b8239e7fea.tar.bz2 marco-744f9ff68b10b168bcceb20e550ac0b8239e7fea.tar.xz | |
testboxes: Fix find_closest_point_to_line() test
Eeeks, testing floating points for equality ...
upstream commit:
https://gitlab.gnome.org/GNOME/mutter/commit/0fccb0fc8
| -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 739d8a3e..fecca881 100644 --- a/src/core/testboxes.c +++ b/src/core/testboxes.c @@ -27,6 +27,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 @@ -1340,6 +1341,7 @@ test_gravity_resize (void)    printf ("%s passed.\n", G_STRFUNC);  } +#define EPSILON 0.000000001  static void  test_find_closest_point_to_line (void)  { @@ -1354,7 +1356,7 @@ test_find_closest_point_to_line (void)                                                    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; @@ -1365,7 +1367,7 @@ test_find_closest_point_to_line (void)                                                    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; @@ -1376,7 +1378,7 @@ test_find_closest_point_to_line (void)                                                    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; @@ -1387,7 +1389,7 @@ test_find_closest_point_to_line (void)                                                    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);  } | 
