summaryrefslogtreecommitdiff
path: root/tests/test-array-mergesort.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test-array-mergesort.c')
-rw-r--r--tests/test-array-mergesort.c37
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);