From 6e1ceafcc28d8345858e80cce0091df2c673c560 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Thu, 28 Jul 2022 23:22:07 +0200 Subject: [PATCH] Add more tests for tree. --- tests/test-mtree.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/test-mtree.c b/tests/test-mtree.c index f90935e1..bbdb2db6 100644 --- a/tests/test-mtree.c +++ b/tests/test-mtree.c @@ -284,6 +284,18 @@ static void test_basic(void) tree_get_str(s, t, false); assert(string_equal_str_p(s, "[{0,[{-1,[{3}]},{2,[{1,[{5}]}]}]}]")); + tree_sort_child(it0); + tree_get_str(s, t, false); + assert(string_equal_str_p(s, "[{0,[{-1,[{3}]},{2,[{1,[{5}]}]}]}]")); + + tree_swap_at(root, it2, true); + tree_sort_child(it0); + tree_get_str(s, t, false); + assert(string_equal_str_p(s, "[{0,[{-1,[{3}]},{2,[{1,[{5}]}]}]}]")); + + tree_it_set(&it, root); + assert(tree_it_equal_p(it, root)); + size_t hash = tree_hash(t); assert(hash != 0); @@ -368,9 +380,12 @@ static void test_gen(void) if (!tree_it_equal_p(g_tree[ref], g_root)) { // We only do it if the ref node is not root (too many corner cases to undo) insert(cmd, ref); + assert(!tree_equal_p(t, t0)); tree_remove( g_tree[g_num]); g_num--; assert(tree_equal_p(t, t0)); + tree_swap(t, t0); + assert(tree_equal_p(t, t0)); } } string_clear(s);