aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2023-11-14 22:42:08 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2023-11-14 22:42:08 +0100
commitd5e7698d0c7ecb61fe49263982f750c053147089 (patch)
tree5a6c16f28bbec007665f4b85e5c96344dd4ed617
parente0f38c7e42d9e48ac654f9dcedf8722ff1136106 (diff)
downloadnissy-core-d5e7698d0c7ecb61fe49263982f750c053147089.tar.gz
nissy-core-d5e7698d0c7ecb61fe49263982f750c053147089.zip
Added tests allowednext
-rw-r--r--TODO.txt2
-rw-r--r--cube.c27
-rw-r--r--test/080_allowednext/00_empty_U.in2
-rw-r--r--test/080_allowednext/00_empty_U.out1
-rw-r--r--test/080_allowednext/02_F_F2.in3
-rw-r--r--test/080_allowednext/02_F_F2.out1
-rw-r--r--test/080_allowednext/02_U_F.in3
-rw-r--r--test/080_allowednext/02_U_F.out1
-rw-r--r--test/080_allowednext/03_R_L_R.in4
-rw-r--r--test/080_allowednext/03_R_L_R.out1
-rw-r--r--test/080_allowednext/04_longer_true.in12
-rw-r--r--test/080_allowednext/04_longer_true.out1
-rw-r--r--test/080_allowednext/05_longer_false.in9
-rw-r--r--test/080_allowednext/05_longer_false.out1
-rw-r--r--test/080_allowednext/06_D_U_false_order.in3
-rw-r--r--test/080_allowednext/06_D_U_false_order.out1
-rw-r--r--test/080_allowednext/allowednext_tests.c42
-rw-r--r--test/090_solve_simple/01_U_U3.in (renamed from test/080_solve_simple/01_U_U3.in)0
-rw-r--r--test/090_solve_simple/01_U_U3.out (renamed from test/080_solve_simple/01_U_U3.out)0
-rw-r--r--test/090_solve_simple/02_MUMU_alloptimal.in (renamed from test/080_solve_simple/02_MUMU_alloptimal.in)0
-rw-r--r--test/090_solve_simple/02_MUMU_alloptimal.out (renamed from test/080_solve_simple/02_MUMU_alloptimal.out)0
-rw-r--r--test/090_solve_simple/solve_simple_tests.c (renamed from test/080_solve_simple/solve_simple_tests.c)0
22 files changed, 97 insertions, 17 deletions
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
22## Small change 22## Small change
23 23
24* solve tests: make smaller, split 24* solve tests: make smaller, split
25* add lots of tests for things that were static, now visible:
26 allowednextmove
27 25
28## Solving 26## Solving
29 27
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)
3165 while (*b == ' ' || *b == '\t' || *b == '\n') 3165 while (*b == ' ' || *b == '\t' || *b == '\n')
3166 b++; 3166 b++;
3167 if (*b == '\0') 3167 if (*b == '\0')
3168 goto readmoves_finish; 3168 goto applymoves_finish;
3169 if ((r = readmove(*b)) == _error) 3169 if ((r = readmove(*b)) == _error)
3170 goto readmoves_error; 3170 goto applymoves_error;
3171 if ((m = readmodifier(*(b+1))) != 0) 3171 if ((m = readmodifier(*(b+1))) != 0)
3172 b++; 3172 b++;
3173 fast = move(fast, r + m); 3173 fast = move(fast, r + m);
3174 } 3174 }
3175 3175
3176readmoves_finish: 3176applymoves_finish:
3177 return fasttocube(fast); 3177 return fasttocube(fast);
3178 3178
3179readmoves_error: 3179applymoves_error:
3180 DBG_LOG("readmoves error\n"); 3180 DBG_LOG("applymoves error\n");
3181 return zero; 3181 return zero;
3182} 3182}
3183 3183
@@ -3725,7 +3725,7 @@ int64_t solve(cube_t, char *, char *, char *, int8_t, int8_t, int64_t, int8_t,
3725void multisolve(int, cube_t *, char *, void *, char *); 3725void multisolve(int, cube_t *, char *, void *, char *);
3726int64_t gendata(char *, void *); 3726int64_t gendata(char *, void *);
3727 3727
3728_static bool allowednextmove(dfsarg_generic_t, uint8_t); 3728_static bool allowednextmove(uint8_t *, int, uint8_t);
3729_static void solve_generic_appendsolution(dfsarg_generic_t); 3729_static void solve_generic_appendsolution(dfsarg_generic_t);
3730_static int solve_generic_dfs(dfsarg_generic_t); 3730_static int solve_generic_dfs(dfsarg_generic_t);
3731_static int64_t solve_generic(cube_t, char *, int8_t, int8_t, int64_t, int8_t, 3731_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)
3796} 3796}
3797 3797
3798_static bool 3798_static bool
3799allowednextmove(dfsarg_generic_t arg, uint8_t m) 3799allowednextmove(uint8_t *moves, int n, uint8_t m)
3800{ 3800{
3801 int n;
3802 uint8_t mbase, l1base, l2base, maxis, l1axis, l2axis; 3801 uint8_t mbase, l1base, l2base, maxis, l1axis, l2axis;
3803 3802
3804 n = arg.nmoves;
3805
3806 if (n == 0) 3803 if (n == 0)
3807 return true; 3804 return true;
3808 3805
3809 mbase = movebase(m); 3806 mbase = movebase(m);
3810 maxis = moveaxis(m); 3807 maxis = moveaxis(m);
3811 l1base = movebase(arg.moves[n-1]); 3808 l1base = movebase(moves[n-1]);
3812 l1axis = moveaxis(arg.moves[n-1]); 3809 l1axis = moveaxis(moves[n-1]);
3813 3810
3814 if (mbase == l1base || (maxis == l1axis && mbase < l1base)) 3811 if (mbase == l1base || (maxis == l1axis && mbase < l1base))
3815 return false; 3812 return false;
@@ -3817,8 +3814,8 @@ allowednextmove(dfsarg_generic_t arg, uint8_t m)
3817 if (n == 1) 3814 if (n == 1)
3818 return true; 3815 return true;
3819 3816
3820 l2base = movebase(arg.moves[n-2]); 3817 l2base = movebase(moves[n-2]);
3821 l2axis = moveaxis(arg.moves[n-2]); 3818 l2axis = moveaxis(moves[n-2]);
3822 3819
3823 return l1axis != l2axis || mbase != l2base; 3820 return l1axis != l2axis || mbase != l2base;
3824} 3821}
@@ -3858,7 +3855,7 @@ solve_generic_dfs(dfsarg_generic_t arg)
3858 memcpy(&nextarg, &arg, sizeof(dfsarg_generic_t)); 3855 memcpy(&nextarg, &arg, sizeof(dfsarg_generic_t));
3859 nextarg.nmoves = arg.nmoves + 1; 3856 nextarg.nmoves = arg.nmoves + 1;
3860 for (m = 0, ret = 0; m < 18; m++) { 3857 for (m = 0, ret = 0; m < 18; m++) {
3861 if (allowednextmove(arg, m)) { 3858 if (allowednextmove(arg.moves, arg.nmoves, m)) {
3862 nextarg.cube = move(arg.cube, m); 3859 nextarg.cube = move(arg.cube, m);
3863 nextarg.moves[arg.nmoves] = m; 3860 nextarg.moves[arg.nmoves] = m;
3864 ret += solve_generic_dfs(nextarg); 3861 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 @@
10
2U
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 @@
11
2F
3F2
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 @@
11
2U
3F
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 @@
12
2R
3L'
4R2
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 @@
110
2F2
3B
4D2
5D'
6L
7R2
8U
9U'
10D
11F
12L
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 @@
17
2D
3B2
4F'
5L'
6F'
7L'
8R2
9L
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 @@
11
2D
3U
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 @@
1#include "../test.h"
2
3bool allowednextmove(uint8_t *, int, uint8_t);
4
5static char *moves[] = {
6 "U", "U2", "U'",
7 "D", "D2", "D'",
8 "R", "R2", "R'",
9 "L", "L2", "L'",
10 "F", "F2", "F'",
11 "B", "B2", "B'",
12};
13
14int main() {
15 char movestr[STRLENMAX];
16 uint8_t m[100], next;
17 int n, i, j;
18
19 fgets(movestr, STRLENMAX, stdin);
20 n = atoi(movestr);
21
22 for (i = 0; i < n; i++) {
23 fgets(movestr, STRLENMAX, stdin);
24 movestr[strcspn(movestr, "\n")] = 0;
25 for (j = 0; j < 18; j++)
26 if (!strcmp(movestr, moves[j]))
27 m[i] = j;
28 }
29 fgets(movestr, STRLENMAX, stdin);
30 movestr[strcspn(movestr, "\n")] = 0;
31 for (j = 0; j < 18; j++)
32 if (!strcmp(movestr, moves[j]))
33 next = j;
34
35 fprintf(stderr, "Last two: %s, %s\nNext: %s\n",
36 n > 1 ? moves[m[n-2]] : "-",
37 n > 0 ? moves[m[n-1]] : "-",
38 moves[next]);
39 printf("%s\n", allowednextmove(m, n, next) ? "true" : "false");
40
41 return 0;
42}
diff --git a/test/080_solve_simple/01_U_U3.in b/test/090_solve_simple/01_U_U3.in
index c0f7930..c0f7930 100644
--- a/test/080_solve_simple/01_U_U3.in
+++ b/test/090_solve_simple/01_U_U3.in
diff --git a/test/080_solve_simple/01_U_U3.out b/test/090_solve_simple/01_U_U3.out
index ca934b4..ca934b4 100644
--- a/test/080_solve_simple/01_U_U3.out
+++ b/test/090_solve_simple/01_U_U3.out
diff --git a/test/080_solve_simple/02_MUMU_alloptimal.in b/test/090_solve_simple/02_MUMU_alloptimal.in
index f97c95f..f97c95f 100644
--- a/test/080_solve_simple/02_MUMU_alloptimal.in
+++ b/test/090_solve_simple/02_MUMU_alloptimal.in
diff --git a/test/080_solve_simple/02_MUMU_alloptimal.out b/test/090_solve_simple/02_MUMU_alloptimal.out
index 06cd521..06cd521 100644
--- a/test/080_solve_simple/02_MUMU_alloptimal.out
+++ b/test/090_solve_simple/02_MUMU_alloptimal.out
diff --git a/test/080_solve_simple/solve_simple_tests.c b/test/090_solve_simple/solve_simple_tests.c
index 4756dc0..4756dc0 100644
--- a/test/080_solve_simple/solve_simple_tests.c
+++ b/test/090_solve_simple/solve_simple_tests.c

Generated with cgit - Back to sebastiano.tronto.net