summaryrefslogtreecommitdiffstats
path: root/tests/trie.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/trie.c')
-rw-r--r--tests/trie.c56
1 files changed, 27 insertions, 29 deletions
diff --git a/tests/trie.c b/tests/trie.c
index ced14d4..e687f96 100644
--- a/tests/trie.c
+++ b/tests/trie.c
@@ -1,11 +1,9 @@
// Copyright © Tavian Barnes <tavianator@tavianator.com>
// SPDX-License-Identifier: 0BSD
-#undef NDEBUG
-
#include "../src/trie.h"
#include "../src/config.h"
-#include <assert.h>
+#include "../src/diag.h"
#include <stdlib.h>
#include <string.h>
@@ -45,7 +43,7 @@ int main(void) {
trie_init(&trie);
for (size_t i = 0; i < nkeys; ++i) {
- assert(!trie_find_str(&trie, keys[i]));
+ bfs_verify(!trie_find_str(&trie, keys[i]));
const char *prefix = NULL;
for (size_t j = 0; j < i; ++j) {
@@ -58,38 +56,38 @@ int main(void) {
struct trie_leaf *leaf = trie_find_prefix(&trie, keys[i]);
if (prefix) {
- assert(leaf);
- assert(strcmp(prefix, leaf->key) == 0);
+ bfs_verify(leaf);
+ bfs_verify(strcmp(prefix, leaf->key) == 0);
} else {
- assert(!leaf);
+ bfs_verify(!leaf);
}
leaf = trie_insert_str(&trie, keys[i]);
- assert(leaf);
- assert(strcmp(keys[i], leaf->key) == 0);
- assert(leaf->length == strlen(keys[i]) + 1);
+ bfs_verify(leaf);
+ bfs_verify(strcmp(keys[i], leaf->key) == 0);
+ bfs_verify(leaf->length == strlen(keys[i]) + 1);
}
{
size_t i = 0;
TRIE_FOR_EACH(&trie, leaf) {
- assert(leaf == trie_find_str(&trie, keys[i]));
- assert(!leaf->prev || leaf->prev->next == leaf);
- assert(!leaf->next || leaf->next->prev == leaf);
+ bfs_verify(leaf == trie_find_str(&trie, keys[i]));
+ bfs_verify(!leaf->prev || leaf->prev->next == leaf);
+ bfs_verify(!leaf->next || leaf->next->prev == leaf);
++i;
}
- assert(i == nkeys);
+ bfs_verify(i == nkeys);
}
for (size_t i = 0; i < nkeys; ++i) {
struct trie_leaf *leaf = trie_find_str(&trie, keys[i]);
- assert(leaf);
- assert(strcmp(keys[i], leaf->key) == 0);
- assert(leaf->length == strlen(keys[i]) + 1);
+ bfs_verify(leaf);
+ bfs_verify(strcmp(keys[i], leaf->key) == 0);
+ bfs_verify(leaf->length == strlen(keys[i]) + 1);
trie_remove(&trie, leaf);
leaf = trie_find_str(&trie, keys[i]);
- assert(!leaf);
+ bfs_verify(!leaf);
const char *postfix = NULL;
for (size_t j = i + 1; j < nkeys; ++j) {
@@ -102,33 +100,33 @@ int main(void) {
leaf = trie_find_postfix(&trie, keys[i]);
if (postfix) {
- assert(leaf);
- assert(strcmp(postfix, leaf->key) == 0);
+ bfs_verify(leaf);
+ bfs_verify(strcmp(postfix, leaf->key) == 0);
} else {
- assert(!leaf);
+ bfs_verify(!leaf);
}
}
TRIE_FOR_EACH(&trie, leaf) {
- assert(false);
+ bfs_verify(false);
}
// This tests the "jump" node handling on 32-bit platforms
size_t longsize = 1 << 20;
char *longstr = malloc(longsize);
- assert(longstr);
+ bfs_verify(longstr);
memset(longstr, 0xAC, longsize);
- assert(!trie_find_mem(&trie, longstr, longsize));
- assert(trie_insert_mem(&trie, longstr, longsize));
+ bfs_verify(!trie_find_mem(&trie, longstr, longsize));
+ bfs_verify(trie_insert_mem(&trie, longstr, longsize));
memset(longstr + longsize/2, 0xAB, longsize/2);
- assert(!trie_find_mem(&trie, longstr, longsize));
- assert(trie_insert_mem(&trie, longstr, longsize));
+ bfs_verify(!trie_find_mem(&trie, longstr, longsize));
+ bfs_verify(trie_insert_mem(&trie, longstr, longsize));
memset(longstr, 0xAA, longsize/2);
- assert(!trie_find_mem(&trie, longstr, longsize));
- assert(trie_insert_mem(&trie, longstr, longsize));
+ bfs_verify(!trie_find_mem(&trie, longstr, longsize));
+ bfs_verify(trie_insert_mem(&trie, longstr, longsize));
free(longstr);
trie_destroy(&trie);