From d5e7698d0c7ecb61fe49263982f750c053147089 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Tue, 14 Nov 2023 22:42:08 +0100 Subject: Added tests allowednext --- TODO.txt | 2 -- cube.c | 27 +++++++-------- test/080_allowednext/00_empty_U.in | 2 ++ test/080_allowednext/00_empty_U.out | 1 + test/080_allowednext/02_F_F2.in | 3 ++ test/080_allowednext/02_F_F2.out | 1 + test/080_allowednext/02_U_F.in | 3 ++ test/080_allowednext/02_U_F.out | 1 + test/080_allowednext/03_R_L_R.in | 4 +++ test/080_allowednext/03_R_L_R.out | 1 + test/080_allowednext/04_longer_true.in | 12 +++++++ test/080_allowednext/04_longer_true.out | 1 + test/080_allowednext/05_longer_false.in | 9 +++++ test/080_allowednext/05_longer_false.out | 1 + test/080_allowednext/06_D_U_false_order.in | 3 ++ test/080_allowednext/06_D_U_false_order.out | 1 + test/080_allowednext/allowednext_tests.c | 42 +++++++++++++++++++++++ test/080_solve_simple/01_U_U3.in | 8 ----- test/080_solve_simple/01_U_U3.out | 1 - test/080_solve_simple/02_MUMU_alloptimal.in | 8 ----- test/080_solve_simple/02_MUMU_alloptimal.out | 4 --- test/080_solve_simple/solve_simple_tests.c | 50 ---------------------------- test/090_solve_simple/01_U_U3.in | 8 +++++ test/090_solve_simple/01_U_U3.out | 1 + test/090_solve_simple/02_MUMU_alloptimal.in | 8 +++++ test/090_solve_simple/02_MUMU_alloptimal.out | 4 +++ test/090_solve_simple/solve_simple_tests.c | 50 ++++++++++++++++++++++++++++ 27 files changed, 168 insertions(+), 88 deletions(-) create mode 100644 test/080_allowednext/00_empty_U.in create mode 100644 test/080_allowednext/00_empty_U.out create mode 100644 test/080_allowednext/02_F_F2.in create mode 100644 test/080_allowednext/02_F_F2.out create mode 100644 test/080_allowednext/02_U_F.in create mode 100644 test/080_allowednext/02_U_F.out create mode 100644 test/080_allowednext/03_R_L_R.in create mode 100644 test/080_allowednext/03_R_L_R.out create mode 100644 test/080_allowednext/04_longer_true.in create mode 100644 test/080_allowednext/04_longer_true.out create mode 100644 test/080_allowednext/05_longer_false.in create mode 100644 test/080_allowednext/05_longer_false.out create mode 100644 test/080_allowednext/06_D_U_false_order.in create mode 100644 test/080_allowednext/06_D_U_false_order.out create mode 100644 test/080_allowednext/allowednext_tests.c delete mode 100644 test/080_solve_simple/01_U_U3.in delete mode 100644 test/080_solve_simple/01_U_U3.out delete mode 100644 test/080_solve_simple/02_MUMU_alloptimal.in delete mode 100644 test/080_solve_simple/02_MUMU_alloptimal.out delete mode 100644 test/080_solve_simple/solve_simple_tests.c create mode 100644 test/090_solve_simple/01_U_U3.in create mode 100644 test/090_solve_simple/01_U_U3.out create mode 100644 test/090_solve_simple/02_MUMU_alloptimal.in create mode 100644 test/090_solve_simple/02_MUMU_alloptimal.out create mode 100644 test/090_solve_simple/solve_simple_tests.c diff --git a/TODO.txt b/TODO.txt index 1841d38..5e2cfd0 100644 --- a/TODO.txt +++ b/TODO.txt @@ -22,8 +22,6 @@ See the sections below for details ## Small change * solve tests: make smaller, split -* add lots of tests for things that were static, now visible: - allowednextmove ## Solving diff --git a/cube.c b/cube.c index 780c3a6..23c5132 100644 --- a/cube.c +++ b/cube.c @@ -3165,19 +3165,19 @@ applymoves(cube_t cube, char *buf) while (*b == ' ' || *b == '\t' || *b == '\n') b++; if (*b == '\0') - goto readmoves_finish; + goto applymoves_finish; if ((r = readmove(*b)) == _error) - goto readmoves_error; + goto applymoves_error; if ((m = readmodifier(*(b+1))) != 0) b++; fast = move(fast, r + m); } -readmoves_finish: +applymoves_finish: return fasttocube(fast); -readmoves_error: - DBG_LOG("readmoves error\n"); +applymoves_error: + DBG_LOG("applymoves error\n"); return zero; } @@ -3725,7 +3725,7 @@ int64_t solve(cube_t, char *, char *, char *, int8_t, int8_t, int64_t, int8_t, void multisolve(int, cube_t *, char *, void *, char *); int64_t gendata(char *, void *); -_static bool allowednextmove(dfsarg_generic_t, uint8_t); +_static bool allowednextmove(uint8_t *, int, uint8_t); _static void solve_generic_appendsolution(dfsarg_generic_t); _static int solve_generic_dfs(dfsarg_generic_t); _static int64_t solve_generic(cube_t, char *, int8_t, int8_t, int64_t, int8_t, @@ -3796,20 +3796,17 @@ gendata(char *solver, void *data) } _static bool -allowednextmove(dfsarg_generic_t arg, uint8_t m) +allowednextmove(uint8_t *moves, int n, uint8_t m) { - int n; uint8_t mbase, l1base, l2base, maxis, l1axis, l2axis; - n = arg.nmoves; - if (n == 0) return true; mbase = movebase(m); maxis = moveaxis(m); - l1base = movebase(arg.moves[n-1]); - l1axis = moveaxis(arg.moves[n-1]); + l1base = movebase(moves[n-1]); + l1axis = moveaxis(moves[n-1]); if (mbase == l1base || (maxis == l1axis && mbase < l1base)) return false; @@ -3817,8 +3814,8 @@ allowednextmove(dfsarg_generic_t arg, uint8_t m) if (n == 1) return true; - l2base = movebase(arg.moves[n-2]); - l2axis = moveaxis(arg.moves[n-2]); + l2base = movebase(moves[n-2]); + l2axis = moveaxis(moves[n-2]); return l1axis != l2axis || mbase != l2base; } @@ -3858,7 +3855,7 @@ solve_generic_dfs(dfsarg_generic_t arg) memcpy(&nextarg, &arg, sizeof(dfsarg_generic_t)); nextarg.nmoves = arg.nmoves + 1; for (m = 0, ret = 0; m < 18; m++) { - if (allowednextmove(arg, m)) { + if (allowednextmove(arg.moves, arg.nmoves, m)) { nextarg.cube = move(arg.cube, m); nextarg.moves[arg.nmoves] = m; ret += solve_generic_dfs(nextarg); diff --git a/test/080_allowednext/00_empty_U.in b/test/080_allowednext/00_empty_U.in new file mode 100644 index 0000000..feb4bc3 --- /dev/null +++ b/test/080_allowednext/00_empty_U.in @@ -0,0 +1,2 @@ +0 +U diff --git a/test/080_allowednext/00_empty_U.out b/test/080_allowednext/00_empty_U.out new file mode 100644 index 0000000..27ba77d --- /dev/null +++ b/test/080_allowednext/00_empty_U.out @@ -0,0 +1 @@ +true diff --git a/test/080_allowednext/02_F_F2.in b/test/080_allowednext/02_F_F2.in new file mode 100644 index 0000000..06f504f --- /dev/null +++ b/test/080_allowednext/02_F_F2.in @@ -0,0 +1,3 @@ +1 +F +F2 diff --git a/test/080_allowednext/02_F_F2.out b/test/080_allowednext/02_F_F2.out new file mode 100644 index 0000000..c508d53 --- /dev/null +++ b/test/080_allowednext/02_F_F2.out @@ -0,0 +1 @@ +false diff --git a/test/080_allowednext/02_U_F.in b/test/080_allowednext/02_U_F.in new file mode 100644 index 0000000..3a41149 --- /dev/null +++ b/test/080_allowednext/02_U_F.in @@ -0,0 +1,3 @@ +1 +U +F diff --git a/test/080_allowednext/02_U_F.out b/test/080_allowednext/02_U_F.out new file mode 100644 index 0000000..27ba77d --- /dev/null +++ b/test/080_allowednext/02_U_F.out @@ -0,0 +1 @@ +true diff --git a/test/080_allowednext/03_R_L_R.in b/test/080_allowednext/03_R_L_R.in new file mode 100644 index 0000000..e215381 --- /dev/null +++ b/test/080_allowednext/03_R_L_R.in @@ -0,0 +1,4 @@ +2 +R +L' +R2 diff --git a/test/080_allowednext/03_R_L_R.out b/test/080_allowednext/03_R_L_R.out new file mode 100644 index 0000000..c508d53 --- /dev/null +++ b/test/080_allowednext/03_R_L_R.out @@ -0,0 +1 @@ +false diff --git a/test/080_allowednext/04_longer_true.in b/test/080_allowednext/04_longer_true.in new file mode 100644 index 0000000..e1f1d62 --- /dev/null +++ b/test/080_allowednext/04_longer_true.in @@ -0,0 +1,12 @@ +10 +F2 +B +D2 +D' +L +R2 +U +U' +D +F +L diff --git a/test/080_allowednext/04_longer_true.out b/test/080_allowednext/04_longer_true.out new file mode 100644 index 0000000..27ba77d --- /dev/null +++ b/test/080_allowednext/04_longer_true.out @@ -0,0 +1 @@ +true diff --git a/test/080_allowednext/05_longer_false.in b/test/080_allowednext/05_longer_false.in new file mode 100644 index 0000000..6befeff --- /dev/null +++ b/test/080_allowednext/05_longer_false.in @@ -0,0 +1,9 @@ +7 +D +B2 +F' +L' +F' +L' +R2 +L diff --git a/test/080_allowednext/05_longer_false.out b/test/080_allowednext/05_longer_false.out new file mode 100644 index 0000000..c508d53 --- /dev/null +++ b/test/080_allowednext/05_longer_false.out @@ -0,0 +1 @@ +false diff --git a/test/080_allowednext/06_D_U_false_order.in b/test/080_allowednext/06_D_U_false_order.in new file mode 100644 index 0000000..7bfd8c2 --- /dev/null +++ b/test/080_allowednext/06_D_U_false_order.in @@ -0,0 +1,3 @@ +1 +D +U diff --git a/test/080_allowednext/06_D_U_false_order.out b/test/080_allowednext/06_D_U_false_order.out new file mode 100644 index 0000000..c508d53 --- /dev/null +++ b/test/080_allowednext/06_D_U_false_order.out @@ -0,0 +1 @@ +false diff --git a/test/080_allowednext/allowednext_tests.c b/test/080_allowednext/allowednext_tests.c new file mode 100644 index 0000000..98a437f --- /dev/null +++ b/test/080_allowednext/allowednext_tests.c @@ -0,0 +1,42 @@ +#include "../test.h" + +bool allowednextmove(uint8_t *, int, uint8_t); + +static char *moves[] = { + "U", "U2", "U'", + "D", "D2", "D'", + "R", "R2", "R'", + "L", "L2", "L'", + "F", "F2", "F'", + "B", "B2", "B'", +}; + +int main() { + char movestr[STRLENMAX]; + uint8_t m[100], next; + int n, i, j; + + fgets(movestr, STRLENMAX, stdin); + n = atoi(movestr); + + for (i = 0; i < n; i++) { + fgets(movestr, STRLENMAX, stdin); + movestr[strcspn(movestr, "\n")] = 0; + for (j = 0; j < 18; j++) + if (!strcmp(movestr, moves[j])) + m[i] = j; + } + fgets(movestr, STRLENMAX, stdin); + movestr[strcspn(movestr, "\n")] = 0; + for (j = 0; j < 18; j++) + if (!strcmp(movestr, moves[j])) + next = j; + + fprintf(stderr, "Last two: %s, %s\nNext: %s\n", + n > 1 ? moves[m[n-2]] : "-", + n > 0 ? moves[m[n-1]] : "-", + moves[next]); + printf("%s\n", allowednextmove(m, n, next) ? "true" : "false"); + + return 0; +} diff --git a/test/080_solve_simple/01_U_U3.in b/test/080_solve_simple/01_U_U3.in deleted file mode 100644 index c0f7930..0000000 --- a/test/080_solve_simple/01_U_U3.in +++ /dev/null @@ -1,8 +0,0 @@ -UR0 UL0 DB0 DF0 UB0 UF0 DL0 DR0 FR0 FL0 BL0 BR0 UBR0 UFL0 DFL0 DBR0 UFR0 UBL0 DFR0 DBL0 -simple - -normal -0 -3 -3 --1 diff --git a/test/080_solve_simple/01_U_U3.out b/test/080_solve_simple/01_U_U3.out deleted file mode 100644 index ca934b4..0000000 --- a/test/080_solve_simple/01_U_U3.out +++ /dev/null @@ -1 +0,0 @@ -U' diff --git a/test/080_solve_simple/02_MUMU_alloptimal.in b/test/080_solve_simple/02_MUMU_alloptimal.in deleted file mode 100644 index f97c95f..0000000 --- a/test/080_solve_simple/02_MUMU_alloptimal.in +++ /dev/null @@ -1,8 +0,0 @@ -UB0 DF0 DB0 UF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 -simple - -normal -0 --1 -10 -0 diff --git a/test/080_solve_simple/02_MUMU_alloptimal.out b/test/080_solve_simple/02_MUMU_alloptimal.out deleted file mode 100644 index 06cd521..0000000 --- a/test/080_solve_simple/02_MUMU_alloptimal.out +++ /dev/null @@ -1,4 +0,0 @@ -U2 R' L F2 R L' -R U2 R' L F2 L' -R L' U2 R' L F2 -L' U2 R' L F2 R diff --git a/test/080_solve_simple/solve_simple_tests.c b/test/080_solve_simple/solve_simple_tests.c deleted file mode 100644 index 4756dc0..0000000 --- a/test/080_solve_simple/solve_simple_tests.c +++ /dev/null @@ -1,50 +0,0 @@ -#include "../test.h" - -int64_t solve(cube_t, char *, char *, char *, int8_t, int8_t, int64_t, int8_t, - void *, char *); - -int main() { - char cubestr[STRLENMAX], solverstr[STRLENMAX], optionsstr[STRLENMAX]; - char nisstypestr[STRLENMAX], minmovesstr[STRLENMAX]; - char maxmovesstr[STRLENMAX], maxsolsstr[STRLENMAX]; - char optimalstr[STRLENMAX], solutionsstr[STRLENMAX]; - cube_t cube; - int64_t maxsols; - int8_t minmoves, maxmoves, optimal; - - fgets(cubestr, STRLENMAX, stdin); - fgets(solverstr, STRLENMAX, stdin); - fgets(optionsstr, STRLENMAX, stdin); - fgets(nisstypestr, STRLENMAX, stdin); - fgets(minmovesstr, STRLENMAX, stdin); - fgets(maxmovesstr, STRLENMAX, stdin); - fgets(maxsolsstr, STRLENMAX, stdin); - fgets(optimalstr, STRLENMAX, stdin); - - solverstr[strcspn(solverstr, "\n")] = 0; - optionsstr[strcspn(optionsstr, "\n")] = 0; - nisstypestr[strcspn(nisstypestr, "\n")] = 0; - - cube = readcube("H48", cubestr); - minmoves = atoi(minmovesstr); - maxmoves = atoi(maxmovesstr); - maxsols = atoi(maxsolsstr); - optimal = atoi(optimalstr); - - solve( - cube, - solverstr, - optionsstr, - nisstypestr, - minmoves, - maxmoves, - maxsols, - optimal, - NULL, - solutionsstr - ); - - printf("%s", solutionsstr); - - return 0; -} diff --git a/test/090_solve_simple/01_U_U3.in b/test/090_solve_simple/01_U_U3.in new file mode 100644 index 0000000..c0f7930 --- /dev/null +++ b/test/090_solve_simple/01_U_U3.in @@ -0,0 +1,8 @@ +UR0 UL0 DB0 DF0 UB0 UF0 DL0 DR0 FR0 FL0 BL0 BR0 UBR0 UFL0 DFL0 DBR0 UFR0 UBL0 DFR0 DBL0 +simple + +normal +0 +3 +3 +-1 diff --git a/test/090_solve_simple/01_U_U3.out b/test/090_solve_simple/01_U_U3.out new file mode 100644 index 0000000..ca934b4 --- /dev/null +++ b/test/090_solve_simple/01_U_U3.out @@ -0,0 +1 @@ +U' diff --git a/test/090_solve_simple/02_MUMU_alloptimal.in b/test/090_solve_simple/02_MUMU_alloptimal.in new file mode 100644 index 0000000..f97c95f --- /dev/null +++ b/test/090_solve_simple/02_MUMU_alloptimal.in @@ -0,0 +1,8 @@ +UB0 DF0 DB0 UF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 +simple + +normal +0 +-1 +10 +0 diff --git a/test/090_solve_simple/02_MUMU_alloptimal.out b/test/090_solve_simple/02_MUMU_alloptimal.out new file mode 100644 index 0000000..06cd521 --- /dev/null +++ b/test/090_solve_simple/02_MUMU_alloptimal.out @@ -0,0 +1,4 @@ +U2 R' L F2 R L' +R U2 R' L F2 L' +R L' U2 R' L F2 +L' U2 R' L F2 R diff --git a/test/090_solve_simple/solve_simple_tests.c b/test/090_solve_simple/solve_simple_tests.c new file mode 100644 index 0000000..4756dc0 --- /dev/null +++ b/test/090_solve_simple/solve_simple_tests.c @@ -0,0 +1,50 @@ +#include "../test.h" + +int64_t solve(cube_t, char *, char *, char *, int8_t, int8_t, int64_t, int8_t, + void *, char *); + +int main() { + char cubestr[STRLENMAX], solverstr[STRLENMAX], optionsstr[STRLENMAX]; + char nisstypestr[STRLENMAX], minmovesstr[STRLENMAX]; + char maxmovesstr[STRLENMAX], maxsolsstr[STRLENMAX]; + char optimalstr[STRLENMAX], solutionsstr[STRLENMAX]; + cube_t cube; + int64_t maxsols; + int8_t minmoves, maxmoves, optimal; + + fgets(cubestr, STRLENMAX, stdin); + fgets(solverstr, STRLENMAX, stdin); + fgets(optionsstr, STRLENMAX, stdin); + fgets(nisstypestr, STRLENMAX, stdin); + fgets(minmovesstr, STRLENMAX, stdin); + fgets(maxmovesstr, STRLENMAX, stdin); + fgets(maxsolsstr, STRLENMAX, stdin); + fgets(optimalstr, STRLENMAX, stdin); + + solverstr[strcspn(solverstr, "\n")] = 0; + optionsstr[strcspn(optionsstr, "\n")] = 0; + nisstypestr[strcspn(nisstypestr, "\n")] = 0; + + cube = readcube("H48", cubestr); + minmoves = atoi(minmovesstr); + maxmoves = atoi(maxmovesstr); + maxsols = atoi(maxsolsstr); + optimal = atoi(optimalstr); + + solve( + cube, + solverstr, + optionsstr, + nisstypestr, + minmoves, + maxmoves, + maxsols, + optimal, + NULL, + solutionsstr + ); + + printf("%s", solutionsstr); + + return 0; +} -- cgit v1.3