diff options
Diffstat (limited to 'tests/test_fst.c')
| -rw-r--r-- | tests/test_fst.c | 184 |
1 files changed, 0 insertions, 184 deletions
diff --git a/tests/test_fst.c b/tests/test_fst.c deleted file mode 100644 index ad1caba..0000000 --- a/tests/test_fst.c +++ /dev/null | |||
| @@ -1,184 +0,0 @@ | |||
| 1 | #include "inc.h" | ||
| 2 | #include "../src/fst.h" | ||
| 3 | |||
| 4 | static bool cube_to_fst_to_cube(Cube *c, Alg *a); | ||
| 5 | static bool fst_consistent(Cube *c, Alg *a); | ||
| 6 | static bool fst_move_test(Cube *c, Alg *a); | ||
| 7 | static bool fst_inverse_test(Cube *c, Alg *a); | ||
| 8 | static bool try_str(CubeTester f, char *algstr, char *msg); | ||
| 9 | static bool try_all_str(CubeTester f, char *msg); | ||
| 10 | |||
| 11 | static bool test_fst_consistent_algs(); | ||
| 12 | static bool test_cube_to_fst_to_cube_algs(); | ||
| 13 | static bool test_fst_move_algs(); | ||
| 14 | static bool test_fst_inverse_algs(); | ||
| 15 | |||
| 16 | static Tester test[] = { | ||
| 17 | test_fst_consistent_algs, | ||
| 18 | test_cube_to_fst_to_cube_algs, | ||
| 19 | test_fst_move_algs, | ||
| 20 | test_fst_inverse_algs, | ||
| 21 | NULL | ||
| 22 | }; | ||
| 23 | |||
| 24 | static char *name[] = { | ||
| 25 | "Consistency of FST (converted from cube)", | ||
| 26 | "Cube to FST to cube", | ||
| 27 | "FST move", | ||
| 28 | "FST inverse", | ||
| 29 | }; | ||
| 30 | |||
| 31 | static char *algs[] = { | ||
| 32 | "", | ||
| 33 | "U", "U2", "U'", "D", "D2", "D'", "R", "R2", "R'", | ||
| 34 | "L", "L2", "L'", "F", "F2", "F'", "B", "B2", "B'", | ||
| 35 | "U2 R2 U2 R2 U2", | ||
| 36 | "U2 F2 R2 B2 U2 D2 F2 L2 B2", | ||
| 37 | "RUR'URU2R'", | ||
| 38 | "L2 D R U2 B2 L", | ||
| 39 | "R'U'F", | ||
| 40 | "F2 U' R2 D' B2 D2 R2 D2 R2 U' F L' U' R B F2 R B' D2", | ||
| 41 | "D L2 F2 R2 D R2 U L2 U' B2 D L' F2 U2 B' L D' U' R' B2 F2", | ||
| 42 | "F' L2 F' D' R F2 L U L' D2 R2 F2 D2 R2 B' L2 B2 U2 F D2 B", | ||
| 43 | NULL, | ||
| 44 | }; | ||
| 45 | |||
| 46 | static bool | ||
| 47 | fst_consistent(Cube *c, Alg *a) | ||
| 48 | { | ||
| 49 | FstCube fst; | ||
| 50 | |||
| 51 | fst = cube_to_fst(c); | ||
| 52 | |||
| 53 | /* TODO: check consistency of fr_* and rd_* with uf_* */ | ||
| 54 | |||
| 55 | return true; | ||
| 56 | } | ||
| 57 | |||
| 58 | static bool | ||
| 59 | cube_to_fst_to_cube(Cube *c, Alg *a) | ||
| 60 | { | ||
| 61 | Cube d; | ||
| 62 | FstCube fst; | ||
| 63 | |||
| 64 | fst = cube_to_fst(c); | ||
| 65 | fst_to_cube(fst, &d); | ||
| 66 | |||
| 67 | if (!equal(c, &d)) { | ||
| 68 | printf("Cubes are different:\n\n"); | ||
| 69 | printf("Cube 1:\n"); | ||
| 70 | print_cube(c); | ||
| 71 | printf("\nCube 2:\n"); | ||
| 72 | print_cube(&d); | ||
| 73 | printf("\n"); | ||
| 74 | return false; | ||
| 75 | } | ||
| 76 | |||
| 77 | return true; | ||
| 78 | } | ||
| 79 | |||
| 80 | static bool | ||
| 81 | fst_move_test(Cube *c, Alg *a) | ||
| 82 | { | ||
| 83 | int i; | ||
| 84 | Cube d; | ||
| 85 | FstCube fst; | ||
| 86 | |||
| 87 | fst = cube_to_fst(c); | ||
| 88 | |||
| 89 | for (i = 0; i < a->len; i++) { | ||
| 90 | if (a->inv[i] || a->move[i] > B3) { | ||
| 91 | printf("Cannot apply the following alg to FST: "); | ||
| 92 | print_alg(a, false); | ||
| 93 | return false; | ||
| 94 | } | ||
| 95 | fst = fst_move(a->move[i], fst); | ||
| 96 | } | ||
| 97 | |||
| 98 | fst_to_cube(fst, &d); | ||
| 99 | |||
| 100 | return equal(c, &d); | ||
| 101 | } | ||
| 102 | |||
| 103 | static bool | ||
| 104 | fst_inverse_test(Cube *c, Alg *a) | ||
| 105 | { | ||
| 106 | Cube d; | ||
| 107 | |||
| 108 | fst_to_cube(fst_inverse(cube_to_fst(c)), &d); | ||
| 109 | invert_cube(c); | ||
| 110 | |||
| 111 | return equal(c, &d); | ||
| 112 | } | ||
| 113 | |||
| 114 | static bool | ||
| 115 | try_str(CubeTester f, char *algstr, char *msg) | ||
| 116 | { | ||
| 117 | bool b; | ||
| 118 | Alg *a; | ||
| 119 | Cube c; | ||
| 120 | |||
| 121 | a = new_alg(algstr); | ||
| 122 | make_solved(&c); | ||
| 123 | apply_alg(a, &c); | ||
| 124 | |||
| 125 | if (!(b = f(&c, a))) | ||
| 126 | printf("%s with alg %s\n", msg, algstr); | ||
| 127 | |||
| 128 | free_alg(a); | ||
| 129 | |||
| 130 | return b; | ||
| 131 | } | ||
| 132 | |||
| 133 | static bool | ||
| 134 | try_all_str(CubeTester f, char *msg) | ||
| 135 | { | ||
| 136 | bool b; | ||
| 137 | int i; | ||
| 138 | |||
| 139 | b = true; | ||
| 140 | for (i = 0; algs[i] != NULL; i++) | ||
| 141 | b = b && try_str(f, algs[i], msg); | ||
| 142 | |||
| 143 | return b; | ||
| 144 | } | ||
| 145 | |||
| 146 | static bool | ||
| 147 | test_cube_to_fst_to_cube_algs() | ||
| 148 | { | ||
| 149 | return try_all_str(cube_to_fst_to_cube, "Cube to FST to cube failed"); | ||
| 150 | } | ||
| 151 | |||
| 152 | static bool | ||
| 153 | test_fst_consistent_algs() | ||
| 154 | { | ||
| 155 | return try_all_str(fst_consistent, "FST from cube not consistent"); | ||
| 156 | } | ||
| 157 | |||
| 158 | static bool | ||
| 159 | test_fst_move_algs() | ||
| 160 | { | ||
| 161 | return try_all_str(fst_move_test, "FST move incorrect"); | ||
| 162 | } | ||
| 163 | |||
| 164 | static bool | ||
| 165 | test_fst_inverse_algs() | ||
| 166 | { | ||
| 167 | return try_all_str(fst_inverse_test, "FST test incorrect"); | ||
| 168 | } | ||
| 169 | |||
| 170 | void test_fst_all() { | ||
| 171 | int i; | ||
| 172 | |||
| 173 | init_trans(); | ||
| 174 | |||
| 175 | for (i = 0; test[i] != NULL; i++) { | ||
| 176 | printf("Test: %s\n", name[i]); | ||
| 177 | if (!test[i]()) { | ||
| 178 | printf("Failed!\n"); | ||
| 179 | exit(1); | ||
| 180 | } | ||
| 181 | printf("Passed.\n\n"); | ||
| 182 | } | ||
| 183 | printf("All FST tests passed.\n\n"); | ||
| 184 | } | ||
