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.c131
1 files changed, 131 insertions, 0 deletions
diff --git a/tests/fst_tests.c b/tests/fst_tests.c
new file mode 100644
index 0000000..14aee1c
--- /dev/null
+++ b/tests/fst_tests.c
@@ -0,0 +1,131 @@
1#include "fst_tests.h"
2
3static bool check_equal_and_log(Cube *, Cube *);
4static void void_to_cube(void *, Cube *);
5
6char *algs[] = {
7 "",
8 "U", "U2", "U'", "D", "D2", "D'", "R", "R2", "R'",
9 "L", "L2", "L'", "F", "F2", "F'", "B", "B2", "B'",
10 "U2 R2 U2 R2 U2",
11 "U2 F2 R2 B2 U2 D2 F2 L2 B2",
12 "RUR'URU2R'",
13 "L2 D R U2 B2 L",
14 "R'U'F",
15 "F2 U' R2 D' B2 D2 R2 D2 R2 U' F L' U' R B F2 R B' D2",
16 "D L2 F2 R2 D R2 U L2 U' B2 D L' F2 U2 B' L D' U' R' B2 F2",
17 "F' L2 F' D' R F2 L U L' D2 R2 F2 D2 R2 B' L2 B2 U2 F D2 B",
18 NULL,
19};
20
21static bool
22check_equal_and_log(Cube *c, Cube *d)
23{
24 bool ret = equal(c, d);
25
26 if (!ret) {
27 printf("\n");
28 printf("These cubes should be equal, but are not:\n\n");
29 print_cube(c);
30 printf("\n");
31 print_cube(d);
32 printf("\n");
33 }
34
35 return ret;
36}
37
38static void
39void_to_cube(void *a, Cube *c)
40{
41 char *algstr;
42 Alg *alg;
43
44 algstr = (char *)a;
45 alg = new_alg(algstr);
46 make_solved(c);
47 apply_alg(alg, c);
48 free_alg(alg);
49}
50
51bool
52testmethod_fst_is_consistent(void *a)
53{
54 FstCube fst_uf, fst_fr, fst_rd;
55 Cube c, c_fr, c_rd;
56 bool consistent_fr, consistent_rd, result;
57
58 void_to_cube(a, &c);
59 copy_cube(&c, &c_fr);
60 apply_trans(fr, &c_fr);
61
62 copy_cube(&c, &c_rd);
63 apply_trans(rd, &c_rd);
64
65 fst_uf = cube_to_fst(&c);
66 fst_fr = cube_to_fst(&c_fr);
67 fst_rd = cube_to_fst(&c_rd);
68
69 consistent_fr = fst_uf.fr_eofb == fst_fr.uf_eofb &&
70 fst_uf.fr_eposepe == fst_fr.uf_eposepe &&
71 fst_uf.fr_coud == fst_fr.uf_coud;
72
73 consistent_rd = fst_uf.rd_eofb == fst_rd.uf_eofb &&
74 fst_uf.rd_eposepe == fst_rd.uf_eposepe &&
75 fst_uf.rd_coud == fst_rd.uf_coud;
76
77 result = consistent_fr && consistent_rd;
78
79 if (!result)
80 printf("\nFailed with alg %s\n", (char *)a);
81
82 return result;
83}
84
85bool
86testmethod_cube_to_fst_to_cube(void *a)
87{
88 Cube c, d;
89 FstCube fst;
90
91 void_to_cube(a, &c);
92 fst = cube_to_fst(&c);
93 fst_to_cube(fst, &d);
94
95 return check_equal_and_log(&c, &d);;
96}
97
98bool
99testmethod_fst_move(void *a)
100{
101 int i;
102 Alg *alg;
103 Cube c, d;
104 FstCube fst;
105
106 void_to_cube(a, &d);
107 alg = new_alg((char *)a);
108 make_solved(&d);
109 fst = cube_to_fst(&d);
110
111 for (i = 0; i < alg->len; i++)
112 fst = fst_move(alg->move[i], fst);
113
114 fst_to_cube(fst, &d);
115
116 free_alg(alg);
117
118 return check_equal_and_log(&c, &d);
119}
120
121bool
122testmethod_fst_inverse(void *a)
123{
124 Cube c, d;
125
126 void_to_cube(a, &c);
127 fst_to_cube(fst_inverse(cube_to_fst(&c)), &d);
128 invert_cube(&c);
129
130 return check_equal_and_log(&c, &d);
131}

Generated with cgit - Back to sebastiano.tronto.net