]> pd.if.org Git - hexagon/blob - t/distance.c
c3ff1cc2a57b0673256c9e1c5bee8f3f057d0a68
[hexagon] / t / distance.c
1 #include "hexagon.h"
2
3 #include "tap.h"
4
5 void dcheck(int x1, int y1, int x2, int y2, int expect) {
6         int from, to, dist;
7         from = HL_cantor_xy(x1,y1);
8         to = HL_cantor_xy(x2,y2);
9         dist = HL_distance(from,to);
10         ok(dist == expect,
11                 "distance from (%02d, %02d) to (%02d, %02d) = %d (expect %d)",
12                 x1, y1, x2, y2, dist, expect);
13 }
14
15 int main(void) {
16         plan_tests(8);
17
18         dcheck(1,1,2,1,1);
19         dcheck(1,1,2,2,2);
20         dcheck(2,2,2,1,1);
21         dcheck(1,1,2,3,3);
22         dcheck(3,3,3,3,0);
23         dcheck(0,0,1,1,1);
24         dcheck(-1,-1,1,2,4);
25         dcheck(-1,-1,-1,-2,1);
26
27         return exit_status();
28 }