Implemented tee.
[frac.git] / tee_test.c
blob1ac2e460963c9113b4b56e7ae5c59e841659f2a3
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <gmp.h>
5 #include "cf.h"
6 #include "test.h"
8 static void *count_int_fn(cf_t cf) {
9 int n = 1;
10 while(cf_wait(cf)) {
11 cf_put_int(cf, n);
12 n++;
14 return NULL;
17 int main() {
18 mpz_t z;
19 mpz_init(z);
20 cf_t x = cf_new_const(count_int_fn);
21 cf_t out[2];
22 int i[2];
23 cf_tee(out, x);
25 void get(int k, int n) {
26 while(n) {
27 cf_get(z, out[k]);
28 EXPECT(!mpz_cmp_ui(z, i[k]++));
29 n--;
33 i[0] = 1;
34 i[1] = 1;
35 get(0, 5);
36 get(1, 10);
37 get(0, 20);
39 cf_free(out[0]);
40 get(1, 100);
41 cf_free(out[1]);
43 mpz_clear(z);
44 return 0;