diff options
Diffstat (limited to '')
| -rw-r--r-- | tools/401_solvetest_opt0_EO_FB/scrambles.h | 3 | ||||
| -rw-r--r-- | tools/solvetest.h | 96 | ||||
| -rwxr-xr-x | utils/solvetest_gen.sh | 2 |
3 files changed, 75 insertions, 26 deletions
diff --git a/tools/401_solvetest_opt0_EO_FB/scrambles.h b/tools/401_solvetest_opt0_EO_FB/scrambles.h index 09cde32..bef6d77 100644 --- a/tools/401_solvetest_opt0_EO_FB/scrambles.h +++ b/tools/401_solvetest_opt0_EO_FB/scrambles.h | |||
| @@ -297,4 +297,7 @@ struct { | |||
| 297 | "(R F L F B)\n" | 297 | "(R F L F B)\n" |
| 298 | "(R F L' F B)\n" | 298 | "(R F L' F B)\n" |
| 299 | }, | 299 | }, |
| 300 | { | ||
| 301 | .scramble = "", /* End-of-list signal */ | ||
| 302 | } | ||
| 300 | }; | 303 | }; |
diff --git a/tools/solvetest.h b/tools/solvetest.h index 4a36736..5939d5d 100644 --- a/tools/solvetest.h +++ b/tools/solvetest.h | |||
| @@ -1,48 +1,94 @@ | |||
| 1 | #include "tool.h" | 1 | #include "tool.h" |
| 2 | 2 | ||
| 3 | #define SOL_BUFFER_LEN 100000 | 3 | #define SOL_BUFFER_LEN 100000 |
| 4 | #define MAX_SOLUTIONS 1000 | ||
| 5 | #define MAX_SOLUTION_LEN 1000 | ||
| 4 | 6 | ||
| 5 | char *solver; | 7 | char *solver; |
| 6 | int64_t size = 0; | 8 | int64_t size = 0; |
| 7 | unsigned char *buf; | 9 | unsigned char *buf; |
| 8 | 10 | ||
| 9 | bool check_one(char *actual, char *expected) { | 11 | bool check_one( |
| 10 | unsigned i; | 12 | const char *astr, |
| 11 | size_t l_actual, l_expected; | 13 | const char *aname, |
| 14 | const char *bstr, | ||
| 15 | const char *bname, | ||
| 16 | bool exp[static MAXSOLUTIONS] | ||
| 17 | ) { | ||
| 18 | size_t i, j, nn, lb; | ||
| 19 | char b[MAX_SOLUTION_LEN]; | ||
| 12 | 20 | ||
| 13 | for (l_actual = 0; actual[l_actual] != '\n'; l_actual++) ; | 21 | lb = strlen(bstr); |
| 14 | l_expected = strlen(expected); | 22 | for (i = 0, j = 0, nn = 0; i < lb; j++, i = ++nn) { |
| 15 | if (l_actual > l_expected) | 23 | while (bstr[nn] != '\n') nn++; |
| 16 | return false; | 24 | strncpy(b, &bstr[i], nn-i); |
| 17 | for (i = 0; i < l_expected; i++) { | 25 | b[nn-i] = '\0'; |
| 18 | if (!strncmp(actual, &expected[i], l_actual)) | 26 | if (nissy_comparemoves(astr, b) == NISSY_COMPARE_MOVES_EQUAL) { |
| 27 | if (exp[j]) { | ||
| 28 | printf("%s solution %s found twice\n", | ||
| 29 | aname, b); | ||
| 30 | return false; | ||
| 31 | } | ||
| 32 | exp[j] = true; | ||
| 19 | return true; | 33 | return true; |
| 20 | while(expected[i] != '\n') i++; | 34 | } |
| 21 | } | 35 | } |
| 36 | |||
| 37 | printf("%s solution %s not found in %s\n", aname, astr, bname); | ||
| 22 | return false; | 38 | return false; |
| 23 | } | 39 | } |
| 24 | 40 | ||
| 25 | bool check_all(char *actual, char *expected) { | 41 | size_t count_lines(const char *str) { |
| 26 | unsigned i, found, n_expected; | 42 | size_t i, ret; |
| 27 | size_t l_actual; | 43 | |
| 44 | for (i = 0, ret = 0; str[i] != '\0'; i++) | ||
| 45 | ret += str[i] == '\n'; | ||
| 46 | |||
| 47 | return ret; | ||
| 48 | } | ||
| 49 | |||
| 50 | bool find_strlist( | ||
| 51 | const char *astr, | ||
| 52 | const char *aname, | ||
| 53 | const char *bstr, | ||
| 54 | const char *bname | ||
| 55 | ) | ||
| 56 | { | ||
| 57 | size_t i, nn, la; | ||
| 58 | char a[MAX_SOLUTION_LEN]; | ||
| 59 | bool exp[MAX_SOLUTIONS]; | ||
| 60 | |||
| 61 | memset(exp, false, MAX_SOLUTIONS * sizeof(bool)); | ||
| 28 | 62 | ||
| 29 | l_actual = strlen(actual); | 63 | la = strlen(astr); |
| 30 | if (l_actual != strlen(expected)) | 64 | for (i = 0, nn = 0; i < la; i = ++nn) { |
| 31 | return false; | 65 | while (astr[nn] != '\n') nn++; |
| 66 | strncpy(a, &astr[i], nn-i); | ||
| 67 | a[nn-i] = '\0'; | ||
| 68 | if (!check_one(a, aname, bstr, bname, exp)) | ||
| 69 | return false; | ||
| 70 | } | ||
| 71 | |||
| 72 | return true; | ||
| 73 | } | ||
| 32 | 74 | ||
| 33 | for (i = 0, n_expected = 0; expected[i]; i++) | 75 | bool check_all(const char *actual, const char *expected) { |
| 34 | n_expected += expected[i] == '\n'; | 76 | size_t n_actual, n_expected; |
| 35 | 77 | ||
| 36 | for (i = 0, found = 0; i < l_actual; i++) | 78 | n_actual = count_lines(actual); |
| 37 | if (i == 0 || actual[i-1] == '\n') | 79 | n_expected = count_lines(expected); |
| 38 | found += check_one(&actual[i], expected); | 80 | if (n_actual < n_expected) |
| 81 | printf("Found less solutions than expected\n"); | ||
| 82 | if (n_actual > n_expected) | ||
| 83 | printf("Found more solutions than expected\n"); | ||
| 39 | 84 | ||
| 40 | return found == n_expected; | 85 | return n_actual > n_expected ? |
| 86 | find_strlist(actual, "actual", expected, "expected") : | ||
| 87 | find_strlist(expected, "expected", actual, "actual"); | ||
| 41 | } | 88 | } |
| 42 | 89 | ||
| 43 | void run(void) { | 90 | void run(void) { |
| 44 | int i; | 91 | int i; |
| 45 | int64_t n; | ||
| 46 | long long stats[NISSY_SIZE_SOLVE_STATS]; | 92 | long long stats[NISSY_SIZE_SOLVE_STATS]; |
| 47 | char sol[SOL_BUFFER_LEN], cube[NISSY_SIZE_CUBE]; | 93 | char sol[SOL_BUFFER_LEN], cube[NISSY_SIZE_CUBE]; |
| 48 | 94 | ||
| @@ -55,7 +101,7 @@ void run(void) { | |||
| 55 | printf("Invalid scramble\n"); | 101 | printf("Invalid scramble\n"); |
| 56 | continue; | 102 | continue; |
| 57 | } | 103 | } |
| 58 | n = nissy_solve(cube, solver, | 104 | nissy_solve(cube, solver, |
| 59 | NISSFLAG, MINMOVES, MAXMOVES, MAXSOLUTIONS, OPTIMAL, | 105 | NISSFLAG, MINMOVES, MAXMOVES, MAXSOLUTIONS, OPTIMAL, |
| 60 | 0, size, buf, SOL_BUFFER_LEN, sol, stats, | 106 | 0, size, buf, SOL_BUFFER_LEN, sol, stats, |
| 61 | NULL, NULL); | 107 | NULL, NULL); |
diff --git a/utils/solvetest_gen.sh b/utils/solvetest_gen.sh index c782ed8..11dcd07 100755 --- a/utils/solvetest_gen.sh +++ b/utils/solvetest_gen.sh | |||
| @@ -20,4 +20,4 @@ while read -r scramble; do | |||
| 20 | i=$((i+1)) | 20 | i=$((i+1)) |
| 21 | done | 21 | done |
| 22 | 22 | ||
| 23 | printf "};\n" | 23 | printf '{\n\t.scramble = "", /* End-of-list signal */\n}\n};\n' |
