h48

A prototype for an optimal Rubik's cube solver, work in progress.
git clone https://git.tronto.net/h48
Download | Log | Files | Refs | README | LICENSE

tables_readwrite_tests.c (1743B)


      1 #include "../test.h"
      2 
      3 bool readtableinfo(uint64_t, const char *, tableinfo_t *);
      4 bool writetableinfo(const tableinfo_t *, uint64_t, char *);
      5 
      6 uint64_t readn(void) {
      7 	char str[STRLENMAX];
      8 
      9 	fgets(str, STRLENMAX, stdin);
     10 	return atoll(str);
     11 }
     12 
     13 tableinfo_t test_readinfo(void) {
     14 	int i;
     15 	tableinfo_t ret;
     16 	char emptyline[2];
     17 
     18 	fgets(ret.solver, INFO_SOLVER_STRLEN, stdin);
     19 	for (i = 0; i < INFO_SOLVER_STRLEN; i++)
     20 		if (ret.solver[i] == '\n')
     21 			ret.solver[i] = 0;
     22 
     23 	fgets(emptyline, 2, stdin);
     24 
     25 	ret.type = readn();
     26 	ret.infosize = readn();
     27 	ret.fullsize = readn();
     28 	ret.hash = readn();
     29 	ret.entries = readn();
     30 	ret.classes = readn();
     31 	ret.h48h = (uint8_t)readn();
     32 	ret.bits = (uint8_t)readn();
     33 	ret.base = (uint8_t)readn();
     34 	ret.maxvalue = (uint8_t)readn();
     35 	ret.next = readn();
     36 
     37 	fgets(emptyline, 2, stdin);
     38 
     39 	for (i = 0; i < INFO_DISTRIBUTION_LEN; i++)
     40 		ret.distribution[i] = readn();
     41 
     42 	return ret;
     43 }
     44 
     45 void test_writeinfo(tableinfo_t info) {
     46 	int i;
     47 
     48 	printf("%s\n", info.solver);
     49 	printf("\n");
     50 
     51 	printf("%" PRIu64 "\n", info.type);
     52 	printf("%" PRIu64 "\n", info.infosize);
     53 	printf("%" PRIu64 "\n", info.fullsize);
     54 	printf("%" PRIu64 "\n", info.hash);
     55 	printf("%" PRIu64 "\n", info.entries);
     56 	printf("%" PRIu64 "\n", info.classes);
     57 	printf("%" PRIu8 "\n", info.h48h);
     58 	printf("%" PRIu8 "\n", info.bits);
     59 	printf("%" PRIu8 "\n", info.base);
     60 	printf("%" PRIu8 "\n", info.maxvalue);
     61 	printf("%" PRIu64 "\n", info.next);
     62 	printf("\n");
     63 
     64 	for (i = 0; i < INFO_DISTRIBUTION_LEN; i++)
     65 		printf("%" PRIu64 "\n", info.distribution[i]);
     66 }
     67 
     68 void run(void) {
     69 	char buf[INFOSIZE];
     70 	tableinfo_t expected, actual;
     71 
     72 	expected = test_readinfo();
     73 	writetableinfo(&expected, INFOSIZE, buf);
     74 	readtableinfo(INFOSIZE, buf, &actual);
     75 	test_writeinfo(actual);
     76 }