-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinterval_test.c
More file actions
76 lines (69 loc) · 1.88 KB
/
Copy pathinterval_test.c
File metadata and controls
76 lines (69 loc) · 1.88 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "test.h"
#include <math.h>
struct iv {
float lo,hi;
};
static struct iv iv_add(struct iv x, struct iv y) {
return (struct iv){x.lo + y.lo, x.hi + y.hi};
}
static struct iv iv_sub(struct iv x, struct iv y) {
return (struct iv){x.lo - y.hi, x.hi - y.lo};
}
static struct iv iv_mul(struct iv x, struct iv y) {
float const a = x.lo * y.lo,
b = x.lo * y.hi,
c = x.hi * y.lo,
d = x.hi * y.hi;
return (struct iv){ fminf(fminf(a,b), fminf(c,d)),
fmaxf(fmaxf(a,b), fmaxf(c,d)) };
}
static void test_add(void) {
struct iv z = iv_add((struct iv){3,4},
(struct iv){1,2});
expect(equiv(4, z.lo));
expect(equiv(6, z.hi));
}
static void test_sub(void) {
struct iv z = iv_sub((struct iv){3,4},
(struct iv){1,2});
expect(equiv(1, z.lo));
expect(equiv(3, z.hi));
}
static void test_mul(void) {
{
struct iv z = iv_mul((struct iv){+3,+4},
(struct iv){+1,+2});
expect(equiv(+3, z.lo));
expect(equiv(+8, z.hi));
}
{
struct iv z = iv_mul((struct iv){-3,+4},
(struct iv){+1,+2});
expect(equiv(-6, z.lo));
expect(equiv(+8, z.hi));
}
{
struct iv z = iv_mul((struct iv){+3,-4},
(struct iv){+1,+2});
expect(equiv(-8, z.lo));
expect(equiv(+6, z.hi));
}
{
struct iv z = iv_mul((struct iv){-3,-4},
(struct iv){+1,+2});
expect(equiv(-8, z.lo));
expect(equiv(-3, z.hi));
}
{
struct iv z = iv_mul((struct iv){-3,-4},
(struct iv){-1,+2});
expect(equiv(-8, z.lo));
expect(equiv(+4, z.hi));
}
}
int main(void) {
test_add();
test_sub();
test_mul();
return 0;
}