summaryrefslogtreecommitdiffstats
path: root/tests/trie.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/trie.c')
-rw-r--r--tests/trie.c57
1 files changed, 28 insertions, 29 deletions
diff --git a/tests/trie.c b/tests/trie.c
index 4667322..9e9a294 100644
--- a/tests/trie.c
+++ b/tests/trie.c
@@ -1,14 +1,16 @@
// Copyright © Tavian Barnes <tavianator@tavianator.com>
// SPDX-License-Identifier: 0BSD
-#include "prelude.h"
#include "tests.h"
-#include "trie.h"
+
+#include "bfs.h"
#include "diag.h"
+#include "trie.h"
+
#include <stdlib.h>
#include <string.h>
-const char *keys[] = {
+static const char *keys[] = {
"foo",
"bar",
"baz",
@@ -37,16 +39,14 @@ const char *keys[] = {
">>>",
};
-const size_t nkeys = countof(keys);
-
-bool check_trie(void) {
- bool ret = true;
+static const size_t nkeys = countof(keys);
+void check_trie(void) {
struct trie trie;
trie_init(&trie);
for (size_t i = 0; i < nkeys; ++i) {
- ret &= bfs_check(!trie_find_str(&trie, keys[i]));
+ bfs_check(!trie_find_str(&trie, keys[i]));
const char *prefix = NULL;
for (size_t j = 0; j < i; ++j) {
@@ -60,37 +60,37 @@ bool check_trie(void) {
struct trie_leaf *leaf = trie_find_prefix(&trie, keys[i]);
if (prefix) {
bfs_verify(leaf);
- ret &= bfs_check(strcmp(prefix, leaf->key) == 0);
+ bfs_check(strcmp(prefix, leaf->key) == 0);
} else {
- ret &= bfs_check(!leaf);
+ bfs_check(!leaf);
}
leaf = trie_insert_str(&trie, keys[i]);
bfs_verify(leaf);
- ret &= bfs_check(strcmp(keys[i], leaf->key) == 0);
- ret &= bfs_check(leaf->length == strlen(keys[i]) + 1);
+ bfs_check(strcmp(keys[i], leaf->key) == 0);
+ bfs_check(leaf->length == strlen(keys[i]) + 1);
}
{
size_t i = 0;
for_trie (leaf, &trie) {
- 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);
+ bfs_check(leaf == trie_find_str(&trie, keys[i]));
+ bfs_check(!leaf->prev || leaf->prev->next == leaf);
+ bfs_check(!leaf->next || leaf->next->prev == leaf);
++i;
}
- ret &= bfs_check(i == nkeys);
+ 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);
- ret &= bfs_check(strcmp(keys[i], leaf->key) == 0);
- ret &= bfs_check(leaf->length == strlen(keys[i]) + 1);
+ bfs_check(strcmp(keys[i], leaf->key) == 0);
+ bfs_check(leaf->length == strlen(keys[i]) + 1);
trie_remove(&trie, leaf);
leaf = trie_find_str(&trie, keys[i]);
- ret &= bfs_check(!leaf);
+ bfs_check(!leaf);
const char *postfix = NULL;
for (size_t j = i + 1; j < nkeys; ++j) {
@@ -104,14 +104,14 @@ bool check_trie(void) {
leaf = trie_find_postfix(&trie, keys[i]);
if (postfix) {
bfs_verify(leaf);
- ret &= bfs_check(strcmp(postfix, leaf->key) == 0);
+ bfs_check(strcmp(postfix, leaf->key) == 0);
} else {
- ret &= bfs_check(!leaf);
+ bfs_check(!leaf);
}
}
for_trie (leaf, &trie) {
- ret &= bfs_check(false, "trie should be empty");
+ bfs_check(false, "trie should be empty");
}
// This tests the "jump" node handling on 32-bit platforms
@@ -120,18 +120,17 @@ bool check_trie(void) {
bfs_verify(longstr);
memset(longstr, 0xAC, longsize);
- ret &= bfs_check(!trie_find_mem(&trie, longstr, longsize));
- ret &= bfs_check(trie_insert_mem(&trie, longstr, longsize));
+ bfs_check(!trie_find_mem(&trie, longstr, longsize));
+ bfs_check(trie_insert_mem(&trie, longstr, longsize));
memset(longstr + longsize / 2, 0xAB, longsize / 2);
- ret &= bfs_check(!trie_find_mem(&trie, longstr, longsize));
- ret &= bfs_check(trie_insert_mem(&trie, longstr, longsize));
+ bfs_check(!trie_find_mem(&trie, longstr, longsize));
+ bfs_check(trie_insert_mem(&trie, longstr, longsize));
memset(longstr, 0xAA, longsize / 2);
- ret &= bfs_check(!trie_find_mem(&trie, longstr, longsize));
- ret &= bfs_check(trie_insert_mem(&trie, longstr, longsize));
+ bfs_check(!trie_find_mem(&trie, longstr, longsize));
+ bfs_check(trie_insert_mem(&trie, longstr, longsize));
free(longstr);
trie_destroy(&trie);
- return ret;
}