Improved tests. Appears to be a bug in bihom.c.
[frac.git] / cf_test.c
blobc83694bf1d609246c5c48e06741f6c658f797994
1 // Test demand channel infrastructure.
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <gmp.h>
6 #include "cf.h"
7 #include "test.h"
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);
17 mpz_clear(z);
18 return NULL;
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));
30 cf_free(a);
31 mpz_clear(z);
32 return 0;