diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-04-13 15:31:32 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-04-13 15:31:32 +0200 |
| commit | a18d4b0ba97b301193597a963a77a40ef7c2254b (patch) | |
| tree | e2137f21fd162380a2cf8ec6e54af959ad4c4d90 | |
| parent | ae055f1fc993d406939f57f11553d218e1efde82 (diff) | |
| download | cubecore-a18d4b0ba97b301193597a963a77a40ef7c2254b.tar.gz cubecore-a18d4b0ba97b301193597a963a77a40ef7c2254b.zip | |
Some renaming
| -rw-r--r-- | cube.c | 87 | ||||
| -rw-r--r-- | cube.h | 40 | ||||
| -rw-r--r-- | debugcube.o | bin | 0 -> 113064 bytes | |||
| -rw-r--r-- | test/000_basic/basic_tests.c | 11 | ||||
| -rw-r--r-- | test/001_cube_conversion/cube_conversion_tests.c | 4 | ||||
| -rw-r--r-- | test/020_io_H48_read_write/io_H48_tests.c | 4 | ||||
| -rw-r--r-- | test/023_io_LST_write/io_LST_tests.c | 4 | ||||
| -rw-r--r-- | test/024_io_LST_read/io_LST_tests.c | 4 | ||||
| -rw-r--r-- | test/030_move/move_tests.c | 4 | ||||
| -rw-r--r-- | test/040_inverse_cube/inverse_tests.c | 8 | ||||
| -rw-r--r-- | test/050_compose/compose_tests.c | 4 | ||||
| -rw-r--r-- | test/060_transform/transform_tests.c | 4 | ||||
| -rw-r--r-- | test/061_inverse_trans/inverse_trans_tests.c | 8 | ||||
| -rw-r--r-- | test/last.err | 0 | ||||
| -rw-r--r-- | test/last.out | 1 | ||||
| -rw-r--r-- | test/test.h | 21 |
16 files changed, 72 insertions, 132 deletions
| @@ -229,26 +229,6 @@ Some of these routines depend on the efficient functions implemented in the | |||
| 229 | previous sections, while some other operate directly on the cube. | 229 | previous sections, while some other operate directly on the cube. |
| 230 | ******************************************************************************/ | 230 | ******************************************************************************/ |
| 231 | 231 | ||
| 232 | #define _premove(M, c) compose_fast(_move_cube_ ## M, c) | ||
| 233 | |||
| 234 | #define _foreach_move(_m, _c, _d, instruction) \ | ||
| 235 | for (_m = 0; _m < 18; _m++) { _d = move(_c, _m); instruction } | ||
| 236 | #define _foreach_trans(_t, _c, _d, instruction) \ | ||
| 237 | for (_t = 0; _t < 48; _t++) { _d = transform(_c, _t); instruction } | ||
| 238 | |||
| 239 | cube_t solvedcube(void); | ||
| 240 | bool isconsistent(cube_t); | ||
| 241 | bool issolvable(cube_t); | ||
| 242 | bool issolved(cube_t cube); | ||
| 243 | bool equal(cube_t, cube_t); | ||
| 244 | bool iserror(cube_t); | ||
| 245 | cube_t compose(cube_t, cube_t); | ||
| 246 | cube_t inverse(cube_t); | ||
| 247 | cube_t applymoves(cube_t, char *); | ||
| 248 | cube_t applytrans(cube_t, char *); | ||
| 249 | cube_t readcube(char *, char *); | ||
| 250 | void writecube(char *, cube_t, char *); | ||
| 251 | |||
| 252 | _static int permsign(uint8_t *, int); | 232 | _static int permsign(uint8_t *, int); |
| 253 | _static uint8_t readco(char *); | 233 | _static uint8_t readco(char *); |
| 254 | _static uint8_t readcp(char *); | 234 | _static uint8_t readcp(char *); |
| @@ -269,13 +249,23 @@ _static cube_fast_t move(cube_fast_t, move_t); | |||
| 269 | _static cube_fast_t transform(cube_fast_t, trans_t); | 249 | _static cube_fast_t transform(cube_fast_t, trans_t); |
| 270 | 250 | ||
| 271 | cube_t | 251 | cube_t |
| 272 | solvedcube(void) | 252 | cube_new(void) |
| 273 | { | 253 | { |
| 274 | return solved; | 254 | return solved; |
| 275 | } | 255 | } |
| 276 | 256 | ||
| 257 | cube_t | ||
| 258 | cube_clone(cube_t c) | ||
| 259 | { | ||
| 260 | cube_t ret; | ||
| 261 | |||
| 262 | memcpy(&ret, &c, sizeof(cube_t)); | ||
| 263 | |||
| 264 | return ret; | ||
| 265 | } | ||
| 266 | |||
| 277 | bool | 267 | bool |
| 278 | isconsistent(cube_t cube) | 268 | cube_consistent(cube_t cube) |
| 279 | { | 269 | { |
| 280 | uint8_t i, p, e, piece; | 270 | uint8_t i, p, e, piece; |
| 281 | bool found[12]; | 271 | bool found[12]; |
| @@ -329,12 +319,12 @@ inconsistent_co: | |||
| 329 | } | 319 | } |
| 330 | 320 | ||
| 331 | bool | 321 | bool |
| 332 | issolvable(cube_t cube) | 322 | cube_solvable(cube_t cube) |
| 333 | { | 323 | { |
| 334 | uint8_t i, eo, co, piece, edges[12], corners[8]; | 324 | uint8_t i, eo, co, piece, edges[12], corners[8]; |
| 335 | 325 | ||
| 336 | DBG_ASSERT(isconsistent(cube), false, | 326 | DBG_ASSERT(cube_consistent(cube), false, |
| 337 | "issolvable: cube is inconsistent\n"); | 327 | "cube_solvable: cube is inconsistent\n"); |
| 338 | 328 | ||
| 339 | for (i = 0; i < 12; i++) | 329 | for (i = 0; i < 12; i++) |
| 340 | edges[i] = cube.edge[i] & _pbits; | 330 | edges[i] = cube.edge[i] & _pbits; |
| @@ -342,7 +332,7 @@ issolvable(cube_t cube) | |||
| 342 | corners[i] = cube.corner[i] & _pbits; | 332 | corners[i] = cube.corner[i] & _pbits; |
| 343 | 333 | ||
| 344 | if (permsign(edges, 12) != permsign(corners, 8)) | 334 | if (permsign(edges, 12) != permsign(corners, 8)) |
| 345 | goto issolvable_parity; | 335 | goto solvable_parity; |
| 346 | 336 | ||
| 347 | eo = 0; | 337 | eo = 0; |
| 348 | for (i = 0; i < 12; i++) { | 338 | for (i = 0; i < 12; i++) { |
| @@ -350,7 +340,7 @@ issolvable(cube_t cube) | |||
| 350 | eo += (piece & _eobit) >> _eoshift; | 340 | eo += (piece & _eobit) >> _eoshift; |
| 351 | } | 341 | } |
| 352 | if (eo % 2 != 0) | 342 | if (eo % 2 != 0) |
| 353 | goto issolvable_eo; | 343 | goto solvable_eo; |
| 354 | 344 | ||
| 355 | co = 0; | 345 | co = 0; |
| 356 | for (i = 0; i < 8; i++) { | 346 | for (i = 0; i < 8; i++) { |
| @@ -358,29 +348,29 @@ issolvable(cube_t cube) | |||
| 358 | co += (piece & _cobits) >> _coshift; | 348 | co += (piece & _cobits) >> _coshift; |
| 359 | } | 349 | } |
| 360 | if (co % 3 != 0) | 350 | if (co % 3 != 0) |
| 361 | goto issolvable_co; | 351 | goto solvable_co; |
| 362 | 352 | ||
| 363 | return true; | 353 | return true; |
| 364 | 354 | ||
| 365 | issolvable_parity: | 355 | solvable_parity: |
| 366 | DBG_LOG("EP and CP parities are different\n"); | 356 | DBG_LOG("EP and CP parities are different\n"); |
| 367 | return false; | 357 | return false; |
| 368 | issolvable_eo: | 358 | solvable_eo: |
| 369 | DBG_LOG("Odd number of flipped edges\n"); | 359 | DBG_LOG("Odd number of flipped edges\n"); |
| 370 | return false; | 360 | return false; |
| 371 | issolvable_co: | 361 | solvable_co: |
| 372 | DBG_LOG("Sum of corner orientation is not multiple of 3\n"); | 362 | DBG_LOG("Sum of corner orientation is not multiple of 3\n"); |
| 373 | return false; | 363 | return false; |
| 374 | } | 364 | } |
| 375 | 365 | ||
| 376 | bool | 366 | bool |
| 377 | issolved(cube_t cube) | 367 | cube_solved(cube_t cube) |
| 378 | { | 368 | { |
| 379 | return equal(cube, solved); | 369 | return cube_equal(cube, solved); |
| 380 | } | 370 | } |
| 381 | 371 | ||
| 382 | bool | 372 | bool |
| 383 | equal(cube_t c1, cube_t c2) | 373 | cube_equal(cube_t c1, cube_t c2) |
| 384 | { | 374 | { |
| 385 | int i; | 375 | int i; |
| 386 | bool ret; | 376 | bool ret; |
| @@ -395,28 +385,28 @@ equal(cube_t c1, cube_t c2) | |||
| 395 | } | 385 | } |
| 396 | 386 | ||
| 397 | bool | 387 | bool |
| 398 | iserror(cube_t cube) | 388 | cube_error(cube_t cube) |
| 399 | { | 389 | { |
| 400 | return equal(cube, zero); | 390 | return cube_equal(cube, zero); |
| 401 | } | 391 | } |
| 402 | 392 | ||
| 403 | cube_t | 393 | cube_t |
| 404 | compose(cube_t c1, cube_t c2) | 394 | cube_compose(cube_t c1, cube_t c2) |
| 405 | { | 395 | { |
| 406 | DBG_ASSERT(isconsistent(c1) && isconsistent(c2), | 396 | DBG_ASSERT(cube_consistent(c1) && cube_consistent(c2), |
| 407 | zero, "compose error: inconsistent cube\n") | 397 | zero, "cube_compose error: inconsistent cube\n") |
| 408 | 398 | ||
| 409 | return fasttocube(compose_fast(cubetofast(c1), cubetofast(c2))); | 399 | return fasttocube(compose_fast(cubetofast(c1), cubetofast(c2))); |
| 410 | } | 400 | } |
| 411 | 401 | ||
| 412 | cube_t | 402 | cube_t |
| 413 | inverse(cube_t cube) | 403 | cube_inverse(cube_t cube) |
| 414 | { | 404 | { |
| 415 | cube_t ret; | 405 | cube_t ret; |
| 416 | uint8_t i, piece, orien; | 406 | uint8_t i, piece, orien; |
| 417 | 407 | ||
| 418 | DBG_ASSERT(isconsistent(cube), zero, | 408 | DBG_ASSERT(cube_consistent(cube), zero, |
| 419 | "inverse error: inconsistent cube\n"); | 409 | "cube_inverse error: inconsistent cube\n"); |
| 420 | 410 | ||
| 421 | ret = zero; | 411 | ret = zero; |
| 422 | 412 | ||
| @@ -442,7 +432,7 @@ applymoves(cube_t cube, char *buf) | |||
| 442 | uint8_t r, m; | 432 | uint8_t r, m; |
| 443 | char *b; | 433 | char *b; |
| 444 | 434 | ||
| 445 | DBG_ASSERT(isconsistent(cube), zero, | 435 | DBG_ASSERT(cube_consistent(cube), zero, |
| 446 | "move error: inconsistent cube\n"); | 436 | "move error: inconsistent cube\n"); |
| 447 | 437 | ||
| 448 | fast = cubetofast(cube); | 438 | fast = cubetofast(cube); |
| @@ -473,7 +463,7 @@ applytrans(cube_t cube, char *buf) | |||
| 473 | cube_fast_t fast; | 463 | cube_fast_t fast; |
| 474 | uint8_t t; | 464 | uint8_t t; |
| 475 | 465 | ||
| 476 | DBG_ASSERT(isconsistent(cube), zero, | 466 | DBG_ASSERT(cube_consistent(cube), zero, |
| 477 | "transformation error: inconsistent cube\n"); | 467 | "transformation error: inconsistent cube\n"); |
| 478 | 468 | ||
| 479 | t = readtrans(buf); | 469 | t = readtrans(buf); |
| @@ -506,7 +496,7 @@ writecube(char *format, cube_t cube, char *buf) | |||
| 506 | char *errormsg; | 496 | char *errormsg; |
| 507 | size_t len; | 497 | size_t len; |
| 508 | 498 | ||
| 509 | if (!isconsistent(cube)) { | 499 | if (!cube_consistent(cube)) { |
| 510 | errormsg = "ERROR: cannot write inconsistent cube"; | 500 | errormsg = "ERROR: cannot write inconsistent cube"; |
| 511 | goto writecube_error; | 501 | goto writecube_error; |
| 512 | } | 502 | } |
| @@ -837,13 +827,6 @@ transform(cube_fast_t c, trans_t t) | |||
| 837 | invertco_fast(compose_fast(compose_fast(tcube, c), tinv)); | 827 | invertco_fast(compose_fast(compose_fast(tcube, c), tinv)); |
| 838 | } | 828 | } |
| 839 | 829 | ||
| 840 | /****************************************************************************** | ||
| 841 | Section: moves, move sequences and transformations | ||
| 842 | |||
| 843 | This section contains methods to work with moves and arrays of moves. They | ||
| 844 | do not rely on the cube structure. | ||
| 845 | ******************************************************************************/ | ||
| 846 | |||
| 847 | _static_inline uint8_t inverse_trans(uint8_t); | 830 | _static_inline uint8_t inverse_trans(uint8_t); |
| 848 | _static_inline uint8_t movebase(uint8_t); | 831 | _static_inline uint8_t movebase(uint8_t); |
| 849 | _static_inline uint8_t moveaxis(uint8_t); | 832 | _static_inline uint8_t moveaxis(uint8_t); |
| @@ -16,13 +16,6 @@ corners is with respect to U/D. | |||
| 16 | 16 | ||
| 17 | The permutation of the center pieces is not stored. This means that the | 17 | The permutation of the center pieces is not stored. This means that the |
| 18 | cube is assumed to be in a fixed orientation. | 18 | cube is assumed to be in a fixed orientation. |
| 19 | |||
| 20 | TODO: define EO and CO better, explain how to use them | ||
| 21 | TODO: encode centers? | ||
| 22 | |||
| 23 | The exact cube type structure depends on your system's configuration. If | ||
| 24 | you operate on the cube only via the functions provided below, you don't | ||
| 25 | need to worry about this. | ||
| 26 | ******************************************************************************/ | 19 | ******************************************************************************/ |
| 27 | 20 | ||
| 28 | typedef struct { | 21 | typedef struct { |
| @@ -30,30 +23,15 @@ typedef struct { | |||
| 30 | uint8_t edge[12]; | 23 | uint8_t edge[12]; |
| 31 | } cube_t; | 24 | } cube_t; |
| 32 | 25 | ||
| 33 | /* Returns a copy of the solved cube */ | 26 | cube_t cube_new(void); |
| 34 | cube_t solvedcube(void); | 27 | cube_t cube_clone(cube_t); |
| 35 | 28 | bool cube_consistent(cube_t); | |
| 36 | /* Basic checks on the cube */ | 29 | bool cube_solvable(cube_t); |
| 37 | bool isconsistent(cube_t); | 30 | bool cube_solved(cube_t); |
| 38 | bool issolvable(cube_t); | 31 | bool cube_equal(cube_t, cube_t); |
| 39 | bool issolved(cube_t); | 32 | bool cube_error(cube_t); |
| 40 | bool equal(cube_t, cube_t); | 33 | cube_t cube_compose(cube_t, cube_t); |
| 41 | 34 | cube_t cube_inverse(cube_t); | |
| 42 | /* All functions can return an error value, use iserror() to check this */ | ||
| 43 | bool iserror(cube_t); | ||
| 44 | |||
| 45 | /* Apply the second cube on the first as a move sequence */ | ||
| 46 | cube_t compose(cube_t, cube_t); | ||
| 47 | |||
| 48 | /* Invert the cube */ | ||
| 49 | cube_t inverse(cube_t); | ||
| 50 | |||
| 51 | /* Check if a cube represent a valid state (possibly unsolvable) */ | ||
| 52 | |||
| 53 | /* TODO comment on these and the format for moves and trans */ | ||
| 54 | /* For trans, only one trans is supported */ | ||
| 55 | cube_t applymoves(cube_t, char *); | ||
| 56 | cube_t applytrans(cube_t, char *); | ||
| 57 | 35 | ||
| 58 | /****************************************************************************** | 36 | /****************************************************************************** |
| 59 | Read / write utilities | 37 | Read / write utilities |
diff --git a/debugcube.o b/debugcube.o new file mode 100644 index 0000000..a37ffff --- /dev/null +++ b/debugcube.o | |||
| Binary files differ | |||
diff --git a/test/000_basic/basic_tests.c b/test/000_basic/basic_tests.c index c4434c5..53ccc9f 100644 --- a/test/000_basic/basic_tests.c +++ b/test/000_basic/basic_tests.c | |||
| @@ -1,27 +1,24 @@ | |||
| 1 | #include "../test.h" | 1 | #include "../test.h" |
| 2 | 2 | ||
| 3 | bool issolved(cube_t); | ||
| 4 | bool equal(cube_t, cube_t); | ||
| 5 | |||
| 6 | void | 3 | void |
| 7 | check(cube_t cube, char *name) | 4 | check(cube_t cube, char *name) |
| 8 | { | 5 | { |
| 9 | printf("%s is%s solvable\n", name, issolvable(cube) ? "" : " NOT"); | 6 | printf("%s is%s solvable\n", name, cube_solvable(cube) ? "" : " NOT"); |
| 10 | printf("%s is%s solved\n", name, issolved(cube) ? "" : " NOT"); | 7 | printf("%s is%s solved\n", name, cube_solved(cube) ? "" : " NOT"); |
| 11 | } | 8 | } |
| 12 | 9 | ||
| 13 | void | 10 | void |
| 14 | check2(cube_t cube1, char *name1, cube_t cube2, char *name2) | 11 | check2(cube_t cube1, char *name1, cube_t cube2, char *name2) |
| 15 | { | 12 | { |
| 16 | printf("%s and %s are%s equal\n", name1, name2, | 13 | printf("%s and %s are%s equal\n", name1, name2, |
| 17 | equal(cube1, cube2) ? "" : " NOT"); | 14 | cube_equal(cube1, cube2) ? "" : " NOT"); |
| 18 | } | 15 | } |
| 19 | 16 | ||
| 20 | int main(void) { | 17 | int main(void) { |
| 21 | cube_t zero, solved; | 18 | cube_t zero, solved; |
| 22 | 19 | ||
| 23 | memset(&zero, 0, sizeof(cube_t)); | 20 | memset(&zero, 0, sizeof(cube_t)); |
| 24 | solved = solvedcube(); | 21 | solved = cube_new(); |
| 25 | check(solved, "Solved"); | 22 | check(solved, "Solved"); |
| 26 | check(zero, "Zero"); | 23 | check(zero, "Zero"); |
| 27 | 24 | ||
diff --git a/test/001_cube_conversion/cube_conversion_tests.c b/test/001_cube_conversion/cube_conversion_tests.c index 589eb82..fe8a68f 100644 --- a/test/001_cube_conversion/cube_conversion_tests.c +++ b/test/001_cube_conversion/cube_conversion_tests.c | |||
| @@ -14,9 +14,9 @@ int main(void) { | |||
| 14 | fast = cubetofast(cube); | 14 | fast = cubetofast(cube); |
| 15 | cube2 = fasttocube(fast); | 15 | cube2 = fasttocube(fast); |
| 16 | 16 | ||
| 17 | if (iserror(cube)) { | 17 | if (cube_error(cube)) { |
| 18 | printf("Error reading cube\n"); | 18 | printf("Error reading cube\n"); |
| 19 | } else if (iserror(cube2)) { | 19 | } else if (cube_error(cube2)) { |
| 20 | printf("Error converting cube\n"); | 20 | printf("Error converting cube\n"); |
| 21 | } else { | 21 | } else { |
| 22 | writecube("H48", cube2, cubestr); | 22 | writecube("H48", cube2, cubestr); |
diff --git a/test/020_io_H48_read_write/io_H48_tests.c b/test/020_io_H48_read_write/io_H48_tests.c index 705356c..222e4d4 100644 --- a/test/020_io_H48_read_write/io_H48_tests.c +++ b/test/020_io_H48_read_write/io_H48_tests.c | |||
| @@ -11,9 +11,9 @@ int main(void) { | |||
| 11 | 11 | ||
| 12 | cube = readcube("H48", str); | 12 | cube = readcube("H48", str); |
| 13 | 13 | ||
| 14 | if (iserror(cube)) { | 14 | if (cube_error(cube)) { |
| 15 | printf("Error reading cube\n"); | 15 | printf("Error reading cube\n"); |
| 16 | } else if (!issolvable(cube)) { | 16 | } else if (!cube_solvable(cube)) { |
| 17 | printf("Cube is not solvable\n"); | 17 | printf("Cube is not solvable\n"); |
| 18 | } else { | 18 | } else { |
| 19 | writecube("H48", cube, str); | 19 | writecube("H48", cube, str); |
diff --git a/test/023_io_LST_write/io_LST_tests.c b/test/023_io_LST_write/io_LST_tests.c index df35632..8a3ce22 100644 --- a/test/023_io_LST_write/io_LST_tests.c +++ b/test/023_io_LST_write/io_LST_tests.c | |||
| @@ -11,9 +11,9 @@ int main(void) { | |||
| 11 | 11 | ||
| 12 | cube = readcube("H48", str); | 12 | cube = readcube("H48", str); |
| 13 | 13 | ||
| 14 | if (iserror(cube)) { | 14 | if (cube_error(cube)) { |
| 15 | printf("Error reading cube\n"); | 15 | printf("Error reading cube\n"); |
| 16 | } else if (!issolvable(cube)) { | 16 | } else if (!cube_solvable(cube)) { |
| 17 | printf("Cube is not solvable\n"); | 17 | printf("Cube is not solvable\n"); |
| 18 | } else { | 18 | } else { |
| 19 | writecube("LST", cube, str); | 19 | writecube("LST", cube, str); |
diff --git a/test/024_io_LST_read/io_LST_tests.c b/test/024_io_LST_read/io_LST_tests.c index 506a23d..81d4c54 100644 --- a/test/024_io_LST_read/io_LST_tests.c +++ b/test/024_io_LST_read/io_LST_tests.c | |||
| @@ -11,9 +11,9 @@ int main(void) { | |||
| 11 | 11 | ||
| 12 | cube = readcube("LST", str); | 12 | cube = readcube("LST", str); |
| 13 | 13 | ||
| 14 | if (iserror(cube)) { | 14 | if (cube_error(cube)) { |
| 15 | printf("Error reading cube\n"); | 15 | printf("Error reading cube\n"); |
| 16 | } else if (!issolvable(cube)) { | 16 | } else if (!cube_solvable(cube)) { |
| 17 | printf("Cube is not solvable\n"); | 17 | printf("Cube is not solvable\n"); |
| 18 | } else { | 18 | } else { |
| 19 | writecube("H48", cube, str); | 19 | writecube("H48", cube, str); |
diff --git a/test/030_move/move_tests.c b/test/030_move/move_tests.c index 73e9dbe..39458ba 100644 --- a/test/030_move/move_tests.c +++ b/test/030_move/move_tests.c | |||
| @@ -12,9 +12,9 @@ int main(void) { | |||
| 12 | 12 | ||
| 13 | cube = applymoves(cube, movestr); | 13 | cube = applymoves(cube, movestr); |
| 14 | 14 | ||
| 15 | if (iserror(cube)) { | 15 | if (cube_error(cube)) { |
| 16 | printf("Error moving cube\n"); | 16 | printf("Error moving cube\n"); |
| 17 | } else if (!issolvable(cube)) { | 17 | } else if (!cube_solvable(cube)) { |
| 18 | printf("Moved cube is not solvable\n"); | 18 | printf("Moved cube is not solvable\n"); |
| 19 | } else { | 19 | } else { |
| 20 | writecube("H48", cube, cubestr); | 20 | writecube("H48", cube, cubestr); |
diff --git a/test/040_inverse_cube/inverse_tests.c b/test/040_inverse_cube/inverse_tests.c index 2ff3bc7..ca7e481 100644 --- a/test/040_inverse_cube/inverse_tests.c +++ b/test/040_inverse_cube/inverse_tests.c | |||
| @@ -1,18 +1,16 @@ | |||
| 1 | #include "../test.h" | 1 | #include "../test.h" |
| 2 | 2 | ||
| 3 | cube_t inverse(cube_t); | ||
| 4 | |||
| 5 | int main(void) { | 3 | int main(void) { |
| 6 | char str[STRLENMAX]; | 4 | char str[STRLENMAX]; |
| 7 | cube_t cube, inv; | 5 | cube_t cube, inv; |
| 8 | 6 | ||
| 9 | fgets(str, STRLENMAX, stdin); | 7 | fgets(str, STRLENMAX, stdin); |
| 10 | cube = readcube("H48", str); | 8 | cube = readcube("H48", str); |
| 11 | inv = inverse(cube); | 9 | inv = cube_inverse(cube); |
| 12 | 10 | ||
| 13 | if (iserror(inv)) { | 11 | if (cube_error(inv)) { |
| 14 | printf("Error inverting cube\n"); | 12 | printf("Error inverting cube\n"); |
| 15 | } else if (!issolvable(inv)) { | 13 | } else if (!cube_solvable(inv)) { |
| 16 | printf("Inverted cube is not solvable\n"); | 14 | printf("Inverted cube is not solvable\n"); |
| 17 | } else { | 15 | } else { |
| 18 | writecube("H48", inv, str); | 16 | writecube("H48", inv, str); |
diff --git a/test/050_compose/compose_tests.c b/test/050_compose/compose_tests.c index 0ea4eff..c0bbbef 100644 --- a/test/050_compose/compose_tests.c +++ b/test/050_compose/compose_tests.c | |||
| @@ -13,9 +13,9 @@ int main(void) { | |||
| 13 | 13 | ||
| 14 | c3 = compose(c1, c2); | 14 | c3 = compose(c1, c2); |
| 15 | 15 | ||
| 16 | if (iserror(c3)) { | 16 | if (cube_error(c3)) { |
| 17 | printf("Error composing cubes\n"); | 17 | printf("Error composing cubes\n"); |
| 18 | } else if (!issolvable(c3)) { | 18 | } else if (!cube_solvable(c3)) { |
| 19 | printf("Composed cube is not solvable\n"); | 19 | printf("Composed cube is not solvable\n"); |
| 20 | } else { | 20 | } else { |
| 21 | writecube("H48", c3, str); | 21 | writecube("H48", c3, str); |
diff --git a/test/060_transform/transform_tests.c b/test/060_transform/transform_tests.c index f95ad67..8680a0b 100644 --- a/test/060_transform/transform_tests.c +++ b/test/060_transform/transform_tests.c | |||
| @@ -12,9 +12,9 @@ int main(void) { | |||
| 12 | 12 | ||
| 13 | cube = applytrans(cube, transtr); | 13 | cube = applytrans(cube, transtr); |
| 14 | 14 | ||
| 15 | if (iserror(cube)) { | 15 | if (cube_error(cube)) { |
| 16 | printf("Error transforming cube\n"); | 16 | printf("Error transforming cube\n"); |
| 17 | } else if (!issolvable(cube)) { | 17 | } else if (!cube_solvable(cube)) { |
| 18 | printf("Transformed cube is not solvable\n"); | 18 | printf("Transformed cube is not solvable\n"); |
| 19 | } else { | 19 | } else { |
| 20 | writecube("H48", cube, cubestr); | 20 | writecube("H48", cube, cubestr); |
diff --git a/test/061_inverse_trans/inverse_trans_tests.c b/test/061_inverse_trans/inverse_trans_tests.c index 77bd40b..7de8f66 100644 --- a/test/061_inverse_trans/inverse_trans_tests.c +++ b/test/061_inverse_trans/inverse_trans_tests.c | |||
| @@ -11,7 +11,7 @@ int main(void) { | |||
| 11 | cube_t cube; | 11 | cube_t cube; |
| 12 | 12 | ||
| 13 | for (t = 0; t < 48; t++) { | 13 | for (t = 0; t < 48; t++) { |
| 14 | cube = solvedcube(); | 14 | cube = cube_new(); |
| 15 | cube = applymoves(cube, "R"); | 15 | cube = applymoves(cube, "R"); |
| 16 | cube = applymoves(cube, "U"); | 16 | cube = applymoves(cube, "U"); |
| 17 | cube = applymoves(cube, "F"); | 17 | cube = applymoves(cube, "F"); |
| @@ -20,15 +20,15 @@ int main(void) { | |||
| 20 | tinv = inverse_trans(t); | 20 | tinv = inverse_trans(t); |
| 21 | cube = applytrans(cube, transstr[tinv]); | 21 | cube = applytrans(cube, transstr[tinv]); |
| 22 | 22 | ||
| 23 | if (iserror(cube)) { | 23 | if (cube_error(cube)) { |
| 24 | printf("Error transforming cube\n"); | 24 | printf("Error transforming cube\n"); |
| 25 | } else if (!issolvable(cube)) { | 25 | } else if (!cube_solvable(cube)) { |
| 26 | printf("Transformed cube is not solvable\n"); | 26 | printf("Transformed cube is not solvable\n"); |
| 27 | } else { | 27 | } else { |
| 28 | cube = applymoves(cube, "F'"); | 28 | cube = applymoves(cube, "F'"); |
| 29 | cube = applymoves(cube, "U'"); | 29 | cube = applymoves(cube, "U'"); |
| 30 | cube = applymoves(cube, "R'"); | 30 | cube = applymoves(cube, "R'"); |
| 31 | if (!issolved(cube)) | 31 | if (!cube_solved(cube)) |
| 32 | printf("%s: Error! Got %" PRIu8 "\n", | 32 | printf("%s: Error! Got %" PRIu8 "\n", |
| 33 | transstr[t], tinv); | 33 | transstr[t], tinv); |
| 34 | } | 34 | } |
diff --git a/test/last.err b/test/last.err new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/last.err | |||
diff --git a/test/last.out b/test/last.out new file mode 100644 index 0000000..102ac1b --- /dev/null +++ b/test/last.out | |||
| @@ -0,0 +1 @@ | |||
| UL1 UB0 DL1 UR0 BL1 DR1 BR0 DB0 FL1 UF0 FR1 DF0 DFR2 DFL0 DBL0 UFL0 UBR1 UBL0 UFR2 DBR1 | |||
diff --git a/test/test.h b/test/test.h index 3cbfd10..92ed0db 100644 --- a/test/test.h +++ b/test/test.h | |||
| @@ -4,24 +4,7 @@ | |||
| 4 | #include <stdlib.h> | 4 | #include <stdlib.h> |
| 5 | #include <string.h> | 5 | #include <string.h> |
| 6 | 6 | ||
| 7 | #define STRLENMAX 10000 | 7 | #include "../cube.h" |
| 8 | |||
| 9 | typedef struct { | ||
| 10 | uint8_t corner[8]; | ||
| 11 | uint8_t edge[12]; | ||
| 12 | } cube_t; | ||
| 13 | 8 | ||
| 14 | #ifdef CUBE_AVX2 | 9 | #define STRLENMAX 10000 |
| 15 | #include <immintrin.h> | ||
| 16 | typedef __m256i cube_fast_t; | ||
| 17 | #else | ||
| 18 | typedef cube_t cube_fast_t; | 10 | typedef cube_t cube_fast_t; |
| 19 | #endif | ||
| 20 | |||
| 21 | /* Basic functions used in most tests */ | ||
| 22 | cube_t solvedcube(void); | ||
| 23 | bool iserror(cube_t); | ||
| 24 | bool issolvable(cube_t); | ||
| 25 | bool issolved(cube_t); | ||
| 26 | cube_t readcube(char *, char *); | ||
| 27 | void writecube(char *, cube_t, char *); | ||
