aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/00_basic/all.out3
-rw-r--r--test/00_basic/basic_tests.c27
-rw-r--r--test/01_io/io_tests.c2
-rw-r--r--test/02_move/move_tests.c2
-rw-r--r--test/03_inverse/00_solved.in1
-rw-r--r--test/03_inverse/00_solved.out1
-rw-r--r--test/03_inverse/01_scrambled.in1
-rw-r--r--test/03_inverse/01_scrambled.out1
-rw-r--r--test/03_inverse/inverse_tests.c27
-rwxr-xr-xtest/test.sh2
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
2Solved is solved 2Solved is solved
3Zero is NOT consistent 3Zero is NOT consistent
4Zero is NOT solved 4Zero is NOT solved
5Solved and Solved are equal
6Solved and Zero are NOT equal
7Zero 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
7void
8check(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
14void
15check2(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
7int main() { 21int 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
9int 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 \
5if [ $(uname) != "OpenBSD" ]; then 5if [ $(uname) != "OpenBSD" ]; then
6 CC="$CC -fsanitize=address -fsanitize=undefined" 6 CC="$CC -fsanitize=address -fsanitize=undefined"
7fi 7fi
8SRC="src/cube.c" 8SRC="src/array_cube.c"
9TESTBIN="test/run" 9TESTBIN="test/run"
10TESTOUT="test/last.out" 10TESTOUT="test/last.out"
11TESTERR="test/last.err" 11TESTERR="test/last.err"

Generated with cgit - Back to sebastiano.tronto.net