diff options
Diffstat (limited to 'testcases.c')
-rw-r--r-- | testcases.c | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/testcases.c b/testcases.c index 612d1c2..eba3983 100644 --- a/testcases.c +++ b/testcases.c @@ -10,6 +10,13 @@ int buffer[MAX_SIZE]; unsigned long comparisons; +void assert_sorted(size_t size, cmpfun cmp) +{ + for (size_t i = 1; i < size; i++) { + if (cmp(buffer + i-1, buffer + i) > 0) abort(); + } +} + static int compare(const void *a, const void *b) { const int *aa = a; @@ -24,7 +31,7 @@ static int compare(const void *a, const void *b) return 0; } -static void init_random(int *buffer, size_t size) +static void init_random(size_t size) { srandom(1); for (size_t i = 0; i < size; i++) buffer[i] = random(); @@ -43,22 +50,22 @@ static void init_random(int *buffer, size_t size) #endif } -static void init_sorted(int *buffer, size_t size) +static void init_sorted(size_t size) { for (size_t i = 0; i < size; i++) buffer[i] = i; } -static void init_reverse(int *buffer, size_t size) +static void init_reverse(size_t size) { for (size_t i = 0; i < size; i++) buffer[i] = size - i - 1; } -static void init_constant(int *buffer, size_t size) +static void init_constant(size_t size) { for (size_t i = 0; i < size; i++) buffer[i] = 42; } -static void add_noise(int *buffer, size_t size) +static void add_noise(size_t size) { int noisemax = size / 4; int noiseoff = size / 8; @@ -71,16 +78,16 @@ static void add_noise(int *buffer, size_t size) } } -static void init_sorted_noise(int *buffer, size_t size) +static void init_sorted_noise(size_t size) { - init_sorted(buffer, size); - add_noise(buffer, size); + init_sorted(size); + add_noise(size); } -static void init_reverse_noise(int *buffer, size_t size) +static void init_reverse_noise(size_t size) { - init_reverse(buffer, size); - add_noise(buffer, size); + init_reverse(size); + add_noise(size); } const struct testcase testcases[] = { |