appendsolution_tests.c (1698B)
1 /* 2 Input format for appendsolution tests: 3 4 moves on normal 5 moves on inverse (without parentheses) 6 unniss flag (0=false, 1=true) 7 number of transformations 8 transformations, one per line 9 10 See below for the output format. 11 */ 12 13 #include "../test.h" 14 15 uint8_t readtrans(const char [NISSY_SIZE_TRANSFORMATION]); 16 int64_t readmoves(const char *, size_t n, uint8_t [n]); 17 void solution_moves_reset(solution_moves_t [static 1]); 18 bool solution_list_init(solution_list_t [static 1], size_t n, char [n]); 19 int64_t appendsolution(const solution_moves_t [static 1], 20 const solution_settings_t [static 1], solution_list_t [static 1], bool, 21 const char *); 22 23 void run(void) { 24 int i, ntrans; 25 char str[STRLENMAX], buf[STRLENMAX]; 26 solution_moves_t moves; 27 solution_settings_t settings; 28 solution_list_t list; 29 30 solution_moves_reset(&moves); 31 solution_list_init(&list, STRLENMAX, buf); 32 settings = (solution_settings_t) { 33 .tmask = UINT64_C(0), 34 .unniss = false, 35 .maxmoves = 20, 36 .maxsolutions = 100, 37 .optimal = -1, 38 }; 39 40 fgets(str, STRLENMAX, stdin); 41 moves.nmoves = (uint8_t)readmoves(str, 20, moves.moves); 42 fgets(str, STRLENMAX, stdin); 43 moves.npremoves = (uint8_t)readmoves(str, 20, moves.premoves); 44 fgets(str, STRLENMAX, stdin); 45 settings.unniss = (bool)atoi(str); 46 fgets(str, STRLENMAX, stdin); 47 ntrans = atoi(str); 48 for (i = 0; i < ntrans; i++) { 49 fgets(str, STRLENMAX, stdin); 50 settings.tmask |= UINT64_C(1) << (uint64_t)readtrans(str); 51 } 52 53 appendsolution(&moves, &settings, &list, false, "Test"); 54 55 printf("%s", list.buf); 56 printf("Number of solutions: %" PRIu64 "\n", list.nsols); 57 printf("Shortest solution length: %" PRIu8 "\n", list.shortest_sol); 58 printf("Used bytes: %zu\n", list.used); 59 }