From 2edc8c01fba711f4410279b59c784a43cf2dde41 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Sun, 8 Oct 2023 14:04:11 +0200 Subject: Added write to SRC format --- .gitignore | 1 + src/cube.h | 11 +-- src/cube_array.c | 118 +++++++++++++++++++---- test/010_io_H48/00_garbage.in | 3 + test/010_io_H48/00_garbage.out | 1 + test/010_io_H48/01_solved_oneline.in | 1 + test/010_io_H48/01_solved_oneline.out | 1 + test/010_io_H48/02_solved_oneline_whitespace.in | 1 + test/010_io_H48/02_solved_oneline_whitespace.out | 1 + test/010_io_H48/03_solved_multiline.in | 9 ++ test/010_io_H48/03_solved_multiline.out | 1 + test/010_io_H48/04_unsolvable_ep.in | 1 + test/010_io_H48/04_unsolvable_ep.out | 1 + test/010_io_H48/05_unsolvable_eo.in | 1 + test/010_io_H48/05_unsolvable_eo.out | 1 + test/010_io_H48/06_unsolvable_cp.in | 1 + test/010_io_H48/06_unsolvable_cp.out | 1 + test/010_io_H48/07_unsolvable_co.in | 1 + test/010_io_H48/07_unsolvable_co.out | 1 + test/010_io_H48/08_unsolved.in | 6 ++ test/010_io_H48/08_unsolved.out | 1 + test/010_io_H48/io_H48_tests.c | 28 ++++++ test/011_io_SRC/01_solved.in | 1 + test/011_io_SRC/01_solved.out | 4 + test/011_io_SRC/io_SRC_tests.c | 28 ++++++ test/01_io/00_garbage.in | 3 - test/01_io/00_garbage.out | 1 - test/01_io/01_solved_oneline.in | 1 - test/01_io/01_solved_oneline.out | 1 - test/01_io/02_solved_oneline_whitespace.in | 1 - test/01_io/02_solved_oneline_whitespace.out | 1 - test/01_io/03_solved_multiline.in | 9 -- test/01_io/03_solved_multiline.out | 1 - test/01_io/04_unsolvable_ep.in | 1 - test/01_io/04_unsolvable_ep.out | 1 - test/01_io/05_unsolvable_eo.in | 1 - test/01_io/05_unsolvable_eo.out | 1 - test/01_io/06_unsolvable_cp.in | 1 - test/01_io/06_unsolvable_cp.out | 1 - test/01_io/07_unsolvable_co.in | 1 - test/01_io/07_unsolvable_co.out | 1 - test/01_io/08_unsolved.in | 6 -- test/01_io/08_unsolved.out | 1 - test/01_io/io_tests.c | 28 ------ test/02_move/move_tests.c | 4 +- test/03_inverse/inverse_tests.c | 4 +- test/04_compose/compose_tests.c | 6 +- test/test.sh | 2 +- utils/FORMAT.txt | 15 ++- 49 files changed, 220 insertions(+), 96 deletions(-) create mode 100644 test/010_io_H48/00_garbage.in create mode 100644 test/010_io_H48/00_garbage.out create mode 100644 test/010_io_H48/01_solved_oneline.in create mode 100644 test/010_io_H48/01_solved_oneline.out create mode 100644 test/010_io_H48/02_solved_oneline_whitespace.in create mode 100644 test/010_io_H48/02_solved_oneline_whitespace.out create mode 100644 test/010_io_H48/03_solved_multiline.in create mode 100644 test/010_io_H48/03_solved_multiline.out create mode 100644 test/010_io_H48/04_unsolvable_ep.in create mode 100644 test/010_io_H48/04_unsolvable_ep.out create mode 100644 test/010_io_H48/05_unsolvable_eo.in create mode 100644 test/010_io_H48/05_unsolvable_eo.out create mode 100644 test/010_io_H48/06_unsolvable_cp.in create mode 100644 test/010_io_H48/06_unsolvable_cp.out create mode 100644 test/010_io_H48/07_unsolvable_co.in create mode 100644 test/010_io_H48/07_unsolvable_co.out create mode 100644 test/010_io_H48/08_unsolved.in create mode 100644 test/010_io_H48/08_unsolved.out create mode 100644 test/010_io_H48/io_H48_tests.c create mode 100644 test/011_io_SRC/01_solved.in create mode 100644 test/011_io_SRC/01_solved.out create mode 100644 test/011_io_SRC/io_SRC_tests.c delete mode 100644 test/01_io/00_garbage.in delete mode 100644 test/01_io/00_garbage.out delete mode 100644 test/01_io/01_solved_oneline.in delete mode 100644 test/01_io/01_solved_oneline.out delete mode 100644 test/01_io/02_solved_oneline_whitespace.in delete mode 100644 test/01_io/02_solved_oneline_whitespace.out delete mode 100644 test/01_io/03_solved_multiline.in delete mode 100644 test/01_io/03_solved_multiline.out delete mode 100644 test/01_io/04_unsolvable_ep.in delete mode 100644 test/01_io/04_unsolvable_ep.out delete mode 100644 test/01_io/05_unsolvable_eo.in delete mode 100644 test/01_io/05_unsolvable_eo.out delete mode 100644 test/01_io/06_unsolvable_cp.in delete mode 100644 test/01_io/06_unsolvable_cp.out delete mode 100644 test/01_io/07_unsolvable_co.in delete mode 100644 test/01_io/07_unsolvable_co.out delete mode 100644 test/01_io/08_unsolved.in delete mode 100644 test/01_io/08_unsolved.out delete mode 100644 test/01_io/io_tests.c diff --git a/.gitignore b/.gitignore index e0538cd..5f06d9a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ test/*/runtest test/run test/last.* test/*.o +*.o diff --git a/src/cube.h b/src/cube.h index 3319b1e..129062d 100644 --- a/src/cube.h +++ b/src/cube.h @@ -7,12 +7,11 @@ typedef uint8_t trans_t; extern cube_t solvedcube; -/* For the textual representation of the cube, see utils/FORMAT.txt */ -cube_t readcube(char *); -void writecube(cube_t, char *); - -/* Writes a cube in C source code format */ -void writecubesrc(cube_t, char *); +/* Not all formats are supported for both read and write. */ +/* See utils/FORMAT.txt for details. */ +typedef enum {H48, SRC} format_t; +cube_t readcube(format_t, char *); +void writecube(format_t, cube_t, char *); bool issolvable(cube_t); bool equal(cube_t, cube_t); diff --git a/src/cube_array.c b/src/cube_array.c index a9b9709..1d2da86 100644 --- a/src/cube_array.c +++ b/src/cube_array.c @@ -156,6 +156,10 @@ static uint8_t readeo(char *); static uint8_t readep(char *); static uint8_t readmove(char); static uint8_t readmodifier(char); +static cube_t readcube_H48(char *); +static void writecube_H48(cube_t, char *); +static int writepiece_SRC(uint8_t, char *); +static void writecube_SRC(cube_t, char *); static int permsign(uint8_t *, int); static uint8_t @@ -219,8 +223,8 @@ readep(char *str) return _error; } -cube_t -readcube(char *buf) +static cube_t +readcube_H48(char *buf) { int i; uint8_t piece, orient; @@ -231,10 +235,10 @@ readcube(char *buf) while (*b == ' ' || *b == '\t' || *b == '\n') b++; if ((piece = readep(b)) == _error) - goto readcube_error; + return errorcube; b += 2; if ((orient = readeo(b)) == _error) - goto readcube_error; + return errorcube; b++; ret.e[i] = piece | orient; } @@ -242,36 +246,46 @@ readcube(char *buf) while (*b == ' ' || *b == '\t' || *b == '\n') b++; if ((piece = readcp(b)) == _error) - goto readcube_error; + return errorcube; b += 3; if ((orient = readco(b)) == _error) - goto readcube_error; + return errorcube; b++; ret.c[i] = piece | orient; } return ret; +} + +cube_t +readcube(format_t format, char *buf) +{ + cube_t ret; + + switch (format) { + case H48: + ret = readcube_H48(buf); + break; + default: + #ifdef DEBUG + fprintf(stderr, "Cannot read cube in the given format\n"); + #endif + ret = errorcube; + } -readcube_error: #ifdef DEBUG - fprintf(stderr, "readcube error\n"); + if (iserror(ret)) + fprintf(stderr, "readcube error\n"); #endif - return errorcube; + return ret; } -void -writecube(cube_t cube, char *buf) +static void +writecube_H48(cube_t cube, char *buf) { - char *errormsg; uint8_t piece, orient; - size_t len; int i; - if (!isconsistent(cube)) { - errormsg = "ERROR: cannot write inconsistent cube"; - goto writecube_error; - } - for (i = 0; i < 12; i++) { piece = cube.e[i] & _pbits; orient = (cube.e[i] & _eobit) >> _eoshift; @@ -291,6 +305,73 @@ writecube(cube_t cube, char *buf) } buf[48+39] = '\0'; +} + +static int +writepiece_SRC(uint8_t piece, char *buf) +{ + char digits[3]; + int i, len = 0; + + while (piece != 0) { + digits[len++] = (piece % 10) + '0'; + piece /= 10; + } + + if (len == 0) + digits[len++] = '0'; + + for (i = 0; i < len; i++) + buf[i] = digits[len-i-1]; + + buf[len] = ','; + buf[len+1] = ' '; + + return len+2; +} + +static void +writecube_SRC(cube_t cube, char *buf) +{ + int i, ptr; + + memcpy(buf, "{\n\t.c = {", 9); + ptr = 9; + + for (i = 0; i < 8; i++) + ptr += writepiece_SRC(cube.c[i], buf + ptr); + + memcpy(buf+ptr-2, "},\n\t.e = {", 10); + ptr += 8; + + for (i = 0; i < 12; i++) + ptr += writepiece_SRC(cube.e[i], buf + ptr); + + memcpy(buf+ptr-2, "}\n}\0", 4); +} + +void +writecube(format_t format, cube_t cube, char *buf) +{ + char *errormsg; + size_t len; + + if (!isconsistent(cube)) { + errormsg = "ERROR: cannot write inconsistent cube"; + goto writecube_error; + } + + switch (format) { + case H48: + writecube_H48(cube, buf); + break; + case SRC: + writecube_SRC(cube, buf); + break; + default: + errormsg = "ERROR: cannot write cube in the given format"; + goto writecube_error; + } return; @@ -304,7 +385,6 @@ writecube_error: buf[len+1] = '\0'; } - static uint8_t readmove(char c) { diff --git a/test/010_io_H48/00_garbage.in b/test/010_io_H48/00_garbage.in new file mode 100644 index 0000000..9ac203a --- /dev/null +++ b/test/010_io_H48/00_garbage.in @@ -0,0 +1,3 @@ +FUF0 UBBBR2 k4 +hello +garbage diff --git a/test/010_io_H48/00_garbage.out b/test/010_io_H48/00_garbage.out new file mode 100644 index 0000000..5b9114e --- /dev/null +++ b/test/010_io_H48/00_garbage.out @@ -0,0 +1 @@ +Error reading cube diff --git a/test/010_io_H48/01_solved_oneline.in b/test/010_io_H48/01_solved_oneline.in new file mode 100644 index 0000000..dff224d --- /dev/null +++ b/test/010_io_H48/01_solved_oneline.in @@ -0,0 +1 @@ +UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 diff --git a/test/010_io_H48/01_solved_oneline.out b/test/010_io_H48/01_solved_oneline.out new file mode 100644 index 0000000..dff224d --- /dev/null +++ b/test/010_io_H48/01_solved_oneline.out @@ -0,0 +1 @@ +UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 diff --git a/test/010_io_H48/02_solved_oneline_whitespace.in b/test/010_io_H48/02_solved_oneline_whitespace.in new file mode 100644 index 0000000..5d10368 --- /dev/null +++ b/test/010_io_H48/02_solved_oneline_whitespace.in @@ -0,0 +1 @@ +UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 diff --git a/test/010_io_H48/02_solved_oneline_whitespace.out b/test/010_io_H48/02_solved_oneline_whitespace.out new file mode 100644 index 0000000..dff224d --- /dev/null +++ b/test/010_io_H48/02_solved_oneline_whitespace.out @@ -0,0 +1 @@ +UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 diff --git a/test/010_io_H48/03_solved_multiline.in b/test/010_io_H48/03_solved_multiline.in new file mode 100644 index 0000000..9f9652b --- /dev/null +++ b/test/010_io_H48/03_solved_multiline.in @@ -0,0 +1,9 @@ +UF0 UB0 +DB0 DF0 UR0 UL0 DL0 +DR0 FR0 FL0 BL0 BR0 UFR0 + +UBL0 DFL0 DBR0 + + +UFL0 UBR0 DFR0 + DBL0 diff --git a/test/010_io_H48/03_solved_multiline.out b/test/010_io_H48/03_solved_multiline.out new file mode 100644 index 0000000..dff224d --- /dev/null +++ b/test/010_io_H48/03_solved_multiline.out @@ -0,0 +1 @@ +UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 diff --git a/test/010_io_H48/04_unsolvable_ep.in b/test/010_io_H48/04_unsolvable_ep.in new file mode 100644 index 0000000..8483962 --- /dev/null +++ b/test/010_io_H48/04_unsolvable_ep.in @@ -0,0 +1 @@ +UB0 UF0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 diff --git a/test/010_io_H48/04_unsolvable_ep.out b/test/010_io_H48/04_unsolvable_ep.out new file mode 100644 index 0000000..e35c6e4 --- /dev/null +++ b/test/010_io_H48/04_unsolvable_ep.out @@ -0,0 +1 @@ +Cube is not solvable diff --git a/test/010_io_H48/05_unsolvable_eo.in b/test/010_io_H48/05_unsolvable_eo.in new file mode 100644 index 0000000..a92089d --- /dev/null +++ b/test/010_io_H48/05_unsolvable_eo.in @@ -0,0 +1 @@ +UF1 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 diff --git a/test/010_io_H48/05_unsolvable_eo.out b/test/010_io_H48/05_unsolvable_eo.out new file mode 100644 index 0000000..e35c6e4 --- /dev/null +++ b/test/010_io_H48/05_unsolvable_eo.out @@ -0,0 +1 @@ +Cube is not solvable diff --git a/test/010_io_H48/06_unsolvable_cp.in b/test/010_io_H48/06_unsolvable_cp.in new file mode 100644 index 0000000..2085dd5 --- /dev/null +++ b/test/010_io_H48/06_unsolvable_cp.in @@ -0,0 +1 @@ +UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UBL0 UFR0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 diff --git a/test/010_io_H48/06_unsolvable_cp.out b/test/010_io_H48/06_unsolvable_cp.out new file mode 100644 index 0000000..e35c6e4 --- /dev/null +++ b/test/010_io_H48/06_unsolvable_cp.out @@ -0,0 +1 @@ +Cube is not solvable diff --git a/test/010_io_H48/07_unsolvable_co.in b/test/010_io_H48/07_unsolvable_co.in new file mode 100644 index 0000000..abd74e2 --- /dev/null +++ b/test/010_io_H48/07_unsolvable_co.in @@ -0,0 +1 @@ +UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR1 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 diff --git a/test/010_io_H48/07_unsolvable_co.out b/test/010_io_H48/07_unsolvable_co.out new file mode 100644 index 0000000..e35c6e4 --- /dev/null +++ b/test/010_io_H48/07_unsolvable_co.out @@ -0,0 +1 @@ +Cube is not solvable diff --git a/test/010_io_H48/08_unsolved.in b/test/010_io_H48/08_unsolved.in new file mode 100644 index 0000000..c992ce7 --- /dev/null +++ b/test/010_io_H48/08_unsolved.in @@ -0,0 +1,6 @@ +UL1 DR0 UB0 DL1 +UR0 FR1 DB0 BR0 +UF1 DF0 BL0 FL0 + +UBL0 DLF1 DBR2 UFR1 +DFR1 UBR1 UFL0 DBL0 diff --git a/test/010_io_H48/08_unsolved.out b/test/010_io_H48/08_unsolved.out new file mode 100644 index 0000000..8c132cf --- /dev/null +++ b/test/010_io_H48/08_unsolved.out @@ -0,0 +1 @@ +UL1 DR0 UB0 DL1 UR0 FR1 DB0 BR0 UF1 DF0 BL0 FL0 UBL0 DFL1 DBR2 UFR1 DFR1 UBR1 UFL0 DBL0 diff --git a/test/010_io_H48/io_H48_tests.c b/test/010_io_H48/io_H48_tests.c new file mode 100644 index 0000000..7c3978e --- /dev/null +++ b/test/010_io_H48/io_H48_tests.c @@ -0,0 +1,28 @@ +#include +#include +#include + +#include "../../src/cube.h" + +#define STRLENMAX 10000 + +int main() { + char *c, str[STRLENMAX]; + cube_t cube; + + for (c = str; (*c = getchar()) != EOF; c++) ; + *c = '\0'; + + cube = readcube(H48, str); + + if (iserror(cube)) { + printf("Error reading cube\n"); + } else if (!issolvable(cube)) { + printf("Cube is not solvable\n"); + } else { + writecube(H48, cube, str); + printf("%s\n", str); + } + + return 0; +} diff --git a/test/011_io_SRC/01_solved.in b/test/011_io_SRC/01_solved.in new file mode 100644 index 0000000..dff224d --- /dev/null +++ b/test/011_io_SRC/01_solved.in @@ -0,0 +1 @@ +UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 diff --git a/test/011_io_SRC/01_solved.out b/test/011_io_SRC/01_solved.out new file mode 100644 index 0000000..3853027 --- /dev/null +++ b/test/011_io_SRC/01_solved.out @@ -0,0 +1,4 @@ +{ + .c = {0, 1, 2, 3, 4, 5, 6, 7}, + .e = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11} +} diff --git a/test/011_io_SRC/io_SRC_tests.c b/test/011_io_SRC/io_SRC_tests.c new file mode 100644 index 0000000..f454b6f --- /dev/null +++ b/test/011_io_SRC/io_SRC_tests.c @@ -0,0 +1,28 @@ +#include +#include +#include + +#include "../../src/cube.h" + +#define STRLENMAX 10000 + +int main() { + char *c, str[STRLENMAX]; + cube_t cube; + + for (c = str; (*c = getchar()) != EOF; c++) ; + *c = '\0'; + + cube = readcube(H48, str); + + if (iserror(cube)) { + printf("Error reading cube\n"); + } else if (!issolvable(cube)) { + printf("Cube is not solvable\n"); + } else { + writecube(SRC, cube, str); + printf("%s\n", str); + } + + return 0; +} diff --git a/test/01_io/00_garbage.in b/test/01_io/00_garbage.in deleted file mode 100644 index 9ac203a..0000000 --- a/test/01_io/00_garbage.in +++ /dev/null @@ -1,3 +0,0 @@ -FUF0 UBBBR2 k4 -hello -garbage diff --git a/test/01_io/00_garbage.out b/test/01_io/00_garbage.out deleted file mode 100644 index 5b9114e..0000000 --- a/test/01_io/00_garbage.out +++ /dev/null @@ -1 +0,0 @@ -Error reading cube diff --git a/test/01_io/01_solved_oneline.in b/test/01_io/01_solved_oneline.in deleted file mode 100644 index dff224d..0000000 --- a/test/01_io/01_solved_oneline.in +++ /dev/null @@ -1 +0,0 @@ -UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 diff --git a/test/01_io/01_solved_oneline.out b/test/01_io/01_solved_oneline.out deleted file mode 100644 index dff224d..0000000 --- a/test/01_io/01_solved_oneline.out +++ /dev/null @@ -1 +0,0 @@ -UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 diff --git a/test/01_io/02_solved_oneline_whitespace.in b/test/01_io/02_solved_oneline_whitespace.in deleted file mode 100644 index 5d10368..0000000 --- a/test/01_io/02_solved_oneline_whitespace.in +++ /dev/null @@ -1 +0,0 @@ -UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 diff --git a/test/01_io/02_solved_oneline_whitespace.out b/test/01_io/02_solved_oneline_whitespace.out deleted file mode 100644 index dff224d..0000000 --- a/test/01_io/02_solved_oneline_whitespace.out +++ /dev/null @@ -1 +0,0 @@ -UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 diff --git a/test/01_io/03_solved_multiline.in b/test/01_io/03_solved_multiline.in deleted file mode 100644 index 9f9652b..0000000 --- a/test/01_io/03_solved_multiline.in +++ /dev/null @@ -1,9 +0,0 @@ -UF0 UB0 -DB0 DF0 UR0 UL0 DL0 -DR0 FR0 FL0 BL0 BR0 UFR0 - -UBL0 DFL0 DBR0 - - -UFL0 UBR0 DFR0 - DBL0 diff --git a/test/01_io/03_solved_multiline.out b/test/01_io/03_solved_multiline.out deleted file mode 100644 index dff224d..0000000 --- a/test/01_io/03_solved_multiline.out +++ /dev/null @@ -1 +0,0 @@ -UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 diff --git a/test/01_io/04_unsolvable_ep.in b/test/01_io/04_unsolvable_ep.in deleted file mode 100644 index 8483962..0000000 --- a/test/01_io/04_unsolvable_ep.in +++ /dev/null @@ -1 +0,0 @@ -UB0 UF0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 diff --git a/test/01_io/04_unsolvable_ep.out b/test/01_io/04_unsolvable_ep.out deleted file mode 100644 index e35c6e4..0000000 --- a/test/01_io/04_unsolvable_ep.out +++ /dev/null @@ -1 +0,0 @@ -Cube is not solvable diff --git a/test/01_io/05_unsolvable_eo.in b/test/01_io/05_unsolvable_eo.in deleted file mode 100644 index a92089d..0000000 --- a/test/01_io/05_unsolvable_eo.in +++ /dev/null @@ -1 +0,0 @@ -UF1 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 diff --git a/test/01_io/05_unsolvable_eo.out b/test/01_io/05_unsolvable_eo.out deleted file mode 100644 index e35c6e4..0000000 --- a/test/01_io/05_unsolvable_eo.out +++ /dev/null @@ -1 +0,0 @@ -Cube is not solvable diff --git a/test/01_io/06_unsolvable_cp.in b/test/01_io/06_unsolvable_cp.in deleted file mode 100644 index 2085dd5..0000000 --- a/test/01_io/06_unsolvable_cp.in +++ /dev/null @@ -1 +0,0 @@ -UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UBL0 UFR0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 diff --git a/test/01_io/06_unsolvable_cp.out b/test/01_io/06_unsolvable_cp.out deleted file mode 100644 index e35c6e4..0000000 --- a/test/01_io/06_unsolvable_cp.out +++ /dev/null @@ -1 +0,0 @@ -Cube is not solvable diff --git a/test/01_io/07_unsolvable_co.in b/test/01_io/07_unsolvable_co.in deleted file mode 100644 index abd74e2..0000000 --- a/test/01_io/07_unsolvable_co.in +++ /dev/null @@ -1 +0,0 @@ -UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR1 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 diff --git a/test/01_io/07_unsolvable_co.out b/test/01_io/07_unsolvable_co.out deleted file mode 100644 index e35c6e4..0000000 --- a/test/01_io/07_unsolvable_co.out +++ /dev/null @@ -1 +0,0 @@ -Cube is not solvable diff --git a/test/01_io/08_unsolved.in b/test/01_io/08_unsolved.in deleted file mode 100644 index c992ce7..0000000 --- a/test/01_io/08_unsolved.in +++ /dev/null @@ -1,6 +0,0 @@ -UL1 DR0 UB0 DL1 -UR0 FR1 DB0 BR0 -UF1 DF0 BL0 FL0 - -UBL0 DLF1 DBR2 UFR1 -DFR1 UBR1 UFL0 DBL0 diff --git a/test/01_io/08_unsolved.out b/test/01_io/08_unsolved.out deleted file mode 100644 index 8c132cf..0000000 --- a/test/01_io/08_unsolved.out +++ /dev/null @@ -1 +0,0 @@ -UL1 DR0 UB0 DL1 UR0 FR1 DB0 BR0 UF1 DF0 BL0 FL0 UBL0 DFL1 DBR2 UFR1 DFR1 UBR1 UFL0 DBL0 diff --git a/test/01_io/io_tests.c b/test/01_io/io_tests.c deleted file mode 100644 index 913ec1d..0000000 --- a/test/01_io/io_tests.c +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include -#include - -#include "../../src/cube.h" - -#define STRLENMAX 10000 - -int main() { - char *c, str[STRLENMAX]; - cube_t cube; - - for (c = str; (*c = getchar()) != EOF; c++) ; - *c = '\0'; - - cube = readcube(str); - - if (iserror(cube)) { - printf("Error reading cube\n"); - } else if (!issolvable(cube)) { - printf("Cube is not solvable\n"); - } else { - writecube(cube, str); - printf("%s\n", str); - } - - return 0; -} diff --git a/test/02_move/move_tests.c b/test/02_move/move_tests.c index 333c8ee..054466b 100644 --- a/test/02_move/move_tests.c +++ b/test/02_move/move_tests.c @@ -22,7 +22,7 @@ int main() { } fgets(str, STRLENMAX, stdin); - cube = readcube(str); + cube = readcube(H48, str); for (i = 0; i < n; i++) cube = move(cube, moves[i]); @@ -32,7 +32,7 @@ int main() { } else if (!issolvable(cube)) { printf("Moved cube is not solvable\n"); } else { - writecube(cube, str); + writecube(H48, cube, str); printf("%s\n", str); } diff --git a/test/03_inverse/inverse_tests.c b/test/03_inverse/inverse_tests.c index c8d8d95..0a56568 100644 --- a/test/03_inverse/inverse_tests.c +++ b/test/03_inverse/inverse_tests.c @@ -11,7 +11,7 @@ int main() { cube_t cube, inv; fgets(str, STRLENMAX, stdin); - cube = readcube(str); + cube = readcube(H48, str); inv = inverse(cube); if (iserror(inv)) { @@ -19,7 +19,7 @@ int main() { } else if (!issolvable(inv)) { printf("Inverted cube is not solvable\n"); } else { - writecube(inv, str); + writecube(H48, inv, str); printf("%s\n", str); } diff --git a/test/04_compose/compose_tests.c b/test/04_compose/compose_tests.c index 575c2c9..a4a5f00 100644 --- a/test/04_compose/compose_tests.c +++ b/test/04_compose/compose_tests.c @@ -11,9 +11,9 @@ int main() { cube_t c1, c2, c3; fgets(str, STRLENMAX, stdin); - c1 = readcube(str); + c1 = readcube(H48, str); fgets(str, STRLENMAX, stdin); - c2 = readcube(str); + c2 = readcube(H48, str); c3 = compose(c1, c2); @@ -22,7 +22,7 @@ int main() { } else if (!issolvable(c3)) { printf("Composed cube is not solvable\n"); } else { - writecube(c3, str); + writecube(H48, c3, str); printf("%s\n", str); } diff --git a/test/test.sh b/test/test.sh index 5e17d33..9eae127 100755 --- a/test/test.sh +++ b/test/test.sh @@ -11,7 +11,7 @@ TESTOUT="test/last.out" TESTERR="test/last.err" CUBEOBJ="test/cube.o" -$CC -c $SRC -o $CUBEOBJ +$CC -c $SRC -o $CUBEOBJ || exit 1 for t in test/*; do if [ ! -d $t ]; then continue; fi diff --git a/utils/FORMAT.txt b/utils/FORMAT.txt index 74e7442..091104c 100644 --- a/utils/FORMAT.txt +++ b/utils/FORMAT.txt @@ -1,4 +1,8 @@ -The functions readcube() and writecube() use the following format. +The functions readcube() and writecube() use different formats to read +and write a cube to text. Not all formats are supported for both input +and output. + +# H48 - standard format for h48 (read, write) Each edge is represented by two letters denoting the sides it belongs to and one number denoting its orientation (0 oriented, 1 mis-oriented). @@ -21,4 +25,11 @@ The cube after the moves R'U'F looks like this: FL1 BR0 DB0 UR1 UF0 UB0 DL0 FR0 UL1 DF1 BL0 DR0 UBL1 DBR1 UFR2 DFR2 DFL2 UBL2 UFL2 DBL0 -More formats might be supported in the future. +# SRC - representation of the object in C code (write) + +The exact format depends on the internal cube representation. It is +guaranteed that, if OUT is the output in this format, the line + +cube_t cube = OUT; + +is interpreted correctly by h48. -- cgit v1.3