]> pd.if.org Git - hexagon/commitdiff
added test for very long path
authorNathan Wagner <nw@hydaspes.if.org>
Sun, 20 Dec 2015 21:47:36 +0000 (15:47 -0600)
committerNathan Wagner <nw@hydaspes.if.org>
Sun, 20 Dec 2015 21:49:26 +0000 (15:49 -0600)
Makefile
t/astarlg.c [new file with mode: 0644]

index 071205befb3708b17a04925d59d0696ae98d2cf3..1662968c9d485bdbbb4007d220719f6a0d90635c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -7,7 +7,7 @@ CFLAGS= -Wall -Wno-parentheses $(ARCH) -I. -I..
 OBJS= hexagon.o astar.o
 SRC=$(OBJS:.o=.c)
 TESTS= t/cantor.t t/distance.t t/adjacency.t t/range.t t/hexbin.t \
-       t/gridsize.t t/center.t t/astar.t
+       t/gridsize.t t/center.t t/astar.t t/astarlg.t
 PREFIX=/usr/local
 
 all:   libhexagon.a docs testfiles
diff --git a/t/astarlg.c b/t/astarlg.c
new file mode 100644 (file)
index 0000000..7d2ef6b
--- /dev/null
@@ -0,0 +1,52 @@
+#include <stdio.h>
+
+#include "hexagon.h"
+
+#include "tap.h"
+
+void pcheck(struct HL_astar *p, int x1, int y1, int x2, int y2, int expect) {
+       int from, to, dist;
+
+       from = HL_cantor_xy(x1,y1);
+       to = HL_cantor_xy(x2,y2);
+
+       HL_astar_clear(p);
+
+       p->start = from;
+       p->goal = to;
+
+       dist = HL_findpath(p,0);
+       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)",
+               x1, y1, x2, y2, dist, expect);
+}
+
+/* make hex 55 missing */
+int neighbor55(int hex, int dir) {
+       int neighbor;
+
+       do {
+               neighbor = HL_adjacent_hex(hex, dir++);
+       } while (neighbor == HL_cantor_xy(5,5));
+
+       return neighbor;
+}
+
+int main(void) {
+       struct HL_astar *p;
+#if 0
+       int length;
+#endif
+
+       plan_tests(2);
+
+       p = HL_astar_init(0);
+
+       pcheck(p, 1,1, 10000,10000, 14999);
+
+       HL_astar_free(p);
+
+       return exit_status();
+}