aboutsummaryrefslogtreecommitdiff
path: root/tools/solvetest.h
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-07-31 11:18:49 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2025-07-31 11:43:04 +0200
commit037461be140429aaa80af75fcd110ee60ba410ee (patch)
tree1ee8ef3af4e3fe6702a5f903386206e46d64854c /tools/solvetest.h
parent992de12cc081e7dde16c3c231f83bfa77c67825a (diff)
downloadnissy-core-037461be140429aaa80af75fcd110ee60ba410ee.tar.gz
nissy-core-037461be140429aaa80af75fcd110ee60ba410ee.zip
Fixed multisolve tool for EO, but found bug in coord solver
Diffstat (limited to '')
-rw-r--r--tools/solvetest.h96
1 files changed, 71 insertions, 25 deletions
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
5char *solver; 7char *solver;
6int64_t size = 0; 8int64_t size = 0;
7unsigned char *buf; 9unsigned char *buf;
8 10
9bool check_one(char *actual, char *expected) { 11bool 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
25bool check_all(char *actual, char *expected) { 41size_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
50bool 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++) 75bool 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
43void run(void) { 90void 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);

Generated with cgit - Back to sebastiano.tronto.net