aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2022-12-26 12:41:36 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2022-12-26 12:41:36 +0100
commitcecdb7c5a0fc4821bc56c6aae5428925ec1baa15 (patch)
tree5f478c2154ffafe55f1866edd82546d1472fb6c3 /tests
parent1ac26de8dcb76323a5f96eab200a027236cb55d0 (diff)
downloadnissy-cecdb7c5a0fc4821bc56c6aae5428925ec1baa15.tar.gz
nissy-cecdb7c5a0fc4821bc56c6aae5428925ec1baa15.zip
Fixed fst_inverse
Diffstat (limited to 'tests')
-rw-r--r--tests/fst_post_init_tests.c114
-rw-r--r--tests/fst_pre_init_tests.c89
-rw-r--r--tests/fst_test_util.c64
-rw-r--r--tests/fst_test_util.h7
-rw-r--r--tests/inc.h1
-rw-r--r--tests/nissy_tests.c12
-rw-r--r--tests/test_all.c10
-rw-r--r--tests/test_fst.c184
8 files changed, 286 insertions, 195 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}
diff --git a/tests/fst_pre_init_tests.c b/tests/fst_pre_init_tests.c
new file mode 100644
index 0000000..6b7a440
--- /dev/null
+++ b/tests/fst_pre_init_tests.c
@@ -0,0 +1,89 @@
1#include "fst_test_util.h"
2
3static bool cube_to_fst_to_cube_testcase(Cube *c, Alg *a);
4static bool fst_is_consistent_testcase(Cube *c, Alg *a);
5
6static bool fst_is_consistent_test();
7static bool cube_to_fst_to_cube_test();
8
9static Tester test[] = {
10 fst_is_consistent_test,
11 cube_to_fst_to_cube_test,
12 NULL
13};
14
15static char *name[] = {
16 "Consistency of FST (converted from cube)",
17 "Cube to FST to cube",
18};
19
20static bool
21fst_is_consistent_testcase(Cube *c, Alg *a)
22{
23 FstCube fst_uf, fst_fr, fst_rd;
24 Cube c_fr, c_rd;
25 bool consistent_fr, consistent_rd;
26
27 copy_cube(c, &c_fr);
28 apply_trans(fr, &c_fr);
29
30 copy_cube(c, &c_rd);
31 apply_trans(rd, &c_rd);
32
33 fst_uf = cube_to_fst(c);
34 fst_fr = cube_to_fst(&c_fr);
35 fst_rd = cube_to_fst(&c_rd);
36
37 consistent_fr = fst_uf.fr_eofb == fst_fr.uf_eofb &&
38 fst_uf.fr_eposepe == fst_fr.uf_eposepe &&
39 fst_uf.fr_coud == fst_fr.uf_coud;
40
41 consistent_rd = fst_uf.rd_eofb == fst_rd.uf_eofb &&
42 fst_uf.rd_eposepe == fst_rd.uf_eposepe &&
43 fst_uf.rd_coud == fst_rd.uf_coud;
44
45 return consistent_fr && consistent_rd;
46}
47
48static bool
49cube_to_fst_to_cube_testcase(Cube *c, Alg *a)
50{
51 Cube d;
52 FstCube fst;
53
54 fst = cube_to_fst(c);
55 fst_to_cube(fst, &d);
56
57 return equal_and_log(c, &d);;
58}
59
60static bool
61cube_to_fst_to_cube_test()
62{
63 return try_all_str(
64 cube_to_fst_to_cube_testcase, "Cube to FST to cube failed");
65}
66
67static bool
68fst_is_consistent_test()
69{
70 return try_all_str(
71 fst_is_consistent_testcase, "FST from cube not consistent");
72}
73
74void fst_pre_init_testall() {
75 int i;
76
77 init_env();
78 init_trans();
79
80 for (i = 0; test[i] != NULL; i++) {
81 printf("Test: %s\n", name[i]);
82 if (!test[i]()) {
83 printf("Failed!\n");
84 exit(1);
85 }
86 printf("Passed.\n\n");
87 }
88 printf("All FST pre-init tests passed.\n\n");
89}
diff --git a/tests/fst_test_util.c b/tests/fst_test_util.c
new file mode 100644
index 0000000..35c1e9f
--- /dev/null
+++ b/tests/fst_test_util.c
@@ -0,0 +1,64 @@
1#include "fst_test_util.h"
2
3char *algs[] = {
4 "",
5 "U", "U2", "U'", "D", "D2", "D'", "R", "R2", "R'",
6 "L", "L2", "L'", "F", "F2", "F'", "B", "B2", "B'",
7 "U2 R2 U2 R2 U2",
8 "U2 F2 R2 B2 U2 D2 F2 L2 B2",
9 "RUR'URU2R'",
10 "L2 D R U2 B2 L",
11 "R'U'F",
12 "F2 U' R2 D' B2 D2 R2 D2 R2 U' F L' U' R B F2 R B' D2",
13 "D L2 F2 R2 D R2 U L2 U' B2 D L' F2 U2 B' L D' U' R' B2 F2",
14 "F' L2 F' D' R F2 L U L' D2 R2 F2 D2 R2 B' L2 B2 U2 F D2 B",
15 NULL,
16};
17
18bool
19equal_and_log(Cube *c, Cube *d)
20{
21 bool ret = equal(c, d);
22
23 if (!ret) {
24 printf("These cubes should be equal, but are not:\n\n");
25 print_cube(c);
26 printf("\n");
27 print_cube(d);
28 printf("\n");
29 }
30
31 return ret;
32}
33
34bool
35try_str(CubeTester f, char *algstr, char *msg)
36{
37 bool b;
38 Alg *a;
39 Cube c;
40
41 a = new_alg(algstr);
42 make_solved(&c);
43 apply_alg(a, &c);
44
45 if (!(b = f(&c, a)))
46 printf("%s with alg %s\n", msg, algstr);
47
48 free_alg(a);
49
50 return b;
51}
52
53bool
54try_all_str(CubeTester f, char *msg)
55{
56 bool b;
57 int i;
58
59 b = true;
60 for (i = 0; algs[i] != NULL; i++)
61 b = b && try_str(f, algs[i], msg);
62
63 return b;
64}
diff --git a/tests/fst_test_util.h b/tests/fst_test_util.h
new file mode 100644
index 0000000..b67b945
--- /dev/null
+++ b/tests/fst_test_util.h
@@ -0,0 +1,7 @@
1#include "../src/fst.h"
2
3extern char *algs[];
4
5bool equal_and_log(Cube *c, Cube *d);
6bool try_str(CubeTester f, char *algstr, char *msg);
7bool try_all_str(CubeTester f, char *msg);
diff --git a/tests/inc.h b/tests/inc.h
deleted file mode 100644
index 53c5fdf..0000000
--- a/tests/inc.h
+++ /dev/null
@@ -1 +0,0 @@
1#include <stdio.h>
diff --git a/tests/nissy_tests.c b/tests/nissy_tests.c
new file mode 100644
index 0000000..d959423
--- /dev/null
+++ b/tests/nissy_tests.c
@@ -0,0 +1,12 @@
1#include <stdio.h>
2
3void fst_pre_init_testall();
4void fst_post_init_testall();
5
6int main() {
7 fst_pre_init_testall();
8 fst_post_init_testall();
9
10 printf("All tests passed.\n");
11 return 0;
12}
diff --git a/tests/test_all.c b/tests/test_all.c
deleted file mode 100644
index 4daeec0..0000000
--- a/tests/test_all.c
+++ /dev/null
@@ -1,10 +0,0 @@
1#include "inc.h"
2
3void test_fst_all();
4
5int main() {
6 test_fst_all();
7
8 printf("All tests passed.\n");
9 return 0;
10}
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
4static bool cube_to_fst_to_cube(Cube *c, Alg *a);
5static bool fst_consistent(Cube *c, Alg *a);
6static bool fst_move_test(Cube *c, Alg *a);
7static bool fst_inverse_test(Cube *c, Alg *a);
8static bool try_str(CubeTester f, char *algstr, char *msg);
9static bool try_all_str(CubeTester f, char *msg);
10
11static bool test_fst_consistent_algs();
12static bool test_cube_to_fst_to_cube_algs();
13static bool test_fst_move_algs();
14static bool test_fst_inverse_algs();
15
16static 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
24static char *name[] = {
25 "Consistency of FST (converted from cube)",
26 "Cube to FST to cube",
27 "FST move",
28 "FST inverse",
29};
30
31static 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
46static bool
47fst_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
58static bool
59cube_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
80static bool
81fst_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
103static bool
104fst_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
114static bool
115try_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
133static bool
134try_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
146static bool
147test_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
152static bool
153test_fst_consistent_algs()
154{
155 return try_all_str(fst_consistent, "FST from cube not consistent");
156}
157
158static bool
159test_fst_move_algs()
160{
161 return try_all_str(fst_move_test, "FST move incorrect");
162}
163
164static bool
165test_fst_inverse_algs()
166{
167 return try_all_str(fst_inverse_test, "FST test incorrect");
168}
169
170void 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}

Generated with cgit - Back to sebastiano.tronto.net