aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-09-09 17:33:16 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-09-09 17:33:16 +0200
commit16cf844396181e743403b046c06a21f1dca39426 (patch)
tree48889f2275f732a9f9bcff9c711d26931a74c025 /test
parent317ced6e3bbfc9a4f2ebe1ca1b4705a0fddf6df4 (diff)
downloadnissy-core-16cf844396181e743403b046c06a21f1dca39426.tar.gz
nissy-core-16cf844396181e743403b046c06a21f1dca39426.zip
Added tableinfo
Diffstat (limited to 'test')
-rw-r--r--test/090_tables_readwrite/00_table.in31
-rw-r--r--test/090_tables_readwrite/00_table.out31
-rw-r--r--test/090_tables_readwrite/tables_readwrite_tests.c84
3 files changed, 146 insertions, 0 deletions
diff --git a/test/090_tables_readwrite/00_table.in b/test/090_tables_readwrite/00_table.in
new file mode 100644
index 0000000..1816242
--- /dev/null
+++ b/test/090_tables_readwrite/00_table.in
@@ -0,0 +1,31 @@
1Test solver
2
3512
4100000000000
512345678912345
6399999999998
72
80
920
10
11100
12101
13102
14103
15104
16105
17106
18107
19108
20109
21110
22111
23112
24113
25114
26115
27116
28117
29118
30119
31120
diff --git a/test/090_tables_readwrite/00_table.out b/test/090_tables_readwrite/00_table.out
new file mode 100644
index 0000000..1816242
--- /dev/null
+++ b/test/090_tables_readwrite/00_table.out
@@ -0,0 +1,31 @@
1Test solver
2
3512
4100000000000
512345678912345
6399999999998
72
80
920
10
11100
12101
13102
14103
15104
16105
17106
18107
19108
20109
21110
22111
23112
24113
25114
26115
27116
28117
29118
30119
31120
diff --git a/test/090_tables_readwrite/tables_readwrite_tests.c b/test/090_tables_readwrite/tables_readwrite_tests.c
new file mode 100644
index 0000000..97b8ab7
--- /dev/null
+++ b/test/090_tables_readwrite/tables_readwrite_tests.c
@@ -0,0 +1,84 @@
1#include "../test.h"
2
3#define INFOSIZE 512
4#define INFO_SOLVER_STRLEN 20
5#define INFO_DISTRIBUTION_LEN 21
6
7typedef struct {
8 char solver[INFO_SOLVER_STRLEN];
9 uint64_t infosize;
10 uint64_t fullsize;
11 uint64_t hash;
12 uint64_t entries;
13 uint8_t bits;
14 uint8_t base;
15 uint8_t maxvalue;
16 uint64_t distribution[INFO_DISTRIBUTION_LEN];
17} tableinfo_t;
18
19bool readtableinfo(const void *, tableinfo_t *);
20bool writetableinfo(const tableinfo_t *, void *);
21
22uint64_t readn(void) {
23 char str[STRLENMAX];
24
25 fgets(str, STRLENMAX, stdin);
26 return atoll(str);
27}
28
29tableinfo_t test_readinfo(void) {
30 int i;
31 tableinfo_t ret;
32 char emptyline[2];
33
34 fgets(ret.solver, INFO_SOLVER_STRLEN, stdin);
35 for (i = 0; i < INFO_SOLVER_STRLEN; i++)
36 if (ret.solver[i] == '\n')
37 ret.solver[i] = 0;
38
39 fgets(emptyline, 2, stdin);
40
41 ret.infosize = readn();
42 ret.fullsize = readn();
43 ret.hash = readn();
44 ret.entries = readn();
45 ret.bits = (uint8_t)readn();
46 ret.base = (uint8_t)readn();
47 ret.maxvalue = (uint8_t)readn();
48
49 fgets(emptyline, 2, stdin);
50
51 for (i = 0; i < INFO_DISTRIBUTION_LEN; i++)
52 ret.distribution[i] = readn();
53
54 return ret;
55}
56
57void test_writeinfo(tableinfo_t info) {
58 int i;
59
60 printf("%s\n", info.solver);
61 printf("\n");
62
63 printf("%" PRIu64 "\n", info.infosize);
64 printf("%" PRIu64 "\n", info.fullsize);
65 printf("%" PRIu64 "\n", info.hash);
66 printf("%" PRIu64 "\n", info.entries);
67 printf("%" PRIu8 "\n", info.bits);
68 printf("%" PRIu8 "\n", info.base);
69 printf("%" PRIu8 "\n", info.maxvalue);
70 printf("\n");
71
72 for (i = 0; i < INFO_DISTRIBUTION_LEN; i++)
73 printf("%" PRIu64 "\n", info.distribution[i]);
74}
75
76void run(void) {
77 char buf[INFOSIZE];
78 tableinfo_t expected, actual;
79
80 expected = test_readinfo();
81 writetableinfo(&expected, buf);
82 readtableinfo(buf, &actual);
83 test_writeinfo(actual);
84}

Generated with cgit - Back to sebastiano.tronto.net