appendsolution_tests.c (1912B)
1 /* 2 Input format for appendsolution tests: 3 4 moves on normal (with NISS notation) 5 unniss flag (0=false, 1=true) 6 number of transformations 7 transformations, one per line 8 the orientation of the cube, as a number from 0 to 23 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, size_t m, 17 uint64_t *, uint64_t *, uint8_t [n], uint8_t [m]); 18 void solution_moves_reset(solution_moves_t [static 1]); 19 bool solution_list_init(solution_list_t [static 1], size_t n, char [n]); 20 int64_t appendsolution(const solution_moves_t [static 1], 21 const solution_settings_t [static 1], solution_list_t [static 1], bool, 22 const char *); 23 24 void run(void) { 25 int i, ntrans; 26 int64_t tot; 27 uint64_t nm, np; 28 char str[STRLENMAX], buf[STRLENMAX]; 29 solution_moves_t moves; 30 solution_settings_t settings; 31 solution_list_t list; 32 33 solution_moves_reset(&moves); 34 solution_list_init(&list, STRLENMAX, buf); 35 settings = (solution_settings_t) { 36 .tmask = UINT64_C(0), 37 .unniss = false, 38 .maxmoves = 20, 39 .maxsolutions = 100, 40 .optimal = -1, 41 }; 42 43 fgets(str, STRLENMAX, stdin); 44 tot = readmoves(str, 20, 20, &nm, &np, moves.moves, moves.premoves); 45 if (tot < 0) { 46 printf("Test error reading moves\n"); 47 return; 48 } 49 moves.nmoves = nm; 50 moves.npremoves = np; 51 fgets(str, STRLENMAX, stdin); 52 settings.unniss = (bool)atoi(str); 53 fgets(str, STRLENMAX, stdin); 54 ntrans = atoi(str); 55 for (i = 0; i < ntrans; i++) { 56 fgets(str, STRLENMAX, stdin); 57 settings.tmask |= UINT64_C(1) << (uint64_t)readtrans(str); 58 } 59 fgets(str, STRLENMAX, stdin); 60 settings.orientation = atoi(str); 61 62 appendsolution(&moves, &settings, &list, false, "Test"); 63 64 printf("%s", list.buf); 65 printf("Number of solutions: %" PRIu64 "\n", list.nsols); 66 printf("Shortest solution length: %" PRIu8 "\n", list.shortest_sol); 67 printf("Used bytes: %zu\n", list.used); 68 }