summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-10-27 21:57:02 +0200
committerKimplul <kimi.h.kuparinen@gmail.com>2024-10-27 21:57:02 +0200
commit1f57645d9550e486a5bc209a0652bfad7fb8872a (patch)
tree2ff0fca8539c0fe147b463dca9e4d0e308336b95 /tests
parent5940254d9363ed8de9ba79a65cb074ec5aa4e69f (diff)
downloadconts-1f57645d9550e486a5bc209a0652bfad7fb8872a.tar.gz
conts-1f57645d9550e486a5bc209a0652bfad7fb8872a.zip
add map
Diffstat (limited to 'tests')
-rw-r--r--tests/map.c33
-rw-r--r--tests/sptree.c37
-rw-r--r--tests/vec.c13
3 files changed, 83 insertions, 0 deletions
diff --git a/tests/map.c b/tests/map.c
new file mode 100644
index 0000000..e9362ab
--- /dev/null
+++ b/tests/map.c
@@ -0,0 +1,33 @@
+#include <assert.h>
+#include <stdio.h>
+
+#define MAP_KEY int
+#define MAP_TYPE int
+#define MAP_CMP(a, b) ((a) - (b))
+#define MAP_NAME ints
+#include <conts/map.h>
+
+int main()
+{
+ struct ints ints = ints_create();
+ for (int i = 0; i < 1000000; ++i) {
+ ints_insert(&ints, i, i);
+ }
+ assert(ints_len(&ints) == 1000000);
+
+ for (int i = 0; i < 1000000; ++i) {
+ int *v = ints_find(&ints, i);
+ assert(v && *v == i);
+ }
+
+ foreach(ints, iter, &ints) {
+ assert(iter->key == iter->data);
+ }
+
+ for (int i = 0; i < 1000000; ++i) {
+ ints_remove(&ints, i);
+ }
+
+ assert(ints_len(&ints) == 0);
+ ints_destroy(&ints);
+}
diff --git a/tests/sptree.c b/tests/sptree.c
new file mode 100644
index 0000000..b8d1e5a
--- /dev/null
+++ b/tests/sptree.c
@@ -0,0 +1,37 @@
+#include <assert.h>
+#include <stdio.h>
+
+#define SPTREE_TYPE int
+#define SPTREE_CMP(a, b) ((b) - (a))
+#define SPTREE_NAME ints
+#include <conts/sptree.h>
+
+int main()
+{
+ struct ints ints = ints_create();
+ for (int i = 0; i < 1000000; ++i) {
+ ints_insert(&ints, i);
+ }
+ assert(ints_len(&ints) == 1000000);
+
+ for (int i = 0; i < 1000000; ++i) {
+ int *v = ints_find(&ints, i);
+ assert(v && *v == i);
+ }
+
+ int i = 0;
+ foreach(ints, iter, &ints) {
+ /* since my trees are ordered, this must hold, although you
+ * might consider it an implementation detail that shouldn't be
+ * relied on */
+ assert(iter && *iter == i);
+ i++;
+ }
+
+ for (int i = 0; i < 1000000; ++i) {
+ ints_remove(&ints, i);
+ }
+
+ assert(ints_len(&ints) == 0);
+ ints_destroy(&ints);
+}
diff --git a/tests/vec.c b/tests/vec.c
index 4bc06e7..a84096c 100644
--- a/tests/vec.c
+++ b/tests/vec.c
@@ -10,10 +10,23 @@ int main()
for (int i = 0; i < 1000000; ++i) {
ints_append(&ints, i);
}
+ assert(ints_len(&ints) == 1000000);
for (int i = 0; i < 1000000; ++i) {
int *v = ints_at(&ints, i);
assert(v && *v == i);
}
+
+ int i = 0;
+ foreach(ints, iter, &ints) {
+ assert(iter && *iter == i);
+ i++;
+ }
+
+ for (int i = 1000000 - 1; i >= 0; --i) {
+ ints_remove(&ints, i);
+ }
+ assert(ints_len(&ints) == 0);
+
ints_destroy(&ints);
}