#include #include #include #include #include #include "hexagon.h" #include "tap.h" int icmp(const void *ap, const void *bp) { int a; int b; a = *((int *)(ap)); b = *((int *)(bp)); return a-b; } void sort(int *r, int ct) { qsort(r, ct, sizeof *r, icmp); } int main(void) { int start; int i, count; int range[32]; int testrange[32]; plan_tests(7+4); printf("range = 1 from 3,3\n"); start = HL_cantor_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); sort(testrange, 6); for (i = 0; i < count; i++) { ok(range[i] == testrange[i], "3, 3 range 1 hex %d", testrange[i]); } start = HL_cantor_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); 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); 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); count = HL_hexes_at_range(start, 2, range, 0); ok(count == 12, "6 hexes at range1 from 3,3"); return exit_status(); }