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
Quadratic algorithm supports sign, as does decimal conversion.
[frac.git]
/
cf_test.c
blob
c83694bf1d609246c5c48e06741f6c658f797994
1
// Test demand channel infrastructure.
2
3
#include <stdio.h>
4
#include <stdlib.h>
5
#include <gmp.h>
6
#include
"cf.h"
7
#include
"test.h"
8
9
static void
*
count_fn
(
cf_t cf
) {
10
mpz_t z
;
11
mpz_init
(
z
);
12
mpz_set_ui
(
z
,
0
);
13
while
(
cf_wait
(
cf
)) {
14
cf_put
(
cf
,
z
);
15
mpz_add_ui
(
z
,
z
,
1
);
16
}
17
mpz_clear
(
z
);
18
return
NULL
;
19
}
20
21
int
main
() {
22
mpz_t z
;
23
mpz_init
(
z
);
24
cf_t a
;
25
a
=
cf_new
(
count_fn
,
NULL
);
26
for
(
int
i
=
0
;
i
<
100
;
i
++) {
27
cf_get
(
z
,
a
);
28
EXPECT
(!
mpz_cmp_ui
(
z
,
i
));
29
}
30
cf_free
(
a
);
31
mpz_clear
(
z
);
32
return
0
;
33
}