mirror of
https://github.com/brl/mutter.git
synced 2024-11-28 19:10:43 -05:00
testboxes: Fix find_closest_point_to_line() test
Eeeks, testing floating points for equality ...
This commit is contained in:
parent
8100cefd4c
commit
0fccb0fc86
@ -25,6 +25,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <X11/Xutil.h> /* Just for the definition of the various gravities */
|
#include <X11/Xutil.h> /* Just for the definition of the various gravities */
|
||||||
#include <time.h> /* To initialize random seed */
|
#include <time.h> /* To initialize random seed */
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#define NUM_RANDOM_RUNS 10000
|
#define NUM_RANDOM_RUNS 10000
|
||||||
|
|
||||||
@ -1332,6 +1333,7 @@ test_gravity_resize ()
|
|||||||
printf ("%s passed.\n", G_STRFUNC);
|
printf ("%s passed.\n", G_STRFUNC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define EPSILON 0.000000001
|
||||||
static void
|
static void
|
||||||
test_find_closest_point_to_line ()
|
test_find_closest_point_to_line ()
|
||||||
{
|
{
|
||||||
@ -1346,7 +1348,7 @@ test_find_closest_point_to_line ()
|
|||||||
x2, y2,
|
x2, y2,
|
||||||
px, py,
|
px, py,
|
||||||
&rx, &ry);
|
&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 */
|
/* Special test for x1 == x2, so that slop of line is infinite */
|
||||||
x1 = 3.0; y1 = 49.0;
|
x1 = 3.0; y1 = 49.0;
|
||||||
@ -1357,7 +1359,7 @@ test_find_closest_point_to_line ()
|
|||||||
x2, y2,
|
x2, y2,
|
||||||
px, py,
|
px, py,
|
||||||
&rx, &ry);
|
&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 */
|
/* Special test for y1 == y2, so perp line has slope of infinity */
|
||||||
x1 = 3.14; y1 = 7.0;
|
x1 = 3.14; y1 = 7.0;
|
||||||
@ -1368,7 +1370,7 @@ test_find_closest_point_to_line ()
|
|||||||
x2, y2,
|
x2, y2,
|
||||||
px, py,
|
px, py,
|
||||||
&rx, &ry);
|
&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 */
|
/* Test when we the point we want to be closest to is actually on the line */
|
||||||
x1 = 3.0; y1 = 49.0;
|
x1 = 3.0; y1 = 49.0;
|
||||||
@ -1379,7 +1381,7 @@ test_find_closest_point_to_line ()
|
|||||||
x2, y2,
|
x2, y2,
|
||||||
px, py,
|
px, py,
|
||||||
&rx, &ry);
|
&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);
|
printf ("%s passed.\n", G_STRFUNC);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user