From ce3f1cc0ef9f46d70ab5387b1458e9098b40711d Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Sat, 22 Mar 2025 06:43:11 +0100 Subject: Some safety with move arrays, small refactor appendchar --- test/010_math_permtoindex/permtoindex_tests.c | 4 ++-- test/011_math_indextoperm/indextoperm_tests.c | 2 +- test/012_math_permsign/permsign_tests.c | 4 ++-- test/013_math_digitstosumzero/digitstosumzero_tests.c | 7 ++++--- test/014_math_sumzerotodigits/sumzerotodigits.c | 2 +- test/032_invertmoves/invertmoves_tests.c | 8 ++++---- test/080_allowednext/allowednext_tests.c | 4 ++-- test/test.h | 2 +- 8 files changed, 17 insertions(+), 16 deletions(-) (limited to 'test') diff --git a/test/010_math_permtoindex/permtoindex_tests.c b/test/010_math_permtoindex/permtoindex_tests.c index 98c8207..ff61945 100644 --- a/test/010_math_permtoindex/permtoindex_tests.c +++ b/test/010_math_permtoindex/permtoindex_tests.c @@ -1,6 +1,6 @@ #include "../test.h" -int64_t permtoindex(uint8_t *, int64_t); +int64_t permtoindex(size_t n, const uint8_t [n]); void run(void) { char str[STRLENMAX]; @@ -14,6 +14,6 @@ void run(void) { a[i] = atoi(str); } - p = permtoindex(a, n); + p = permtoindex(n, a); printf("%" PRId64 "\n", p); } diff --git a/test/011_math_indextoperm/indextoperm_tests.c b/test/011_math_indextoperm/indextoperm_tests.c index cb1306d..87399ef 100644 --- a/test/011_math_indextoperm/indextoperm_tests.c +++ b/test/011_math_indextoperm/indextoperm_tests.c @@ -1,6 +1,6 @@ #include "../test.h" -void indextoperm(int64_t, int64_t, uint8_t *); +void indextoperm(int64_t, size_t n, uint8_t [n]); void run(void) { char str[STRLENMAX]; diff --git a/test/012_math_permsign/permsign_tests.c b/test/012_math_permsign/permsign_tests.c index fa8ce9b..0ec22af 100644 --- a/test/012_math_permsign/permsign_tests.c +++ b/test/012_math_permsign/permsign_tests.c @@ -1,6 +1,6 @@ #include "../test.h" -int permsign(uint8_t *, int64_t); +int permsign(size_t n, const uint8_t [n]); void run(void) { char str[STRLENMAX]; @@ -16,6 +16,6 @@ void run(void) { a[i] = atoi(str); } - p = permsign(a, n); + p = permsign(n, a); printf("%d\n", p); } diff --git a/test/013_math_digitstosumzero/digitstosumzero_tests.c b/test/013_math_digitstosumzero/digitstosumzero_tests.c index f28c02a..795bd9b 100644 --- a/test/013_math_digitstosumzero/digitstosumzero_tests.c +++ b/test/013_math_digitstosumzero/digitstosumzero_tests.c @@ -1,10 +1,11 @@ #include "../test.h" -int64_t digitstosumzero(uint8_t *, uint8_t, uint8_t); +int64_t digitstosumzero(size_t n, uint8_t [n], uint8_t); void run(void) { char str[STRLENMAX]; - uint8_t i, n, b, a[100]; + uint8_t i, b, a[100]; + size_t n; int64_t p; fgets(str, STRLENMAX, stdin); @@ -16,6 +17,6 @@ void run(void) { a[i] = atoi(str); } - p = digitstosumzero(a, n, b); + p = digitstosumzero(n, a, b); printf("%" PRId64 "\n", p); } diff --git a/test/014_math_sumzerotodigits/sumzerotodigits.c b/test/014_math_sumzerotodigits/sumzerotodigits.c index 5bea7ca..19272ea 100644 --- a/test/014_math_sumzerotodigits/sumzerotodigits.c +++ b/test/014_math_sumzerotodigits/sumzerotodigits.c @@ -1,6 +1,6 @@ #include "../test.h" -void sumzerotodigits(int64_t, uint8_t, uint8_t, uint8_t *); +void sumzerotodigits(int64_t, size_t n, uint8_t, uint8_t [n]); void run(void) { char str[STRLENMAX]; diff --git a/test/032_invertmoves/invertmoves_tests.c b/test/032_invertmoves/invertmoves_tests.c index d5da323..d791524 100644 --- a/test/032_invertmoves/invertmoves_tests.c +++ b/test/032_invertmoves/invertmoves_tests.c @@ -3,8 +3,8 @@ #define MAXMOVES 20 int64_t readmoves(const char *, int, uint8_t *); -void writemoves(uint8_t *, int, uint64_t, char *); -void invertmoves(uint8_t *, uint8_t, uint8_t *); +void writemoves(size_t n, uint8_t [n], size_t m, char [m]); +void invertmoves(size_t n, const uint8_t [n], uint8_t [n]); void run(void) { char movestr[STRLENMAX], outstr[STRLENMAX]; @@ -14,8 +14,8 @@ void run(void) { fgets(movestr, STRLENMAX, stdin); c = readmoves(movestr, MAXMOVES, moves); - invertmoves(moves, c, ret); - writemoves(ret, c, STRLENMAX, outstr); + invertmoves(c, moves, ret); + writemoves(c, ret, STRLENMAX, outstr); printf("%s\n", outstr); } diff --git a/test/080_allowednext/allowednext_tests.c b/test/080_allowednext/allowednext_tests.c index 644d4c5..08fe491 100644 --- a/test/080_allowednext/allowednext_tests.c +++ b/test/080_allowednext/allowednext_tests.c @@ -1,6 +1,6 @@ #include "../test.h" -bool allowednextmove(uint8_t *, uint8_t); +bool allowednextmove(size_t n, const uint8_t [n]); static char *moves[] = { "U", "U2", "U'", @@ -31,5 +31,5 @@ void run(void) { n > 2 ? moves[m[n-3]] : "-", n > 1 ? moves[m[n-2]] : "-", n > 0 ? moves[m[n-1]] : "-"); - printf("%s\n", allowednextmove(m, n) ? "true" : "false"); + printf("%s\n", allowednextmove(n, m) ? "true" : "false"); } diff --git a/test/test.h b/test/test.h index 4b281e0..3854520 100644 --- a/test/test.h +++ b/test/test.h @@ -25,7 +25,7 @@ bool isconsistent(cube_t); bool issolvable(cube_t); bool issolved(cube_t); cube_t readcube(char *, char *); -int64_t writecube(char *, cube_t, uint64_t, char *); +int64_t writecube(char *, cube_t, size_t n, char [n]); /* Test function to be implemented by all tests */ void run(void); -- cgit v1.3