diff options
| author | Tom Harley | 2020-01-24 05:15:35 +0000 |
|---|---|---|
| committer | Tom Harley | 2020-01-24 05:15:35 +0000 |
| commit | c9f0de12be31eea463bf022f3eee76490b30f8dc (patch) | |
| tree | a80718ff00fa2dcb1c52c2af6828feffc7f89d8b /test/pipeline-tests.c | |
| download | parapat-master.tar.gz parapat-master.zip | |
Diffstat (limited to 'test/pipeline-tests.c')
| -rw-r--r-- | test/pipeline-tests.c | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/test/pipeline-tests.c b/test/pipeline-tests.c new file mode 100644 index 0000000..2d446a5 --- /dev/null +++ b/test/pipeline-tests.c @@ -0,0 +1,83 @@ +#include <stdlib.h> +#include <stdio.h> + +#include "minunit.h" + +#include "parapat.h" + +#define unused(x) (x = x) + +int tests_run = 0; + +int x = 1; + +int test_emitter(void **v, void *_) { + int *p = malloc(sizeof *p); + unused(_); + *p = x++; + *v = p; + return x > 3; +} + +void *test_worker(void *v, void *_) { + int *p = v; + unused(_); + *p *= 2; + return v; +} + +void *test_collector(void *l, void *r, void *_) { + int *p = l; + int *q = r; + unused(_); + if (!p) { + p = malloc(sizeof *p); + *p = 0; + } + *p += *q; + free(q); + return p; +} + +char *pipeline_simple() { + int a, *res; + worker *wfns[] = { test_worker, test_worker, test_worker, test_worker }; + x = 1; + a = 0; + res = create_pipeline(test_emitter, wfns, 4, test_collector, NULL, NULL, + &a); + + mu_assert("error, *res != 96", *res == 96); + return 0; +} + +char *pipeline_one() { + int a, *res; + worker *wfns[] = { test_worker }; + x = 1; + a = 0; + res = create_pipeline(test_emitter, wfns, 1, test_collector, NULL, NULL, + &a); + + printf("answer is %d\n", *res); + mu_assert("error, *res != 12", *res == 12); + return 0; +} + +static char *all_tests() { + mu_run_test(pipeline_simple); + mu_run_test(pipeline_one); + return 0; +} + +int main() { + char *error = all_tests(); + if (error) { + printf("%s\n", error); + } else { + printf("ALL TESTS PASSED\n"); + } + printf("Tests run: %d\n", tests_run); + + return error != 0; +} |
