diff options
Diffstat (limited to 'test/farm-tests.c')
| -rw-r--r-- | test/farm-tests.c | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/test/farm-tests.c b/test/farm-tests.c new file mode 100644 index 0000000..470aa7d --- /dev/null +++ b/test/farm-tests.c @@ -0,0 +1,89 @@ +#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 > 10; +} + +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 *farm_simple() { + int a, *res; + x = 1; + a = 0; + res = create_farm(test_emitter, test_worker, test_collector, 5, NULL, NULL, + &a); + + mu_assert("error, *res != 110", *res == 110); + return 0; +} + +/* char *farm_one() { */ +/* int a, *res; */ +/* x = 1; */ +/* a = 0; */ +/* res = create_farm(test_emitter, test_worker, test_collector, 1, NULL, NULL, */ +/* &a); */ + +/* mu_assert("error, *res != 110", *res == 110); */ +/* return 0; */ +/* } */ + +/* char *farm_zero() { */ +/* void *res = create_farm(test_emitter, test_worker, test_collector, 0, NULL, */ +/* NULL, NULL); */ + +/* mu_assert("error, res != NULL", res == NULL); */ +/* return 0; */ +/* } */ + +static char *all_tests() { + mu_run_test(farm_simple); + /* mu_run_test(farm_one); */ + /* mu_run_test(farm_zero); */ + 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; +} |
