diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2022-10-09 18:12:39 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2022-10-09 18:12:39 +0200 |
| commit | 445364a4b495c275e2723a05e7f4be0090ba5d0a (patch) | |
| tree | bc8b58ccef2efde356dc5f955cb7a08850d8f407 /tests/test_fst.c | |
| parent | 2dce2a8a0ebd95e9e65d9d53206c4b2babc2af2f (diff) | |
| download | nissy-445364a4b495c275e2723a05e7f4be0090ba5d0a.tar.gz nissy-445364a4b495c275e2723a05e7f4be0090ba5d0a.zip | |
Finished fst, added tests. STILL NOT WORKING.
Diffstat (limited to '')
| -rw-r--r-- | tests/test_fst.c | 88 |
1 files changed, 88 insertions, 0 deletions
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 @@ | |||
| 1 | #include "inc.h" | ||
| 2 | #include "../src/fst.h" | ||
| 3 | |||
| 4 | static bool test_cube_to_fst_to_cube(Cube *c); | ||
| 5 | |||
| 6 | static bool test_cube_to_fst_to_cube_solved(); | ||
| 7 | static bool test_cube_to_fst_to_cube_unsolved(); | ||
| 8 | |||
| 9 | static Tester test[] = { | ||
| 10 | test_cube_to_fst_to_cube_solved, | ||
| 11 | test_cube_to_fst_to_cube_unsolved, | ||
| 12 | NULL | ||
| 13 | }; | ||
| 14 | |||
| 15 | static char *name[] = { | ||
| 16 | "Cube to FST to cube (solved)", | ||
| 17 | "Cube to FST to cube (unsolved)", | ||
| 18 | }; | ||
| 19 | |||
| 20 | static bool | ||
| 21 | test_cube_to_fst_to_cube(Cube *c) | ||
| 22 | { | ||
| 23 | Cube d; | ||
| 24 | FstCube fst; | ||
| 25 | |||
| 26 | fst = cube_to_fst(c); | ||
| 27 | fst_to_cube(fst, &d); | ||
| 28 | |||
| 29 | return equal(c, &d); | ||
| 30 | } | ||
| 31 | |||
| 32 | static bool | ||
| 33 | test_cube_to_fst_to_cube_solved() | ||
| 34 | { | ||
| 35 | Cube c; | ||
| 36 | |||
| 37 | make_solved(&c); | ||
| 38 | return test_cube_to_fst_to_cube(&c); | ||
| 39 | } | ||
| 40 | |||
| 41 | static bool | ||
| 42 | test_cube_to_fst_to_cube_unsolved() | ||
| 43 | { | ||
| 44 | bool b; | ||
| 45 | int i; | ||
| 46 | Alg *a; | ||
| 47 | Cube c; | ||
| 48 | char *algs[] = { | ||
| 49 | "U2 R2 U2 R2 U2", | ||
| 50 | "U2 F2 R2 B2 U2 D2 F2 L2 B2", | ||
| 51 | "RUR'URU2R'", | ||
| 52 | "L2 D R U2 B2 L", | ||
| 53 | "R'U'F", | ||
| 54 | "F2 U' R2 D' B2 D2 R2 D2 R2 U' F L' U' R B F2 R B' D2", | ||
| 55 | "D L2 F2 R2 D R2 U L2 U' B2 D L' F2 U2 B' L D' U' R' B2 F2", | ||
| 56 | "F' L2 F' D' R F2 L U L' D2 R2 F2 D2 R2 B' L2 B2 U2 F D2 B", | ||
| 57 | NULL, | ||
| 58 | }; | ||
| 59 | |||
| 60 | for (i = 0; algs[i] != NULL; i++) { | ||
| 61 | make_solved(&c); | ||
| 62 | a = new_alg(algs[i]); | ||
| 63 | apply_alg(a, &c); | ||
| 64 | b = test_cube_to_fst_to_cube(&c); | ||
| 65 | free_alg(a); | ||
| 66 | if (!b) { | ||
| 67 | printf("Failed with alg %s\n", algs[i]); | ||
| 68 | return false; | ||
| 69 | } | ||
| 70 | } | ||
| 71 | return true; | ||
| 72 | } | ||
| 73 | |||
| 74 | void test_fst_all() { | ||
| 75 | int i; | ||
| 76 | |||
| 77 | init_fst(); | ||
| 78 | |||
| 79 | for (i = 0; test[i] != NULL; i++) { | ||
| 80 | printf("Test: %s\n", name[i]); | ||
| 81 | if (!test[i]()) { | ||
| 82 | printf("Failed!\n"); | ||
| 83 | exit(1); | ||
| 84 | } | ||
| 85 | printf("Passed.\n"); | ||
| 86 | } | ||
| 87 | printf("All FST tests passed.\n\n"); | ||
| 88 | } | ||
