X-Git-Url: https://pd.if.org/git/?p=hexagon;a=blobdiff_plain;f=t%2Frange.c;fp=t%2Frange.c;h=76028454fecfc15e75ffd5ea41a35cef00979421;hp=783a089f130cd87679b49e301cc001427bfa8dc4;hb=06868ef42497f1cbc480831029f5f69b395dfdd2;hpb=c5a7aa5029146b2bcea5daae53c6aa3e5e33ed04 diff --git a/t/range.c b/t/range.c index 783a089..7602845 100644 --- a/t/range.c +++ b/t/range.c @@ -9,57 +9,62 @@ #include "ctap.h" int icmp(const void *ap, const void *bp) { - int a; - int b; + struct HL_hex const *a; + struct HL_hex const *b; - a = *((int *)(ap)); - b = *((int *)(bp)); + a = ap; + b = bp; - return a-b; + if (a->x < b->x) return -1; + if (a->x > b->x) return 1; + if (a->y < b->y) return -1; + if (a->y > b->y) return 1; + + return 0; } -void sort(int *r, int ct) { +void sort(struct HL_hex *r, int ct) { qsort(r, ct, sizeof *r, icmp); } int main(void) { - int start; + struct HL_hex start; int i, count; - int range[32]; - int testrange[32]; + struct HL_hex range[32]; + struct HL_hex testrange[32]; plan(7+4); /* printf("range = 1 from 3,3\n"); */ - start = HL_cantor_xy(3,3); + start = HL_hex_xy(3,3); count = HL_hexes_at_range(start, 1, range, 0); ok(count == 6, "6 hexes at range 1"); count = HL_hexes_at_range(start, 1, range, count); sort(range, 6); - testrange[0] = HL_cantor_xy(3,2); - testrange[1] = HL_cantor_xy(3,4); - testrange[2] = HL_cantor_xy(4,3); - testrange[3] = HL_cantor_xy(4,2); - testrange[4] = HL_cantor_xy(2,3); - testrange[5] = HL_cantor_xy(2,2); + testrange[0] = HL_hex_xy(3,2); + testrange[1] = HL_hex_xy(3,4); + testrange[2] = HL_hex_xy(4,3); + testrange[3] = HL_hex_xy(4,2); + testrange[4] = HL_hex_xy(2,3); + testrange[5] = HL_hex_xy(2,2); sort(testrange, 6); for (i = 0; i < count; i++) { - ok(range[i] == testrange[i], "3, 3 range 1 hex %d", testrange[i]); + ok(HL_hex_eq(&range[i], &testrange[i]), "3, 3 range 1 hex %d", testrange[i]); } - start = HL_cantor_xy(0,3); + start = HL_hex_xy(0,3); count = HL_hexes_at_range(start, 1, range, 0); ok(count == 6, "6 hexes at range1 from 0,3"); - start = HL_cantor_xy(-1,5); + start = HL_hex_xy(-1,5); count = HL_hexes_at_range(start, 1, range, 0); ok(count == 6, "6 hexes at range1 from -1,5"); - start = HL_cantor_xy(-2,3); + start = HL_hex_xy(-2,3); count = HL_hexes_at_range(start, 1, range, 0); ok(count == 6, "6 hexes at range1 from -2,3"); - start = HL_cantor_xy(3,3); + start = HL_hex_xy(3,3); count = HL_hexes_at_range(start, 2, range, 0); ok(count == 12, "6 hexes at range1 from 3,3");