aboutsummaryrefslogtreecommitdiff
path: root/tests/fst_post_init_tests.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/fst_post_init_tests.c')
-rw-r--r--tests/fst_post_init_tests.c114
1 files changed, 114 insertions, 0 deletions
diff --git a/tests/fst_post_init_tests.c b/tests/fst_post_init_tests.c
new file mode 100644
index 0000000..653e379
--- /dev/null
+++ b/tests/fst_post_init_tests.c
@@ -0,0 +1,114 @@
1#include "fst_test_util.h"
2
3static bool fst_move_testcase(Cube *c, Alg *a);
4static bool fst_inverse_testcase(Cube *c, Alg *a);
5
6static bool fst_move_test();
7static bool fst_where_is_edge_test();
8static bool fst_inverse_test();
9
10static Tester test[] = {
11 fst_move_test,
12 fst_where_is_edge_test,
13 fst_inverse_test,
14 NULL
15};
16
17static char *name[] = {
18 "FST move",
19 "FST where is edge",
20 "FST inverse",
21};
22
23static bool
24fst_move_testcase(Cube *c, Alg *a)
25{
26 int i;
27 Cube d;
28 FstCube fst;
29
30 make_solved(&d);
31 fst = cube_to_fst(&d);
32
33 for (i = 0; i < a->len; i++) {
34 if (a->inv[i] || a->move[i] > B3) {
35 printf("Cannot apply the following alg to FST: ");
36 print_alg(a, false);
37 return false;
38 }
39 fst = fst_move(a->move[i], fst);
40 }
41
42 fst_to_cube(fst, &d);
43
44 return equal_and_log(c, &d);
45}
46
47static bool
48fst_inverse_testcase(Cube *c, Alg *a)
49{
50 Cube d;
51
52 fst_to_cube(fst_inverse(cube_to_fst(c)), &d);
53 invert_cube(c);
54
55 return equal_and_log(c, &d);
56}
57
58static bool
59fst_move_test()
60{
61 return try_all_str(fst_move_testcase, "FST move incorrect");
62}
63
64static bool
65fst_where_is_edge_test()
66{
67 int i;
68 Alg *scr;
69 Cube c, d;
70 FstCube fst;
71
72 /* Testing on a single scramble is fine for now */
73 scr = new_alg("RUFDL2B2FRD");
74 make_solved(&c);
75 apply_alg(scr, &c);
76 fst = cube_to_fst(&c);
77
78 for (i = 0; i < 12; i++) {
79 if (fst_where_is_edge(c.ep[i], fst) != i) {
80 fst_to_cube(fst, &d);
81 printf("Alg: ");
82 print_alg(scr, false);
83 printf("Expected:\n");
84 print_cube(&c);
85 printf("But got:\n");
86 print_cube(&d);
87 return false;
88 }
89 }
90
91 return true;
92}
93
94static bool
95fst_inverse_test()
96{
97 return try_all_str(fst_inverse_testcase, "FST test incorrect");
98}
99
100void fst_post_init_testall() {
101 int i;
102
103 init_fst();
104
105 for (i = 0; test[i] != NULL; i++) {
106 printf("Test: %s\n", name[i]);
107 if (!test[i]()) {
108 printf("Failed!\n");
109 exit(1);
110 }
111 printf("Passed.\n\n");
112 }
113 printf("All FST post-init tests passed.\n\n");
114}

Generated with cgit - Back to sebastiano.tronto.net