diff options
author | EuAndreh <eu@euandre.org> | 2024-05-31 15:52:54 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-05-31 15:54:02 -0300 |
commit | 15cdd6447ddb70e6c1e1ffda66d6130f5fcffdad (patch) | |
tree | 05a8b132e35ba6e2ac9edc15bb6a9b4ce75d5449 /tests | |
parent | Add initial private functions for src/set.c and src/tree.c (diff) | |
download | pindaiba-15cdd6447ddb70e6c1e1ffda66d6130f5fcffdad.tar.gz pindaiba-15cdd6447ddb70e6c1e1ffda66d6130f5fcffdad.tar.xz |
tests/tree.c: Add first test for tree_contains()
Diffstat (limited to 'tests')
-rw-r--r-- | tests/tree.c | 27 | ||||
-rw-r--r-- | tests/vector.c | 1 |
2 files changed, 27 insertions, 1 deletions
diff --git a/tests/tree.c b/tests/tree.c index b848f48..e2b2e0c 100644 --- a/tests/tree.c +++ b/tests/tree.c @@ -3,6 +3,7 @@ #include "../src/testing.h" + static int test_tree_new(void) { int rc = -1; @@ -28,6 +29,9 @@ test_tree_new(void) { rc = 0; out: + if (t != NULL) { + tree_free(&t); + } return rc; } @@ -39,7 +43,7 @@ test_tree_free(void) { test_start("tree_free()"); { - testing("simple free"); + testing("*t becomes NULL again after tree_free(&t)"); assert(t == NULL); @@ -50,6 +54,7 @@ test_tree_free(void) { assert(t != NULL); tree_free(&t); + assert(t == NULL); test_ok(); } @@ -62,6 +67,24 @@ out: return rc; } +static void +test_tree_contains(void) { + + const int y0 = 7; + const int n0 = 1; + + const struct Tree root = { + .value = &y0, + .value_size = sizeof(int), + .left = NULL, + .right = NULL, + .height = 3U, + }; + + assert(tree_contains(&root, &y0)); + + assert(!tree_contains(&root, &n0)); +} int main(void) { @@ -77,6 +100,8 @@ main(void) { goto out; } + test_tree_contains(); + rc = 0; out: return !!rc; diff --git a/tests/vector.c b/tests/vector.c index 72d796e..3a13cda 100644 --- a/tests/vector.c +++ b/tests/vector.c @@ -152,6 +152,7 @@ test_vector_free(void) { assert(v != NULL); vector_free(&v); + assert(v == NULL); test_ok(); } |