diff options
author | Andreas Rottmann <a.rottmann@gmx.at> | 2010-05-27 18:23:15 +0200 |
---|---|---|
committer | Andreas Rottmann <a.rottmann@gmx.at> | 2010-05-27 18:23:15 +0200 |
commit | 3e0814cd9862b89c7a39672672937477bd87ddfb (patch) | |
tree | 159134a624e51509f40ed8823249f09a70d1dda3 /tests/test-array-mergesort.c | |
parent | 3bebb94360f1c2333feb8d504a9fa4f96984d8b7 (diff) |
Imported Upstream version 0.9.3upstream/0.9.3
Diffstat (limited to 'tests/test-array-mergesort.c')
-rw-r--r-- | tests/test-array-mergesort.c | 37 |
1 files changed, 13 insertions, 24 deletions
diff --git a/tests/test-array-mergesort.c b/tests/test-array-mergesort.c index 8a47b676..3f5d0821 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 <stdio.h> #include <stdlib.h> -#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); |