diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-03-24 23:09:26 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-03-24 23:09:26 +0100 |
| commit | d45e1595ec1cffeab83ac6602b748250b66bea03 (patch) | |
| tree | 44b35714cdae22026fc5e15648e91684a2fbb154 /test/130_appendsolution/appendsolution_tests.c | |
| parent | ce3f1cc0ef9f46d70ab5387b1458e9098b40711d (diff) | |
| download | nissy-core-d45e1595ec1cffeab83ac6602b748250b66bea03.tar.gz nissy-core-d45e1595ec1cffeab83ac6602b748250b66bea03.zip | |
Big cleanup for appendsolution()
With this PR the appendsolution routine is extracted from the h48
solver and the new coordinate solver and made generic. This has
many advantages:
- less repetition (even if the two versions are different enough that
*for now* it was not a big deal)
- smaller h48/solve.h file, which is already a big beast
- easier to test the appendsolution() routine separately
Diffstat (limited to 'test/130_appendsolution/appendsolution_tests.c')
| -rw-r--r-- | test/130_appendsolution/appendsolution_tests.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/test/130_appendsolution/appendsolution_tests.c b/test/130_appendsolution/appendsolution_tests.c new file mode 100644 index 0000000..066c305 --- /dev/null +++ b/test/130_appendsolution/appendsolution_tests.c | |||
| @@ -0,0 +1,58 @@ | |||
| 1 | /* | ||
| 2 | Input format for appendsolution tests: | ||
| 3 | |||
| 4 | moves on normal | ||
| 5 | moves on inverse (without parentheses) | ||
| 6 | unniss flag (0=false, 1=true) | ||
| 7 | number of transformations | ||
| 8 | transformations, one per line | ||
| 9 | |||
| 10 | See below for the output format. | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include "../test.h" | ||
| 14 | |||
| 15 | uint8_t readtrans(const char [NISSY_SIZE_TRANSFORMATION]); | ||
| 16 | int64_t readmoves(const char *, size_t n, uint8_t [n]); | ||
| 17 | void solution_moves_reset(solution_moves_t [static 1]); | ||
| 18 | bool solution_list_init(solution_list_t [static 1], size_t n, char [n]); | ||
| 19 | int64_t appendsolution(const solution_moves_t [static 1], | ||
| 20 | const solution_settings_t [static 1], solution_list_t [static 1]); | ||
| 21 | |||
| 22 | void run(void) { | ||
| 23 | int i, ntrans; | ||
| 24 | char str[STRLENMAX], buf[STRLENMAX]; | ||
| 25 | solution_moves_t moves; | ||
| 26 | solution_settings_t settings; | ||
| 27 | solution_list_t list; | ||
| 28 | |||
| 29 | solution_moves_reset(&moves); | ||
| 30 | solution_list_init(&list, STRLENMAX, buf); | ||
| 31 | settings = (solution_settings_t) { | ||
| 32 | .tmask = UINT64_C(0), | ||
| 33 | .unniss = false, | ||
| 34 | .maxmoves = 20, | ||
| 35 | .maxsolutions = 100, | ||
| 36 | .optimal = -1, | ||
| 37 | }; | ||
| 38 | |||
| 39 | fgets(str, STRLENMAX, stdin); | ||
| 40 | moves.nmoves = (uint8_t)readmoves(str, 20, moves.moves); | ||
| 41 | fgets(str, STRLENMAX, stdin); | ||
| 42 | moves.npremoves = (uint8_t)readmoves(str, 20, moves.premoves); | ||
| 43 | fgets(str, STRLENMAX, stdin); | ||
| 44 | settings.unniss = (bool)atoi(str); | ||
| 45 | fgets(str, STRLENMAX, stdin); | ||
| 46 | ntrans = atoi(str); | ||
| 47 | for (i = 0; i < ntrans; i++) { | ||
| 48 | fgets(str, STRLENMAX, stdin); | ||
| 49 | settings.tmask |= UINT64_C(1) << (uint64_t)readtrans(str); | ||
| 50 | } | ||
| 51 | |||
| 52 | appendsolution(&moves, &settings, &list); | ||
| 53 | |||
| 54 | printf("%s", list.buf); | ||
| 55 | printf("Number of solutions: %" PRIu64 "\n", list.nsols); | ||
| 56 | printf("Shortest solution length: %" PRIu8 "\n", list.shortest_sol); | ||
| 57 | printf("Used bytes: %zu\n", list.used); | ||
| 58 | } | ||
