]> pd.if.org Git - hexagon/blob - t/range.c
use ctap
[hexagon] / t / range.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <assert.h>
4 #include <limits.h>
5 #include <math.h>
6
7 #include "hexagon.h"
8
9 #include "ctap.h"
10
11 int icmp(const void *ap, const void *bp) {
12         int a;
13         int b;
14         
15         a = *((int *)(ap));
16         b = *((int *)(bp));
17
18         return a-b;
19 }
20
21 void sort(int *r, int ct) {
22         qsort(r, ct, sizeof *r, icmp);
23 }
24
25 int main(void) {
26         int start;
27         int i, count;
28         int range[32];
29         int testrange[32];
30
31         plan(7+4);
32
33         /* printf("range = 1 from 3,3\n"); */
34         start = HL_cantor_xy(3,3);
35         count = HL_hexes_at_range(start, 1, range, 0);
36         ok(count == 6, "6 hexes at range 1");
37         count = HL_hexes_at_range(start, 1, range, count);
38         sort(range, 6);
39         testrange[0] = HL_cantor_xy(3,2);
40         testrange[1] = HL_cantor_xy(3,4);
41         testrange[2] = HL_cantor_xy(4,3);
42         testrange[3] = HL_cantor_xy(4,2);
43         testrange[4] = HL_cantor_xy(2,3);
44         testrange[5] = HL_cantor_xy(2,2);
45         sort(testrange, 6);
46         for (i = 0; i < count; i++) {
47                 ok(range[i] == testrange[i], "3, 3 range 1 hex %d", testrange[i]);
48         }
49
50         start = HL_cantor_xy(0,3);
51         count = HL_hexes_at_range(start, 1, range, 0);
52         ok(count == 6, "6 hexes at range1 from 0,3");
53
54         start = HL_cantor_xy(-1,5);
55         count = HL_hexes_at_range(start, 1, range, 0);
56         ok(count == 6, "6 hexes at range1 from -1,5");
57
58         start = HL_cantor_xy(-2,3);
59         count = HL_hexes_at_range(start, 1, range, 0);
60         ok(count == 6, "6 hexes at range1 from -2,3");
61
62         start = HL_cantor_xy(3,3);
63         count = HL_hexes_at_range(start, 2, range, 0);
64         ok(count == 12, "6 hexes at range1 from 3,3");
65
66         return 0;
67 }