commit 832ad3dcf3818e57c53304ea9b09a943e785a16b parent 1cecea625ed405c7203d1977e687da36d835fc9a Author: Sebastiano Tronto <sebastiano@tronto.net> Date: Mon, 10 Jun 2024 19:26:47 +0200 Added tests for B32 Diffstat:
32 files changed, 34 insertions(+), 8 deletions(-)
diff --git a/TODO.txt b/TODO.txt @@ -1,14 +1,13 @@ Refactoring: remove cube_fast_t and add b32 format - see TODO comments in cube.h - - switch to b32 by default (part 1) - add tests for b32 (write at some by hand) - fix utility code in utils/*.c replace h48_to_lst with convert.c fix invert.c fix utils/*.sh scripts to use the new convert convert all utils/cubes/*.txt files in b32 format - - switch to b32 by default (part 2) + - switch to b32 by default change all tests to use b32 + split read and write for H48 - if all public functions work with strings, always use return value as error code (solve already does this), and use string as buffer to print error diff --git a/src/io_cube.h b/src/io_cube.h @@ -324,17 +324,17 @@ writecube_LST(cube_t cube, char *buf) _static uint8_t b32toedge(char c) { - if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'g')) + if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'f'))) return 255; - return c <= 'Z' ? (uint8_t)(c - 'A') : (uint8_t)(c - 'a'); + return c <= 'Z' ? (uint8_t)(c - 'A') : (uint8_t)(c - 'a') + 26; } _static uint8_t b32tocorner(char c) { uint8_t val; - if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'g')) + if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'f'))) return 255; val = c <= 'Z' ? (uint8_t)(c - 'A') : (uint8_t)(c - 'a') + 26; @@ -345,7 +345,7 @@ b32tocorner(char c) { _static char edgetob32(uint8_t edge) { - return edge <= 26 ? 'A' + (char)edge : 'a' + (char)(edge - 26); + return edge < 26 ? 'A' + (char)edge : 'a' + (char)(edge - 26); } _static char @@ -355,5 +355,5 @@ cornertob32(uint8_t corner) val = (corner & 7) | ((corner & 96) >> 2); - return val <= 26 ? 'A' + (char)val : 'a' + (char)(val - 26); + return val < 26 ? 'A' + (char)val : 'a' + (char)(val - 26); } diff --git a/test/020_io_H48_read_write/00_garbage.in b/test/020_io_B32_read_write/00_garbage.in diff --git a/test/020_io_H48_read_write/00_garbage.out b/test/020_io_B32_read_write/00_garbage.out diff --git a/test/020_io_B32_read_write/01_solved.in b/test/020_io_B32_read_write/01_solved.in @@ -0,0 +1 @@ +ABCDEFGH=ABCDEFGHIJKL diff --git a/test/020_io_B32_read_write/01_solved.out b/test/020_io_B32_read_write/01_solved.out @@ -0,0 +1 @@ +ABCDEFGH=ABCDEFGHIJKL diff --git a/test/020_io_B32_read_write/02_F.in b/test/020_io_B32_read_write/02_F.in @@ -0,0 +1 @@ +MBODSFQH=ZBCYEFGHQTKL diff --git a/test/020_io_B32_read_write/02_F.out b/test/020_io_B32_read_write/02_F.out @@ -0,0 +1 @@ +MBODSFQH=ZBCYEFGHQTKL diff --git a/test/020_io_B32_read_write/03_scrambled.in b/test/020_io_B32_read_write/03_scrambled.in @@ -0,0 +1 @@ +OINUTCXB=JCRIEDAbVaGH diff --git a/test/020_io_B32_read_write/03_scrambled.out b/test/020_io_B32_read_write/03_scrambled.out @@ -0,0 +1 @@ +OINUTCXB=JCRIEDAbVaGH diff --git a/test/020_io_B32_read_write/io_B32_tests.c b/test/020_io_B32_read_write/io_B32_tests.c @@ -0,0 +1,21 @@ +#include "../test.h" + +int main(void) { + char str[STRLENMAX]; + cube_t cube; + + fgets(str, STRLENMAX, stdin); + + cube = readcube("B32", str); + + if (iserror(cube)) { + printf("Error reading cube\n"); + } else if (!issolvable(cube)) { + printf("Cube is not solvable\n"); + } else { + writecube("B32", cube, str); + printf("%s\n", str); + } + + return 0; +} diff --git a/test/020_io_H48_read_write/00_garbage.in b/test/021_io_H48_read_write/00_garbage.in diff --git a/test/020_io_H48_read_write/00_garbage.out b/test/021_io_H48_read_write/00_garbage.out diff --git a/test/020_io_H48_read_write/01_solved_oneline.in b/test/021_io_H48_read_write/01_solved_oneline.in diff --git a/test/020_io_H48_read_write/01_solved_oneline.out b/test/021_io_H48_read_write/01_solved_oneline.out diff --git a/test/020_io_H48_read_write/02_solved_oneline_whitespace.in b/test/021_io_H48_read_write/02_solved_oneline_whitespace.in diff --git a/test/020_io_H48_read_write/02_solved_oneline_whitespace.out b/test/021_io_H48_read_write/02_solved_oneline_whitespace.out diff --git a/test/020_io_H48_read_write/03_solved_multiline.in b/test/021_io_H48_read_write/03_solved_multiline.in diff --git a/test/020_io_H48_read_write/03_solved_multiline.out b/test/021_io_H48_read_write/03_solved_multiline.out diff --git a/test/020_io_H48_read_write/04_unsolvable_ep.in b/test/021_io_H48_read_write/04_unsolvable_ep.in diff --git a/test/020_io_H48_read_write/04_unsolvable_ep.out b/test/021_io_H48_read_write/04_unsolvable_ep.out diff --git a/test/020_io_H48_read_write/05_unsolvable_eo.in b/test/021_io_H48_read_write/05_unsolvable_eo.in diff --git a/test/020_io_H48_read_write/05_unsolvable_eo.out b/test/021_io_H48_read_write/05_unsolvable_eo.out diff --git a/test/020_io_H48_read_write/06_unsolvable_cp.in b/test/021_io_H48_read_write/06_unsolvable_cp.in diff --git a/test/020_io_H48_read_write/06_unsolvable_cp.out b/test/021_io_H48_read_write/06_unsolvable_cp.out diff --git a/test/020_io_H48_read_write/07_unsolvable_co.in b/test/021_io_H48_read_write/07_unsolvable_co.in diff --git a/test/020_io_H48_read_write/07_unsolvable_co.out b/test/021_io_H48_read_write/07_unsolvable_co.out diff --git a/test/020_io_H48_read_write/08_unsolved.in b/test/021_io_H48_read_write/08_unsolved.in diff --git a/test/020_io_H48_read_write/08_unsolved.out b/test/021_io_H48_read_write/08_unsolved.out diff --git a/test/020_io_H48_read_write/io_H48_tests.c b/test/021_io_H48_read_write/io_H48_tests.c diff --git a/test/023_io_LST_write/io_LST_tests.c b/test/023_io_LST_write/io_LST_write_tests.c diff --git a/test/024_io_LST_read/io_LST_tests.c b/test/024_io_LST_read/io_LST_read_tests.c