Merged signal and get.
[frac.git] / cf_test.c
blob76dd62f3fe7466772b1eaa655d05a85727dbf536
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <gmp.h>
4 #include "cf.h"
5 #include "test.h"
7 static void *count_fn(cf_t cf) {
8 mpz_t z;
9 mpz_init(z);
10 mpz_set_ui(z, 0);
11 while(cf_wait(cf)) {
12 mpz_add_ui(z, z, 1);
13 cf_put(cf, z);
15 mpz_clear(z);
16 return NULL;
19 int main() {
20 mpz_t z;
21 mpz_init(z);
22 cf_t a;
23 a = cf_new(count_fn, NULL);
24 for (int i = 1; i <= 10; i++) {
25 cf_get(z, a);
26 EXPECT(!mpz_cmp_ui(z, i));
28 cf_free(a);
29 mpz_clear(z);
30 return 0;