From d45e1595ec1cffeab83ac6602b748250b66bea03 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Mon, 24 Mar 2025 23:09:26 +0100 Subject: 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 --- test/032_invertmoves/001_onemove.in | 1 - test/032_invertmoves/001_onemove.out | 1 - test/032_invertmoves/002_20moves.in | 1 - test/032_invertmoves/002_20moves.out | 1 - test/032_invertmoves/invertmoves_tests.c | 21 -------- test/062_transform_move/transform_move_tests.c | 2 +- test/130_appendsolution/00_empty.in | 5 ++ test/130_appendsolution/00_empty.out | 4 ++ .../01_simple_onlynormal_nounniss.in | 5 ++ .../01_simple_onlynormal_nounniss.out | 4 ++ .../02_simple_onlynormal_nounnis_multitrans.in | 8 +++ .../02_simple_onlynormal_nounnis_multitrans.out | 7 +++ test/130_appendsolution/03_simple_unniss.in | 5 ++ test/130_appendsolution/03_simple_unniss.out | 4 ++ test/130_appendsolution/04_niss_nounniss.in | 5 ++ test/130_appendsolution/04_niss_nounniss.out | 4 ++ test/130_appendsolution/05_sort_parallel.in | 5 ++ test/130_appendsolution/05_sort_parallel.out | 4 ++ test/130_appendsolution/06_unniss_trans_sort.in | 5 ++ test/130_appendsolution/06_unniss_trans_sort.out | 4 ++ test/130_appendsolution/07_unniss_cancel_nosol.in | 5 ++ test/130_appendsolution/07_unniss_cancel_nosol.out | 3 ++ .../08_unniss_cancel_nosol_v2.in | 5 ++ .../08_unniss_cancel_nosol_v2.out | 3 ++ test/130_appendsolution/appendsolution_tests.c | 58 ++++++++++++++++++++++ test/test.h | 1 + 26 files changed, 145 insertions(+), 26 deletions(-) delete mode 100644 test/032_invertmoves/001_onemove.in delete mode 100644 test/032_invertmoves/001_onemove.out delete mode 100644 test/032_invertmoves/002_20moves.in delete mode 100644 test/032_invertmoves/002_20moves.out delete mode 100644 test/032_invertmoves/invertmoves_tests.c create mode 100644 test/130_appendsolution/00_empty.in create mode 100644 test/130_appendsolution/00_empty.out create mode 100644 test/130_appendsolution/01_simple_onlynormal_nounniss.in create mode 100644 test/130_appendsolution/01_simple_onlynormal_nounniss.out create mode 100644 test/130_appendsolution/02_simple_onlynormal_nounnis_multitrans.in create mode 100644 test/130_appendsolution/02_simple_onlynormal_nounnis_multitrans.out create mode 100644 test/130_appendsolution/03_simple_unniss.in create mode 100644 test/130_appendsolution/03_simple_unniss.out create mode 100644 test/130_appendsolution/04_niss_nounniss.in create mode 100644 test/130_appendsolution/04_niss_nounniss.out create mode 100644 test/130_appendsolution/05_sort_parallel.in create mode 100644 test/130_appendsolution/05_sort_parallel.out create mode 100644 test/130_appendsolution/06_unniss_trans_sort.in create mode 100644 test/130_appendsolution/06_unniss_trans_sort.out create mode 100644 test/130_appendsolution/07_unniss_cancel_nosol.in create mode 100644 test/130_appendsolution/07_unniss_cancel_nosol.out create mode 100644 test/130_appendsolution/08_unniss_cancel_nosol_v2.in create mode 100644 test/130_appendsolution/08_unniss_cancel_nosol_v2.out create mode 100644 test/130_appendsolution/appendsolution_tests.c (limited to 'test') diff --git a/test/032_invertmoves/001_onemove.in b/test/032_invertmoves/001_onemove.in deleted file mode 100644 index cf84443..0000000 --- a/test/032_invertmoves/001_onemove.in +++ /dev/null @@ -1 +0,0 @@ -F diff --git a/test/032_invertmoves/001_onemove.out b/test/032_invertmoves/001_onemove.out deleted file mode 100644 index 6ab6e07..0000000 --- a/test/032_invertmoves/001_onemove.out +++ /dev/null @@ -1 +0,0 @@ -F' diff --git a/test/032_invertmoves/002_20moves.in b/test/032_invertmoves/002_20moves.in deleted file mode 100644 index 052ed94..0000000 --- a/test/032_invertmoves/002_20moves.in +++ /dev/null @@ -1 +0,0 @@ -B2 R D2 B2 R D2 F2 L2 F2 R' F2 D' L D2 L U2 L B2 F2 U diff --git a/test/032_invertmoves/002_20moves.out b/test/032_invertmoves/002_20moves.out deleted file mode 100644 index bc6a079..0000000 --- a/test/032_invertmoves/002_20moves.out +++ /dev/null @@ -1 +0,0 @@ -U' F2 B2 L' U2 L' D2 L' D F2 R F2 L2 F2 D2 R' B2 D2 R' B2 diff --git a/test/032_invertmoves/invertmoves_tests.c b/test/032_invertmoves/invertmoves_tests.c deleted file mode 100644 index d791524..0000000 --- a/test/032_invertmoves/invertmoves_tests.c +++ /dev/null @@ -1,21 +0,0 @@ -#include "../test.h" - -#define MAXMOVES 20 - -int64_t readmoves(const char *, int, uint8_t *); -void writemoves(size_t n, uint8_t [n], size_t m, char [m]); -void invertmoves(size_t n, const uint8_t [n], uint8_t [n]); - -void run(void) { - char movestr[STRLENMAX], outstr[STRLENMAX]; - uint8_t moves[MAXMOVES], ret[MAXMOVES]; - int c; - - fgets(movestr, STRLENMAX, stdin); - c = readmoves(movestr, MAXMOVES, moves); - - invertmoves(c, moves, ret); - writemoves(c, ret, STRLENMAX, outstr); - - printf("%s\n", outstr); -} diff --git a/test/062_transform_move/transform_move_tests.c b/test/062_transform_move/transform_move_tests.c index 4b7f420..7cd555f 100644 --- a/test/062_transform_move/transform_move_tests.c +++ b/test/062_transform_move/transform_move_tests.c @@ -4,7 +4,7 @@ cube_t applytrans(cube_t, const char *); uint8_t transform_move(uint8_t, uint8_t); -int readmoves(const char *, int, uint8_t *); +int64_t readmoves(const char *, size_t n, uint8_t [n]); cube_t move(cube_t, uint8_t); cube_t applymoves(cube_t, const char *); uint8_t readtrans(const char[static NISSY_SIZE_TRANSFORMATION]); diff --git a/test/130_appendsolution/00_empty.in b/test/130_appendsolution/00_empty.in new file mode 100644 index 0000000..c4cad6e --- /dev/null +++ b/test/130_appendsolution/00_empty.in @@ -0,0 +1,5 @@ + + +0 +1 +rotation UF diff --git a/test/130_appendsolution/00_empty.out b/test/130_appendsolution/00_empty.out new file mode 100644 index 0000000..8581416 --- /dev/null +++ b/test/130_appendsolution/00_empty.out @@ -0,0 +1,4 @@ + +Number of solutions: 1 +Shortest solution length: 0 +Used bytes: 1 diff --git a/test/130_appendsolution/01_simple_onlynormal_nounniss.in b/test/130_appendsolution/01_simple_onlynormal_nounniss.in new file mode 100644 index 0000000..37b6f3d --- /dev/null +++ b/test/130_appendsolution/01_simple_onlynormal_nounniss.in @@ -0,0 +1,5 @@ +U F R D2 B' + +0 +1 +rotation UF diff --git a/test/130_appendsolution/01_simple_onlynormal_nounniss.out b/test/130_appendsolution/01_simple_onlynormal_nounniss.out new file mode 100644 index 0000000..b577962 --- /dev/null +++ b/test/130_appendsolution/01_simple_onlynormal_nounniss.out @@ -0,0 +1,4 @@ +U F R D2 B' +Number of solutions: 1 +Shortest solution length: 5 +Used bytes: 12 diff --git a/test/130_appendsolution/02_simple_onlynormal_nounnis_multitrans.in b/test/130_appendsolution/02_simple_onlynormal_nounnis_multitrans.in new file mode 100644 index 0000000..c4ff41a --- /dev/null +++ b/test/130_appendsolution/02_simple_onlynormal_nounnis_multitrans.in @@ -0,0 +1,8 @@ +U F R + +0 +4 +rotation UF +mirrored UR +rotation BD +mirrored LB diff --git a/test/130_appendsolution/02_simple_onlynormal_nounnis_multitrans.out b/test/130_appendsolution/02_simple_onlynormal_nounnis_multitrans.out new file mode 100644 index 0000000..e1b5631 --- /dev/null +++ b/test/130_appendsolution/02_simple_onlynormal_nounnis_multitrans.out @@ -0,0 +1,7 @@ +U F R +B D L +U' L' B' +R' B' D' +Number of solutions: 4 +Shortest solution length: 3 +Used bytes: 30 diff --git a/test/130_appendsolution/03_simple_unniss.in b/test/130_appendsolution/03_simple_unniss.in new file mode 100644 index 0000000..231f60c --- /dev/null +++ b/test/130_appendsolution/03_simple_unniss.in @@ -0,0 +1,5 @@ +U F B2 +R' F D +1 +1 +rotation UF diff --git a/test/130_appendsolution/03_simple_unniss.out b/test/130_appendsolution/03_simple_unniss.out new file mode 100644 index 0000000..3ca210e --- /dev/null +++ b/test/130_appendsolution/03_simple_unniss.out @@ -0,0 +1,4 @@ +U F B2 D' F' R +Number of solutions: 1 +Shortest solution length: 6 +Used bytes: 15 diff --git a/test/130_appendsolution/04_niss_nounniss.in b/test/130_appendsolution/04_niss_nounniss.in new file mode 100644 index 0000000..39c6518 --- /dev/null +++ b/test/130_appendsolution/04_niss_nounniss.in @@ -0,0 +1,5 @@ +U F B2 +R' F D +0 +1 +rotation UF diff --git a/test/130_appendsolution/04_niss_nounniss.out b/test/130_appendsolution/04_niss_nounniss.out new file mode 100644 index 0000000..a616b4c --- /dev/null +++ b/test/130_appendsolution/04_niss_nounniss.out @@ -0,0 +1,4 @@ +U F B2 (R' F D) +Number of solutions: 1 +Shortest solution length: 6 +Used bytes: 16 diff --git a/test/130_appendsolution/05_sort_parallel.in b/test/130_appendsolution/05_sort_parallel.in new file mode 100644 index 0000000..7c8c4f5 --- /dev/null +++ b/test/130_appendsolution/05_sort_parallel.in @@ -0,0 +1,5 @@ +L R' B2 F + +0 +1 +rotation UF diff --git a/test/130_appendsolution/05_sort_parallel.out b/test/130_appendsolution/05_sort_parallel.out new file mode 100644 index 0000000..fc09830 --- /dev/null +++ b/test/130_appendsolution/05_sort_parallel.out @@ -0,0 +1,4 @@ +R' L F B2 +Number of solutions: 1 +Shortest solution length: 4 +Used bytes: 10 diff --git a/test/130_appendsolution/06_unniss_trans_sort.in b/test/130_appendsolution/06_unniss_trans_sort.in new file mode 100644 index 0000000..9be03a6 --- /dev/null +++ b/test/130_appendsolution/06_unniss_trans_sort.in @@ -0,0 +1,5 @@ +B +R2 F2 +1 +1 +rotation UR diff --git a/test/130_appendsolution/06_unniss_trans_sort.out b/test/130_appendsolution/06_unniss_trans_sort.out new file mode 100644 index 0000000..28d7827 --- /dev/null +++ b/test/130_appendsolution/06_unniss_trans_sort.out @@ -0,0 +1,4 @@ +R2 L B2 +Number of solutions: 1 +Shortest solution length: 3 +Used bytes: 8 diff --git a/test/130_appendsolution/07_unniss_cancel_nosol.in b/test/130_appendsolution/07_unniss_cancel_nosol.in new file mode 100644 index 0000000..561c909 --- /dev/null +++ b/test/130_appendsolution/07_unniss_cancel_nosol.in @@ -0,0 +1,5 @@ +B' F +R2 B2 +1 +1 +rotation UF diff --git a/test/130_appendsolution/07_unniss_cancel_nosol.out b/test/130_appendsolution/07_unniss_cancel_nosol.out new file mode 100644 index 0000000..ed5ea65 --- /dev/null +++ b/test/130_appendsolution/07_unniss_cancel_nosol.out @@ -0,0 +1,3 @@ +Number of solutions: 0 +Shortest solution length: 21 +Used bytes: 0 diff --git a/test/130_appendsolution/08_unniss_cancel_nosol_v2.in b/test/130_appendsolution/08_unniss_cancel_nosol_v2.in new file mode 100644 index 0000000..e707537 --- /dev/null +++ b/test/130_appendsolution/08_unniss_cancel_nosol_v2.in @@ -0,0 +1,5 @@ +F' B +R2 F2 +1 +1 +rotation UF diff --git a/test/130_appendsolution/08_unniss_cancel_nosol_v2.out b/test/130_appendsolution/08_unniss_cancel_nosol_v2.out new file mode 100644 index 0000000..ed5ea65 --- /dev/null +++ b/test/130_appendsolution/08_unniss_cancel_nosol_v2.out @@ -0,0 +1,3 @@ +Number of solutions: 0 +Shortest solution length: 21 +Used bytes: 0 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 @@ +/* +Input format for appendsolution tests: + +moves on normal +moves on inverse (without parentheses) +unniss flag (0=false, 1=true) +number of transformations +transformations, one per line + +See below for the output format. +*/ + +#include "../test.h" + +uint8_t readtrans(const char [NISSY_SIZE_TRANSFORMATION]); +int64_t readmoves(const char *, size_t n, uint8_t [n]); +void solution_moves_reset(solution_moves_t [static 1]); +bool solution_list_init(solution_list_t [static 1], size_t n, char [n]); +int64_t appendsolution(const solution_moves_t [static 1], + const solution_settings_t [static 1], solution_list_t [static 1]); + +void run(void) { + int i, ntrans; + char str[STRLENMAX], buf[STRLENMAX]; + solution_moves_t moves; + solution_settings_t settings; + solution_list_t list; + + solution_moves_reset(&moves); + solution_list_init(&list, STRLENMAX, buf); + settings = (solution_settings_t) { + .tmask = UINT64_C(0), + .unniss = false, + .maxmoves = 20, + .maxsolutions = 100, + .optimal = -1, + }; + + fgets(str, STRLENMAX, stdin); + moves.nmoves = (uint8_t)readmoves(str, 20, moves.moves); + fgets(str, STRLENMAX, stdin); + moves.npremoves = (uint8_t)readmoves(str, 20, moves.premoves); + fgets(str, STRLENMAX, stdin); + settings.unniss = (bool)atoi(str); + fgets(str, STRLENMAX, stdin); + ntrans = atoi(str); + for (i = 0; i < ntrans; i++) { + fgets(str, STRLENMAX, stdin); + settings.tmask |= UINT64_C(1) << (uint64_t)readtrans(str); + } + + appendsolution(&moves, &settings, &list); + + printf("%s", list.buf); + printf("Number of solutions: %" PRIu64 "\n", list.nsols); + printf("Shortest solution length: %" PRIu8 "\n", list.shortest_sol); + printf("Used bytes: %zu\n", list.used); +} diff --git a/test/test.h b/test/test.h index 3854520..8c117cb 100644 --- a/test/test.h +++ b/test/test.h @@ -10,6 +10,7 @@ #include "../src/nissy.h" #include "../src/arch/arch.h" +#include "../src/solvers/solutions_types_macros.h" #include "../src/solvers/tables_types_macros.h" #include "../src/solvers/h48/coordinate_macros.h" #include "../src/solvers/h48/map_types_macros.h" -- cgit v1.3