summaryrefslogtreecommitdiffstats
path: root/tests/trie.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/trie.c')
-rw-r--r--tests/trie.c46
1 files changed, 24 insertions, 22 deletions
diff --git a/tests/trie.c b/tests/trie.c
index f94d7c8..fec0de2 100644
--- a/tests/trie.c
+++ b/tests/trie.c
@@ -40,11 +40,13 @@ const char *keys[] = {
const size_t nkeys = countof(keys);
bool check_trie(void) {
+ bool ret = true;
+
struct trie trie;
trie_init(&trie);
for (size_t i = 0; i < nkeys; ++i) {
- bfs_verify(!trie_find_str(&trie, keys[i]));
+ ret &= bfs_check(!trie_find_str(&trie, keys[i]));
const char *prefix = NULL;
for (size_t j = 0; j < i; ++j) {
@@ -58,37 +60,37 @@ bool check_trie(void) {
struct trie_leaf *leaf = trie_find_prefix(&trie, keys[i]);
if (prefix) {
bfs_verify(leaf);
- bfs_verify(strcmp(prefix, leaf->key) == 0);
+ ret &= bfs_check(strcmp(prefix, leaf->key) == 0);
} else {
- bfs_verify(!leaf);
+ ret &= bfs_check(!leaf);
}
leaf = trie_insert_str(&trie, keys[i]);
bfs_verify(leaf);
- bfs_verify(strcmp(keys[i], leaf->key) == 0);
- bfs_verify(leaf->length == strlen(keys[i]) + 1);
+ ret &= bfs_check(strcmp(keys[i], leaf->key) == 0);
+ ret &= bfs_check(leaf->length == strlen(keys[i]) + 1);
}
{
size_t i = 0;
for_trie (leaf, &trie) {
- 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);
+ ret &= bfs_check(leaf == trie_find_str(&trie, keys[i]));
+ ret &= bfs_check(!leaf->prev || leaf->prev->next == leaf);
+ ret &= bfs_check(!leaf->next || leaf->next->prev == leaf);
++i;
}
- bfs_verify(i == nkeys);
+ ret &= bfs_check(i == nkeys);
}
for (size_t i = 0; i < nkeys; ++i) {
struct trie_leaf *leaf = trie_find_str(&trie, keys[i]);
bfs_verify(leaf);
- bfs_verify(strcmp(keys[i], leaf->key) == 0);
- bfs_verify(leaf->length == strlen(keys[i]) + 1);
+ ret &= bfs_check(strcmp(keys[i], leaf->key) == 0);
+ ret &= bfs_check(leaf->length == strlen(keys[i]) + 1);
trie_remove(&trie, leaf);
leaf = trie_find_str(&trie, keys[i]);
- bfs_verify(!leaf);
+ ret &= bfs_check(!leaf);
const char *postfix = NULL;
for (size_t j = i + 1; j < nkeys; ++j) {
@@ -102,14 +104,14 @@ bool check_trie(void) {
leaf = trie_find_postfix(&trie, keys[i]);
if (postfix) {
bfs_verify(leaf);
- bfs_verify(strcmp(postfix, leaf->key) == 0);
+ ret &= bfs_check(strcmp(postfix, leaf->key) == 0);
} else {
- bfs_verify(!leaf);
+ ret &= bfs_check(!leaf);
}
}
for_trie (leaf, &trie) {
- bfs_verify(false);
+ ret &= bfs_check(false, "trie should be empty");
}
// This tests the "jump" node handling on 32-bit platforms
@@ -118,18 +120,18 @@ bool check_trie(void) {
bfs_verify(longstr);
memset(longstr, 0xAC, longsize);
- bfs_verify(!trie_find_mem(&trie, longstr, longsize));
- bfs_verify(trie_insert_mem(&trie, longstr, longsize));
+ ret &= bfs_check(!trie_find_mem(&trie, longstr, longsize));
+ ret &= bfs_check(trie_insert_mem(&trie, longstr, longsize));
memset(longstr + longsize / 2, 0xAB, longsize / 2);
- bfs_verify(!trie_find_mem(&trie, longstr, longsize));
- bfs_verify(trie_insert_mem(&trie, longstr, longsize));
+ ret &= bfs_check(!trie_find_mem(&trie, longstr, longsize));
+ ret &= bfs_check(trie_insert_mem(&trie, longstr, longsize));
memset(longstr, 0xAA, longsize / 2);
- bfs_verify(!trie_find_mem(&trie, longstr, longsize));
- bfs_verify(trie_insert_mem(&trie, longstr, longsize));
+ ret &= bfs_check(!trie_find_mem(&trie, longstr, longsize));
+ ret &= bfs_check(trie_insert_mem(&trie, longstr, longsize));
free(longstr);
trie_destroy(&trie);
- return true;
+ return ret;
}