aboutsummaryrefslogtreecommitdiff
path: root/test/104_h48set/h48set_tests.c
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-07-14 21:28:37 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-07-14 21:28:37 +0200
commit61e03f9f4eecf3d5811b11c44c9ef778f0a93bc7 (patch)
treea7a6edc2e44689ed62472bdece1d9bf6a300419f /test/104_h48set/h48set_tests.c
parenta016aa7f78c86c59bab3ae4970f8cc339186bc91 (diff)
downloadnissy-core-61e03f9f4eecf3d5811b11c44c9ef778f0a93bc7.tar.gz
nissy-core-61e03f9f4eecf3d5811b11c44c9ef778f0a93bc7.zip
Found a sneaky bug (it's all a mess now)
Diffstat (limited to 'test/104_h48set/h48set_tests.c')
-rw-r--r--test/104_h48set/h48set_tests.c64
1 files changed, 0 insertions, 64 deletions
diff --git a/test/104_h48set/h48set_tests.c b/test/104_h48set/h48set_tests.c
deleted file mode 100644
index d9310a9..0000000
--- a/test/104_h48set/h48set_tests.c
+++ /dev/null
@@ -1,64 +0,0 @@
1#include "../test.h"
2
3char str[STRLENMAX];
4
5typedef struct {
6 int64_t n;
7 int64_t capacity;
8 int64_t mod;
9 int64_t *table;
10} h48set_t;
11
12void h48set_create(h48set_t *, int64_t, int64_t);
13void h48set_clear(h48set_t *);
14void h48set_destroy(h48set_t *);
15int64_t h48set_lookup(h48set_t *, int64_t);
16void h48set_insert(h48set_t *, int64_t);
17bool h48set_contains(h48set_t *, int64_t);
18int64_t h48set_save(h48set_t *, int64_t *);
19
20int compare(const void *x, const void *y) {
21 int64_t a = *(int64_t *)x;
22 int64_t b = *(int64_t *)y;
23
24 if (a > b) return 1;
25 if (a == b) return 0;
26 return -1;
27}
28
29int64_t readl(void) {
30 fgets(str, STRLENMAX, stdin);
31 return atoll(str);
32}
33
34void run(void) {
35 h48set_t set;
36 int64_t n, i, k, capacity, mod, *a, *b;
37
38 capacity = readl();
39 mod = readl();
40 n = readl();
41
42 a = malloc(n * sizeof(int64_t));
43 b = malloc(n * sizeof(int64_t));
44 for (i = 0; i < n; i++)
45 a[i] = readl();
46
47 h48set_create(&set, capacity, mod);
48 for (i = 0; i < n; i++)
49 h48set_insert(&set, a[i]);
50
51 k = h48set_save(&set, b);
52 qsort(b, k, sizeof(int64_t), compare);
53
54 printf("%" PRId64 "\n", k);
55 for (i = 0; i < k; i++)
56 printf("%" PRId64 "\n", b[i]);
57 for (i = 0; i < n; i++)
58 if (!h48set_contains(&set, a[i]))
59 printf("Set does not contain %" PRId64 "\n", a[i]);
60
61 h48set_destroy(&set);
62 free(a);
63 free(b);
64}

Generated with cgit - Back to sebastiano.tronto.net