commit 6e0f63d8f4608ce32c161691f490914650f4f5c1
parent e419ca484e62f2771766a87bfaedf75a5f99c2b1
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Thu, 5 Sep 2024 17:01:28 +0200
Added test for premove and a comment
Diffstat:
8 files changed, 41 insertions(+), 0 deletions(-)
diff --git a/src/core/moves.h b/src/core/moves.h
@@ -111,6 +111,7 @@ move(cube_t c, uint8_t m)
}
}
+/* Applies the INVERSE of m BEFORE the scramble corresponding to c */
STATIC cube_t
premove(cube_t c, uint8_t m)
{
diff --git a/test/031_premove/001_U_solved.in b/test/031_premove/001_U_solved.in
@@ -0,0 +1,2 @@
+U
+UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0
diff --git a/test/031_premove/001_U_solved.out b/test/031_premove/001_U_solved.out
@@ -0,0 +1 @@
+UL0 UR0 DB0 DF0 UF0 UB0 DL0 DR0 FR0 FL0 BL0 BR0 UFL0 UBR0 DFL0 DBR0 UBL0 UFR0 DFR0 DBL0
diff --git a/test/031_premove/002_U_scrambled.in b/test/031_premove/002_U_scrambled.in
@@ -0,0 +1,4 @@
+U
+UL0 BL0 BR1 DL0 FR0 DF0 DB1 DR1 UB0 FL0 UF0 UR1 DFL0 UFR1 DBR1 UBR2 DBL2 DFR0 UFL1 UBL2
+
+// Scramble: U R D' L D' F L2 D L F B D2 B' L2 F U2 L2 D2 R2 L2 B'
diff --git a/test/031_premove/002_U_scrambled.out b/test/031_premove/002_U_scrambled.out
@@ -0,0 +1 @@
+UB0 BL0 BR1 DL0 FR0 DF0 DB1 DR1 UR0 FL0 UL0 UF1 DFL0 UFL1 DBR1 UFR2 DBL2 DFR0 UBL1 UBR2
diff --git a/test/031_premove/003_F3_scrambled.in b/test/031_premove/003_F3_scrambled.in
@@ -0,0 +1,4 @@
+F'
+UL0 BL0 BR1 DL0 FR0 DF0 DB1 DR1 UB0 FL0 UF0 UR1 DFL0 UFR1 DBR1 UBR2 DBL2 DFR0 UFL1 UBL2
+
+// Scramble: U R D' L D' F L2 D L F B D2 B' L2 F U2 L2 D2 R2 L2 B'
diff --git a/test/031_premove/003_F3_scrambled.out b/test/031_premove/003_F3_scrambled.out
@@ -0,0 +1 @@
+UL0 BL0 BR1 DL0 UF1 FR1 DB1 DR1 UB0 DF1 FL1 UR1 DFR1 UFL2 DBR1 UBR2 DBL2 UFR2 DFL0 UBL2
diff --git a/test/031_premove/premove_tests.c b/test/031_premove/premove_tests.c
@@ -0,0 +1,27 @@
+#include "../test.h"
+
+uint8_t readmove(char);
+uint8_t readmodifier(char);
+cube_t premove(cube_t, uint8_t);
+
+void run(void) {
+ char movestr[STRLENMAX], cubestr[STRLENMAX];
+ uint8_t move;
+ cube_t cube;
+
+ fgets(movestr, STRLENMAX, stdin);
+ move = readmove(movestr[0]) + readmodifier(movestr[1]);
+ fgets(cubestr, STRLENMAX, stdin);
+ cube = readcube("H48", cubestr);
+
+ cube = premove(cube, move);
+
+ if (iserror(cube)) {
+ printf("Error moving cube\n");
+ } else if (!issolvable(cube)) {
+ printf("Moved cube is not solvable\n");
+ } else {
+ writecube("H48", cube, cubestr);
+ printf("%s\n", cubestr);
+ }
+}