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 | |
| 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')
26 files changed, 145 insertions, 26 deletions
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 @@ | |||
| 1 | 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 @@ | |||
| 1 | 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 @@ | |||
| 1 | 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 @@ | |||
| 1 | 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 @@ | |||
| 1 | #include "../test.h" | ||
| 2 | |||
| 3 | #define MAXMOVES 20 | ||
| 4 | |||
| 5 | int64_t readmoves(const char *, int, uint8_t *); | ||
| 6 | void writemoves(size_t n, uint8_t [n], size_t m, char [m]); | ||
| 7 | void invertmoves(size_t n, const uint8_t [n], uint8_t [n]); | ||
| 8 | |||
| 9 | void run(void) { | ||
| 10 | char movestr[STRLENMAX], outstr[STRLENMAX]; | ||
| 11 | uint8_t moves[MAXMOVES], ret[MAXMOVES]; | ||
| 12 | int c; | ||
| 13 | |||
| 14 | fgets(movestr, STRLENMAX, stdin); | ||
| 15 | c = readmoves(movestr, MAXMOVES, moves); | ||
| 16 | |||
| 17 | invertmoves(c, moves, ret); | ||
| 18 | writemoves(c, ret, STRLENMAX, outstr); | ||
| 19 | |||
| 20 | printf("%s\n", outstr); | ||
| 21 | } | ||
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 @@ | |||
| 4 | 4 | ||
| 5 | cube_t applytrans(cube_t, const char *); | 5 | cube_t applytrans(cube_t, const char *); |
| 6 | uint8_t transform_move(uint8_t, uint8_t); | 6 | uint8_t transform_move(uint8_t, uint8_t); |
| 7 | int readmoves(const char *, int, uint8_t *); | 7 | int64_t readmoves(const char *, size_t n, uint8_t [n]); |
| 8 | cube_t move(cube_t, uint8_t); | 8 | cube_t move(cube_t, uint8_t); |
| 9 | cube_t applymoves(cube_t, const char *); | 9 | cube_t applymoves(cube_t, const char *); |
| 10 | uint8_t readtrans(const char[static NISSY_SIZE_TRANSFORMATION]); | 10 | 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 @@ | |||
| 1 | |||
| 2 | |||
| 3 | 0 | ||
| 4 | 1 | ||
| 5 | 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 @@ | |||
| 1 | |||
| 2 | Number of solutions: 1 | ||
| 3 | Shortest solution length: 0 | ||
| 4 | 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 @@ | |||
| 1 | U F R D2 B' | ||
| 2 | |||
| 3 | 0 | ||
| 4 | 1 | ||
| 5 | 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 @@ | |||
| 1 | U F R D2 B' | ||
| 2 | Number of solutions: 1 | ||
| 3 | Shortest solution length: 5 | ||
| 4 | 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 @@ | |||
| 1 | U F R | ||
| 2 | |||
| 3 | 0 | ||
| 4 | 4 | ||
| 5 | rotation UF | ||
| 6 | mirrored UR | ||
| 7 | rotation BD | ||
| 8 | 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 @@ | |||
| 1 | U F R | ||
| 2 | B D L | ||
| 3 | U' L' B' | ||
| 4 | R' B' D' | ||
| 5 | Number of solutions: 4 | ||
| 6 | Shortest solution length: 3 | ||
| 7 | 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 @@ | |||
| 1 | U F B2 | ||
| 2 | R' F D | ||
| 3 | 1 | ||
| 4 | 1 | ||
| 5 | 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 @@ | |||
| 1 | U F B2 D' F' R | ||
| 2 | Number of solutions: 1 | ||
| 3 | Shortest solution length: 6 | ||
| 4 | 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 @@ | |||
| 1 | U F B2 | ||
| 2 | R' F D | ||
| 3 | 0 | ||
| 4 | 1 | ||
| 5 | 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 @@ | |||
| 1 | U F B2 (R' F D) | ||
| 2 | Number of solutions: 1 | ||
| 3 | Shortest solution length: 6 | ||
| 4 | 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 @@ | |||
| 1 | L R' B2 F | ||
| 2 | |||
| 3 | 0 | ||
| 4 | 1 | ||
| 5 | 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 @@ | |||
| 1 | R' L F B2 | ||
| 2 | Number of solutions: 1 | ||
| 3 | Shortest solution length: 4 | ||
| 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 @@ | |||
| 1 | B | ||
| 2 | R2 F2 | ||
| 3 | 1 | ||
| 4 | 1 | ||
| 5 | 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 @@ | |||
| 1 | R2 L B2 | ||
| 2 | Number of solutions: 1 | ||
| 3 | Shortest solution length: 3 | ||
| 4 | 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 @@ | |||
| 1 | B' F | ||
| 2 | R2 B2 | ||
| 3 | 1 | ||
| 4 | 1 | ||
| 5 | 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 @@ | |||
| 1 | Number of solutions: 0 | ||
| 2 | Shortest solution length: 21 | ||
| 3 | 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 @@ | |||
| 1 | F' B | ||
| 2 | R2 F2 | ||
| 3 | 1 | ||
| 4 | 1 | ||
| 5 | 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 @@ | |||
| 1 | Number of solutions: 0 | ||
| 2 | Shortest solution length: 21 | ||
| 3 | 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 @@ | |||
| 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 | } | ||
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 @@ | |||
| 10 | 10 | ||
| 11 | #include "../src/nissy.h" | 11 | #include "../src/nissy.h" |
| 12 | #include "../src/arch/arch.h" | 12 | #include "../src/arch/arch.h" |
| 13 | #include "../src/solvers/solutions_types_macros.h" | ||
| 13 | #include "../src/solvers/tables_types_macros.h" | 14 | #include "../src/solvers/tables_types_macros.h" |
| 14 | #include "../src/solvers/h48/coordinate_macros.h" | 15 | #include "../src/solvers/h48/coordinate_macros.h" |
| 15 | #include "../src/solvers/h48/map_types_macros.h" | 16 | #include "../src/solvers/h48/map_types_macros.h" |
