From d5e7698d0c7ecb61fe49263982f750c053147089 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Tue, 14 Nov 2023 22:42:08 +0100 Subject: Added tests allowednext --- test/080_allowednext/allowednext_tests.c | 42 ++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 test/080_allowednext/allowednext_tests.c (limited to 'test/080_allowednext/allowednext_tests.c') diff --git a/test/080_allowednext/allowednext_tests.c b/test/080_allowednext/allowednext_tests.c new file mode 100644 index 0000000..98a437f --- /dev/null +++ b/test/080_allowednext/allowednext_tests.c @@ -0,0 +1,42 @@ +#include "../test.h" + +bool allowednextmove(uint8_t *, int, uint8_t); + +static char *moves[] = { + "U", "U2", "U'", + "D", "D2", "D'", + "R", "R2", "R'", + "L", "L2", "L'", + "F", "F2", "F'", + "B", "B2", "B'", +}; + +int main() { + char movestr[STRLENMAX]; + uint8_t m[100], next; + int n, i, j; + + fgets(movestr, STRLENMAX, stdin); + n = atoi(movestr); + + for (i = 0; i < n; i++) { + fgets(movestr, STRLENMAX, stdin); + movestr[strcspn(movestr, "\n")] = 0; + for (j = 0; j < 18; j++) + if (!strcmp(movestr, moves[j])) + m[i] = j; + } + fgets(movestr, STRLENMAX, stdin); + movestr[strcspn(movestr, "\n")] = 0; + for (j = 0; j < 18; j++) + if (!strcmp(movestr, moves[j])) + next = j; + + fprintf(stderr, "Last two: %s, %s\nNext: %s\n", + n > 1 ? moves[m[n-2]] : "-", + n > 0 ? moves[m[n-1]] : "-", + moves[next]); + printf("%s\n", allowednextmove(m, n, next) ? "true" : "false"); + + return 0; +} -- cgit v1.3