From 4d08bf731a099de2d174c73489636e1a12935aee Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Fri, 8 Sep 2023 18:28:30 +0200 Subject: New implementation, moved old to experiments/ --- test/00_basic/all.out | 3 +++ test/00_basic/basic_tests.c | 27 ++++++++++++++++++++------- test/01_io/io_tests.c | 2 +- test/02_move/move_tests.c | 2 +- test/03_inverse/00_solved.in | 1 + test/03_inverse/00_solved.out | 1 + test/03_inverse/01_scrambled.in | 1 + test/03_inverse/01_scrambled.out | 1 + test/03_inverse/inverse_tests.c | 27 +++++++++++++++++++++++++++ test/test.sh | 2 +- 10 files changed, 57 insertions(+), 10 deletions(-) create mode 100644 test/03_inverse/00_solved.in create mode 100644 test/03_inverse/00_solved.out create mode 100644 test/03_inverse/01_scrambled.in create mode 100644 test/03_inverse/01_scrambled.out create mode 100644 test/03_inverse/inverse_tests.c (limited to 'test') diff --git a/test/00_basic/all.out b/test/00_basic/all.out index d77f7f4..aad167e 100644 --- a/test/00_basic/all.out +++ b/test/00_basic/all.out @@ -2,3 +2,6 @@ Solved is consistent Solved is solved Zero is NOT consistent Zero is NOT solved +Solved and Solved are equal +Solved and Zero are NOT equal +Zero and Solved are NOT equal diff --git a/test/00_basic/basic_tests.c b/test/00_basic/basic_tests.c index cc2a55c..8c52941 100644 --- a/test/00_basic/basic_tests.c +++ b/test/00_basic/basic_tests.c @@ -4,16 +4,29 @@ #include "../../src/cube.h" +void +check(cube_t cube, char *name) +{ + printf("%s is%s consistent\n", name, isconsistent(cube) ? "" : " NOT"); + printf("%s is%s solved\n", name, issolved(cube) ? "" : " NOT"); +} + +void +check2(cube_t cube1, char *name1, cube_t cube2, char *name2) +{ + printf("%s and %s are%s equal\n", name1, name2, + equal(cube1, cube2) ? "" : " NOT"); +} + int main() { - cube_t z, s; + cube_t zero = (cube_t){0}; - s = solvedcube; - printf("Solved %s consistent\n", isconsistent(s) ? "is" : "is NOT"); - printf("Solved %s solved\n", issolved(s) ? "is" : "is NOT"); + check(solvedcube, "Solved"); + check(zero, "Zero"); - z = (cube_t){0}; - printf("Zero %s consistent\n", isconsistent(z) ? "is" : "is NOT"); - printf("Zero %s solved\n", issolved(z) ? "is" : "is NOT"); + check2(solvedcube, "Solved", solvedcube, "Solved"); + check2(solvedcube, "Solved", zero, "Zero"); + check2(zero, "Zero", solvedcube, "Solved"); return 0; } diff --git a/test/01_io/io_tests.c b/test/01_io/io_tests.c index 1ef99d0..42ef9b8 100644 --- a/test/01_io/io_tests.c +++ b/test/01_io/io_tests.c @@ -15,7 +15,7 @@ int main() { cube = readcube(str); - if (cube.e == errorcube.e && cube.c == errorcube.c) { + if (iserror(cube)) { printf("Error reading cube\n"); } else if (!isconsistent(cube)) { printf("Cube is inconsistent\n"); diff --git a/test/02_move/move_tests.c b/test/02_move/move_tests.c index 23fc45e..ac25de3 100644 --- a/test/02_move/move_tests.c +++ b/test/02_move/move_tests.c @@ -27,7 +27,7 @@ int main() { for (i = 0; i < n; i++) cube = move(cube, moves[i]); - if (cube.e == errorcube.e && cube.c == errorcube.c) { + if (iserror(cube)) { printf("Error moving cube\n"); } else if (!isconsistent(cube)) { printf("Moved cube is inconsistent\n"); diff --git a/test/03_inverse/00_solved.in b/test/03_inverse/00_solved.in new file mode 100644 index 0000000..dff224d --- /dev/null +++ b/test/03_inverse/00_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/03_inverse/00_solved.out b/test/03_inverse/00_solved.out new file mode 100644 index 0000000..dff224d --- /dev/null +++ b/test/03_inverse/00_solved.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/03_inverse/01_scrambled.in b/test/03_inverse/01_scrambled.in new file mode 100644 index 0000000..263213b --- /dev/null +++ b/test/03_inverse/01_scrambled.in @@ -0,0 +1 @@ +DR0 DB0 BL0 DF1 UB0 UR1 FR1 UF0 FL1 DL0 BR1 UL1 DBL2 DFL0 UBR1 DFR2 UFR0 DBR1 UBL0 UFL0 diff --git a/test/03_inverse/01_scrambled.out b/test/03_inverse/01_scrambled.out new file mode 100644 index 0000000..25089c6 --- /dev/null +++ b/test/03_inverse/01_scrambled.out @@ -0,0 +1 @@ +DR0 UR0 UB0 DF1 UL1 BR1 FL0 UF0 DL1 FR1 DB0 BL1 UFL0 DFR0 UBL0 UBR2 DBL0 DFL2 DBR1 UFR1 diff --git a/test/03_inverse/inverse_tests.c b/test/03_inverse/inverse_tests.c new file mode 100644 index 0000000..5fab71a --- /dev/null +++ b/test/03_inverse/inverse_tests.c @@ -0,0 +1,27 @@ +#include +#include +#include + +#include "../../src/cube.h" + +#define STRLENMAX 10000 + +int main() { + char str[STRLENMAX]; + cube_t cube, inv; + + fgets(str, STRLENMAX, stdin); + cube = readcube(str); + inv = inverse(cube); + + if (iserror(inv)) { + printf("Error inverting cube\n"); + } else if (!isconsistent(inv)) { + printf("Inverted cube is inconsistent\n"); + } else { + writecube(inv, str); + printf("%s\n", str); + } + + return 0; +} diff --git a/test/test.sh b/test/test.sh index d59270b..75be809 100755 --- a/test/test.sh +++ b/test/test.sh @@ -5,7 +5,7 @@ CC="cc -DDEBUG -std=c99 -pthread -pedantic -Wall -Wextra \ if [ $(uname) != "OpenBSD" ]; then CC="$CC -fsanitize=address -fsanitize=undefined" fi -SRC="src/cube.c" +SRC="src/array_cube.c" TESTBIN="test/run" TESTOUT="test/last.out" TESTERR="test/last.err" -- cgit v1.3