From 445364a4b495c275e2723a05e7f4be0090ba5d0a Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Sun, 9 Oct 2022 18:12:39 +0200 Subject: Finished fst, added tests. STILL NOT WORKING. --- tests/inc.h | 1 + tests/test_all.c | 10 +++++++ tests/test_fst.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 tests/inc.h create mode 100644 tests/test_all.c create mode 100644 tests/test_fst.c (limited to 'tests') diff --git a/tests/inc.h b/tests/inc.h new file mode 100644 index 0000000..53c5fdf --- /dev/null +++ b/tests/inc.h @@ -0,0 +1 @@ +#include diff --git a/tests/test_all.c b/tests/test_all.c new file mode 100644 index 0000000..4daeec0 --- /dev/null +++ b/tests/test_all.c @@ -0,0 +1,10 @@ +#include "inc.h" + +void test_fst_all(); + +int main() { + test_fst_all(); + + printf("All tests passed.\n"); + return 0; +} diff --git a/tests/test_fst.c b/tests/test_fst.c new file mode 100644 index 0000000..fc1185c --- /dev/null +++ b/tests/test_fst.c @@ -0,0 +1,88 @@ +#include "inc.h" +#include "../src/fst.h" + +static bool test_cube_to_fst_to_cube(Cube *c); + +static bool test_cube_to_fst_to_cube_solved(); +static bool test_cube_to_fst_to_cube_unsolved(); + +static Tester test[] = { + test_cube_to_fst_to_cube_solved, + test_cube_to_fst_to_cube_unsolved, + NULL +}; + +static char *name[] = { + "Cube to FST to cube (solved)", + "Cube to FST to cube (unsolved)", +}; + +static bool +test_cube_to_fst_to_cube(Cube *c) +{ + Cube d; + FstCube fst; + + fst = cube_to_fst(c); + fst_to_cube(fst, &d); + + return equal(c, &d); +} + +static bool +test_cube_to_fst_to_cube_solved() +{ + Cube c; + + make_solved(&c); + return test_cube_to_fst_to_cube(&c); +} + +static bool +test_cube_to_fst_to_cube_unsolved() +{ + bool b; + int i; + Alg *a; + Cube c; + char *algs[] = { + "U2 R2 U2 R2 U2", + "U2 F2 R2 B2 U2 D2 F2 L2 B2", + "RUR'URU2R'", + "L2 D R U2 B2 L", + "R'U'F", + "F2 U' R2 D' B2 D2 R2 D2 R2 U' F L' U' R B F2 R B' D2", + "D L2 F2 R2 D R2 U L2 U' B2 D L' F2 U2 B' L D' U' R' B2 F2", + "F' L2 F' D' R F2 L U L' D2 R2 F2 D2 R2 B' L2 B2 U2 F D2 B", + NULL, + }; + + for (i = 0; algs[i] != NULL; i++) { + make_solved(&c); + a = new_alg(algs[i]); + apply_alg(a, &c); + b = test_cube_to_fst_to_cube(&c); + free_alg(a); + if (!b) { + printf("Failed with alg %s\n", algs[i]); + return false; + } + } + return true; +} + +void test_fst_all() { + int i; + + init_fst(); + + for (i = 0; test[i] != NULL; i++) { + printf("Test: %s\n", name[i]); + if (!test[i]()) { + printf("Failed!\n"); + exit(1); + } + printf("Passed.\n"); + } + printf("All FST tests passed.\n\n"); +} -- cgit v1.3