diff options
Diffstat (limited to '')
26 files changed, 252 insertions, 20 deletions
| @@ -1,7 +1,7 @@ | |||
| 1 | In progress: go back to nissy-style BFS for eosep data computation | 1 | In progress: go back to nissy-style BFS for eosep data computation |
| 2 | - (done) compute selfsim and cocsep representatives | 2 | - (done) compute selfsim and cocsep representatives |
| 3 | - implement set_eo_fast for invcoord_h48 (with tests for set_eo_fast) | 3 | - (done) implement set_eo_fast for invcoord_h48 |
| 4 | also: implement other set_stuff methods for fast cube representation | 4 | - add unit tests for invcoord_h48 (compute tables, if needed) |
| 5 | - in gendata_esep, compute representatives for esep inverse coordinate | 5 | - in gendata_esep, compute representatives for esep inverse coordinate |
| 6 | - change to BFS | 6 | - change to BFS |
| 7 | 7 | ||
| @@ -1,5 +1,6 @@ | |||
| 1 | #include <inttypes.h> | 1 | #include <inttypes.h> |
| 2 | #include <stdbool.h> | 2 | #include <stdbool.h> |
| 3 | #include <stdlib.h> /* TODO: Used only for malloc, remove if possible */ | ||
| 3 | #include <string.h> | 4 | #include <string.h> |
| 4 | 5 | ||
| 5 | #ifdef DEBUG | 6 | #ifdef DEBUG |
diff --git a/src/cube_avx2.h b/src/cube_avx2.h index 42fb9d1..8d1c940 100644 --- a/src/cube_avx2.h +++ b/src/cube_avx2.h | |||
| @@ -23,9 +23,12 @@ _static_inline int64_t coord_fast_co(cube_fast_t); | |||
| 23 | _static_inline int64_t coord_fast_csep(cube_fast_t); | 23 | _static_inline int64_t coord_fast_csep(cube_fast_t); |
| 24 | _static_inline int64_t coord_fast_cocsep(cube_fast_t); | 24 | _static_inline int64_t coord_fast_cocsep(cube_fast_t); |
| 25 | _static_inline int64_t coord_fast_eo(cube_fast_t); | 25 | _static_inline int64_t coord_fast_eo(cube_fast_t); |
| 26 | _static_inline void set_eo_fast(cube_fast_t *, int64_t); | ||
| 27 | _static_inline int64_t coord_fast_esep(cube_fast_t); | 26 | _static_inline int64_t coord_fast_esep(cube_fast_t); |
| 28 | 27 | ||
| 28 | _static_inline void copy_corners_fast(cube_fast_t *, cube_fast_t); | ||
| 29 | _static_inline void copy_edges_fast(cube_fast_t *, cube_fast_t); | ||
| 30 | _static_inline void set_eo_fast(cube_fast_t *, int64_t); | ||
| 31 | |||
| 29 | _static_inline cube_fast_t | 32 | _static_inline cube_fast_t |
| 30 | fastcube( | 33 | fastcube( |
| 31 | uint8_t c_ufr, | 34 | uint8_t c_ufr, |
| @@ -199,12 +202,6 @@ coord_fast_eo(cube_fast_t c) | |||
| 199 | return mask >> 17; | 202 | return mask >> 17; |
| 200 | } | 203 | } |
| 201 | 204 | ||
| 202 | _static_inline void | ||
| 203 | set_eo_fast(cube_fast_t *c, int64_t eo) | ||
| 204 | { | ||
| 205 | /* TODO */ | ||
| 206 | } | ||
| 207 | |||
| 208 | _static_inline int64_t | 205 | _static_inline int64_t |
| 209 | coord_fast_esep(cube_fast_t c) | 206 | coord_fast_esep(cube_fast_t c) |
| 210 | { | 207 | { |
| @@ -234,3 +231,40 @@ coord_fast_esep(cube_fast_t c) | |||
| 234 | 231 | ||
| 235 | return ret1 * 70 + ret2; | 232 | return ret1 * 70 + ret2; |
| 236 | } | 233 | } |
| 234 | |||
| 235 | _static_inline void | ||
| 236 | copy_corners_fast(cube_fast_t *dest, cube_fast_t src) | ||
| 237 | { | ||
| 238 | *dest = _mm256_blend_epi32(*dest, src, 0x0F); | ||
| 239 | } | ||
| 240 | |||
| 241 | _static_inline void | ||
| 242 | copy_edges_fast(cube_fast_t *dest, cube_fast_t src) | ||
| 243 | { | ||
| 244 | *dest = _mm256_blend_epi32(*dest, src, 0xF0); | ||
| 245 | } | ||
| 246 | |||
| 247 | _static_inline void | ||
| 248 | set_eo_fast(cube_fast_t *cube, int64_t eo) | ||
| 249 | { | ||
| 250 | int64_t eo12, eotop, eobot; | ||
| 251 | __m256i veo; | ||
| 252 | |||
| 253 | eo12 = (eo << 1) + (_mm_popcnt_u64(eo) % 2); | ||
| 254 | eotop = (eo12 & (1 << 11)) << 17 | | ||
| 255 | (eo12 & (1 << 10)) << 10 | | ||
| 256 | (eo12 & (1 << 9)) << 3 | | ||
| 257 | (eo12 & (1 << 8)) >> 4; | ||
| 258 | eobot = (eo12 & (1 << 7)) << 53 | | ||
| 259 | (eo12 & (1 << 6)) << 46 | | ||
| 260 | (eo12 & (1 << 5)) << 39 | | ||
| 261 | (eo12 & (1 << 4)) << 32 | | ||
| 262 | (eo12 & (1 << 3)) << 25 | | ||
| 263 | (eo12 & (1 << 2)) << 18 | | ||
| 264 | (eo12 & (1 << 1)) << 11 | | ||
| 265 | (eo12 & 1) << 4; | ||
| 266 | veo = _mm256_set_epi64x(eotop, eobot, 0, 0); | ||
| 267 | |||
| 268 | *cube = _mm256_andnot_si256(_eo_avx2, *cube); | ||
| 269 | *cube = _mm256_or_si256(*cube, veo); | ||
| 270 | } | ||
diff --git a/src/cube_portable.h b/src/cube_portable.h index fcd1d55..125c300 100644 --- a/src/cube_portable.h +++ b/src/cube_portable.h | |||
| @@ -17,9 +17,12 @@ _static_inline int64_t coord_fast_co(cube_fast_t); | |||
| 17 | _static_inline int64_t coord_fast_csep(cube_fast_t); | 17 | _static_inline int64_t coord_fast_csep(cube_fast_t); |
| 18 | _static_inline int64_t coord_fast_cocsep(cube_fast_t); | 18 | _static_inline int64_t coord_fast_cocsep(cube_fast_t); |
| 19 | _static_inline int64_t coord_fast_eo(cube_fast_t); | 19 | _static_inline int64_t coord_fast_eo(cube_fast_t); |
| 20 | _static_inline void set_eo_fast(cube_fast_t *, int64_t eo); | ||
| 21 | _static_inline int64_t coord_fast_esep(cube_fast_t); | 20 | _static_inline int64_t coord_fast_esep(cube_fast_t); |
| 22 | 21 | ||
| 22 | _static_inline void copy_corners_fast(cube_fast_t *, cube_fast_t); | ||
| 23 | _static_inline void copy_edges_fast(cube_fast_t *, cube_fast_t); | ||
| 24 | _static_inline void set_eo_fast(cube_fast_t *, int64_t); | ||
| 25 | |||
| 23 | _static_inline cube_fast_t | 26 | _static_inline cube_fast_t |
| 24 | fastcube( | 27 | fastcube( |
| 25 | uint8_t c_ufr, | 28 | uint8_t c_ufr, |
| @@ -189,12 +192,6 @@ coord_fast_eo(cube_fast_t c) | |||
| 189 | return ret; | 192 | return ret; |
| 190 | } | 193 | } |
| 191 | 194 | ||
| 192 | _static_inline void | ||
| 193 | _set_eo_fast(cube_fast_t *cube, int64_t eo) | ||
| 194 | { | ||
| 195 | /* TODO */ | ||
| 196 | } | ||
| 197 | |||
| 198 | /* | 195 | /* |
| 199 | We encode the edge separation as a number from 0 to C(12,4)*C(8,4). | 196 | We encode the edge separation as a number from 0 to C(12,4)*C(8,4). |
| 200 | It can be seen as the composition of two "subset index" coordinates. | 197 | It can be seen as the composition of two "subset index" coordinates. |
| @@ -229,3 +226,28 @@ coord_fast_esep(cube_fast_t c) | |||
| 229 | 226 | ||
| 230 | return ret1 * 70 + ret2; | 227 | return ret1 * 70 + ret2; |
| 231 | } | 228 | } |
| 229 | |||
| 230 | _static_inline void | ||
| 231 | copy_corners_fast(cube_fast_t *dest, cube_fast_t src) | ||
| 232 | { | ||
| 233 | memcpy(&dest->corner, src.corner, sizeof(src.corner)); | ||
| 234 | } | ||
| 235 | |||
| 236 | _static_inline void | ||
| 237 | copy_edges_fast(cube_fast_t *dest, cube_fast_t src) | ||
| 238 | { | ||
| 239 | memcpy(&dest->edge, src.edge, sizeof(src.edge)); | ||
| 240 | } | ||
| 241 | |||
| 242 | _static_inline void | ||
| 243 | set_eo_fast(cube_fast_t *cube, int64_t eo) | ||
| 244 | { | ||
| 245 | int i, sum, flip; | ||
| 246 | |||
| 247 | for (sum = 0, i = 1; i < 12; i++, eo >>= 1) { | ||
| 248 | flip = eo % 2; | ||
| 249 | sum += flip; | ||
| 250 | cube->edge[i] = (cube->edge[i] & ~_eobit) | (_eobit * flip); | ||
| 251 | } | ||
| 252 | cube->edge[0] = (cube->edge[0] & ~_eobit) | (_eobit * (sum%2)); | ||
| 253 | } | ||
diff --git a/src/solve_h48.h b/src/solve_h48.h index e3e6de1..2fe1d69 100644 --- a/src/solve_h48.h +++ b/src/solve_h48.h | |||
| @@ -88,16 +88,17 @@ invcoord_h48( | |||
| 88 | cube_fast_t ret; | 88 | cube_fast_t ret; |
| 89 | int64_t coclass, ee, esep, eo; | 89 | int64_t coclass, ee, esep, eo; |
| 90 | 90 | ||
| 91 | DBG_ASSERT(h <= 11, cubetofast(zero), | ||
| 92 | "invcoord_h48: h must be between 0 and 11\n"); | ||
| 93 | |||
| 91 | coclass = i / H48_ESIZE; | 94 | coclass = i / H48_ESIZE; |
| 92 | ee = i % H48_ESIZE; | 95 | ee = i % H48_ESIZE; |
| 93 | esep = ee >> h; | 96 | esep = ee >> h; |
| 94 | eo = (ee & ((1<<h)-1)) << (11-h); | 97 | eo = (ee & ((1<<h)-1)) << (11-h); |
| 95 | 98 | ||
| 96 | /* TODO: implement set_stuff methods | 99 | copy_corners_fast(&ret, crep[coclass]); |
| 97 | ret.c = crep[coclass]; | 100 | copy_edges_fast(&ret, erep[esep]); |
| 98 | ret.e = erep[esep]; | ||
| 99 | set_eo_fast(&ret, eo); | 101 | set_eo_fast(&ret, eo); |
| 100 | */ | ||
| 101 | 102 | ||
| 102 | return ret; | 103 | return ret; |
| 103 | } | 104 | } |
diff --git a/test/075_set_eo/00_solved_0.in b/test/075_set_eo/00_solved_0.in new file mode 100644 index 0000000..55bb6bf --- /dev/null +++ b/test/075_set_eo/00_solved_0.in | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 | ||
| 2 | 0 | ||
diff --git a/test/075_set_eo/00_solved_0.out b/test/075_set_eo/00_solved_0.out new file mode 100644 index 0000000..dff224d --- /dev/null +++ b/test/075_set_eo/00_solved_0.out | |||
| @@ -0,0 +1 @@ | |||
| UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 | |||
diff --git a/test/075_set_eo/01_solved_1.in b/test/075_set_eo/01_solved_1.in new file mode 100644 index 0000000..edd864e --- /dev/null +++ b/test/075_set_eo/01_solved_1.in | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 | ||
| 2 | 2047 | ||
diff --git a/test/075_set_eo/01_solved_1.out b/test/075_set_eo/01_solved_1.out new file mode 100644 index 0000000..ec7594a --- /dev/null +++ b/test/075_set_eo/01_solved_1.out | |||
| @@ -0,0 +1 @@ | |||
| UF1 UB1 DB1 DF1 UR1 UL1 DL1 DR1 FR1 FL1 BL1 BR1 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 | |||
diff --git a/test/075_set_eo/02_solved_other.in b/test/075_set_eo/02_solved_other.in new file mode 100644 index 0000000..17e9b02 --- /dev/null +++ b/test/075_set_eo/02_solved_other.in | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 | ||
| 2 | 20 | ||
diff --git a/test/075_set_eo/02_solved_other.out b/test/075_set_eo/02_solved_other.out new file mode 100644 index 0000000..df73ef8 --- /dev/null +++ b/test/075_set_eo/02_solved_other.out | |||
| @@ -0,0 +1 @@ | |||
| UF0 UB0 DB0 DF1 UR0 UL1 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 | |||
diff --git a/test/075_set_eo/03_solved_firstlast.in b/test/075_set_eo/03_solved_firstlast.in new file mode 100644 index 0000000..a16a192 --- /dev/null +++ b/test/075_set_eo/03_solved_firstlast.in | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 | ||
| 2 | 1024 | ||
diff --git a/test/075_set_eo/03_solved_firstlast.out b/test/075_set_eo/03_solved_firstlast.out new file mode 100644 index 0000000..8679be3 --- /dev/null +++ b/test/075_set_eo/03_solved_firstlast.out | |||
| @@ -0,0 +1 @@ | |||
| UF1 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR1 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 | |||
diff --git a/test/075_set_eo/10_scrambled_0.in b/test/075_set_eo/10_scrambled_0.in new file mode 100644 index 0000000..55dccca --- /dev/null +++ b/test/075_set_eo/10_scrambled_0.in | |||
| @@ -0,0 +1,4 @@ | |||
| 1 | UL0 BL0 BR1 DL0 FR0 DF0 DB1 DR1 UB0 FL0 UF0 UR1 DFL0 UFR1 DBR1 UBR2 DBL2 DFR0 UFL1 UBL2 | ||
| 2 | 0 | ||
| 3 | |||
| 4 | // Scramble: U R D' L D' F L2 D L F B D2 B' L2 F U2 L2 D2 R2 L2 B' | ||
diff --git a/test/075_set_eo/10_scrambled_0.out b/test/075_set_eo/10_scrambled_0.out new file mode 100644 index 0000000..0eabd6e --- /dev/null +++ b/test/075_set_eo/10_scrambled_0.out | |||
| @@ -0,0 +1 @@ | |||
| UL0 BL0 BR0 DL0 FR0 DF0 DB0 DR0 UB0 FL0 UF0 UR0 DFL0 UFR1 DBR1 UBR2 DBL2 DFR0 UFL1 UBL2 | |||
diff --git a/test/075_set_eo/11_scrambled_1.in b/test/075_set_eo/11_scrambled_1.in new file mode 100644 index 0000000..0037a04 --- /dev/null +++ b/test/075_set_eo/11_scrambled_1.in | |||
| @@ -0,0 +1,4 @@ | |||
| 1 | UL0 BL0 BR1 DL0 FR0 DF0 DB1 DR1 UB0 FL0 UF0 UR1 DFL0 UFR1 DBR1 UBR2 DBL2 DFR0 UFL1 UBL2 | ||
| 2 | 2047 | ||
| 3 | |||
| 4 | // Scramble: U R D' L D' F L2 D L F B D2 B' L2 F U2 L2 D2 R2 L2 B' | ||
diff --git a/test/075_set_eo/11_scrambled_1.out b/test/075_set_eo/11_scrambled_1.out new file mode 100644 index 0000000..843df0d --- /dev/null +++ b/test/075_set_eo/11_scrambled_1.out | |||
| @@ -0,0 +1 @@ | |||
| UL1 BL1 BR1 DL1 FR1 DF1 DB1 DR1 UB1 FL1 UF1 UR1 DFL0 UFR1 DBR1 UBR2 DBL2 DFR0 UFL1 UBL2 | |||
diff --git a/test/075_set_eo/set_eo_tests.c b/test/075_set_eo/set_eo_tests.c new file mode 100644 index 0000000..ef7215a --- /dev/null +++ b/test/075_set_eo/set_eo_tests.c | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | #include "../test.h" | ||
| 2 | |||
| 3 | int64_t coord_fast_eo(cube_fast_t); | ||
| 4 | void set_eo_fast(cube_fast_t *, int64_t); | ||
| 5 | cube_fast_t cubetofast(cube_t); | ||
| 6 | cube_t fasttocube(cube_fast_t); | ||
| 7 | |||
| 8 | int main(void) { | ||
| 9 | char str[STRLENMAX]; | ||
| 10 | cube_t cube; | ||
| 11 | cube_fast_t fast; | ||
| 12 | int64_t eo; | ||
| 13 | |||
| 14 | fgets(str, STRLENMAX, stdin); | ||
| 15 | cube = readcube("H48", str); | ||
| 16 | fast = cubetofast(cube); | ||
| 17 | fgets(str, STRLENMAX, stdin); | ||
| 18 | eo = atoi(str); | ||
| 19 | |||
| 20 | set_eo_fast(&fast, eo); | ||
| 21 | |||
| 22 | cube = fasttocube(fast); | ||
| 23 | if (iserror(cube)) { | ||
| 24 | printf("Error setting EO\n"); | ||
| 25 | } else if (!isconsistent(cube)) { | ||
| 26 | fprintf(stderr, "edges: "); | ||
| 27 | for (int i = 0; i < 12; i++) fprintf(stderr, "%d ", cube.edge[i]); | ||
| 28 | fprintf(stderr, "\n"); | ||
| 29 | for (int i = 0; i < 8; i++) fprintf(stderr, "%d ", cube.corner[i]); | ||
| 30 | fprintf(stderr, "\n"); | ||
| 31 | printf("Setting EO resulted in inconsistent cube\n"); | ||
| 32 | } else { | ||
| 33 | writecube("H48", cube, str); | ||
| 34 | printf("%s\n", str); | ||
| 35 | } | ||
| 36 | |||
| 37 | return 0; | ||
| 38 | } | ||
diff --git a/test/076_copy_corners/00_solved_scrambled.in b/test/076_copy_corners/00_solved_scrambled.in new file mode 100644 index 0000000..2ff0e6a --- /dev/null +++ b/test/076_copy_corners/00_solved_scrambled.in | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 | ||
| 2 | UL0 BL0 BR1 DL0 FR0 DF0 DB1 DR1 UB0 FL0 UF0 UR1 DFL0 UFR1 DBR1 UBR2 DBL2 DFR0 UFL1 UBL2 | ||
diff --git a/test/076_copy_corners/00_solved_scrambled.out b/test/076_copy_corners/00_solved_scrambled.out new file mode 100644 index 0000000..9c53bcc --- /dev/null +++ b/test/076_copy_corners/00_solved_scrambled.out | |||
| @@ -0,0 +1 @@ | |||
| UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 DFL0 UFR1 DBR1 UBR2 DBL2 DFR0 UFL1 UBL2 | |||
diff --git a/test/076_copy_corners/copy_corners_tests.c b/test/076_copy_corners/copy_corners_tests.c new file mode 100644 index 0000000..fecf14a --- /dev/null +++ b/test/076_copy_corners/copy_corners_tests.c | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | #include "../test.h" | ||
| 2 | |||
| 3 | void copy_corners_fast(cube_fast_t *, cube_fast_t); | ||
| 4 | cube_fast_t cubetofast(cube_t); | ||
| 5 | cube_t fasttocube(cube_fast_t); | ||
| 6 | |||
| 7 | int main(void) { | ||
| 8 | char str[STRLENMAX]; | ||
| 9 | cube_t c1, c2; | ||
| 10 | cube_fast_t f1, f2; | ||
| 11 | |||
| 12 | fgets(str, STRLENMAX, stdin); | ||
| 13 | c1 = readcube("H48", str); | ||
| 14 | f1 = cubetofast(c1); | ||
| 15 | |||
| 16 | fgets(str, STRLENMAX, stdin); | ||
| 17 | c2 = readcube("H48", str); | ||
| 18 | f2 = cubetofast(c2); | ||
| 19 | |||
| 20 | copy_corners_fast(&f1, f2); | ||
| 21 | |||
| 22 | c1 = fasttocube(f1); | ||
| 23 | if (iserror(c1)) { | ||
| 24 | printf("Error setting EO\n"); | ||
| 25 | } else if (!isconsistent(c1)) { | ||
| 26 | printf("Setting EO resulted in inconsistent cube\n"); | ||
| 27 | } else { | ||
| 28 | writecube("H48", c1, str); | ||
| 29 | printf("%s\n", str); | ||
| 30 | } | ||
| 31 | |||
| 32 | return 0; | ||
| 33 | } | ||
diff --git a/test/077_copy_edges/00_solved_scrambled.in b/test/077_copy_edges/00_solved_scrambled.in new file mode 100644 index 0000000..2ff0e6a --- /dev/null +++ b/test/077_copy_edges/00_solved_scrambled.in | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 | ||
| 2 | UL0 BL0 BR1 DL0 FR0 DF0 DB1 DR1 UB0 FL0 UF0 UR1 DFL0 UFR1 DBR1 UBR2 DBL2 DFR0 UFL1 UBL2 | ||
diff --git a/test/077_copy_edges/00_solved_scrambled.out b/test/077_copy_edges/00_solved_scrambled.out new file mode 100644 index 0000000..3af84f4 --- /dev/null +++ b/test/077_copy_edges/00_solved_scrambled.out | |||
| @@ -0,0 +1 @@ | |||
| UL0 BL0 BR1 DL0 FR0 DF0 DB1 DR1 UB0 FL0 UF0 UR1 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 | |||
diff --git a/test/077_copy_edges/copy_edges_tests.c b/test/077_copy_edges/copy_edges_tests.c new file mode 100644 index 0000000..c3e70a3 --- /dev/null +++ b/test/077_copy_edges/copy_edges_tests.c | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | #include "../test.h" | ||
| 2 | |||
| 3 | void copy_edges_fast(cube_fast_t *, cube_fast_t); | ||
| 4 | cube_fast_t cubetofast(cube_t); | ||
| 5 | cube_t fasttocube(cube_fast_t); | ||
| 6 | |||
| 7 | int main(void) { | ||
| 8 | char str[STRLENMAX]; | ||
| 9 | cube_t c1, c2; | ||
| 10 | cube_fast_t f1, f2; | ||
| 11 | |||
| 12 | fgets(str, STRLENMAX, stdin); | ||
| 13 | c1 = readcube("H48", str); | ||
| 14 | f1 = cubetofast(c1); | ||
| 15 | |||
| 16 | fgets(str, STRLENMAX, stdin); | ||
| 17 | c2 = readcube("H48", str); | ||
| 18 | f2 = cubetofast(c2); | ||
| 19 | |||
| 20 | copy_edges_fast(&f1, f2); | ||
| 21 | |||
| 22 | c1 = fasttocube(f1); | ||
| 23 | if (iserror(c1)) { | ||
| 24 | printf("Error setting EO\n"); | ||
| 25 | } else if (!isconsistent(c1)) { | ||
| 26 | printf("Setting EO resulted in inconsistent cube\n"); | ||
| 27 | } else { | ||
| 28 | writecube("H48", c1, str); | ||
| 29 | printf("%s\n", str); | ||
| 30 | } | ||
| 31 | |||
| 32 | return 0; | ||
| 33 | } | ||
diff --git a/test/test b/test/test new file mode 100755 index 0000000..3adee3a --- /dev/null +++ b/test/test | |||
| @@ -0,0 +1,41 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | detectsan() { cc -fsanitize=$1 -dM -E -x c - </dev/null | grep "SANITIZE"; } | ||
| 4 | |||
| 5 | re="${TEST:-$@}" | ||
| 6 | |||
| 7 | CC="cc -DDEBUG -std=c99 -pedantic -Wall -Wextra \ | ||
| 8 | -Wno-unused-parameter -Wno-unused-function -g3 -D$CUBETYPE" | ||
| 9 | |||
| 10 | [ "$CUBETYPE" = "CUBE_AVX2" ] && CC="$CC -mavx2" | ||
| 11 | [ -n "$(detectsan address)" ] && CC="$CC -fsanitize=address" | ||
| 12 | [ -n "$(detectsan undefined)" ] && CC="$CC -fsanitize=undefined" | ||
| 13 | |||
| 14 | TESTBIN="test/run" | ||
| 15 | TESTOUT="test/last.out" | ||
| 16 | TESTERR="test/last.err" | ||
| 17 | CUBEOBJ="debugcube.o" | ||
| 18 | |||
| 19 | for t in test/*; do | ||
| 20 | if [ -n "$re" ] && [ -z "$(echo "$t" | grep "$re")" ]; then | ||
| 21 | continue | ||
| 22 | fi | ||
| 23 | if [ ! -d $t ]; then continue; fi | ||
| 24 | $CC -o $TESTBIN $t/*.c $CUBEOBJ || exit 1; | ||
| 25 | for cin in $t/*.in; do | ||
| 26 | c=$(echo "$cin" | sed 's/\.in//') | ||
| 27 | cout=$c.out | ||
| 28 | printf "$c: " | ||
| 29 | $TESTBIN < "$cin" > $TESTOUT 2> $TESTERR | ||
| 30 | if diff $cout $TESTOUT; then | ||
| 31 | printf "OK\n" | ||
| 32 | else | ||
| 33 | printf "Test failed! stderr:\n" | ||
| 34 | cat $TESTERR | ||
| 35 | exit 1 | ||
| 36 | fi | ||
| 37 | done | ||
| 38 | done | ||
| 39 | |||
| 40 | echo "All tests passed!" | ||
| 41 | rm -rf $TESTBIN $TESTOUT $TESTERR $CUBEOBJ | ||
diff --git a/test/test.h b/test/test.h index 3cbfd10..2086283 100644 --- a/test/test.h +++ b/test/test.h | |||
| @@ -21,6 +21,7 @@ typedef cube_t cube_fast_t; | |||
| 21 | /* Basic functions used in most tests */ | 21 | /* Basic functions used in most tests */ |
| 22 | cube_t solvedcube(void); | 22 | cube_t solvedcube(void); |
| 23 | bool iserror(cube_t); | 23 | bool iserror(cube_t); |
| 24 | bool isconsistent(cube_t); | ||
| 24 | bool issolvable(cube_t); | 25 | bool issolvable(cube_t); |
| 25 | bool issolved(cube_t); | 26 | bool issolved(cube_t); |
| 26 | cube_t readcube(char *, char *); | 27 | cube_t readcube(char *, char *); |
