tests: fix build on os/x
[schroedinger.git] / testsuite / sort.c
blobb16320a01ec08a8a50e30e504d7ee0cff80c8973
2 #ifdef HAVE_CONFIG_H
3 #include "config.h"
4 #endif
6 #include <schroedinger/schrofilter.h>
7 #include <schroedinger/schro.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <time.h>
12 void
13 sort_u8 (uint8_t *d, int n)
15 int start = 0;
16 int end = n;
17 int i;
18 int x;
20 /* OMG bubble sort! */
21 while(start < end) {
22 for(i=start;i<end-1;i++){
23 if (d[i] > d[i+1]) {
24 x = d[i];
25 d[i] = d[i+1];
26 d[i+1] = x;
29 end--;
30 for(i=end-2;i>=start;i--){
31 if (d[i] > d[i+1]) {
32 x = d[i];
33 d[i] = d[i+1];
34 d[i+1] = x;
37 start++;
41 #define N 9
43 int
44 main (int argc, char *argv[])
46 int i;
47 int j;
48 uint8_t list[N];
49 int sum1, sum2;
51 srand(time(NULL));
52 for (i=0;i<100;i++){
53 SCHRO_ERROR("%d:", i);
55 sum1 = 0;
56 for(j=0;j<N;j++){
57 list[j]=rand();
58 SCHRO_ERROR(" %d", list[j]);
59 sum1 += list[j];
62 sort_u8 (list, N);
64 sum2 = 0;
65 for(j=0;j<N;j++){
66 SCHRO_ERROR("* %d", list[j]);
67 sum2 += list[j];
69 SCHRO_ASSERT(sum1 == sum2);
70 for(j=0;j<N-1;j++){
71 SCHRO_ASSERT(list[j] <= list[j+1]);
75 return 0;