aboutsummaryrefslogtreecommitdiff
path: root/tests/fst_tests.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/fst_tests.c')
-rw-r--r--tests/fst_tests.c184
1 files changed, 0 insertions, 184 deletions
diff --git a/tests/fst_tests.c b/tests/fst_tests.c
deleted file mode 100644
index 1a9bedd..0000000
--- a/tests/fst_tests.c
+++ /dev/null
@@ -1,184 +0,0 @@
1#include "fst_tests.h"
2
3static bool testmethod_fst_is_consistent(void *);
4static bool testmethod_cube_to_fst_to_cube(void *);
5static bool testmethod_fst_move(void *);
6static bool testmethod_fst_inverse(void *);
7static bool check_equal_and_log(Cube *, Cube *);
8static void void_to_cube(void *, Cube *);
9
10char *algs[] = {
11 "",
12 "U", "U2", "U'", "D", "D2", "D'", "R", "R2", "R'",
13 "L", "L2", "L'", "F", "F2", "F'", "B", "B2", "B'",
14 "U2 R2 U2 R2 U2",
15 "U2 F2 R2 B2 U2 D2 F2 L2 B2",
16 "RUR'URU2R'",
17 "L2 D R U2 B2 L",
18 "R'U'F",
19 "F2 U' R2 D' B2 D2 R2 D2 R2 U' F L' U' R B F2 R B' D2",
20 "D L2 F2 R2 D R2 U L2 U' B2 D L' F2 U2 B' L D' U' R' B2 F2",
21 "F' L2 F' D' R F2 L U L' D2 R2 F2 D2 R2 B' L2 B2 U2 F D2 B",
22 NULL,
23};
24
25Test test_fst_is_consistent = {
26 .name = "Consitency of FST (converted from cube)",
27 .t = testmethod_fst_is_consistent,
28 .cases = (void **)algs,
29};
30Test test_cube_to_fst_to_cube = {
31 .name = "Cube to FST to cube",
32 .t = testmethod_cube_to_fst_to_cube,
33 .cases = (void **)algs,
34};
35Test test_fst_move = {
36 .name = "FST move",
37 .t = testmethod_fst_move,
38 .cases = (void **)algs,
39};
40Test test_fst_inverse = {
41 .name = "FST inverse",
42 .t = testmethod_fst_inverse,
43 .cases = (void **)algs,
44};
45
46Test *fst_pre_init[] = {
47 &test_fst_is_consistent,
48 &test_cube_to_fst_to_cube,
49 NULL
50};
51TestSuite fst_pre_init_suite = {
52 .setup = NULL,
53 .tests = fst_pre_init,
54 .teardown = NULL,
55};
56
57Test *fst_post_init[] = {
58 &test_fst_move,
59 &test_fst_inverse,
60 NULL
61};
62TestSuite fst_post_init_suite = {
63 .setup = init_fst,
64 .tests = fst_post_init,
65 .teardown = NULL,
66};
67
68TestSuite *fst_suites[] = {
69 &fst_pre_init_suite,
70 &fst_post_init_suite,
71 NULL
72};
73
74static bool
75check_equal_and_log(Cube *c, Cube *d)
76{
77 bool ret = equal(c, d);
78
79 if (!ret) {
80 printf("\n");
81 printf("These cubes should be equal, but are not:\n\n");
82 print_cube(c);
83 printf("\n");
84 print_cube(d);
85 printf("\n");
86 }
87
88 return ret;
89}
90
91static void
92void_to_cube(void *a, Cube *c)
93{
94 char *algstr;
95 Alg *alg;
96
97 algstr = (char *)a;
98 alg = new_alg(algstr);
99 make_solved(c);
100 apply_alg(alg, c);
101 free_alg(alg);
102}
103
104bool
105testmethod_fst_is_consistent(void *a)
106{
107 FstCube fst_uf, fst_fr, fst_rd;
108 Cube c, c_fr, c_rd;
109 bool consistent_fr, consistent_rd, result;
110
111 void_to_cube(a, &c);
112 copy_cube(&c, &c_fr);
113 apply_trans(fr, &c_fr);
114
115 copy_cube(&c, &c_rd);
116 apply_trans(rd, &c_rd);
117
118 fst_uf = cube_to_fst(&c);
119 fst_fr = cube_to_fst(&c_fr);
120 fst_rd = cube_to_fst(&c_rd);
121
122 consistent_fr = fst_uf.fr_eofb == fst_fr.uf_eofb &&
123 fst_uf.fr_eposepe == fst_fr.uf_eposepe &&
124 fst_uf.fr_coud == fst_fr.uf_coud;
125
126 consistent_rd = fst_uf.rd_eofb == fst_rd.uf_eofb &&
127 fst_uf.rd_eposepe == fst_rd.uf_eposepe &&
128 fst_uf.rd_coud == fst_rd.uf_coud;
129
130 result = consistent_fr && consistent_rd;
131
132 if (!result)
133 printf("\nFailed with alg %s\n", (char *)a);
134
135 return result;
136}
137
138bool
139testmethod_cube_to_fst_to_cube(void *a)
140{
141 Cube c, d;
142 FstCube fst;
143
144 void_to_cube(a, &c);
145 fst = cube_to_fst(&c);
146 fst_to_cube(fst, &d);
147
148 return check_equal_and_log(&c, &d);;
149}
150
151bool
152testmethod_fst_move(void *a)
153{
154 int i;
155 Alg *alg;
156 Cube c, d;
157 FstCube fst;
158
159 void_to_cube(a, &c);
160 alg = new_alg((char *)a);
161 make_solved(&d);
162 fst = cube_to_fst(&d);
163
164 for (i = 0; i < alg->len; i++)
165 fst = fst_move(alg->move[i], fst);
166
167 fst_to_cube(fst, &d);
168
169 free_alg(alg);
170
171 return check_equal_and_log(&c, &d);
172}
173
174bool
175testmethod_fst_inverse(void *a)
176{
177 Cube c, d;
178
179 void_to_cube(a, &c);
180 fst_to_cube(fst_inverse(cube_to_fst(&c)), &d);
181 invert_cube(&c);
182
183 return check_equal_and_log(&c, &d);
184}

Generated with cgit - Back to sebastiano.tronto.net