From 914ca426630ccadcbb6f1ff02a599bdaf10b6cb2 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Tue, 15 Jan 2019 01:00:20 -0500 Subject: s/test-solve/solve/ --- meson.build | 8 ++++---- src/solve/main.c | 41 +++++++++++++++++++++++++++++++++++++++++ src/test-solve/main.c | 41 ----------------------------------------- 3 files changed, 45 insertions(+), 45 deletions(-) create mode 100644 src/solve/main.c delete mode 100644 src/test-solve/main.c diff --git a/meson.build b/meson.build index b3204dd..dccfe9a 100644 --- a/meson.build +++ b/meson.build @@ -48,15 +48,15 @@ executable('sprite-packer', sources + [ libm, ]) -# test executable -test_solve = executable('test-solve', sources + [ +# solver +solve = executable('solve', sources + [ 'src/text/levels.c', - 'src/test-solve/main.c', + 'src/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: [ + test('level @0@'.format(i), solve, args: [ '@0@'.format(i), ]) endforeach diff --git a/src/solve/main.c b/src/solve/main.c new file mode 100644 index 0000000..2a9ed53 --- /dev/null +++ b/src/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 %d", (int) 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/test-solve/main.c b/src/test-solve/main.c deleted file mode 100644 index 2a9ed53..0000000 --- a/src/test-solve/main.c +++ /dev/null @@ -1,41 +0,0 @@ -#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 %d", (int) level_num); - } - - // solve level - if (!sok_solve(&ctx, solve_on_error)) { - die("Couldn't solve level"); - } - } - - // return success - return EXIT_SUCCESS; -} -- cgit v1.2.3