Computes decimal digits of pi.
[frac.git] / cf_test.c
blob5f0fa80245751372301ca442debe6468d00eb5ea
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 cf_put(cf, z);
13 mpz_add_ui(z, z, 1);
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 = 0; i < 100; i++) {
25 cf_get(z, a);
26 EXPECT(!mpz_cmp_ui(z, i));
28 cf_free(a);
29 mpz_clear(z);
30 return 0;