-
Notifications
You must be signed in to change notification settings - Fork 10
/
test_types.c
38 lines (31 loc) · 935 Bytes
/
test_types.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "test_guff.h"
static int point_printf_cb(const void *v, void *udata) {
point *p = (point *)v;
char buf[256];
int res = snprintf(buf, 256, "(%g, %g)", p->x, p->y);
if (256 < res) { return -1; }
printf("%s", buf);
return res;
}
static int point_equal_cb(const void *vexp, const void *vgot, void *udata) {
point *exp = (point *)vexp;
point *got = (point *)vgot;
double tol = 0.000000001;
if (udata != NULL) { tol = *(double *)udata; }
if (IS_EMPTY(exp->x) && !IS_EMPTY(got->x)) {
return 0;
} else if (fabs(exp->x - got->x) > tol) {
return 0;
}
if (IS_EMPTY(exp->y) && !IS_EMPTY(got->y)) {
return 0;
} else if (fabs(exp->y - got->y) > tol) {
return 0;
}
return 1;
}
static greatest_type_info type_point_def = {
.equal = point_equal_cb,
.print = point_printf_cb,
};
greatest_type_info *type_point = &type_point_def;