X-Git-Url: https://pd.if.org/git/?p=hexagon;a=blobdiff_plain;f=t%2Fastar.c;h=af88268d4212af1c23484843108e5aeeb4144d81;hp=bab342d0301826f4d1ee5a2bacb79ddce60b68a6;hb=5c48a06bc8649958e69013c53e925b83398ebc74;hpb=67fdcec57ab31e7a972ed624ab5f6df866313206 diff --git a/t/astar.c b/t/astar.c index bab342d..af88268 100644 --- a/t/astar.c +++ b/t/astar.c @@ -10,7 +10,7 @@ void pcheck(struct HL_astar *p, int x1, int y1, int x2, int y2, int expect) { from = HL_cantor_xy(x1,y1); to = HL_cantor_xy(x2,y2); - HL_astar_init(p); + HL_astar_clear(p); p->start = from; p->goal = to; @@ -19,15 +19,27 @@ void pcheck(struct HL_astar *p, int x1, int y1, int x2, int y2, int expect) { ok(p->error == 0, "found path from (%02d, %02d) to (%02d, %02d) with no error", x1, y1, x2, y2); ok(dist == expect, - "found path from (%02d, %02d) to (%02d, %02d) path length = %d (expect %d)\n", + "found path from (%02d, %02d) to (%02d, %02d) path length = %d (expect %d)", x1, y1, x2, y2, dist, expect); } +/* make hex 55 missing */ +int neighbor55(int hex, int dir) { + int neighbor; + + neighbor = HL_adjacent_hex(hex, dir); + if (neighbor == HL_cantor_xy(5,5)) { + return -1; + } + + return neighbor; +} + int main(void) { struct HL_astar *p; int length; - plan_tests(15); + plan_tests(17); p = HL_astar_init(0); ok(p != NULL, "allocated astar struct"); @@ -47,6 +59,10 @@ int main(void) { pcheck(p, 1,1, 3,1, 2); pcheck(p, 1,1, 4,7, 8); + HL_astar_clear(p); + p->neighbor = neighbor55; + pcheck(p,5,4,5,6,3); + HL_astar_free(p); return exit_status();