X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-array-mergesort.c;h=3f5d08211a3c0371ab2c05bebda2f33a16e0fd15;hb=7d4900610fe09a4d16c37a5e3bd4e49160c33eeb;hp=8a47b67651f0875fe355aa717ca074d2453f05f8;hpb=72a81a6703c8f2f9731fd466b6ff10552ee4b31c;p=gnulib.git diff --git a/tests/test-array-mergesort.c b/tests/test-array-mergesort.c index 8a47b6765..3f5d08211 100644 --- a/tests/test-array-mergesort.c +++ b/tests/test-array-mergesort.c @@ -1,5 +1,5 @@ /* Test of stable-sorting of an array using mergesort. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published @@ -24,20 +24,9 @@ struct foo { double x; double index; }; #define STATIC static #include "array-mergesort.h" -#include #include -#define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ - while (0) +#include "macros.h" #define NMAX 257 static const struct foo data[NMAX] = @@ -305,8 +294,8 @@ static int cmp_double (const void *a, const void *b) { return (*(const double *)a < *(const double *)b ? -1 : - *(const double *)a > *(const double *)b ? 1 : - 0); + *(const double *)a > *(const double *)b ? 1 : + 0); } int @@ -336,15 +325,15 @@ main () /* Verify the result. */ qsort_result = (double *) malloc (n * sizeof (double)); for (i = 0; i < n; i++) - qsort_result[i] = data[i].x; + qsort_result[i] = data[i].x; qsort (qsort_result, n, sizeof (double), cmp_double); for (i = 0; i < n; i++) - ASSERT (dst[i].x == qsort_result[i]); + ASSERT (dst[i].x == qsort_result[i]); /* Verify the stability. */ for (i = 0; i < n; i++) - if (i > 0 && dst[i - 1].x == dst[i].x) - ASSERT (dst[i - 1].index < dst[i].index); + if (i > 0 && dst[i - 1].x == dst[i].x) + ASSERT (dst[i - 1].index < dst[i].index); free (qsort_result); free (tmp); @@ -365,7 +354,7 @@ main () tmp[n].x = 0x587EF149; /* canary */ for (i = 0; i < n; i++) - src[i] = data[i]; + src[i] = data[i]; merge_sort_inplace (src, n, tmp); @@ -376,15 +365,15 @@ main () /* Verify the result. */ qsort_result = (double *) malloc (n * sizeof (double)); for (i = 0; i < n; i++) - qsort_result[i] = data[i].x; + qsort_result[i] = data[i].x; qsort (qsort_result, n, sizeof (double), cmp_double); for (i = 0; i < n; i++) - ASSERT (src[i].x == qsort_result[i]); + ASSERT (src[i].x == qsort_result[i]); /* Verify the stability. */ for (i = 0; i < n; i++) - if (i > 0 && src[i - 1].x == src[i].x) - ASSERT (src[i - 1].index < src[i].index); + if (i > 0 && src[i - 1].x == src[i].x) + ASSERT (src[i - 1].index < src[i].index); free (qsort_result); free (tmp);