diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-07-14 21:28:37 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-07-14 21:28:37 +0200 |
| commit | 61e03f9f4eecf3d5811b11c44c9ef778f0a93bc7 (patch) | |
| tree | a7a6edc2e44689ed62472bdece1d9bf6a300419f /test/112_h48set | |
| parent | a016aa7f78c86c59bab3ae4970f8cc339186bc91 (diff) | |
| download | nissy-core-61e03f9f4eecf3d5811b11c44c9ef778f0a93bc7.tar.gz nissy-core-61e03f9f4eecf3d5811b11c44c9ef778f0a93bc7.zip | |
Found a sneaky bug (it's all a mess now)
Diffstat (limited to 'test/112_h48set')
| -rw-r--r-- | test/112_h48set/00_small.in | 6 | ||||
| -rw-r--r-- | test/112_h48set/00_small.out | 3 | ||||
| -rw-r--r-- | test/112_h48set/01_large.in | 153 | ||||
| -rw-r--r-- | test/112_h48set/01_large.out | 83 | ||||
| -rw-r--r-- | test/112_h48set/h48set_tests.c | 64 |
5 files changed, 309 insertions, 0 deletions
diff --git a/test/112_h48set/00_small.in b/test/112_h48set/00_small.in new file mode 100644 index 0000000..d788d5b --- /dev/null +++ b/test/112_h48set/00_small.in | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | 11 | ||
| 2 | 7 | ||
| 3 | 3 | ||
| 4 | 34 | ||
| 5 | 45 | ||
| 6 | 34 | ||
diff --git a/test/112_h48set/00_small.out b/test/112_h48set/00_small.out new file mode 100644 index 0000000..29c08e5 --- /dev/null +++ b/test/112_h48set/00_small.out | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | 2 | ||
| 2 | 34 | ||
| 3 | 45 | ||
diff --git a/test/112_h48set/01_large.in b/test/112_h48set/01_large.in new file mode 100644 index 0000000..a70ef9a --- /dev/null +++ b/test/112_h48set/01_large.in | |||
| @@ -0,0 +1,153 @@ | |||
| 1 | 307 | ||
| 2 | 293 | ||
| 3 | 150 | ||
| 4 | 100053 | ||
| 5 | 100045 | ||
| 6 | 100007 | ||
| 7 | 100007 | ||
| 8 | 100011 | ||
| 9 | 100072 | ||
| 10 | 100033 | ||
| 11 | 100015 | ||
| 12 | 100013 | ||
| 13 | 100068 | ||
| 14 | 100047 | ||
| 15 | 100046 | ||
| 16 | 100000 | ||
| 17 | 100076 | ||
| 18 | 100021 | ||
| 19 | 100019 | ||
| 20 | 100015 | ||
| 21 | 100049 | ||
| 22 | 100052 | ||
| 23 | 100071 | ||
| 24 | 100058 | ||
| 25 | 100009 | ||
| 26 | 100060 | ||
| 27 | 100030 | ||
| 28 | 100051 | ||
| 29 | 100069 | ||
| 30 | 100011 | ||
| 31 | 100051 | ||
| 32 | 100014 | ||
| 33 | 100031 | ||
| 34 | 100017 | ||
| 35 | 100076 | ||
| 36 | 100016 | ||
| 37 | 100030 | ||
| 38 | 100037 | ||
| 39 | 100011 | ||
| 40 | 100002 | ||
| 41 | 100029 | ||
| 42 | 100022 | ||
| 43 | 100038 | ||
| 44 | 100075 | ||
| 45 | 100066 | ||
| 46 | 100051 | ||
| 47 | 100020 | ||
| 48 | 100039 | ||
| 49 | 100029 | ||
| 50 | 100087 | ||
| 51 | 100099 | ||
| 52 | 100041 | ||
| 53 | 100042 | ||
| 54 | 100026 | ||
| 55 | 100060 | ||
| 56 | 100006 | ||
| 57 | 100010 | ||
| 58 | 100079 | ||
| 59 | 100046 | ||
| 60 | 100086 | ||
| 61 | 100010 | ||
| 62 | 100036 | ||
| 63 | 100047 | ||
| 64 | 100069 | ||
| 65 | 100041 | ||
| 66 | 100074 | ||
| 67 | 100090 | ||
| 68 | 100092 | ||
| 69 | 100020 | ||
| 70 | 100096 | ||
| 71 | 100046 | ||
| 72 | 100028 | ||
| 73 | 100072 | ||
| 74 | 100096 | ||
| 75 | 100025 | ||
| 76 | 100001 | ||
| 77 | 100067 | ||
| 78 | 100044 | ||
| 79 | 100063 | ||
| 80 | 100026 | ||
| 81 | 100062 | ||
| 82 | 100091 | ||
| 83 | 100012 | ||
| 84 | 100073 | ||
| 85 | 100051 | ||
| 86 | 100010 | ||
| 87 | 100096 | ||
| 88 | 100043 | ||
| 89 | 100025 | ||
| 90 | 100077 | ||
| 91 | 100089 | ||
| 92 | 100005 | ||
| 93 | 100024 | ||
| 94 | 100091 | ||
| 95 | 100046 | ||
| 96 | 100053 | ||
| 97 | 100058 | ||
| 98 | 100065 | ||
| 99 | 100051 | ||
| 100 | 100056 | ||
| 101 | 100025 | ||
| 102 | 100093 | ||
| 103 | 100088 | ||
| 104 | 100033 | ||
| 105 | 100073 | ||
| 106 | 100048 | ||
| 107 | 100059 | ||
| 108 | 100027 | ||
| 109 | 100045 | ||
| 110 | 100012 | ||
| 111 | 100059 | ||
| 112 | 100084 | ||
| 113 | 100017 | ||
| 114 | 100048 | ||
| 115 | 100004 | ||
| 116 | 100051 | ||
| 117 | 100016 | ||
| 118 | 100088 | ||
| 119 | 100033 | ||
| 120 | 100064 | ||
| 121 | 100060 | ||
| 122 | 100043 | ||
| 123 | 100084 | ||
| 124 | 100026 | ||
| 125 | 100051 | ||
| 126 | 100060 | ||
| 127 | 100069 | ||
| 128 | 100015 | ||
| 129 | 100014 | ||
| 130 | 100038 | ||
| 131 | 100068 | ||
| 132 | 100038 | ||
| 133 | 100097 | ||
| 134 | 100017 | ||
| 135 | 100013 | ||
| 136 | 100053 | ||
| 137 | 100019 | ||
| 138 | 100018 | ||
| 139 | 100081 | ||
| 140 | 100071 | ||
| 141 | 100025 | ||
| 142 | 100014 | ||
| 143 | 100016 | ||
| 144 | 100011 | ||
| 145 | 100069 | ||
| 146 | 100079 | ||
| 147 | 100063 | ||
| 148 | 100070 | ||
| 149 | 100072 | ||
| 150 | 100095 | ||
| 151 | 100042 | ||
| 152 | 100008 | ||
| 153 | 100022 | ||
diff --git a/test/112_h48set/01_large.out b/test/112_h48set/01_large.out new file mode 100644 index 0000000..6632336 --- /dev/null +++ b/test/112_h48set/01_large.out | |||
| @@ -0,0 +1,83 @@ | |||
| 1 | 82 | ||
| 2 | 100000 | ||
| 3 | 100001 | ||
| 4 | 100002 | ||
| 5 | 100004 | ||
| 6 | 100005 | ||
| 7 | 100006 | ||
| 8 | 100007 | ||
| 9 | 100008 | ||
| 10 | 100009 | ||
| 11 | 100010 | ||
| 12 | 100011 | ||
| 13 | 100012 | ||
| 14 | 100013 | ||
| 15 | 100014 | ||
| 16 | 100015 | ||
| 17 | 100016 | ||
| 18 | 100017 | ||
| 19 | 100018 | ||
| 20 | 100019 | ||
| 21 | 100020 | ||
| 22 | 100021 | ||
| 23 | 100022 | ||
| 24 | 100024 | ||
| 25 | 100025 | ||
| 26 | 100026 | ||
| 27 | 100027 | ||
| 28 | 100028 | ||
| 29 | 100029 | ||
| 30 | 100030 | ||
| 31 | 100031 | ||
| 32 | 100033 | ||
| 33 | 100036 | ||
| 34 | 100037 | ||
| 35 | 100038 | ||
| 36 | 100039 | ||
| 37 | 100041 | ||
| 38 | 100042 | ||
| 39 | 100043 | ||
| 40 | 100044 | ||
| 41 | 100045 | ||
| 42 | 100046 | ||
| 43 | 100047 | ||
| 44 | 100048 | ||
| 45 | 100049 | ||
| 46 | 100051 | ||
| 47 | 100052 | ||
| 48 | 100053 | ||
| 49 | 100056 | ||
| 50 | 100058 | ||
| 51 | 100059 | ||
| 52 | 100060 | ||
| 53 | 100062 | ||
| 54 | 100063 | ||
| 55 | 100064 | ||
| 56 | 100065 | ||
| 57 | 100066 | ||
| 58 | 100067 | ||
| 59 | 100068 | ||
| 60 | 100069 | ||
| 61 | 100070 | ||
| 62 | 100071 | ||
| 63 | 100072 | ||
| 64 | 100073 | ||
| 65 | 100074 | ||
| 66 | 100075 | ||
| 67 | 100076 | ||
| 68 | 100077 | ||
| 69 | 100079 | ||
| 70 | 100081 | ||
| 71 | 100084 | ||
| 72 | 100086 | ||
| 73 | 100087 | ||
| 74 | 100088 | ||
| 75 | 100089 | ||
| 76 | 100090 | ||
| 77 | 100091 | ||
| 78 | 100092 | ||
| 79 | 100093 | ||
| 80 | 100095 | ||
| 81 | 100096 | ||
| 82 | 100097 | ||
| 83 | 100099 | ||
diff --git a/test/112_h48set/h48set_tests.c b/test/112_h48set/h48set_tests.c new file mode 100644 index 0000000..d9310a9 --- /dev/null +++ b/test/112_h48set/h48set_tests.c | |||
| @@ -0,0 +1,64 @@ | |||
| 1 | #include "../test.h" | ||
| 2 | |||
| 3 | char str[STRLENMAX]; | ||
| 4 | |||
| 5 | typedef struct { | ||
| 6 | int64_t n; | ||
| 7 | int64_t capacity; | ||
| 8 | int64_t mod; | ||
| 9 | int64_t *table; | ||
| 10 | } h48set_t; | ||
| 11 | |||
| 12 | void h48set_create(h48set_t *, int64_t, int64_t); | ||
| 13 | void h48set_clear(h48set_t *); | ||
| 14 | void h48set_destroy(h48set_t *); | ||
| 15 | int64_t h48set_lookup(h48set_t *, int64_t); | ||
| 16 | void h48set_insert(h48set_t *, int64_t); | ||
| 17 | bool h48set_contains(h48set_t *, int64_t); | ||
| 18 | int64_t h48set_save(h48set_t *, int64_t *); | ||
| 19 | |||
| 20 | int 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 | |||
| 29 | int64_t readl(void) { | ||
| 30 | fgets(str, STRLENMAX, stdin); | ||
| 31 | return atoll(str); | ||
| 32 | } | ||
| 33 | |||
| 34 | void 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 | } | ||
