diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2023-09-08 18:28:30 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2023-09-08 18:28:30 +0200 |
| commit | 4d08bf731a099de2d174c73489636e1a12935aee (patch) | |
| tree | c751858cb6e33172c97a1123432f7c59d7d94d7e /test | |
| parent | c5dfc897160bc9bbc6a91c77b5d58d421fd1cfe1 (diff) | |
| download | nissy-core-4d08bf731a099de2d174c73489636e1a12935aee.tar.gz nissy-core-4d08bf731a099de2d174c73489636e1a12935aee.zip | |
New implementation, moved old to experiments/
Diffstat (limited to '')
| -rw-r--r-- | test/00_basic/all.out | 3 | ||||
| -rw-r--r-- | test/00_basic/basic_tests.c | 27 | ||||
| -rw-r--r-- | test/01_io/io_tests.c | 2 | ||||
| -rw-r--r-- | test/02_move/move_tests.c | 2 | ||||
| -rw-r--r-- | test/03_inverse/00_solved.in | 1 | ||||
| -rw-r--r-- | test/03_inverse/00_solved.out | 1 | ||||
| -rw-r--r-- | test/03_inverse/01_scrambled.in | 1 | ||||
| -rw-r--r-- | test/03_inverse/01_scrambled.out | 1 | ||||
| -rw-r--r-- | test/03_inverse/inverse_tests.c | 27 | ||||
| -rwxr-xr-x | test/test.sh | 2 |
10 files changed, 57 insertions, 10 deletions
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 | |||
| 2 | Solved is solved | 2 | Solved is solved |
| 3 | Zero is NOT consistent | 3 | Zero is NOT consistent |
| 4 | Zero is NOT solved | 4 | Zero is NOT solved |
| 5 | Solved and Solved are equal | ||
| 6 | Solved and Zero are NOT equal | ||
| 7 | 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 @@ | |||
| 4 | 4 | ||
| 5 | #include "../../src/cube.h" | 5 | #include "../../src/cube.h" |
| 6 | 6 | ||
| 7 | void | ||
| 8 | check(cube_t cube, char *name) | ||
| 9 | { | ||
| 10 | printf("%s is%s consistent\n", name, isconsistent(cube) ? "" : " NOT"); | ||
| 11 | printf("%s is%s solved\n", name, issolved(cube) ? "" : " NOT"); | ||
| 12 | } | ||
| 13 | |||
| 14 | void | ||
| 15 | check2(cube_t cube1, char *name1, cube_t cube2, char *name2) | ||
| 16 | { | ||
| 17 | printf("%s and %s are%s equal\n", name1, name2, | ||
| 18 | equal(cube1, cube2) ? "" : " NOT"); | ||
| 19 | } | ||
| 20 | |||
| 7 | int main() { | 21 | int main() { |
| 8 | cube_t z, s; | 22 | cube_t zero = (cube_t){0}; |
| 9 | 23 | ||
| 10 | s = solvedcube; | 24 | check(solvedcube, "Solved"); |
| 11 | printf("Solved %s consistent\n", isconsistent(s) ? "is" : "is NOT"); | 25 | check(zero, "Zero"); |
| 12 | printf("Solved %s solved\n", issolved(s) ? "is" : "is NOT"); | ||
| 13 | 26 | ||
| 14 | z = (cube_t){0}; | 27 | check2(solvedcube, "Solved", solvedcube, "Solved"); |
| 15 | printf("Zero %s consistent\n", isconsistent(z) ? "is" : "is NOT"); | 28 | check2(solvedcube, "Solved", zero, "Zero"); |
| 16 | printf("Zero %s solved\n", issolved(z) ? "is" : "is NOT"); | 29 | check2(zero, "Zero", solvedcube, "Solved"); |
| 17 | 30 | ||
| 18 | return 0; | 31 | return 0; |
| 19 | } | 32 | } |
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() { | |||
| 15 | 15 | ||
| 16 | cube = readcube(str); | 16 | cube = readcube(str); |
| 17 | 17 | ||
| 18 | if (cube.e == errorcube.e && cube.c == errorcube.c) { | 18 | if (iserror(cube)) { |
| 19 | printf("Error reading cube\n"); | 19 | printf("Error reading cube\n"); |
| 20 | } else if (!isconsistent(cube)) { | 20 | } else if (!isconsistent(cube)) { |
| 21 | printf("Cube is inconsistent\n"); | 21 | 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() { | |||
| 27 | for (i = 0; i < n; i++) | 27 | for (i = 0; i < n; i++) |
| 28 | cube = move(cube, moves[i]); | 28 | cube = move(cube, moves[i]); |
| 29 | 29 | ||
| 30 | if (cube.e == errorcube.e && cube.c == errorcube.c) { | 30 | if (iserror(cube)) { |
| 31 | printf("Error moving cube\n"); | 31 | printf("Error moving cube\n"); |
| 32 | } else if (!isconsistent(cube)) { | 32 | } else if (!isconsistent(cube)) { |
| 33 | printf("Moved cube is inconsistent\n"); | 33 | 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 @@ | |||
| 1 | #include <stdbool.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | #include <stdio.h> | ||
| 4 | |||
| 5 | #include "../../src/cube.h" | ||
| 6 | |||
| 7 | #define STRLENMAX 10000 | ||
| 8 | |||
| 9 | int main() { | ||
| 10 | char str[STRLENMAX]; | ||
| 11 | cube_t cube, inv; | ||
| 12 | |||
| 13 | fgets(str, STRLENMAX, stdin); | ||
| 14 | cube = readcube(str); | ||
| 15 | inv = inverse(cube); | ||
| 16 | |||
| 17 | if (iserror(inv)) { | ||
| 18 | printf("Error inverting cube\n"); | ||
| 19 | } else if (!isconsistent(inv)) { | ||
| 20 | printf("Inverted cube is inconsistent\n"); | ||
| 21 | } else { | ||
| 22 | writecube(inv, str); | ||
| 23 | printf("%s\n", str); | ||
| 24 | } | ||
| 25 | |||
| 26 | return 0; | ||
| 27 | } | ||
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 \ | |||
| 5 | if [ $(uname) != "OpenBSD" ]; then | 5 | if [ $(uname) != "OpenBSD" ]; then |
| 6 | CC="$CC -fsanitize=address -fsanitize=undefined" | 6 | CC="$CC -fsanitize=address -fsanitize=undefined" |
| 7 | fi | 7 | fi |
| 8 | SRC="src/cube.c" | 8 | SRC="src/array_cube.c" |
| 9 | TESTBIN="test/run" | 9 | TESTBIN="test/run" |
| 10 | TESTOUT="test/last.out" | 10 | TESTOUT="test/last.out" |
| 11 | TESTERR="test/last.err" | 11 | TESTERR="test/last.err" |
