From 3d0b7418b2c1a87d44144749f5f055cfa0995f6c Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Wed, 9 Jan 2019 11:52:03 -0500 Subject: add test-solve --- meson.build | 17 +++++++++++++++-- src/test-solve/main.c | 41 +++++++++++++++++++++++++++++++++++++++++ src/text/levels.c | 4 ---- 3 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 src/test-solve/main.c diff --git a/meson.build b/meson.build index 74af93a..1d5f2e3 100644 --- a/meson.build +++ b/meson.build @@ -8,7 +8,7 @@ sources = [ 'src/libsok/sok-solve.c', ] -# text interface +# text exe executable('sok-text', sources + [ 'src/text/main.c', 'src/text/levels.c', @@ -16,9 +16,22 @@ executable('sok-text', sources + [ 'src/text/draw.c', ], dependencies: []) -# text interface +# sdl exe executable('sok-sdl', sources + [ 'src/sdl/main.c', ], dependencies: [ # 'sdl2', ]) + +# test executable +test_solve = executable('test-solve', sources + [ + 'src/text/levels.c', + 'src/test-solve/main.c', +], dependencies: []) + +# generate solve tests +foreach i: [0, 3, 4, 11, 18, 23] # long tests: 14, 17, 22, 26 + test('level @0@'.format(i), test_solve, args: [ + '@0@'.format(i), + ]) +endforeach diff --git a/src/test-solve/main.c b/src/test-solve/main.c new file mode 100644 index 0000000..0e6efe0 --- /dev/null +++ b/src/test-solve/main.c @@ -0,0 +1,41 @@ +#include // bool +#include // atoi() +#include // EXIT_{FAILURE,SUCCESS} +#include +#include "../libsok/sok.h" +#include "../text/util.h" +#include "../text/levels.h" + +static void +solve_on_error( + const char * const err +) { + die("Error solving level: %s", err); +} + +int main(int argc, char *argv[]) { + // init context + sok_ctx_t ctx; + sok_ctx_init(&ctx, NULL); + + // walk levels + for (int i = 1; i < argc; i++) { + const size_t level_num = atoi(argv[i]); + + // get level + const level_t *level = levels_get_level(level_num); + + // load level + if (!sok_ctx_set_level(&ctx, level->data)) { + die("Couldn't load level %zu", level_num); + } + + // solve level + if (!sok_solve(&ctx, solve_on_error)) { + die("Couldn't solve level"); + } + } + + // return success + return EXIT_SUCCESS; +} diff --git a/src/text/levels.c b/src/text/levels.c index dc031f8..4db92c8 100644 --- a/src/text/levels.c +++ b/src/text/levels.c @@ -634,10 +634,6 @@ LEVELS[] = {{ .pack = "Microban", .name = "Level 155: The Dungeon", .data = "4 6#15 4#|5#*# 17# ##|#3 3#22 #|#8 8# 4# ## #|3# 4#5 # 4# 4# ##|#*# # .# # # #5 #5 #3 #|#*# # #5 # ## # ## ## #|3#4 3# 3# # ## # ## ##| #3 # #*#6 #5 # #4 #| #3 # 3# 5# 4# #4 #| 5#3 5# 7# 6#| #3 # # #**#15 #|## # #3 #**# 7# ## #|#4 9# #4 5# 3#|# #13 # $8 #*#|#3 9# 3# @5# #*#|5#7 4# 4#3 6#", -}, { - .pack = "", - .name = "", - .data = "", }}; #define NUM_LEVELS (sizeof(LEVELS) / sizeof(level_t)) -- cgit v1.2.3