[goffice] Test improvements.



commit d4bb2635ed42135af27917c356cdfe8ffa5c4952
Author: Morten Welinder <terra gnome org>
Date:   Sun Aug 5 18:10:21 2018 -0400

    Test improvements.

 ChangeLog         |  5 +++++
 tests/test-quad.c | 36 ++++++++++++++++++++++++------------
 2 files changed, 29 insertions(+), 12 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 6d853a96..8e327563 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2018-08-05  Morten Welinder  <terra gnome org>
+
+       * tests/test-quad.c: Try to make the tests work a bit better for
+       the excess-precision case, i.e., x86 in 32-bit mode.
+
 2018-08-03  Morten Welinder  <terra gnome org>
 
        * goffice/goffice.c (libgoffice_init): Use g_type_ensure to avoid
diff --git a/tests/test-quad.c b/tests/test-quad.c
index 1e84e60e..28248f6e 100644
--- a/tests/test-quad.c
+++ b/tests/test-quad.c
@@ -1,9 +1,21 @@
 #include <goffice/goffice.h>
 
+// A rather expensive way of forcing the compiler to drop any excess
+// precision it might have for x.
+static double
+kill_excess_precision (double x)
+{
+       GString *s = g_string_new (NULL);
+       double y;
+       g_string_append_len (s, (char *)&x, sizeof (x));
+       memcpy (&y, s->str, sizeof (y));
+       g_string_free (s, TRUE);
+       return y;
+}
 
 #define UNTEST1(a_,QOP,OP,txt)                                         \
 do {                                                                   \
-       double a, p;                                                    \
+       double a, p, v;                                                 \
        GOQuad qa, qc;                                                  \
        void *state;                                                    \
        a = (a_);                                                       \
@@ -11,18 +23,18 @@ do {                                                                        \
        go_quad_init (&qa, a);                                          \
        QOP (&qc, &qa);                                                 \
        go_quad_end (state);                                            \
-       p = OP (a);                                                     \
-       g_printerr ("%s(%g) = %g  [%g]\n",                              \
-                   txt, a, go_quad_value (&qc), p);                    \
+       p = kill_excess_precision (OP (a));                             \
+       v = kill_excess_precision (go_quad_value (&qc));                \
+       g_printerr ("%s(%g) = %g  [%g]\n", txt, a, v, p);               \
        if (p == floor (p))                                             \
-               g_assert (go_quad_value (&qc) == p);                    \
+               g_assert (v == p);                                      \
        else                                                            \
-               g_assert (fabs (go_quad_value (&qc) - p) / p < 1e-14);  \
+               g_assert (fabs (v - p) / p < 1e-14);                    \
 } while (0)
 
 #define BINTEST1(a_,b_,QOP,OP,txt)                                     \
 do {                                                                   \
-       double a, b, p;                                                 \
+       double a, b, p, v;                                              \
        GOQuad qa, qb, qc;                                              \
        void *state;                                                    \
        a = (a_);                                                       \
@@ -32,13 +44,13 @@ do {                                                                        \
        go_quad_init (&qb, b);                                          \
        QOP (&qc, &qa, &qb);                                            \
        go_quad_end (state);                                            \
-       p = OP (a, b);                                                  \
-       g_printerr ("%s(%g,%g) = %g  [%g]\n",                           \
-                   txt, a, b, go_quad_value (&qc), p);                 \
+       p = kill_excess_precision (OP (a, b));                          \
+       v = kill_excess_precision (go_quad_value (&qc));                \
+       g_printerr ("%s(%g,%g) = %g  [%g]\n", txt, a, b, v, p);         \
        if (p == floor (p))                                             \
-               g_assert (go_quad_value (&qc) == p);                    \
+               g_assert (v == p);                                      \
        else                                                            \
-               g_assert (fabs (go_quad_value (&qc) - p) / p < 1e-14);  \
+               g_assert (fabs (v - p) / p < 1e-14);                    \
 } while (0)
 
 /* ------------------------------------------------------------------------- */


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