summaryrefslogtreecommitdiff
path: root/generators.c
diff options
context:
space:
mode:
authorBobby Bingham <koorogi@koorogi.info>2014-08-03 12:47:33 -0500
committerBobby Bingham <koorogi@koorogi.info>2014-08-03 12:47:33 -0500
commitf07937bb63ed12a50a203c3f8015649f37bc73e5 (patch)
treeb6fb47dcfd1048b4ac0b898480eb539c38ce6282 /generators.c
parent85f2a592114832c67c70b9138905b44890b800bd (diff)
Rename generators to testcases
This is in preparation for adding an implementation of the quicksort-killer test case, which requires a custom comparison function rather than just a custom imput-generation function.
Diffstat (limited to 'generators.c')
-rw-r--r--generators.c74
1 files changed, 0 insertions, 74 deletions
diff --git a/generators.c b/generators.c
deleted file mode 100644
index 4c73454..0000000
--- a/generators.c
+++ /dev/null
@@ -1,74 +0,0 @@
-#include <limits.h>
-#include <stddef.h>
-#include <stdlib.h>
-
-#include "generators.h"
-
-static void generate_random(int *buffer, size_t size)
-{
- srandom(1);
- for (size_t i = 0; i < size; i++) buffer[i] = random();
-
- /* compress the values to nice small numbers to make debugging nicer */
-#if 0
- int maxcompressed = -1;
- for (size_t compressed = 0; compressed < size; compressed++) {
- size_t minidx = -1;
- for (size_t i = 0; i < size; i++) {
- if (maxcompressed < buffer[i] && (minidx >= size || buffer[i] < buffer[minidx]))
- minidx = i;
- }
- buffer[minidx] = ++maxcompressed;
- }
-#endif
-}
-
-static void generate_sorted(int *buffer, size_t size)
-{
- for (size_t i = 0; i < size; i++) buffer[i] = i;
-}
-
-static void generate_reverse(int *buffer, size_t size)
-{
- for (size_t i = 0; i < size; i++) buffer[i] = size - i - 1;
-}
-
-static void generate_constant(int *buffer, size_t size)
-{
- for (size_t i = 0; i < size; i++) buffer[i] = 42;
-}
-
-static void add_noise(int *buffer, size_t size)
-{
- int noisemax = size / 4;
- int noiseoff = size / 8;
-
- srandom(1);
- for (size_t i = 0; i < size; i++) {
- if (random() < 0.2 * RAND_MAX) {
- buffer[i] += random() % noisemax - noiseoff;
- }
- }
-}
-
-static void generate_sorted_noise(int *buffer, size_t size)
-{
- generate_sorted(buffer, size);
- add_noise(buffer, size);
-}
-
-static void generate_reverse_noise(int *buffer, size_t size)
-{
- generate_reverse(buffer, size);
- add_noise(buffer, size);
-}
-
-const struct generator generators[] = {
- { .name = "random", .func = generate_random },
- { .name = "sorted", .func = generate_sorted },
- { .name = "reverse", .func = generate_reverse },
- { .name = "constant", .func = generate_constant },
- { .name = "sorted+noise", .func = generate_sorted_noise },
- { .name = "reverse+noise", .func = generate_reverse_noise },
- { 0 }
-};