summaryrefslogtreecommitdiff
path: root/tests/sptree.c
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2025-08-22 16:12:08 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2025-08-22 16:12:08 +0300
commit13d33be824a0f6a3952045df7b97b35fc69520a8 (patch)
treef2f36de33eeb0e9d366ea49bd722993ba57950b1 /tests/sptree.c
parentb0d619e2c9595f4ec05463e87be9d0d3423c0a70 (diff)
downloadconts-13d33be824a0f6a3952045df7b97b35fc69520a8.tar.gz
conts-13d33be824a0f6a3952045df7b97b35fc69520a8.zip
cover all functionsHEADmaster
+ Not quite all lines due to sptree being dumb >:(((((
Diffstat (limited to 'tests/sptree.c')
-rw-r--r--tests/sptree.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/sptree.c b/tests/sptree.c
index 6ab3d6a..9eff356 100644
--- a/tests/sptree.c
+++ b/tests/sptree.c
@@ -1,4 +1,5 @@
#include <assert.h>
+#include <stdlib.h>
#include <stdio.h>
#include "test.h"
@@ -23,6 +24,11 @@ int main()
#endif
struct ints ints = ints_create();
+ /* check that iterating an empty tree doesn't do anything */
+ foreach(ints, iter, &ints) {
+ assert(false && "iterating empty tree");
+ }
+
for (int i = 0; i < 1000000; ++i) {
if (!ints_insert(&ints, i)) {
fprintf(stderr, "failed inserting %d\n", i);
@@ -37,6 +43,11 @@ int main()
assert(v && *v == i);
}
+ /* check that inserting duplicate returns the original */
+ int *orig = ints_find(&ints, 0);
+ ints_insert(&ints, 0);
+ assert(ints_find(&ints, 0) == orig);
+
int i = 0;
foreach(ints, iter, &ints) {
/* since my trees are ordered, this must hold, although you
@@ -51,5 +62,32 @@ int main()
}
assert(ints_len(&ints) == 0);
+
+ /* check that removing nonexistant item (or empty tree) doesn't crash */
+ ints_remove(&ints, 0);
+
+ /* insert random integers to hopefully exercise the code a bit more */
+ srand(0);
+
+ int inserted[1000];
+ for (int i = 0; i < 1000; ++i) {
+ inserted[i] = rand();
+
+ /* covsrv shouldn't fail anymore */
+ assert(ints_insert(&ints, inserted[i]));
+ }
+
+ for (int i = 0; i < 1000; ++i) {
+ int *v = ints_find(&ints, inserted[i]);
+ assert(v && *v == inserted[i]);
+ }
+
+ for (int i = 0; i < 1000; ++i) {
+ ints_remove(&ints, inserted[i]);
+ }
+
+ assert(ints_len(&ints) == 0);
+
+
ints_destroy(&ints);
}