repo.or.cz
/
frac.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
blame
|
history
|
raw
|
HEAD
Moved old website to README.
[frac.git]
/
tee_test.c
blob
1ac2e460963c9113b4b56e7ae5c59e841659f2a3
1
#include <stdio.h>
2
#include <stdlib.h>
3
#include <string.h>
4
#include <gmp.h>
5
#include
"cf.h"
6
#include
"test.h"
7
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
++;
13
}
14
return
NULL
;
15
}
16
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
);
24
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
--;
30
}
31
}
32
33
i
[
0
] =
1
;
34
i
[
1
] =
1
;
35
get
(
0
,
5
);
36
get
(
1
,
10
);
37
get
(
0
,
20
);
38
39
cf_free
(
out
[
0
]);
40
get
(
1
,
100
);
41
cf_free
(
out
[
1
]);
42
43
mpz_clear
(
z
);
44
return
0
;
45
}